summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2015-02-11 07:01:10 +0000
committerjsing <>2015-02-11 07:01:10 +0000
commit53b67cf53ae755b09e315a3bd30e87b66c4ea769 (patch)
treec6f7f9e067233df00a99495d7e346482bb70b61e /src
parentc6f3fe1fbc8da2fa6de30b10f1f219ab1f809438 (diff)
downloadopenbsd-53b67cf53ae755b09e315a3bd30e87b66c4ea769.tar.gz
openbsd-53b67cf53ae755b09e315a3bd30e87b66c4ea769.tar.bz2
openbsd-53b67cf53ae755b09e315a3bd30e87b66c4ea769.zip
Provide a tls_connect_servername() function that has the same behaviour
as tls_connect(), however allows the name to use for verification to be explicitly provided, rather than being inferred from the host value. Requested by reyk@ ok reyk@ tedu@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libtls/Makefile4
-rw-r--r--src/lib/libtls/tls.h4
-rw-r--r--src/lib/libtls/tls_client.c15
-rw-r--r--src/lib/libtls/tls_init.310
4 files changed, 27 insertions, 6 deletions
diff --git a/src/lib/libtls/Makefile b/src/lib/libtls/Makefile
index 4ae970d093..61368bccfd 100644
--- a/src/lib/libtls/Makefile
+++ b/src/lib/libtls/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.4 2015/02/07 23:45:06 reyk Exp $ 1# $OpenBSD: Makefile,v 1.5 2015/02/11 07:01:10 jsing Exp $
2 2
3CFLAGS+= -Wall -Werror -Wimplicit 3CFLAGS+= -Wall -Werror -Wimplicit
4CFLAGS+= -DLIBRESSL_INTERNAL 4CFLAGS+= -DLIBRESSL_INTERNAL
@@ -45,6 +45,8 @@ MLINKS+=tls_init.3 tls_reset.3
45MLINKS+=tls_init.3 tls_free.3 45MLINKS+=tls_init.3 tls_free.3
46MLINKS+=tls_init.3 tls_close.3 46MLINKS+=tls_init.3 tls_close.3
47MLINKS+=tls_init.3 tls_connect.3 47MLINKS+=tls_init.3 tls_connect.3
48MLINKS+=tls_init.3 tls_connect_fds.3
49MLINKS+=tls_init.3 tls_connect_servername.3
48MLINKS+=tls_init.3 tls_connect_socket.3 50MLINKS+=tls_init.3 tls_connect_socket.3
49MLINKS+=tls_init.3 tls_accept_socket.3 51MLINKS+=tls_init.3 tls_accept_socket.3
50MLINKS+=tls_init.3 tls_read.3 52MLINKS+=tls_init.3 tls_read.3
diff --git a/src/lib/libtls/tls.h b/src/lib/libtls/tls.h
index c266832c80..0a6f8d7258 100644
--- a/src/lib/libtls/tls.h
+++ b/src/lib/libtls/tls.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls.h,v 1.6 2015/02/11 06:46:33 jsing Exp $ */ 1/* $OpenBSD: tls.h,v 1.7 2015/02/11 07:01:10 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -71,6 +71,8 @@ int tls_accept_socket(struct tls *ctx, struct tls **cctx, int socket);
71int tls_connect(struct tls *ctx, const char *host, const char *port); 71int tls_connect(struct tls *ctx, const char *host, const char *port);
72int tls_connect_fds(struct tls *ctx, int fd_read, int fd_write, 72int tls_connect_fds(struct tls *ctx, int fd_read, int fd_write,
73 const char *servername); 73 const char *servername);
74int tls_connect_servername(struct tls *ctx, const char *host, const char *port,
75 const char *servername);
74int tls_connect_socket(struct tls *ctx, int s, const char *servername); 76int tls_connect_socket(struct tls *ctx, int s, const char *servername);
75int tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen); 77int tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen);
76int tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen); 78int tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen);
diff --git a/src/lib/libtls/tls_client.c b/src/lib/libtls/tls_client.c
index baa4805f57..682153ca65 100644
--- a/src/lib/libtls/tls_client.c
+++ b/src/lib/libtls/tls_client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_client.c,v 1.14 2015/02/11 06:46:33 jsing Exp $ */ 1/* $OpenBSD: tls_client.c,v 1.15 2015/02/11 07:01:10 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -83,6 +83,13 @@ tls_connect_host(struct tls *ctx, const char *host, const char *port,
83int 83int
84tls_connect(struct tls *ctx, const char *host, const char *port) 84tls_connect(struct tls *ctx, const char *host, const char *port)
85{ 85{
86 return tls_connect_servername(ctx, host, port, NULL);
87}
88
89int
90tls_connect_servername(struct tls *ctx, const char *host, const char *port,
91 const char *servername)
92{
86 const char *h = NULL, *p = NULL; 93 const char *h = NULL, *p = NULL;
87 char *hs = NULL, *ps = NULL; 94 char *hs = NULL, *ps = NULL;
88 int rv = -1, s = -1, ret; 95 int rv = -1, s = -1, ret;
@@ -128,7 +135,10 @@ tls_connect(struct tls *ctx, const char *host, const char *port)
128 (s = tls_connect_host(ctx, h, p, AF_UNSPEC, AI_ADDRCONFIG)) == -1) 135 (s = tls_connect_host(ctx, h, p, AF_UNSPEC, AI_ADDRCONFIG)) == -1)
129 goto err; 136 goto err;
130 137
131 if (tls_connect_socket(ctx, s, h) != 0) { 138 if (servername == NULL)
139 servername = h;
140
141 if (tls_connect_socket(ctx, s, servername) != 0) {
132 close(s); 142 close(s);
133 goto err; 143 goto err;
134 } 144 }
@@ -136,7 +146,6 @@ tls_connect(struct tls *ctx, const char *host, const char *port)
136 rv = 0; 146 rv = 0;
137 147
138err: 148err:
139
140 free(hs); 149 free(hs);
141 free(ps); 150 free(ps);
142 151
diff --git a/src/lib/libtls/tls_init.3 b/src/lib/libtls/tls_init.3
index 034c125347..c1e59383c4 100644
--- a/src/lib/libtls/tls_init.3
+++ b/src/lib/libtls/tls_init.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: tls_init.3,v 1.11 2015/02/11 06:46:33 jsing Exp $ 1.\" $OpenBSD: tls_init.3,v 1.12 2015/02/11 07:01:10 jsing Exp $
2.\" 2.\"
3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4.\" 4.\"
@@ -47,6 +47,7 @@
47.Nm tls_free , 47.Nm tls_free ,
48.Nm tls_connect , 48.Nm tls_connect ,
49.Nm tls_connect_fds , 49.Nm tls_connect_fds ,
50.Nm tls_connect_servername ,
50.Nm tls_connect_socket , 51.Nm tls_connect_socket ,
51.Nm tls_accept_socket , 52.Nm tls_accept_socket ,
52.Nm tls_read , 53.Nm tls_read ,
@@ -112,6 +113,7 @@
112.Fn tls_connect "struct tls *ctx" "const char *host" "const char *port" 113.Fn tls_connect "struct tls *ctx" "const char *host" "const char *port"
113.Ft "int" 114.Ft "int"
114.Fn tls_connect_fds "struct tls *ctx" "int fd_read" "int fd_write" "const char *servername" 115.Fn tls_connect_fds "struct tls *ctx" "int fd_read" "int fd_write" "const char *servername"
116.Fn tls_connect_servername "struct tls *ctx" "const char *host" "const char *port" "const char *servername"
115.Ft "int" 117.Ft "int"
116.Fn tls_connect_socket "struct tls *ctx" "int s" "const char *servername" 118.Fn tls_connect_socket "struct tls *ctx" "int s" "const char *servername"
117.Ft "int" 119.Ft "int"
@@ -159,6 +161,12 @@ A client connection is initiated after configuration by calling
159.Fn tls_connect . 161.Fn tls_connect .
160This function will create a new socket, connect to the specified host and 162This function will create a new socket, connect to the specified host and
161port, and then establish a secure connection. 163port, and then establish a secure connection.
164The
165.Fn tls_connect_servername
166function has the same behaviour, however the name to use for verification is
167explicitly provided, rather than being inferred from the
168.Ar host
169value.
162An already existing socket can be upgraded to a secure connection by calling 170An already existing socket can be upgraded to a secure connection by calling
163.Fn tls_connect_socket . 171.Fn tls_connect_socket .
164Alternatively, a secure connection can be established over a pair of existing 172Alternatively, a secure connection can be established over a pair of existing