summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2017-08-10 18:18:30 +0000
committerjsing <>2017-08-10 18:18:30 +0000
commitae58363a3ade3f9016687060c0c4efe3702141f8 (patch)
treeaa634cd28684f262545acd66044eaf7fc4201389 /src/lib
parentf6039d62295a1c6b1188b531731d233d196faf0d (diff)
downloadopenbsd-ae58363a3ade3f9016687060c0c4efe3702141f8.tar.gz
openbsd-ae58363a3ade3f9016687060c0c4efe3702141f8.tar.bz2
openbsd-ae58363a3ade3f9016687060c0c4efe3702141f8.zip
Add a tls_config_set_ecdhecurves() function to libtls, which allows the
names of the elliptic curves that may be used during client and server key exchange to be specified. This deprecates tls_config_set_ecdhecurve(), which could only be used to specify a single supported curve. ok beck@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libtls/Symbols.list1
-rw-r--r--src/lib/libtls/man/tls_config_set_protocols.319
-rw-r--r--src/lib/libtls/tls.h5
-rw-r--r--src/lib/libtls/tls_client.c10
-rw-r--r--src/lib/libtls/tls_config.c84
-rw-r--r--src/lib/libtls/tls_internal.h7
-rw-r--r--src/lib/libtls/tls_server.c16
7 files changed, 108 insertions, 34 deletions
diff --git a/src/lib/libtls/Symbols.list b/src/lib/libtls/Symbols.list
index 6d174bc83a..1e7538cfd4 100644
--- a/src/lib/libtls/Symbols.list
+++ b/src/lib/libtls/Symbols.list
@@ -30,6 +30,7 @@ tls_config_set_crl_file
30tls_config_set_crl_mem 30tls_config_set_crl_mem
31tls_config_set_dheparams 31tls_config_set_dheparams
32tls_config_set_ecdhecurve 32tls_config_set_ecdhecurve
33tls_config_set_ecdhecurves
33tls_config_set_key_file 34tls_config_set_key_file
34tls_config_set_key_mem 35tls_config_set_key_mem
35tls_config_set_keypair_file 36tls_config_set_keypair_file
diff --git a/src/lib/libtls/man/tls_config_set_protocols.3 b/src/lib/libtls/man/tls_config_set_protocols.3
index b2f31eabd5..e16abe44d5 100644
--- a/src/lib/libtls/man/tls_config_set_protocols.3
+++ b/src/lib/libtls/man/tls_config_set_protocols.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: tls_config_set_protocols.3,v 1.3 2017/01/28 00:59:36 schwarze Exp $ 1.\" $OpenBSD: tls_config_set_protocols.3,v 1.4 2017/08/10 18:18:30 jsing Exp $
2.\" 2.\"
3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3.\" Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4.\" Copyright (c) 2015, 2016 Joel Sing <jsing@openbsd.org> 4.\" Copyright (c) 2015, 2016 Joel Sing <jsing@openbsd.org>
@@ -16,7 +16,7 @@
16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18.\" 18.\"
19.Dd $Mdocdate: January 28 2017 $ 19.Dd $Mdocdate: August 10 2017 $
20.Dt TLS_CONFIG_SET_PROTOCOLS 3 20.Dt TLS_CONFIG_SET_PROTOCOLS 3
21.Os 21.Os
22.Sh NAME 22.Sh NAME
@@ -25,7 +25,7 @@
25.Nm tls_config_set_alpn , 25.Nm tls_config_set_alpn ,
26.Nm tls_config_set_ciphers , 26.Nm tls_config_set_ciphers ,
27.Nm tls_config_set_dheparams , 27.Nm tls_config_set_dheparams ,
28.Nm tls_config_set_ecdhecurve , 28.Nm tls_config_set_ecdhecurves ,
29.Nm tls_config_prefer_ciphers_client , 29.Nm tls_config_prefer_ciphers_client ,
30.Nm tls_config_prefer_ciphers_server 30.Nm tls_config_prefer_ciphers_server
31.Nd TLS protocol and cipher selection 31.Nd TLS protocol and cipher selection
@@ -57,9 +57,9 @@
57.Fa "const char *params" 57.Fa "const char *params"
58.Fc 58.Fc
59.Ft int 59.Ft int
60.Fo tls_config_set_ecdhecurve 60.Fo tls_config_set_ecdhecurves
61.Fa "struct tls_config *config" 61.Fa "struct tls_config *config"
62.Fa "const char *name" 62.Fa "const char *curves"
63.Fc 63.Fc
64.Ft void 64.Ft void
65.Fn tls_config_prefer_ciphers_client "struct tls_config *config" 65.Fn tls_config_prefer_ciphers_client "struct tls_config *config"
@@ -126,7 +126,14 @@ See the CIPHERS section of
126.Xr openssl 1 126.Xr openssl 1
127for further information. 127for further information.
128.\" XXX tls_config_set_dheparams does what? 128.\" XXX tls_config_set_dheparams does what?
129.\" XXX tls_config_set_ecdhecurve does what? 129.Pp
130.Fn tls_config_set_ecdhecurves
131specifies the names of the elliptic curves that may be used during key exchange.
132This is a comma separated list, given in order of preference.
133The special value of "default" will use the default curves (currently X25519,
134P-256 and P-384). This function replaces
135.Fn tls_config_set_ecdhecurve ,
136which is deprecated.
130.Pp 137.Pp
131.Fn tls_config_prefer_ciphers_client 138.Fn tls_config_prefer_ciphers_client
132prefers ciphers in the client's cipher list when selecting a cipher suite 139prefers ciphers in the client's cipher list when selecting a cipher suite
diff --git a/src/lib/libtls/tls.h b/src/lib/libtls/tls.h
index 1a6701b581..cc8627f2af 100644
--- a/src/lib/libtls/tls.h
+++ b/src/lib/libtls/tls.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls.h,v 1.50 2017/07/06 17:12:22 jsing Exp $ */ 1/* $OpenBSD: tls.h,v 1.51 2017/08/10 18:18:30 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -109,7 +109,8 @@ int tls_config_set_crl_file(struct tls_config *_config, const char *_crl_file);
109int tls_config_set_crl_mem(struct tls_config *_config, const uint8_t *_crl, 109int tls_config_set_crl_mem(struct tls_config *_config, const uint8_t *_crl,
110 size_t _len); 110 size_t _len);
111int tls_config_set_dheparams(struct tls_config *_config, const char *_params); 111int tls_config_set_dheparams(struct tls_config *_config, const char *_params);
112int tls_config_set_ecdhecurve(struct tls_config *_config, const char *_name); 112int tls_config_set_ecdhecurve(struct tls_config *_config, const char *_curve);
113int tls_config_set_ecdhecurves(struct tls_config *_config, const char *_curves);
113int tls_config_set_key_file(struct tls_config *_config, const char *_key_file); 114int tls_config_set_key_file(struct tls_config *_config, const char *_key_file);
114int tls_config_set_key_mem(struct tls_config *_config, const uint8_t *_key, 115int tls_config_set_key_mem(struct tls_config *_config, const uint8_t *_key,
115 size_t _len); 116 size_t _len);
diff --git a/src/lib/libtls/tls_client.c b/src/lib/libtls/tls_client.c
index b92490f25d..c79f462a3a 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.42 2017/05/07 03:27:06 jsing Exp $ */ 1/* $OpenBSD: tls_client.c,v 1.43 2017/08/10 18:18:30 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -198,6 +198,14 @@ tls_connect_common(struct tls *ctx, const char *servername)
198 if (tls_configure_ssl_verify(ctx, ctx->ssl_ctx, SSL_VERIFY_PEER) == -1) 198 if (tls_configure_ssl_verify(ctx, ctx->ssl_ctx, SSL_VERIFY_PEER) == -1)
199 goto err; 199 goto err;
200 200
201 if (ctx->config->ecdhecurves != NULL) {
202 if (SSL_CTX_set1_groups(ctx->ssl_ctx, ctx->config->ecdhecurves,
203 ctx->config->ecdhecurves_len) != 1) {
204 tls_set_errorx(ctx, "failed to set ecdhe curves");
205 goto err;
206 }
207 }
208
201 if (SSL_CTX_set_tlsext_status_cb(ctx->ssl_ctx, tls_ocsp_verify_cb) != 1) { 209 if (SSL_CTX_set_tlsext_status_cb(ctx->ssl_ctx, tls_ocsp_verify_cb) != 1) {
202 tls_set_errorx(ctx, "ssl OCSP verification setup failure"); 210 tls_set_errorx(ctx, "ssl OCSP verification setup failure");
203 goto err; 211 goto err;
diff --git a/src/lib/libtls/tls_config.c b/src/lib/libtls/tls_config.c
index 40374ea220..581c493a55 100644
--- a/src/lib/libtls/tls_config.c
+++ b/src/lib/libtls/tls_config.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_config.c,v 1.42 2017/08/09 21:27:24 claudio Exp $ */ 1/* $OpenBSD: tls_config.c,v 1.43 2017/08/10 18:18:30 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -214,7 +214,7 @@ tls_config_new(void)
214 */ 214 */
215 if (tls_config_set_dheparams(config, "none") != 0) 215 if (tls_config_set_dheparams(config, "none") != 0)
216 goto err; 216 goto err;
217 if (tls_config_set_ecdhecurve(config, "auto") != 0) 217 if (tls_config_set_ecdhecurves(config, "default") != 0)
218 goto err; 218 goto err;
219 if (tls_config_set_ciphers(config, "secure") != 0) 219 if (tls_config_set_ciphers(config, "secure") != 0)
220 goto err; 220 goto err;
@@ -269,6 +269,7 @@ tls_config_free(struct tls_config *config)
269 free((char *)config->ca_path); 269 free((char *)config->ca_path);
270 free((char *)config->ciphers); 270 free((char *)config->ciphers);
271 free((char *)config->crl_mem); 271 free((char *)config->crl_mem);
272 free(config->ecdhecurves);
272 273
273 free(config); 274 free(config);
274} 275}
@@ -616,22 +617,81 @@ tls_config_set_dheparams(struct tls_config *config, const char *params)
616} 617}
617 618
618int 619int
619tls_config_set_ecdhecurve(struct tls_config *config, const char *name) 620tls_config_set_ecdhecurve(struct tls_config *config, const char *curve)
620{ 621{
622 if (strchr(curve, ',') != NULL || strchr(curve, ':') != NULL) {
623 tls_config_set_errorx(config, "invalid ecdhe curve '%s'",
624 curve);
625 return (-1);
626 }
627
628 if (curve == NULL ||
629 strcasecmp(curve, "none") == 0 ||
630 strcasecmp(curve, "auto") == 0)
631 curve = TLS_ECDHE_CURVES;
632
633 return tls_config_set_ecdhecurves(config, curve);
634}
635
636int
637tls_config_set_ecdhecurves(struct tls_config *config, const char *curves)
638{
639 int *curves_list = NULL, *curves_new;
640 size_t curves_num = 0;
641 char *cs = NULL;
642 char *p, *q;
643 int rv = -1;
621 int nid; 644 int nid;
622 645
623 if (name == NULL || strcasecmp(name, "none") == 0) 646 free(config->ecdhecurves);
624 nid = NID_undef; 647 config->ecdhecurves = NULL;
625 else if (strcasecmp(name, "auto") == 0) 648 config->ecdhecurves_len = 0;
626 nid = -1; 649
627 else if ((nid = OBJ_txt2nid(name)) == NID_undef) { 650 if (curves == NULL || strcasecmp(curves, "default") == 0)
628 tls_config_set_errorx(config, "invalid ecdhe curve '%s'", name); 651 curves = TLS_ECDHE_CURVES;
629 return (-1); 652
653 if ((cs = strdup(curves)) == NULL) {
654 tls_config_set_errorx(config, "out of memory");
655 goto err;
656 }
657
658 q = cs;
659 while ((p = strsep(&q, ",:")) != NULL) {
660 while (*p == ' ' || *p == '\t')
661 p++;
662
663 nid = OBJ_sn2nid(p);
664 if (nid == NID_undef)
665 nid = OBJ_ln2nid(p);
666 if (nid == NID_undef)
667 nid = EC_curve_nist2nid(p);
668 if (nid == NID_undef) {
669 tls_config_set_errorx(config,
670 "invalid ecdhe curve '%s'", p);
671 goto err;
672 }
673
674 if ((curves_new = reallocarray(curves_list, curves_num + 1,
675 sizeof(int))) == NULL) {
676 tls_config_set_errorx(config, "out of memory");
677 goto err;
678 }
679 curves_list = curves_new;
680 curves_list[curves_num] = nid;
681 curves_num++;
630 } 682 }
631 683
632 config->ecdhecurve = nid; 684 config->ecdhecurves = curves_list;
685 config->ecdhecurves_len = curves_num;
686 curves_list = NULL;
633 687
634 return (0); 688 rv = 0;
689
690 err:
691 free(cs);
692 free(curves_list);
693
694 return (rv);
635} 695}
636 696
637int 697int
diff --git a/src/lib/libtls/tls_internal.h b/src/lib/libtls/tls_internal.h
index 6079babccf..9e9443dbaf 100644
--- a/src/lib/libtls/tls_internal.h
+++ b/src/lib/libtls/tls_internal.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_internal.h,v 1.63 2017/08/09 21:27:24 claudio Exp $ */ 1/* $OpenBSD: tls_internal.h,v 1.64 2017/08/10 18:18:30 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org> 3 * Copyright (c) 2014 Jeremie Courreges-Anglas <jca@openbsd.org>
4 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 4 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
@@ -33,6 +33,8 @@ __BEGIN_HIDDEN_DECLS
33#define TLS_CIPHERS_LEGACY "HIGH:MEDIUM:!aNULL" 33#define TLS_CIPHERS_LEGACY "HIGH:MEDIUM:!aNULL"
34#define TLS_CIPHERS_ALL "ALL:!aNULL:!eNULL" 34#define TLS_CIPHERS_ALL "ALL:!aNULL:!eNULL"
35 35
36#define TLS_ECDHE_CURVES "X25519,P-256,P-384"
37
36union tls_addr { 38union tls_addr {
37 struct in_addr ip4; 39 struct in_addr ip4;
38 struct in6_addr ip6; 40 struct in6_addr ip6;
@@ -87,7 +89,8 @@ struct tls_config {
87 char *crl_mem; 89 char *crl_mem;
88 size_t crl_len; 90 size_t crl_len;
89 int dheparams; 91 int dheparams;
90 int ecdhecurve; 92 int *ecdhecurves;
93 size_t ecdhecurves_len;
91 struct tls_keypair *keypair; 94 struct tls_keypair *keypair;
92 int ocsp_require_stapling; 95 int ocsp_require_stapling;
93 uint32_t protocols; 96 uint32_t protocols;
diff --git a/src/lib/libtls/tls_server.c b/src/lib/libtls/tls_server.c
index 394cea1e8d..2622e4464f 100644
--- a/src/lib/libtls/tls_server.c
+++ b/src/lib/libtls/tls_server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls_server.c,v 1.40 2017/07/05 15:38:35 jsing Exp $ */ 1/* $OpenBSD: tls_server.c,v 1.41 2017/08/10 18:18:30 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -241,8 +241,6 @@ static int
241tls_configure_server_ssl(struct tls *ctx, SSL_CTX **ssl_ctx, 241tls_configure_server_ssl(struct tls *ctx, SSL_CTX **ssl_ctx,
242 struct tls_keypair *keypair) 242 struct tls_keypair *keypair)
243{ 243{
244 EC_KEY *ecdh_key;
245
246 SSL_CTX_free(*ssl_ctx); 244 SSL_CTX_free(*ssl_ctx);
247 245
248 if ((*ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) { 246 if ((*ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) {
@@ -283,17 +281,13 @@ tls_configure_server_ssl(struct tls *ctx, SSL_CTX **ssl_ctx,
283 else if (ctx->config->dheparams == 1024) 281 else if (ctx->config->dheparams == 1024)
284 SSL_CTX_set_dh_auto(*ssl_ctx, 2); 282 SSL_CTX_set_dh_auto(*ssl_ctx, 2);
285 283
286 if (ctx->config->ecdhecurve == -1) { 284 if (ctx->config->ecdhecurves != NULL) {
287 SSL_CTX_set_ecdh_auto(*ssl_ctx, 1); 285 SSL_CTX_set_ecdh_auto(*ssl_ctx, 1);
288 } else if (ctx->config->ecdhecurve != NID_undef) { 286 if (SSL_CTX_set1_groups(*ssl_ctx, ctx->config->ecdhecurves,
289 if ((ecdh_key = EC_KEY_new_by_curve_name( 287 ctx->config->ecdhecurves_len) != 1) {
290 ctx->config->ecdhecurve)) == NULL) { 288 tls_set_errorx(ctx, "failed to set ecdhe curves");
291 tls_set_errorx(ctx, "failed to set ECDHE curve");
292 goto err; 289 goto err;
293 } 290 }
294 SSL_CTX_set_options(*ssl_ctx, SSL_OP_SINGLE_ECDH_USE);
295 SSL_CTX_set_tmp_ecdh(*ssl_ctx, ecdh_key);
296 EC_KEY_free(ecdh_key);
297 } 291 }
298 292
299 if (ctx->config->ciphers_server == 1) 293 if (ctx->config->ciphers_server == 1)