summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2020-09-11 17:36:27 +0000
committerjsing <>2020-09-11 17:36:27 +0000
commit188f2a73ec9cc4314b9998227079cccb89e8677a (patch)
tree62dedc456145da98fc6ed3e6c1be5685fe0e1232 /src/lib
parent044cfc226bee4d04817ab4f4d3a6b1d0ab4db4ed (diff)
downloadopenbsd-188f2a73ec9cc4314b9998227079cccb89e8677a.tar.gz
openbsd-188f2a73ec9cc4314b9998227079cccb89e8677a.tar.bz2
openbsd-188f2a73ec9cc4314b9998227079cccb89e8677a.zip
Remove cipher_list_by_id.
When parsing a cipher string, a cipher list is created, before being duplicated and sorted - the second copy being stored as cipher_list_by_id. This is done only so that a client can ensure that the cipher selected by a server is in the cipher list. This is pretty pointless given that most clients are short-lived and that we already had to iterate over the cipher list in order to build the client hello. Additionally, any update to the cipher list requires that cipher_list_by_id also be updated and kept in sync. Remove all of this and replace it with a simple linear scan - the overhead of duplicating and sorting the cipher list likely exceeds that of a simple linear scan over the cipher list (64 maximum, more typically ~9 or so). ok beck@ tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/ssl_ciph.c17
-rw-r--r--src/lib/libssl/ssl_ciphers.c15
-rw-r--r--src/lib/libssl/ssl_clnt.c9
-rw-r--r--src/lib/libssl/ssl_lib.c55
-rw-r--r--src/lib/libssl/ssl_locl.h14
-rw-r--r--src/lib/libssl/ssl_srvr.c6
-rw-r--r--src/lib/libssl/tls13_client.c5
7 files changed, 32 insertions, 89 deletions
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
index 37417efc08..4afbcf9896 100644
--- a/src/lib/libssl/ssl_ciph.c
+++ b/src/lib/libssl/ssl_ciph.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_ciph.c,v 1.117 2020/04/19 14:54:14 jsing Exp $ */ 1/* $OpenBSD: ssl_ciph.c,v 1.118 2020/09/11 17:36:27 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 *
@@ -1184,12 +1184,11 @@ ssl_aes_is_accelerated(void)
1184STACK_OF(SSL_CIPHER) * 1184STACK_OF(SSL_CIPHER) *
1185ssl_create_cipher_list(const SSL_METHOD *ssl_method, 1185ssl_create_cipher_list(const SSL_METHOD *ssl_method,
1186 STACK_OF(SSL_CIPHER) **cipher_list, 1186 STACK_OF(SSL_CIPHER) **cipher_list,
1187 STACK_OF(SSL_CIPHER) **cipher_list_by_id,
1188 const char *rule_str) 1187 const char *rule_str)
1189{ 1188{
1190 int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases; 1189 int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
1191 unsigned long disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl; 1190 unsigned long disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl;
1192 STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list; 1191 STACK_OF(SSL_CIPHER) *cipherstack;
1193 const char *rule_p; 1192 const char *rule_p;
1194 CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr; 1193 CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
1195 const SSL_CIPHER **ca_list = NULL; 1194 const SSL_CIPHER **ca_list = NULL;
@@ -1199,7 +1198,7 @@ ssl_create_cipher_list(const SSL_METHOD *ssl_method,
1199 /* 1198 /*
1200 * Return with error if nothing to do. 1199 * Return with error if nothing to do.
1201 */ 1200 */
1202 if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL) 1201 if (rule_str == NULL || cipher_list == NULL)
1203 return NULL; 1202 return NULL;
1204 1203
1205 /* 1204 /*
@@ -1358,19 +1357,9 @@ ssl_create_cipher_list(const SSL_METHOD *ssl_method,
1358 1357
1359 free(co_list); /* Not needed any longer */ 1358 free(co_list); /* Not needed any longer */
1360 1359
1361 tmp_cipher_list = sk_SSL_CIPHER_dup(cipherstack);
1362 if (tmp_cipher_list == NULL) {
1363 sk_SSL_CIPHER_free(cipherstack);
1364 return NULL;
1365 }
1366 sk_SSL_CIPHER_free(*cipher_list); 1360 sk_SSL_CIPHER_free(*cipher_list);
1367 *cipher_list = cipherstack; 1361 *cipher_list = cipherstack;
1368 sk_SSL_CIPHER_free(*cipher_list_by_id);
1369 *cipher_list_by_id = tmp_cipher_list;
1370 (void)sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,
1371 ssl_cipher_ptr_id_cmp);
1372 1362
1373 sk_SSL_CIPHER_sort(*cipher_list_by_id);
1374 return (cipherstack); 1363 return (cipherstack);
1375} 1364}
1376 1365
diff --git a/src/lib/libssl/ssl_ciphers.c b/src/lib/libssl/ssl_ciphers.c
index d13ce7a9c5..478238bd10 100644
--- a/src/lib/libssl/ssl_ciphers.c
+++ b/src/lib/libssl/ssl_ciphers.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_ciphers.c,v 1.5 2020/09/11 15:28:07 jsing Exp $ */ 1/* $OpenBSD: ssl_ciphers.c,v 1.6 2020/09/11 17:36:27 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2015-2017 Doug Hogan <doug@openbsd.org> 3 * Copyright (c) 2015-2017 Doug Hogan <doug@openbsd.org>
4 * Copyright (c) 2015-2018 Joel Sing <jsing@openbsd.org> 4 * Copyright (c) 2015-2018 Joel Sing <jsing@openbsd.org>
@@ -23,6 +23,19 @@
23#include "ssl_locl.h" 23#include "ssl_locl.h"
24 24
25int 25int
26ssl_cipher_in_list(STACK_OF(SSL_CIPHER) *ciphers, const SSL_CIPHER *cipher)
27{
28 int i;
29
30 for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
31 if (sk_SSL_CIPHER_value(ciphers, i)->id == cipher->id)
32 return 1;
33 }
34
35 return 0;
36}
37
38int
26ssl_cipher_allowed_in_version_range(const SSL_CIPHER *cipher, uint16_t min_ver, 39ssl_cipher_allowed_in_version_range(const SSL_CIPHER *cipher, uint16_t min_ver,
27 uint16_t max_ver) 40 uint16_t max_ver)
28{ 41{
diff --git a/src/lib/libssl/ssl_clnt.c b/src/lib/libssl/ssl_clnt.c
index b6dcb8888d..68c7a83595 100644
--- a/src/lib/libssl/ssl_clnt.c
+++ b/src/lib/libssl/ssl_clnt.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_clnt.c,v 1.70 2020/07/03 04:12:50 tb Exp $ */ 1/* $OpenBSD: ssl_clnt.c,v 1.71 2020/09/11 17:36:27 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 *
@@ -802,12 +802,11 @@ ssl3_get_server_hello(SSL *s)
802 uint16_t server_version, cipher_suite; 802 uint16_t server_version, cipher_suite;
803 uint16_t min_version, max_version; 803 uint16_t min_version, max_version;
804 uint8_t compression_method; 804 uint8_t compression_method;
805 STACK_OF(SSL_CIPHER) *sk;
806 const SSL_CIPHER *cipher; 805 const SSL_CIPHER *cipher;
807 const SSL_METHOD *method; 806 const SSL_METHOD *method;
808 unsigned long alg_k; 807 unsigned long alg_k;
809 size_t outlen; 808 size_t outlen;
810 int i, al, ok; 809 int al, ok;
811 long n; 810 long n;
812 811
813 s->internal->first_packet = 1; 812 s->internal->first_packet = 1;
@@ -981,9 +980,7 @@ ssl3_get_server_hello(SSL *s)
981 goto f_err; 980 goto f_err;
982 } 981 }
983 982
984 sk = ssl_get_ciphers_by_id(s); 983 if (!ssl_cipher_in_list(SSL_get_ciphers(s), cipher)) {
985 i = sk_SSL_CIPHER_find(sk, cipher);
986 if (i < 0) {
987 /* we did not say we would use this cipher */ 984 /* we did not say we would use this cipher */
988 al = SSL_AD_ILLEGAL_PARAMETER; 985 al = SSL_AD_ILLEGAL_PARAMETER;
989 SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED); 986 SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED);
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index 34ea6154a4..5bc759d483 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.224 2020/09/11 17:23:44 jsing Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.225 2020/09/11 17:36:27 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 *
@@ -230,7 +230,7 @@ SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth)
230 ctx->method = meth; 230 ctx->method = meth;
231 231
232 ciphers = ssl_create_cipher_list(ctx->method, &ctx->cipher_list, 232 ciphers = ssl_create_cipher_list(ctx->method, &ctx->cipher_list,
233 &ctx->internal->cipher_list_by_id, SSL_DEFAULT_CIPHER_LIST); 233 SSL_DEFAULT_CIPHER_LIST);
234 if (ciphers == NULL || sk_SSL_CIPHER_num(ciphers) <= 0) { 234 if (ciphers == NULL || sk_SSL_CIPHER_num(ciphers) <= 0) {
235 SSLerrorx(SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); 235 SSLerrorx(SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
236 return (0); 236 return (0);
@@ -529,9 +529,7 @@ SSL_free(SSL *s)
529 529
530 BUF_MEM_free(s->internal->init_buf); 530 BUF_MEM_free(s->internal->init_buf);
531 531
532 /* add extra stuff */
533 sk_SSL_CIPHER_free(s->cipher_list); 532 sk_SSL_CIPHER_free(s->cipher_list);
534 sk_SSL_CIPHER_free(s->internal->cipher_list_by_id);
535 533
536 /* Make the next call work :-) */ 534 /* Make the next call work :-) */
537 if (s->session != NULL) { 535 if (s->session != NULL) {
@@ -1240,19 +1238,6 @@ ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b)
1240 return ((l > 0) ? 1:-1); 1238 return ((l > 0) ? 1:-1);
1241} 1239}
1242 1240
1243int
1244ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
1245 const SSL_CIPHER * const *bp)
1246{
1247 long l;
1248
1249 l = (*ap)->id - (*bp)->id;
1250 if (l == 0L)
1251 return (0);
1252 else
1253 return ((l > 0) ? 1:-1);
1254}
1255
1256STACK_OF(SSL_CIPHER) * 1241STACK_OF(SSL_CIPHER) *
1257SSL_get_ciphers(const SSL *s) 1242SSL_get_ciphers(const SSL *s)
1258{ 1243{
@@ -1307,24 +1292,6 @@ SSL_get1_supported_ciphers(SSL *s)
1307 return NULL; 1292 return NULL;
1308} 1293}
1309 1294
1310/*
1311 * Return a STACK of the ciphers available for the SSL and in order of
1312 * algorithm id.
1313 */
1314STACK_OF(SSL_CIPHER) *
1315ssl_get_ciphers_by_id(SSL *s)
1316{
1317 if (s != NULL) {
1318 if (s->internal->cipher_list_by_id != NULL) {
1319 return (s->internal->cipher_list_by_id);
1320 } else if ((s->ctx != NULL) &&
1321 (s->ctx->internal->cipher_list_by_id != NULL)) {
1322 return (s->ctx->internal->cipher_list_by_id);
1323 }
1324 }
1325 return (NULL);
1326}
1327
1328/* See if we have any ECC cipher suites. */ 1295/* See if we have any ECC cipher suites. */
1329int 1296int
1330ssl_has_ecc_ciphers(SSL *s) 1297ssl_has_ecc_ciphers(SSL *s)
@@ -1384,11 +1351,9 @@ SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
1384 * find a cipher matching the given rule string (for example if the 1351 * find a cipher matching the given rule string (for example if the
1385 * rule string specifies a cipher which has been disabled). This is not 1352 * rule string specifies a cipher which has been disabled). This is not
1386 * an error as far as ssl_create_cipher_list is concerned, and hence 1353 * an error as far as ssl_create_cipher_list is concerned, and hence
1387 * ctx->cipher_list and ctx->internal->cipher_list_by_id has been 1354 * ctx->cipher_list has been updated.
1388 * updated.
1389 */ 1355 */
1390 ciphers = ssl_create_cipher_list(ctx->method, &ctx->cipher_list, 1356 ciphers = ssl_create_cipher_list(ctx->method, &ctx->cipher_list, str);
1391 &ctx->internal->cipher_list_by_id, str);
1392 if (ciphers == NULL) { 1357 if (ciphers == NULL) {
1393 return (0); 1358 return (0);
1394 } else if (sk_SSL_CIPHER_num(ciphers) == 0) { 1359 } else if (sk_SSL_CIPHER_num(ciphers) == 0) {
@@ -1405,8 +1370,7 @@ SSL_set_cipher_list(SSL *s, const char *str)
1405 STACK_OF(SSL_CIPHER) *ciphers; 1370 STACK_OF(SSL_CIPHER) *ciphers;
1406 1371
1407 /* See comment in SSL_CTX_set_cipher_list. */ 1372 /* See comment in SSL_CTX_set_cipher_list. */
1408 ciphers = ssl_create_cipher_list(s->ctx->method, &s->cipher_list, 1373 ciphers = ssl_create_cipher_list(s->ctx->method, &s->cipher_list, str);
1409 &s->internal->cipher_list_by_id, str);
1410 if (ciphers == NULL) { 1374 if (ciphers == NULL) {
1411 return (0); 1375 return (0);
1412 } else if (sk_SSL_CIPHER_num(ciphers) == 0) { 1376 } else if (sk_SSL_CIPHER_num(ciphers) == 0) {
@@ -1794,7 +1758,7 @@ SSL_CTX_new(const SSL_METHOD *meth)
1794 goto err; 1758 goto err;
1795 1759
1796 ssl_create_cipher_list(ret->method, &ret->cipher_list, 1760 ssl_create_cipher_list(ret->method, &ret->cipher_list,
1797 &ret->internal->cipher_list_by_id, SSL_DEFAULT_CIPHER_LIST); 1761 SSL_DEFAULT_CIPHER_LIST);
1798 if (ret->cipher_list == NULL || 1762 if (ret->cipher_list == NULL ||
1799 sk_SSL_CIPHER_num(ret->cipher_list) <= 0) { 1763 sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {
1800 SSLerrorx(SSL_R_LIBRARY_HAS_NO_CIPHERS); 1764 SSLerrorx(SSL_R_LIBRARY_HAS_NO_CIPHERS);
@@ -1891,7 +1855,6 @@ SSL_CTX_free(SSL_CTX *ctx)
1891 1855
1892 X509_STORE_free(ctx->cert_store); 1856 X509_STORE_free(ctx->cert_store);
1893 sk_SSL_CIPHER_free(ctx->cipher_list); 1857 sk_SSL_CIPHER_free(ctx->cipher_list);
1894 sk_SSL_CIPHER_free(ctx->internal->cipher_list_by_id);
1895 ssl_cert_free(ctx->internal->cert); 1858 ssl_cert_free(ctx->internal->cert);
1896 sk_X509_NAME_pop_free(ctx->internal->client_CA, X509_NAME_free); 1859 sk_X509_NAME_pop_free(ctx->internal->client_CA, X509_NAME_free);
1897 sk_X509_pop_free(ctx->extra_certs, X509_free); 1860 sk_X509_pop_free(ctx->extra_certs, X509_free);
@@ -2483,17 +2446,11 @@ SSL_dup(SSL *s)
2483 2446
2484 X509_VERIFY_PARAM_inherit(ret->param, s->param); 2447 X509_VERIFY_PARAM_inherit(ret->param, s->param);
2485 2448
2486 /* dup the cipher_list and cipher_list_by_id stacks */
2487 if (s->cipher_list != NULL) { 2449 if (s->cipher_list != NULL) {
2488 if ((ret->cipher_list = 2450 if ((ret->cipher_list =
2489 sk_SSL_CIPHER_dup(s->cipher_list)) == NULL) 2451 sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
2490 goto err; 2452 goto err;
2491 } 2453 }
2492 if (s->internal->cipher_list_by_id != NULL) {
2493 if ((ret->internal->cipher_list_by_id =
2494 sk_SSL_CIPHER_dup(s->internal->cipher_list_by_id)) == NULL)
2495 goto err;
2496 }
2497 2454
2498 /* Dup the client_CA list */ 2455 /* Dup the client_CA list */
2499 if (s->internal->client_CA != NULL) { 2456 if (s->internal->client_CA != NULL) {
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index bfd0ea6733..df07ca68a6 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.289 2020/09/11 15:28:08 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.290 2020/09/11 17:36:27 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 *
@@ -599,9 +599,6 @@ typedef struct ssl_ctx_internal_st {
599 599
600 CRYPTO_EX_DATA ex_data; 600 CRYPTO_EX_DATA ex_data;
601 601
602 /* same cipher_list but sorted for lookup */
603 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
604
605 struct cert_st /* CERT */ *cert; 602 struct cert_st /* CERT */ *cert;
606 603
607 /* Default values used when no per-SSL value is defined follow */ 604 /* Default values used when no per-SSL value is defined follow */
@@ -746,9 +743,6 @@ typedef struct ssl_internal_st {
746 743
747 int hit; /* reusing a previous session */ 744 int hit; /* reusing a previous session */
748 745
749 /* crypto */
750 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
751
752 /* These are the ones being used, the ones in SSL_SESSION are 746 /* These are the ones being used, the ones in SSL_SESSION are
753 * the ones to be 'copied' into these ones */ 747 * the ones to be 'copied' into these ones */
754 int mac_flags; 748 int mac_flags;
@@ -1127,6 +1121,7 @@ int ssl_version_set_min(const SSL_METHOD *meth, uint16_t ver, uint16_t max_ver,
1127int ssl_version_set_max(const SSL_METHOD *meth, uint16_t ver, uint16_t min_ver, 1121int ssl_version_set_max(const SSL_METHOD *meth, uint16_t ver, uint16_t min_ver,
1128 uint16_t *out_ver); 1122 uint16_t *out_ver);
1129int ssl_downgrade_max_version(SSL *s, uint16_t *max_ver); 1123int ssl_downgrade_max_version(SSL *s, uint16_t *max_ver);
1124int ssl_cipher_in_list(STACK_OF(SSL_CIPHER) *ciphers, const SSL_CIPHER *cipher);
1130int ssl_cipher_allowed_in_version_range(const SSL_CIPHER *cipher, 1125int ssl_cipher_allowed_in_version_range(const SSL_CIPHER *cipher,
1131 uint16_t min_ver, uint16_t max_ver); 1126 uint16_t min_ver, uint16_t max_ver);
1132 1127
@@ -1166,13 +1161,10 @@ int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block,
1166int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b); 1161int ssl_cipher_id_cmp(const SSL_CIPHER *a, const SSL_CIPHER *b);
1167SSL_CIPHER *OBJ_bsearch_ssl_cipher_id(SSL_CIPHER *key, SSL_CIPHER const *base, 1162SSL_CIPHER *OBJ_bsearch_ssl_cipher_id(SSL_CIPHER *key, SSL_CIPHER const *base,
1168 int num); 1163 int num);
1169int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
1170 const SSL_CIPHER * const *bp);
1171int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *ciphers, CBB *cbb); 1164int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *ciphers, CBB *cbb);
1172STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, CBS *cbs); 1165STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, CBS *cbs);
1173STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth, 1166STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
1174 STACK_OF(SSL_CIPHER) **pref, STACK_OF(SSL_CIPHER) **sorted, 1167 STACK_OF(SSL_CIPHER) **pref, const char *rule_str);
1175 const char *rule_str);
1176void ssl_update_cache(SSL *s, int mode); 1168void ssl_update_cache(SSL *s, int mode);
1177int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, 1169int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
1178 const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size); 1170 const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size);
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c
index 745b15aad0..cbf7c180b5 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.81 2020/08/31 14:04:51 tb Exp $ */ 1/* $OpenBSD: ssl_srvr.c,v 1.82 2020/09/11 17:36:27 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 *
@@ -1096,11 +1096,7 @@ ssl3_get_client_hello(SSL *s)
1096 s->session->cipher = pref_cipher; 1096 s->session->cipher = pref_cipher;
1097 1097
1098 sk_SSL_CIPHER_free(s->cipher_list); 1098 sk_SSL_CIPHER_free(s->cipher_list);
1099 sk_SSL_CIPHER_free(s->internal->cipher_list_by_id);
1100
1101 s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers); 1099 s->cipher_list = sk_SSL_CIPHER_dup(s->session->ciphers);
1102 s->internal->cipher_list_by_id =
1103 sk_SSL_CIPHER_dup(s->session->ciphers);
1104 } 1100 }
1105 } 1101 }
1106 1102
diff --git a/src/lib/libssl/tls13_client.c b/src/lib/libssl/tls13_client.c
index bd72db8be0..35409d92bd 100644
--- a/src/lib/libssl/tls13_client.c
+++ b/src/lib/libssl/tls13_client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_client.c,v 1.66 2020/07/03 04:12:51 tb Exp $ */ 1/* $OpenBSD: tls13_client.c,v 1.67 2020/09/11 17:36:27 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -304,8 +304,7 @@ tls13_server_hello_process(struct tls13_ctx *ctx, CBS *cbs)
304 * hello and that it matches the TLS version selected. 304 * hello and that it matches the TLS version selected.
305 */ 305 */
306 cipher = ssl3_get_cipher_by_value(cipher_suite); 306 cipher = ssl3_get_cipher_by_value(cipher_suite);
307 if (cipher == NULL || 307 if (cipher == NULL || !ssl_cipher_in_list(SSL_get_ciphers(s), cipher)) {
308 sk_SSL_CIPHER_find(ssl_get_ciphers_by_id(s), cipher) < 0) {
309 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER; 308 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
310 goto err; 309 goto err;
311 } 310 }