diff options
author | jsing <> | 2017-08-30 16:44:37 +0000 |
---|---|---|
committer | jsing <> | 2017-08-30 16:44:37 +0000 |
commit | b19ea396d5602ee93ecc63f75119de83f18ed53c (patch) | |
tree | 3acf5f0d7689b144b0903b95043b87844d147ed7 | |
parent | 071056fa8c2a609a50f3df7c34aef270154e945e (diff) | |
download | openbsd-b19ea396d5602ee93ecc63f75119de83f18ed53c.tar.gz openbsd-b19ea396d5602ee93ecc63f75119de83f18ed53c.tar.bz2 openbsd-b19ea396d5602ee93ecc63f75119de83f18ed53c.zip |
Move the full extension building into tlsext_{client,server}hello_build(),
leaving ssl_add_{client,server}hello_tlsext() as pointer to CBB wrappers.
ok doug@
-rw-r--r-- | src/lib/libssl/ssl_tlsext.c | 30 | ||||
-rw-r--r-- | src/lib/libssl/t1_lib.c | 43 |
2 files changed, 26 insertions, 47 deletions
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c index 340ebeda5c..abc012d3af 100644 --- a/src/lib/libssl/ssl_tlsext.c +++ b/src/lib/libssl/ssl_tlsext.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_tlsext.c,v 1.14 2017/08/29 19:20:13 doug Exp $ */ | 1 | /* $OpenBSD: ssl_tlsext.c,v 1.15 2017/08/30 16:44:37 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> | 4 | * Copyright (c) 2017 Doug Hogan <doug@openbsd.org> |
@@ -1300,11 +1300,12 @@ static struct tls_extension tls_extensions[] = { | |||
1300 | int | 1300 | int |
1301 | tlsext_clienthello_build(SSL *s, CBB *cbb) | 1301 | tlsext_clienthello_build(SSL *s, CBB *cbb) |
1302 | { | 1302 | { |
1303 | CBB extensions, extension_data; | ||
1303 | struct tls_extension *tlsext; | 1304 | struct tls_extension *tlsext; |
1304 | CBB extension_data; | ||
1305 | size_t i; | 1305 | size_t i; |
1306 | 1306 | ||
1307 | memset(&extension_data, 0, sizeof(extension_data)); | 1307 | if (!CBB_add_u16_length_prefixed(cbb, &extensions)) |
1308 | return 0; | ||
1308 | 1309 | ||
1309 | for (i = 0; i < N_TLS_EXTENSIONS; i++) { | 1310 | for (i = 0; i < N_TLS_EXTENSIONS; i++) { |
1310 | tlsext = &tls_extensions[i]; | 1311 | tlsext = &tls_extensions[i]; |
@@ -1312,16 +1313,17 @@ tlsext_clienthello_build(SSL *s, CBB *cbb) | |||
1312 | if (!tlsext->clienthello_needs(s)) | 1313 | if (!tlsext->clienthello_needs(s)) |
1313 | continue; | 1314 | continue; |
1314 | 1315 | ||
1315 | if (!CBB_add_u16(cbb, tlsext->type)) | 1316 | if (!CBB_add_u16(&extensions, tlsext->type)) |
1316 | return 0; | 1317 | return 0; |
1317 | if (!CBB_add_u16_length_prefixed(cbb, &extension_data)) | 1318 | if (!CBB_add_u16_length_prefixed(&extensions, &extension_data)) |
1318 | return 0; | 1319 | return 0; |
1319 | if (!tls_extensions[i].clienthello_build(s, &extension_data)) | 1320 | if (!tls_extensions[i].clienthello_build(s, &extension_data)) |
1320 | return 0; | 1321 | return 0; |
1321 | if (!CBB_flush(cbb)) | ||
1322 | return 0; | ||
1323 | } | 1322 | } |
1324 | 1323 | ||
1324 | if (!CBB_flush(cbb)) | ||
1325 | return 0; | ||
1326 | |||
1325 | return 1; | 1327 | return 1; |
1326 | } | 1328 | } |
1327 | 1329 | ||
@@ -1353,11 +1355,12 @@ tlsext_clienthello_parse_one(SSL *s, CBS *cbs, uint16_t type, int *alert) | |||
1353 | int | 1355 | int |
1354 | tlsext_serverhello_build(SSL *s, CBB *cbb) | 1356 | tlsext_serverhello_build(SSL *s, CBB *cbb) |
1355 | { | 1357 | { |
1358 | CBB extensions, extension_data; | ||
1356 | struct tls_extension *tlsext; | 1359 | struct tls_extension *tlsext; |
1357 | CBB extension_data; | ||
1358 | size_t i; | 1360 | size_t i; |
1359 | 1361 | ||
1360 | memset(&extension_data, 0, sizeof(extension_data)); | 1362 | if (!CBB_add_u16_length_prefixed(cbb, &extensions)) |
1363 | return 0; | ||
1361 | 1364 | ||
1362 | for (i = 0; i < N_TLS_EXTENSIONS; i++) { | 1365 | for (i = 0; i < N_TLS_EXTENSIONS; i++) { |
1363 | tlsext = &tls_extensions[i]; | 1366 | tlsext = &tls_extensions[i]; |
@@ -1365,16 +1368,17 @@ tlsext_serverhello_build(SSL *s, CBB *cbb) | |||
1365 | if (!tlsext->serverhello_needs(s)) | 1368 | if (!tlsext->serverhello_needs(s)) |
1366 | continue; | 1369 | continue; |
1367 | 1370 | ||
1368 | if (!CBB_add_u16(cbb, tlsext->type)) | 1371 | if (!CBB_add_u16(&extensions, tlsext->type)) |
1369 | return 0; | 1372 | return 0; |
1370 | if (!CBB_add_u16_length_prefixed(cbb, &extension_data)) | 1373 | if (!CBB_add_u16_length_prefixed(&extensions, &extension_data)) |
1371 | return 0; | 1374 | return 0; |
1372 | if (!tlsext->serverhello_build(s, &extension_data)) | 1375 | if (!tlsext->serverhello_build(s, &extension_data)) |
1373 | return 0; | 1376 | return 0; |
1374 | if (!CBB_flush(cbb)) | ||
1375 | return 0; | ||
1376 | } | 1377 | } |
1377 | 1378 | ||
1379 | if (!CBB_flush(cbb)) | ||
1380 | return 0; | ||
1381 | |||
1378 | return 1; | 1382 | return 1; |
1379 | } | 1383 | } |
1380 | 1384 | ||
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c index a9f10166fe..0d03b45a97 100644 --- a/src/lib/libssl/t1_lib.c +++ b/src/lib/libssl/t1_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: t1_lib.c,v 1.136 2017/08/27 02:58:04 doug Exp $ */ | 1 | /* $OpenBSD: t1_lib.c,v 1.137 2017/08/30 16:44:37 jsing Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -664,16 +664,13 @@ tls12_get_req_sig_algs(SSL *s, unsigned char **sigalgs, size_t *sigalgs_len) | |||
664 | unsigned char * | 664 | unsigned char * |
665 | ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) | 665 | ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) |
666 | { | 666 | { |
667 | int extdatalen = 0; | ||
668 | unsigned char *ret = p; | ||
669 | size_t len; | 667 | size_t len; |
670 | CBB cbb; | 668 | CBB cbb; |
671 | 669 | ||
672 | ret += 2; | 670 | if (p >= limit) |
673 | if (ret >= limit) | 671 | return NULL; |
674 | return NULL; /* this really never occurs, but ... */ | ||
675 | 672 | ||
676 | if (!CBB_init_fixed(&cbb, ret, limit - ret)) | 673 | if (!CBB_init_fixed(&cbb, p, limit - p)) |
677 | return NULL; | 674 | return NULL; |
678 | if (!tlsext_clienthello_build(s, &cbb)) { | 675 | if (!tlsext_clienthello_build(s, &cbb)) { |
679 | CBB_cleanup(&cbb); | 676 | CBB_cleanup(&cbb); |
@@ -683,30 +680,20 @@ ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) | |||
683 | CBB_cleanup(&cbb); | 680 | CBB_cleanup(&cbb); |
684 | return NULL; | 681 | return NULL; |
685 | } | 682 | } |
686 | if (len > (limit - ret)) | ||
687 | return NULL; | ||
688 | ret += len; | ||
689 | |||
690 | if ((extdatalen = ret - p - 2) == 0) | ||
691 | return p; | ||
692 | 683 | ||
693 | s2n(extdatalen, p); | 684 | return (p + len); |
694 | return ret; | ||
695 | } | 685 | } |
696 | 686 | ||
697 | unsigned char * | 687 | unsigned char * |
698 | ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) | 688 | ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) |
699 | { | 689 | { |
700 | int extdatalen = 0; | ||
701 | unsigned char *ret = p; | ||
702 | size_t len; | 690 | size_t len; |
703 | CBB cbb; | 691 | CBB cbb; |
704 | 692 | ||
705 | ret += 2; | 693 | if (p >= limit) |
706 | if (ret >= limit) | 694 | return NULL; |
707 | return NULL; /* this really never occurs, but ... */ | ||
708 | 695 | ||
709 | if (!CBB_init_fixed(&cbb, ret, limit - ret)) | 696 | if (!CBB_init_fixed(&cbb, p, limit - p)) |
710 | return NULL; | 697 | return NULL; |
711 | if (!tlsext_serverhello_build(s, &cbb)) { | 698 | if (!tlsext_serverhello_build(s, &cbb)) { |
712 | CBB_cleanup(&cbb); | 699 | CBB_cleanup(&cbb); |
@@ -716,20 +703,8 @@ ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) | |||
716 | CBB_cleanup(&cbb); | 703 | CBB_cleanup(&cbb); |
717 | return NULL; | 704 | return NULL; |
718 | } | 705 | } |
719 | if (len > (limit - ret)) | ||
720 | return NULL; | ||
721 | ret += len; | ||
722 | |||
723 | /* | ||
724 | * Currently the server should not respond with a SupportedCurves | ||
725 | * extension. | ||
726 | */ | ||
727 | |||
728 | if ((extdatalen = ret - p - 2) == 0) | ||
729 | return p; | ||
730 | 706 | ||
731 | s2n(extdatalen, p); | 707 | return (p + len); |
732 | return ret; | ||
733 | } | 708 | } |
734 | 709 | ||
735 | int | 710 | int |