summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2017-10-10 16:51:38 +0000
committerjsing <>2017-10-10 16:51:38 +0000
commit098764416bf22cf0022a14e54c917a7d274d5907 (patch)
tree41440fc4cda10bdbc058059722ec231878a235ef /src/lib
parent9541ce793a71add79fbe8d7b3d5b3fae5015bf53 (diff)
downloadopenbsd-098764416bf22cf0022a14e54c917a7d274d5907.tar.gz
openbsd-098764416bf22cf0022a14e54c917a7d274d5907.tar.bz2
openbsd-098764416bf22cf0022a14e54c917a7d274d5907.zip
Make ssl_bytes_to_cipher_list() take a CBS, rather than a pointer and
length, since the caller has already been converted to CBS. A small amount of additional clean up whilst here.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/ssl_lib.c38
-rw-r--r--src/lib/libssl/ssl_locl.h5
-rw-r--r--src/lib/libssl/ssl_srvr.c5
3 files changed, 19 insertions, 29 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index 471fd7009e..b91ba7f0f3 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.170 2017/08/30 16:24:21 jsing Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.171 2017/10/10 16:51:38 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 *
@@ -1428,33 +1428,23 @@ ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, unsigned char *p,
1428} 1428}
1429 1429
1430STACK_OF(SSL_CIPHER) * 1430STACK_OF(SSL_CIPHER) *
1431ssl_bytes_to_cipher_list(SSL *s, const unsigned char *p, int num) 1431ssl_bytes_to_cipher_list(SSL *s, CBS *cbs)
1432{ 1432{
1433 CBS cbs; 1433 STACK_OF(SSL_CIPHER) *ciphers = NULL;
1434 const SSL_CIPHER *c; 1434 const SSL_CIPHER *cipher;
1435 STACK_OF(SSL_CIPHER) *sk = NULL; 1435 uint16_t cipher_value, max_version;
1436 unsigned long cipher_id; 1436 unsigned long cipher_id;
1437 uint16_t cipher_value, max_version;
1438 1437
1439 if (s->s3) 1438 if (s->s3 != NULL)
1440 S3I(s)->send_connection_binding = 0; 1439 S3I(s)->send_connection_binding = 0;
1441 1440
1442 /* 1441 if ((ciphers = sk_SSL_CIPHER_new_null()) == NULL) {
1443 * RFC 5246 section 7.4.1.2 defines the interval as [2,2^16-2].
1444 */
1445 if (num < 2 || num > 0x10000 - 2) {
1446 SSLerror(s, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1447 return (NULL);
1448 }
1449
1450 if ((sk = sk_SSL_CIPHER_new_null()) == NULL) {
1451 SSLerror(s, ERR_R_MALLOC_FAILURE); 1442 SSLerror(s, ERR_R_MALLOC_FAILURE);
1452 goto err; 1443 goto err;
1453 } 1444 }
1454 1445
1455 CBS_init(&cbs, p, num); 1446 while (CBS_len(cbs) > 0) {
1456 while (CBS_len(&cbs) > 0) { 1447 if (!CBS_get_u16(cbs, &cipher_value)) {
1457 if (!CBS_get_u16(&cbs, &cipher_value)) {
1458 SSLerror(s, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST); 1448 SSLerror(s, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1459 goto err; 1449 goto err;
1460 } 1450 }
@@ -1495,18 +1485,18 @@ ssl_bytes_to_cipher_list(SSL *s, const unsigned char *p, int num)
1495 continue; 1485 continue;
1496 } 1486 }
1497 1487
1498 if ((c = ssl3_get_cipher_by_value(cipher_value)) != NULL) { 1488 if ((cipher = ssl3_get_cipher_by_value(cipher_value)) != NULL) {
1499 if (!sk_SSL_CIPHER_push(sk, c)) { 1489 if (!sk_SSL_CIPHER_push(ciphers, cipher)) {
1500 SSLerror(s, ERR_R_MALLOC_FAILURE); 1490 SSLerror(s, ERR_R_MALLOC_FAILURE);
1501 goto err; 1491 goto err;
1502 } 1492 }
1503 } 1493 }
1504 } 1494 }
1505 1495
1506 return (sk); 1496 return (ciphers);
1507 1497
1508err: 1498err:
1509 sk_SSL_CIPHER_free(sk); 1499 sk_SSL_CIPHER_free(ciphers);
1510 1500
1511 return (NULL); 1501 return (NULL);
1512} 1502}
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index eed0803a85..9d9f9c3e41 100644
--- a/src/lib/libssl/ssl_locl.h
+++ b/src/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.195 2017/10/10 15:13:26 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.196 2017/10/10 16:51:38 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 *
@@ -1064,8 +1064,7 @@ int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
1064SSL_CIPHER *OBJ_bsearch_ssl_cipher_id(SSL_CIPHER *key, SSL_CIPHER const *base, int num); 1064SSL_CIPHER *OBJ_bsearch_ssl_cipher_id(SSL_CIPHER *key, SSL_CIPHER const *base, int num);
1065int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, 1065int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
1066 const SSL_CIPHER * const *bp); 1066 const SSL_CIPHER * const *bp);
1067STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, const unsigned char *p, 1067STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, CBS *cbs);
1068 int num);
1069int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk, 1068int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *sk,
1070 unsigned char *p, size_t maxlen, size_t *outlen); 1069 unsigned char *p, size_t maxlen, size_t *outlen);
1071STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth, 1070STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c
index 686d8c8db6..723d82fc82 100644
--- a/src/lib/libssl/ssl_srvr.c
+++ b/src/lib/libssl/ssl_srvr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_srvr.c,v 1.23 2017/10/08 16:46:31 jsing Exp $ */ 1/* $OpenBSD: ssl_srvr.c,v 1.24 2017/10/10 16:51:38 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 *
@@ -872,11 +872,12 @@ ssl3_get_client_hello(SSL *s)
872 872
873 if (CBS_len(&cipher_suites) > 0) { 873 if (CBS_len(&cipher_suites) > 0) {
874 if ((ciphers = ssl_bytes_to_cipher_list(s, 874 if ((ciphers = ssl_bytes_to_cipher_list(s,
875 CBS_data(&cipher_suites), CBS_len(&cipher_suites))) == NULL) 875 &cipher_suites)) == NULL)
876 goto err; 876 goto err;
877 } 877 }
878 878
879 /* If it is a hit, check that the cipher is in the list */ 879 /* If it is a hit, check that the cipher is in the list */
880 /* XXX - CBS_len(&cipher_suites) will always be zero here... */
880 if (s->internal->hit && CBS_len(&cipher_suites) > 0) { 881 if (s->internal->hit && CBS_len(&cipher_suites) > 0) {
881 j = 0; 882 j = 0;
882 id = s->session->cipher->id; 883 id = s->session->cipher->id;