diff options
| author | jsing <> | 2015-02-11 07:01:10 +0000 | 
|---|---|---|
| committer | jsing <> | 2015-02-11 07:01:10 +0000 | 
| commit | d641e8f3aa538ca2210627d0cd491ad424b56353 (patch) | |
| tree | c6f7f9e067233df00a99495d7e346482bb70b61e /src | |
| parent | 18dcc969364b2ee37a91a47c36b37a6fb023fb98 (diff) | |
| download | openbsd-d641e8f3aa538ca2210627d0cd491ad424b56353.tar.gz openbsd-d641e8f3aa538ca2210627d0cd491ad424b56353.tar.bz2 openbsd-d641e8f3aa538ca2210627d0cd491ad424b56353.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 '')
| -rw-r--r-- | src/lib/libtls/Makefile | 4 | ||||
| -rw-r--r-- | src/lib/libtls/tls.h | 4 | ||||
| -rw-r--r-- | src/lib/libtls/tls_client.c | 15 | ||||
| -rw-r--r-- | src/lib/libtls/tls_init.3 | 10 | 
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 | ||
| 3 | CFLAGS+= -Wall -Werror -Wimplicit | 3 | CFLAGS+= -Wall -Werror -Wimplicit | 
| 4 | CFLAGS+= -DLIBRESSL_INTERNAL | 4 | CFLAGS+= -DLIBRESSL_INTERNAL | 
| @@ -45,6 +45,8 @@ MLINKS+=tls_init.3 tls_reset.3 | |||
| 45 | MLINKS+=tls_init.3 tls_free.3 | 45 | MLINKS+=tls_init.3 tls_free.3 | 
| 46 | MLINKS+=tls_init.3 tls_close.3 | 46 | MLINKS+=tls_init.3 tls_close.3 | 
| 47 | MLINKS+=tls_init.3 tls_connect.3 | 47 | MLINKS+=tls_init.3 tls_connect.3 | 
| 48 | MLINKS+=tls_init.3 tls_connect_fds.3 | ||
| 49 | MLINKS+=tls_init.3 tls_connect_servername.3 | ||
| 48 | MLINKS+=tls_init.3 tls_connect_socket.3 | 50 | MLINKS+=tls_init.3 tls_connect_socket.3 | 
| 49 | MLINKS+=tls_init.3 tls_accept_socket.3 | 51 | MLINKS+=tls_init.3 tls_accept_socket.3 | 
| 50 | MLINKS+=tls_init.3 tls_read.3 | 52 | MLINKS+=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); | |||
| 71 | int tls_connect(struct tls *ctx, const char *host, const char *port); | 71 | int tls_connect(struct tls *ctx, const char *host, const char *port); | 
| 72 | int tls_connect_fds(struct tls *ctx, int fd_read, int fd_write, | 72 | int tls_connect_fds(struct tls *ctx, int fd_read, int fd_write, | 
| 73 | const char *servername); | 73 | const char *servername); | 
| 74 | int tls_connect_servername(struct tls *ctx, const char *host, const char *port, | ||
| 75 | const char *servername); | ||
| 74 | int tls_connect_socket(struct tls *ctx, int s, const char *servername); | 76 | int tls_connect_socket(struct tls *ctx, int s, const char *servername); | 
| 75 | int tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen); | 77 | int tls_read(struct tls *ctx, void *buf, size_t buflen, size_t *outlen); | 
| 76 | int tls_write(struct tls *ctx, const void *buf, size_t buflen, size_t *outlen); | 78 | int 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, | |||
| 83 | int | 83 | int | 
| 84 | tls_connect(struct tls *ctx, const char *host, const char *port) | 84 | tls_connect(struct tls *ctx, const char *host, const char *port) | 
| 85 | { | 85 | { | 
| 86 | return tls_connect_servername(ctx, host, port, NULL); | ||
| 87 | } | ||
| 88 | |||
| 89 | int | ||
| 90 | tls_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 | ||
| 138 | err: | 148 | err: | 
| 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 . | 
| 160 | This function will create a new socket, connect to the specified host and | 162 | This function will create a new socket, connect to the specified host and | 
| 161 | port, and then establish a secure connection. | 163 | port, and then establish a secure connection. | 
| 164 | The | ||
| 165 | .Fn tls_connect_servername | ||
| 166 | function has the same behaviour, however the name to use for verification is | ||
| 167 | explicitly provided, rather than being inferred from the | ||
| 168 | .Ar host | ||
| 169 | value. | ||
| 162 | An already existing socket can be upgraded to a secure connection by calling | 170 | An already existing socket can be upgraded to a secure connection by calling | 
| 163 | .Fn tls_connect_socket . | 171 | .Fn tls_connect_socket . | 
| 164 | Alternatively, a secure connection can be established over a pair of existing | 172 | Alternatively, a secure connection can be established over a pair of existing | 
