diff options
author | jsing <> | 2024-07-20 04:04:23 +0000 |
---|---|---|
committer | jsing <> | 2024-07-20 04:04:23 +0000 |
commit | b68193edfb3424eb0f993aec6089c9e057aa5d4d (patch) | |
tree | b04719de2f91b0f8d7c9c7acb93cef76a89b9948 | |
parent | cc7dc6e9b7012526aa3797842d226b3a275a7e70 (diff) | |
download | openbsd-b68193edfb3424eb0f993aec6089c9e057aa5d4d.tar.gz openbsd-b68193edfb3424eb0f993aec6089c9e057aa5d4d.tar.bz2 openbsd-b68193edfb3424eb0f993aec6089c9e057aa5d4d.zip |
Remove cipher from SSL_SESSION.
For a long time SSL_SESSION has had both a cipher ID and a pointer to
an SSL_CIPHER (and not both are guaranteed to be populated). There is also
a pointer to an SSL_CIPHER in the SSL_HANDSHAKE that denotes the cipher
being used for this connection. Some code has been using the cipher from
SSL_SESSION and some code has been using the cipher from SSL_HANDSHAKE.
Remove cipher from SSL_SESSION and use the version in SSL_HANDSHAKE
everywhere. If resuming from a session then we need to use the SSL_SESSION
cipher ID to set the SSL_HANDSHAKE cipher. And we still need to ensure that
we update the cipher ID in the SSL_SESSION whenever the SSL_HANDSHAKE
cipher changes (this only occurs in a few places).
ok tb@
-rw-r--r-- | src/lib/libssl/d1_pkt.c | 6 | ||||
-rw-r--r-- | src/lib/libssl/ssl_asn1.c | 12 | ||||
-rw-r--r-- | src/lib/libssl/ssl_ciph.c | 32 | ||||
-rw-r--r-- | src/lib/libssl/ssl_clnt.c | 11 | ||||
-rw-r--r-- | src/lib/libssl/ssl_lib.c | 7 | ||||
-rw-r--r-- | src/lib/libssl/ssl_local.h | 7 | ||||
-rw-r--r-- | src/lib/libssl/ssl_pkt.c | 9 | ||||
-rw-r--r-- | src/lib/libssl/ssl_sess.c | 11 | ||||
-rw-r--r-- | src/lib/libssl/ssl_srvr.c | 13 | ||||
-rw-r--r-- | src/lib/libssl/ssl_txt.c | 9 | ||||
-rw-r--r-- | src/lib/libssl/t1_enc.c | 18 | ||||
-rw-r--r-- | src/lib/libssl/tls13_client.c | 4 | ||||
-rw-r--r-- | src/lib/libssl/tls13_server.c | 4 |
13 files changed, 70 insertions, 73 deletions
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c index df9581a3ce..cf32ca8cd6 100644 --- a/src/lib/libssl/d1_pkt.c +++ b/src/lib/libssl/d1_pkt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: d1_pkt.c,v 1.128 2023/07/02 20:16:47 tb Exp $ */ | 1 | /* $OpenBSD: d1_pkt.c,v 1.129 2024/07/20 04:04:23 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * DTLS implementation written by Nagendra Modadugu | 3 | * DTLS implementation written by Nagendra Modadugu |
4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. | 4 | * (nagendra@cs.stanford.edu) for the OpenSSL project 2005. |
@@ -596,7 +596,7 @@ dtls1_read_handshake_unexpected(SSL *s) | |||
596 | * It should be impossible to hit this, but keep the safety | 596 | * It should be impossible to hit this, but keep the safety |
597 | * harness for now... | 597 | * harness for now... |
598 | */ | 598 | */ |
599 | if (s->session == NULL || s->session->cipher == NULL) | 599 | if (s->session == NULL || s->s3->hs.cipher == NULL) |
600 | return 1; | 600 | return 1; |
601 | 601 | ||
602 | /* | 602 | /* |
@@ -650,7 +650,7 @@ dtls1_read_handshake_unexpected(SSL *s) | |||
650 | return -1; | 650 | return -1; |
651 | } | 651 | } |
652 | 652 | ||
653 | if (s->session == NULL || s->session->cipher == NULL) { | 653 | if (s->session == NULL || s->s3->hs.cipher == NULL) { |
654 | SSLerror(s, ERR_R_INTERNAL_ERROR); | 654 | SSLerror(s, ERR_R_INTERNAL_ERROR); |
655 | return -1; | 655 | return -1; |
656 | } | 656 | } |
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c index f4552f1c94..ef34cbdb04 100644 --- a/src/lib/libssl/ssl_asn1.c +++ b/src/lib/libssl/ssl_asn1.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_asn1.c,v 1.67 2023/07/08 16:40:13 beck Exp $ */ | 1 | /* $OpenBSD: ssl_asn1.c,v 1.68 2024/07/20 04:04:23 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2016 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2016 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -70,10 +70,7 @@ SSL_SESSION_encode(SSL_SESSION *s, unsigned char **out, size_t *out_len, | |||
70 | goto err; | 70 | goto err; |
71 | 71 | ||
72 | /* Cipher suite ID. */ | 72 | /* Cipher suite ID. */ |
73 | /* XXX - require cipher to be non-NULL or always/only use cipher_id. */ | ||
74 | cid = (uint16_t)(s->cipher_id & SSL3_CK_VALUE_MASK); | 73 | cid = (uint16_t)(s->cipher_id & SSL3_CK_VALUE_MASK); |
75 | if (s->cipher != NULL) | ||
76 | cid = ssl3_cipher_get_value(s->cipher); | ||
77 | if (!CBB_add_asn1(&session, &cipher_suite, CBS_ASN1_OCTETSTRING)) | 74 | if (!CBB_add_asn1(&session, &cipher_suite, CBS_ASN1_OCTETSTRING)) |
78 | goto err; | 75 | goto err; |
79 | if (!CBB_add_u16(&cipher_suite, cid)) | 76 | if (!CBB_add_u16(&cipher_suite, cid)) |
@@ -196,7 +193,7 @@ SSL_SESSION_ticket(SSL_SESSION *ss, unsigned char **out, size_t *out_len) | |||
196 | if (ss == NULL) | 193 | if (ss == NULL) |
197 | return 0; | 194 | return 0; |
198 | 195 | ||
199 | if (ss->cipher == NULL && ss->cipher_id == 0) | 196 | if (ss->cipher_id == 0) |
200 | return 0; | 197 | return 0; |
201 | 198 | ||
202 | return SSL_SESSION_encode(ss, out, out_len, 1); | 199 | return SSL_SESSION_encode(ss, out, out_len, 1); |
@@ -212,7 +209,7 @@ i2d_SSL_SESSION(SSL_SESSION *ss, unsigned char **pp) | |||
212 | if (ss == NULL) | 209 | if (ss == NULL) |
213 | return 0; | 210 | return 0; |
214 | 211 | ||
215 | if (ss->cipher == NULL && ss->cipher_id == 0) | 212 | if (ss->cipher_id == 0) |
216 | return 0; | 213 | return 0; |
217 | 214 | ||
218 | if (!SSL_SESSION_encode(ss, &data, &data_len, 0)) | 215 | if (!SSL_SESSION_encode(ss, &data, &data_len, 0)) |
@@ -287,9 +284,6 @@ d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length) | |||
287 | goto err; | 284 | goto err; |
288 | if (CBS_len(&cipher_suite) != 0) | 285 | if (CBS_len(&cipher_suite) != 0) |
289 | goto err; | 286 | goto err; |
290 | |||
291 | /* XXX - populate cipher instead? */ | ||
292 | s->cipher = NULL; | ||
293 | s->cipher_id = SSL3_CK_ID | cipher_value; | 287 | s->cipher_id = SSL3_CK_ID | cipher_value; |
294 | 288 | ||
295 | /* Session ID. */ | 289 | /* Session ID. */ |
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c index 246d64e7d5..7c32354902 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.144 2024/07/16 14:38:04 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_ciph.c,v 1.145 2024/07/20 04:04:23 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 | * |
@@ -408,25 +408,27 @@ static const SSL_CIPHER cipher_aliases[] = { | |||
408 | }; | 408 | }; |
409 | 409 | ||
410 | int | 410 | int |
411 | ssl_cipher_get_evp(const SSL_SESSION *ss, const EVP_CIPHER **enc, | 411 | ssl_cipher_get_evp(SSL *s, const EVP_CIPHER **enc, const EVP_MD **md, |
412 | const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size) | 412 | int *mac_pkey_type, int *mac_secret_size) |
413 | { | 413 | { |
414 | const SSL_CIPHER *cipher; | ||
415 | |||
414 | *enc = NULL; | 416 | *enc = NULL; |
415 | *md = NULL; | 417 | *md = NULL; |
416 | *mac_pkey_type = NID_undef; | 418 | *mac_pkey_type = NID_undef; |
417 | *mac_secret_size = 0; | 419 | *mac_secret_size = 0; |
418 | 420 | ||
419 | if (ss->cipher == NULL) | 421 | if ((cipher = s->s3->hs.cipher) == NULL) |
420 | return 0; | 422 | return 0; |
421 | 423 | ||
422 | /* | 424 | /* |
423 | * This function does not handle EVP_AEAD. | 425 | * This function does not handle EVP_AEAD. |
424 | * See ssl_cipher_get_evp_aead instead. | 426 | * See ssl_cipher_get_evp_aead instead. |
425 | */ | 427 | */ |
426 | if (ss->cipher->algorithm_mac & SSL_AEAD) | 428 | if (cipher->algorithm_mac & SSL_AEAD) |
427 | return 0; | 429 | return 0; |
428 | 430 | ||
429 | switch (ss->cipher->algorithm_enc) { | 431 | switch (cipher->algorithm_enc) { |
430 | case SSL_3DES: | 432 | case SSL_3DES: |
431 | *enc = EVP_des_ede3_cbc(); | 433 | *enc = EVP_des_ede3_cbc(); |
432 | break; | 434 | break; |
@@ -450,7 +452,7 @@ ssl_cipher_get_evp(const SSL_SESSION *ss, const EVP_CIPHER **enc, | |||
450 | break; | 452 | break; |
451 | } | 453 | } |
452 | 454 | ||
453 | switch (ss->cipher->algorithm_mac) { | 455 | switch (cipher->algorithm_mac) { |
454 | case SSL_MD5: | 456 | case SSL_MD5: |
455 | *md = EVP_md5(); | 457 | *md = EVP_md5(); |
456 | break; | 458 | break; |
@@ -487,16 +489,18 @@ ssl_cipher_get_evp(const SSL_SESSION *ss, const EVP_CIPHER **enc, | |||
487 | * for s->cipher. It returns 1 on success and 0 on error. | 489 | * for s->cipher. It returns 1 on success and 0 on error. |
488 | */ | 490 | */ |
489 | int | 491 | int |
490 | ssl_cipher_get_evp_aead(const SSL_SESSION *ss, const EVP_AEAD **aead) | 492 | ssl_cipher_get_evp_aead(SSL *s, const EVP_AEAD **aead) |
491 | { | 493 | { |
494 | const SSL_CIPHER *cipher; | ||
495 | |||
492 | *aead = NULL; | 496 | *aead = NULL; |
493 | 497 | ||
494 | if (ss->cipher == NULL) | 498 | if ((cipher = s->s3->hs.cipher) == NULL) |
495 | return 0; | 499 | return 0; |
496 | if ((ss->cipher->algorithm_mac & SSL_AEAD) == 0) | 500 | if ((cipher->algorithm_mac & SSL_AEAD) == 0) |
497 | return 0; | 501 | return 0; |
498 | 502 | ||
499 | switch (ss->cipher->algorithm_enc) { | 503 | switch (cipher->algorithm_enc) { |
500 | case SSL_AES128GCM: | 504 | case SSL_AES128GCM: |
501 | *aead = EVP_aead_aes_128_gcm(); | 505 | *aead = EVP_aead_aes_128_gcm(); |
502 | return 1; | 506 | return 1; |
@@ -515,12 +519,14 @@ ssl_cipher_get_evp_aead(const SSL_SESSION *ss, const EVP_AEAD **aead) | |||
515 | int | 519 | int |
516 | ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md) | 520 | ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md) |
517 | { | 521 | { |
522 | const SSL_CIPHER *cipher; | ||
523 | |||
518 | *md = NULL; | 524 | *md = NULL; |
519 | 525 | ||
520 | if (s->s3->hs.cipher == NULL) | 526 | if ((cipher = s->s3->hs.cipher) == NULL) |
521 | return 0; | 527 | return 0; |
522 | 528 | ||
523 | switch (s->s3->hs.cipher->algorithm2 & SSL_HANDSHAKE_MAC_MASK) { | 529 | switch (cipher->algorithm2 & SSL_HANDSHAKE_MAC_MASK) { |
524 | case SSL_HANDSHAKE_MAC_SHA256: | 530 | case SSL_HANDSHAKE_MAC_SHA256: |
525 | *md = EVP_sha256(); | 531 | *md = EVP_sha256(); |
526 | return 1; | 532 | return 1; |
diff --git a/src/lib/libssl/ssl_clnt.c b/src/lib/libssl/ssl_clnt.c index 6cf0ee4a4a..7b2e05d23d 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.166 2024/07/19 08:56:17 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_clnt.c,v 1.167 2024/07/20 04:04:23 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 | * |
@@ -481,7 +481,7 @@ ssl3_connect(SSL *s) | |||
481 | 481 | ||
482 | s->s3->hs.state = SSL3_ST_CW_FINISHED_A; | 482 | s->s3->hs.state = SSL3_ST_CW_FINISHED_A; |
483 | s->init_num = 0; | 483 | s->init_num = 0; |
484 | s->session->cipher = s->s3->hs.cipher; | 484 | s->session->cipher_id = s->s3->hs.cipher->id; |
485 | 485 | ||
486 | if (!tls1_setup_key_block(s)) { | 486 | if (!tls1_setup_key_block(s)) { |
487 | ret = -1; | 487 | ret = -1; |
@@ -946,8 +946,8 @@ ssl3_get_server_hello(SSL *s) | |||
946 | * client cannot change the cipher at this stage, | 946 | * client cannot change the cipher at this stage, |
947 | * as the server has already made a selection. | 947 | * as the server has already made a selection. |
948 | */ | 948 | */ |
949 | if ((s->session->cipher = pref_cipher) == NULL) | 949 | if ((s->s3->hs.cipher = pref_cipher) == NULL) |
950 | s->session->cipher = | 950 | s->s3->hs.cipher = |
951 | ssl3_get_cipher_by_value(cipher_suite); | 951 | ssl3_get_cipher_by_value(cipher_suite); |
952 | s->s3->flags |= SSL3_FLAGS_CCS_OK; | 952 | s->s3->flags |= SSL3_FLAGS_CCS_OK; |
953 | } | 953 | } |
@@ -1016,14 +1016,13 @@ ssl3_get_server_hello(SSL *s) | |||
1016 | * and/or cipher_id values may not be set. Make sure that | 1016 | * and/or cipher_id values may not be set. Make sure that |
1017 | * cipher_id is set and use it for comparison. | 1017 | * cipher_id is set and use it for comparison. |
1018 | */ | 1018 | */ |
1019 | if (s->session->cipher) | ||
1020 | s->session->cipher_id = s->session->cipher->id; | ||
1021 | if (s->hit && (s->session->cipher_id != cipher->id)) { | 1019 | if (s->hit && (s->session->cipher_id != cipher->id)) { |
1022 | al = SSL_AD_ILLEGAL_PARAMETER; | 1020 | al = SSL_AD_ILLEGAL_PARAMETER; |
1023 | SSLerror(s, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED); | 1021 | SSLerror(s, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED); |
1024 | goto fatal_err; | 1022 | goto fatal_err; |
1025 | } | 1023 | } |
1026 | s->s3->hs.cipher = cipher; | 1024 | s->s3->hs.cipher = cipher; |
1025 | s->session->cipher_id = cipher->id; | ||
1027 | 1026 | ||
1028 | if (!tls1_transcript_hash_init(s)) | 1027 | if (!tls1_transcript_hash_init(s)) |
1029 | goto err; | 1028 | goto err; |
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index 4b86b70db8..4cf5c46fda 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.327 2024/07/19 08:54:31 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_lib.c,v 1.328 2024/07/20 04:04:23 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 | * |
@@ -3073,11 +3073,10 @@ LSSL_ALIAS(SSL_get_privatekey); | |||
3073 | const SSL_CIPHER * | 3073 | const SSL_CIPHER * |
3074 | SSL_get_current_cipher(const SSL *s) | 3074 | SSL_get_current_cipher(const SSL *s) |
3075 | { | 3075 | { |
3076 | if ((s->session != NULL) && (s->session->cipher != NULL)) | 3076 | return s->s3->hs.cipher; |
3077 | return (s->session->cipher); | ||
3078 | return (NULL); | ||
3079 | } | 3077 | } |
3080 | LSSL_ALIAS(SSL_get_current_cipher); | 3078 | LSSL_ALIAS(SSL_get_current_cipher); |
3079 | |||
3081 | const void * | 3080 | const void * |
3082 | SSL_get_current_compression(SSL *s) | 3081 | SSL_get_current_compression(SSL *s) |
3083 | { | 3082 | { |
diff --git a/src/lib/libssl/ssl_local.h b/src/lib/libssl/ssl_local.h index e9b6a62bbe..79f41e6dc3 100644 --- a/src/lib/libssl/ssl_local.h +++ b/src/lib/libssl/ssl_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_local.h,v 1.20 2024/07/19 08:54:31 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_local.h,v 1.21 2024/07/20 04:04:23 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 | * |
@@ -438,7 +438,6 @@ struct ssl_session_st { | |||
438 | time_t time; | 438 | time_t time; |
439 | int references; | 439 | int references; |
440 | 440 | ||
441 | const SSL_CIPHER *cipher; | ||
442 | unsigned long cipher_id; /* when ASN.1 loaded, this | 441 | unsigned long cipher_id; /* when ASN.1 loaded, this |
443 | * needs to be used to load | 442 | * needs to be used to load |
444 | * the 'cipher' structure */ | 443 | * the 'cipher' structure */ |
@@ -1267,9 +1266,9 @@ int ssl_merge_cipherlists(STACK_OF(SSL_CIPHER) *cipherlist, | |||
1267 | STACK_OF(SSL_CIPHER) *cipherlist_tls13, | 1266 | STACK_OF(SSL_CIPHER) *cipherlist_tls13, |
1268 | STACK_OF(SSL_CIPHER) **out_cipherlist); | 1267 | STACK_OF(SSL_CIPHER) **out_cipherlist); |
1269 | void ssl_update_cache(SSL *s, int mode); | 1268 | void ssl_update_cache(SSL *s, int mode); |
1270 | int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc, | 1269 | int ssl_cipher_get_evp(SSL *s, const EVP_CIPHER **enc, |
1271 | const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size); | 1270 | const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size); |
1272 | int ssl_cipher_get_evp_aead(const SSL_SESSION *s, const EVP_AEAD **aead); | 1271 | int ssl_cipher_get_evp_aead(SSL *s, const EVP_AEAD **aead); |
1273 | int ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md); | 1272 | int ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md); |
1274 | 1273 | ||
1275 | int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk); | 1274 | int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk); |
diff --git a/src/lib/libssl/ssl_pkt.c b/src/lib/libssl/ssl_pkt.c index 2c33c45386..7d6785a3de 100644 --- a/src/lib/libssl/ssl_pkt.c +++ b/src/lib/libssl/ssl_pkt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_pkt.c,v 1.66 2023/07/11 17:02:47 tb Exp $ */ | 1 | /* $OpenBSD: ssl_pkt.c,v 1.67 2024/07/20 04:04:23 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 | * |
@@ -904,7 +904,7 @@ ssl3_read_handshake_unexpected(SSL *s) | |||
904 | * It should be impossible to hit this, but keep the safety | 904 | * It should be impossible to hit this, but keep the safety |
905 | * harness for now... | 905 | * harness for now... |
906 | */ | 906 | */ |
907 | if (s->session == NULL || s->session->cipher == NULL) | 907 | if (s->session == NULL || s->s3->hs.cipher == NULL) |
908 | return 1; | 908 | return 1; |
909 | 909 | ||
910 | /* | 910 | /* |
@@ -953,7 +953,7 @@ ssl3_read_handshake_unexpected(SSL *s) | |||
953 | return -1; | 953 | return -1; |
954 | } | 954 | } |
955 | 955 | ||
956 | if (s->session == NULL || s->session->cipher == NULL) { | 956 | if (s->session == NULL || s->s3->hs.cipher == NULL) { |
957 | SSLerror(s, ERR_R_INTERNAL_ERROR); | 957 | SSLerror(s, ERR_R_INTERNAL_ERROR); |
958 | return -1; | 958 | return -1; |
959 | } | 959 | } |
@@ -1235,7 +1235,8 @@ ssl3_do_change_cipher_spec(SSL *s) | |||
1235 | return (0); | 1235 | return (0); |
1236 | } | 1236 | } |
1237 | 1237 | ||
1238 | s->session->cipher = s->s3->hs.cipher; | 1238 | s->session->cipher_id = s->s3->hs.cipher->id; |
1239 | |||
1239 | if (!tls1_setup_key_block(s)) | 1240 | if (!tls1_setup_key_block(s)) |
1240 | return (0); | 1241 | return (0); |
1241 | } | 1242 | } |
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c index 76f194ca78..c2bd1bf135 100644 --- a/src/lib/libssl/ssl_sess.c +++ b/src/lib/libssl/ssl_sess.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_sess.c,v 1.126 2024/07/19 08:54:31 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_sess.c,v 1.127 2024/07/20 04:04:23 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 | * |
@@ -287,7 +287,6 @@ ssl_session_dup(SSL_SESSION *sess, int include_ticket) | |||
287 | copy->time = sess->time; | 287 | copy->time = sess->time; |
288 | copy->references = 1; | 288 | copy->references = 1; |
289 | 289 | ||
290 | copy->cipher = sess->cipher; | ||
291 | copy->cipher_id = sess->cipher_id; | 290 | copy->cipher_id = sess->cipher_id; |
292 | 291 | ||
293 | if (sess->tlsext_hostname != NULL) { | 292 | if (sess->tlsext_hostname != NULL) { |
@@ -707,12 +706,6 @@ ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, int *alert) | |||
707 | goto err; | 706 | goto err; |
708 | } | 707 | } |
709 | 708 | ||
710 | if (sess->cipher == NULL) { | ||
711 | sess->cipher = ssl3_get_cipher_by_id(sess->cipher_id); | ||
712 | if (sess->cipher == NULL) | ||
713 | goto err; | ||
714 | } | ||
715 | |||
716 | if (sess->timeout < (time(NULL) - sess->time)) { | 709 | if (sess->timeout < (time(NULL) - sess->time)) { |
717 | s->session_ctx->stats.sess_timeout++; | 710 | s->session_ctx->stats.sess_timeout++; |
718 | if (!ticket_decrypted) { | 711 | if (!ticket_decrypted) { |
@@ -991,7 +984,7 @@ LSSL_ALIAS(SSL_SESSION_get_protocol_version); | |||
991 | const SSL_CIPHER * | 984 | const SSL_CIPHER * |
992 | SSL_SESSION_get0_cipher(const SSL_SESSION *s) | 985 | SSL_SESSION_get0_cipher(const SSL_SESSION *s) |
993 | { | 986 | { |
994 | return s->cipher; | 987 | return ssl3_get_cipher_by_id(s->cipher_id); |
995 | } | 988 | } |
996 | LSSL_ALIAS(SSL_SESSION_get0_cipher); | 989 | LSSL_ALIAS(SSL_SESSION_get0_cipher); |
997 | 990 | ||
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c index 01155a8d6d..be6bd7402c 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.163 2024/07/19 08:56:17 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_srvr.c,v 1.164 2024/07/20 04:04:23 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 | * |
@@ -651,7 +651,7 @@ ssl3_accept(SSL *s) | |||
651 | goto end; | 651 | goto end; |
652 | s->s3->hs.state = SSL3_ST_SW_FINISHED_A; | 652 | s->s3->hs.state = SSL3_ST_SW_FINISHED_A; |
653 | s->init_num = 0; | 653 | s->init_num = 0; |
654 | s->session->cipher = s->s3->hs.cipher; | 654 | s->session->cipher_id = s->s3->hs.cipher->id; |
655 | 655 | ||
656 | if (!tls1_setup_key_block(s)) { | 656 | if (!tls1_setup_key_block(s)) { |
657 | ret = -1; | 657 | ret = -1; |
@@ -978,7 +978,7 @@ ssl3_get_client_hello(SSL *s) | |||
978 | /* XXX - CBS_len(&cipher_suites) will always be zero here... */ | 978 | /* XXX - CBS_len(&cipher_suites) will always be zero here... */ |
979 | if (s->hit && CBS_len(&cipher_suites) > 0) { | 979 | if (s->hit && CBS_len(&cipher_suites) > 0) { |
980 | j = 0; | 980 | j = 0; |
981 | id = s->session->cipher->id; | 981 | id = s->session->cipher_id; |
982 | 982 | ||
983 | for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) { | 983 | for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) { |
984 | c = sk_SSL_CIPHER_value(ciphers, i); | 984 | c = sk_SSL_CIPHER_value(ciphers, i); |
@@ -1098,7 +1098,7 @@ ssl3_get_client_hello(SSL *s) | |||
1098 | SSLerror(s, SSL_R_NO_SHARED_CIPHER); | 1098 | SSLerror(s, SSL_R_NO_SHARED_CIPHER); |
1099 | goto fatal_err; | 1099 | goto fatal_err; |
1100 | } | 1100 | } |
1101 | s->session->cipher = pref_cipher; | 1101 | s->s3->hs.cipher = pref_cipher; |
1102 | 1102 | ||
1103 | /* XXX - why? */ | 1103 | /* XXX - why? */ |
1104 | sk_SSL_CIPHER_free(s->cipher_list); | 1104 | sk_SSL_CIPHER_free(s->cipher_list); |
@@ -1127,8 +1127,11 @@ ssl3_get_client_hello(SSL *s) | |||
1127 | goto fatal_err; | 1127 | goto fatal_err; |
1128 | } | 1128 | } |
1129 | s->s3->hs.cipher = c; | 1129 | s->s3->hs.cipher = c; |
1130 | s->session->cipher_id = s->s3->hs.cipher->id; | ||
1130 | } else { | 1131 | } else { |
1131 | s->s3->hs.cipher = s->session->cipher; | 1132 | s->s3->hs.cipher = ssl3_get_cipher_by_id(s->session->cipher_id); |
1133 | if (s->s3->hs.cipher == NULL) | ||
1134 | goto fatal_err; | ||
1132 | } | 1135 | } |
1133 | 1136 | ||
1134 | if (!tls1_transcript_hash_init(s)) | 1137 | if (!tls1_transcript_hash_init(s)) |
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c index ee3d218d68..26b631d5ab 100644 --- a/src/lib/libssl/ssl_txt.c +++ b/src/lib/libssl/ssl_txt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_txt.c,v 1.37 2023/07/08 16:40:13 beck Exp $ */ | 1 | /* $OpenBSD: ssl_txt.c,v 1.38 2024/07/20 04:04:23 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 | * |
@@ -108,6 +108,7 @@ LSSL_ALIAS(SSL_SESSION_print_fp); | |||
108 | int | 108 | int |
109 | SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) | 109 | SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) |
110 | { | 110 | { |
111 | const SSL_CIPHER *cipher; | ||
111 | size_t i; | 112 | size_t i; |
112 | int ret = 0; | 113 | int ret = 0; |
113 | 114 | ||
@@ -121,15 +122,15 @@ SSL_SESSION_print(BIO *bp, const SSL_SESSION *x) | |||
121 | ssl_version_string(x->ssl_version)) <= 0) | 122 | ssl_version_string(x->ssl_version)) <= 0) |
122 | goto err; | 123 | goto err; |
123 | 124 | ||
124 | if (x->cipher == NULL) { | 125 | if ((cipher = ssl3_get_cipher_by_id(x->cipher_id)) == NULL) { |
125 | if (BIO_printf(bp, " Cipher : %04lX\n", | 126 | if (BIO_printf(bp, " Cipher : %04lX\n", |
126 | x->cipher_id & SSL3_CK_VALUE_MASK) <= 0) | 127 | x->cipher_id & SSL3_CK_VALUE_MASK) <= 0) |
127 | goto err; | 128 | goto err; |
128 | } else { | 129 | } else { |
129 | const char *cipher_name = "unknown"; | 130 | const char *cipher_name = "unknown"; |
130 | 131 | ||
131 | if (x->cipher->name != NULL) | 132 | if (cipher->name != NULL) |
132 | cipher_name = x->cipher->name; | 133 | cipher_name = cipher->name; |
133 | 134 | ||
134 | if (BIO_printf(bp, " Cipher : %s\n", cipher_name) <= 0) | 135 | if (BIO_printf(bp, " Cipher : %s\n", cipher_name) <= 0) |
135 | goto err; | 136 | goto err; |
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c index c6140e9b34..64e1dd5b63 100644 --- a/src/lib/libssl/t1_enc.c +++ b/src/lib/libssl/t1_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: t1_enc.c,v 1.157 2022/11/26 16:08:56 tb Exp $ */ | 1 | /* $OpenBSD: t1_enc.c,v 1.158 2024/07/20 04:04:23 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 | * |
@@ -357,15 +357,17 @@ tls1_setup_key_block(SSL *s) | |||
357 | if (s->s3->hs.tls12.key_block != NULL) | 357 | if (s->s3->hs.tls12.key_block != NULL) |
358 | return (1); | 358 | return (1); |
359 | 359 | ||
360 | if (s->session->cipher && | 360 | if (s->s3->hs.cipher == NULL) |
361 | (s->session->cipher->algorithm_mac & SSL_AEAD)) { | 361 | return (0); |
362 | if (!ssl_cipher_get_evp_aead(s->session, &aead)) { | 362 | |
363 | if ((s->s3->hs.cipher->algorithm_mac & SSL_AEAD) != 0) { | ||
364 | if (!ssl_cipher_get_evp_aead(s, &aead)) { | ||
363 | SSLerror(s, SSL_R_CIPHER_OR_HASH_UNAVAILABLE); | 365 | SSLerror(s, SSL_R_CIPHER_OR_HASH_UNAVAILABLE); |
364 | return (0); | 366 | return (0); |
365 | } | 367 | } |
366 | } else { | 368 | } else { |
367 | /* XXX - mac_type and mac_secret_size are now unused. */ | 369 | /* XXX - mac_type and mac_secret_size are now unused. */ |
368 | if (!ssl_cipher_get_evp(s->session, &cipher, &mac_hash, | 370 | if (!ssl_cipher_get_evp(s, &cipher, &mac_hash, |
369 | &mac_type, &mac_secret_size)) { | 371 | &mac_type, &mac_secret_size)) { |
370 | SSLerror(s, SSL_R_CIPHER_OR_HASH_UNAVAILABLE); | 372 | SSLerror(s, SSL_R_CIPHER_OR_HASH_UNAVAILABLE); |
371 | return (0); | 373 | return (0); |
@@ -395,12 +397,12 @@ tls1_setup_key_block(SSL *s) | |||
395 | */ | 397 | */ |
396 | s->s3->need_empty_fragments = 1; | 398 | s->s3->need_empty_fragments = 1; |
397 | 399 | ||
398 | if (s->session->cipher != NULL) { | 400 | if (s->s3->hs.cipher != NULL) { |
399 | if (s->session->cipher->algorithm_enc == SSL_eNULL) | 401 | if (s->s3->hs.cipher->algorithm_enc == SSL_eNULL) |
400 | s->s3->need_empty_fragments = 0; | 402 | s->s3->need_empty_fragments = 0; |
401 | 403 | ||
402 | #ifndef OPENSSL_NO_RC4 | 404 | #ifndef OPENSSL_NO_RC4 |
403 | if (s->session->cipher->algorithm_enc == SSL_RC4) | 405 | if (s->s3->hs.cipher->algorithm_enc == SSL_RC4) |
404 | s->s3->need_empty_fragments = 0; | 406 | s->s3->need_empty_fragments = 0; |
405 | #endif | 407 | #endif |
406 | } | 408 | } |
diff --git a/src/lib/libssl/tls13_client.c b/src/lib/libssl/tls13_client.c index 053cf1689b..8f6894fd88 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.102 2023/06/10 15:34:36 tb Exp $ */ | 1 | /* $OpenBSD: tls13_client.c,v 1.103 2024/07/20 04:04:23 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 | * |
@@ -347,7 +347,7 @@ tls13_client_engage_record_protection(struct tls13_ctx *ctx) | |||
347 | &shared_key_len)) | 347 | &shared_key_len)) |
348 | goto err; | 348 | goto err; |
349 | 349 | ||
350 | s->session->cipher = ctx->hs->cipher; | 350 | s->session->cipher_id = ctx->hs->cipher->id; |
351 | s->session->ssl_version = ctx->hs->tls13.server_version; | 351 | s->session->ssl_version = ctx->hs->tls13.server_version; |
352 | 352 | ||
353 | if ((ctx->aead = tls13_cipher_aead(ctx->hs->cipher)) == NULL) | 353 | if ((ctx->aead = tls13_cipher_aead(ctx->hs->cipher)) == NULL) |
diff --git a/src/lib/libssl/tls13_server.c b/src/lib/libssl/tls13_server.c index f9cdbdd690..6bd2993cf3 100644 --- a/src/lib/libssl/tls13_server.c +++ b/src/lib/libssl/tls13_server.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_server.c,v 1.107 2024/07/19 08:54:31 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_server.c,v 1.108 2024/07/20 04:04:23 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2020 Bob Beck <beck@openbsd.org> | 4 | * Copyright (c) 2020 Bob Beck <beck@openbsd.org> |
@@ -383,7 +383,7 @@ tls13_server_engage_record_protection(struct tls13_ctx *ctx) | |||
383 | &shared_key_len)) | 383 | &shared_key_len)) |
384 | goto err; | 384 | goto err; |
385 | 385 | ||
386 | s->session->cipher = ctx->hs->cipher; | 386 | s->session->cipher_id = ctx->hs->cipher->id; |
387 | 387 | ||
388 | if ((ctx->aead = tls13_cipher_aead(ctx->hs->cipher)) == NULL) | 388 | if ((ctx->aead = tls13_cipher_aead(ctx->hs->cipher)) == NULL) |
389 | goto err; | 389 | goto err; |