diff options
Diffstat (limited to 'src/lib/libssl/ssl_clnt.c')
| -rw-r--r-- | src/lib/libssl/ssl_clnt.c | 163 |
1 files changed, 34 insertions, 129 deletions
diff --git a/src/lib/libssl/ssl_clnt.c b/src/lib/libssl/ssl_clnt.c index 6ef81a1706..37684aba91 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.171 2026/04/03 12:58:19 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_clnt.c,v 1.177 2026/08/29 08:41:17 tb 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 | * |
| @@ -893,7 +893,7 @@ ssl3_get_server_hello(SSL *s) | |||
| 893 | if (s->s3->hs.our_max_tls_version >= TLS1_2_VERSION && | 893 | if (s->s3->hs.our_max_tls_version >= TLS1_2_VERSION && |
| 894 | s->s3->hs.negotiated_tls_version < s->s3->hs.our_max_tls_version) { | 894 | s->s3->hs.negotiated_tls_version < s->s3->hs.our_max_tls_version) { |
| 895 | /* | 895 | /* |
| 896 | * RFC 8446 section 4.1.3. We must not downgrade if the server | 896 | * RFC 9846 section 4.2.3. We must not downgrade if the server |
| 897 | * random value contains the TLS 1.2 or TLS 1.1 magical value. | 897 | * random value contains the TLS 1.2 or TLS 1.1 magical value. |
| 898 | */ | 898 | */ |
| 899 | if (!CBS_skip(&server_random, | 899 | if (!CBS_skip(&server_random, |
| @@ -1003,16 +1003,17 @@ ssl3_get_server_hello(SSL *s) | |||
| 1003 | goto fatal_err; | 1003 | goto fatal_err; |
| 1004 | } | 1004 | } |
| 1005 | 1005 | ||
| 1006 | /* TLS v1.2 only ciphersuites require v1.2 or later. */ | 1006 | if (!ssl_cipher_in_list(SSL_get_ciphers(s), cipher)) { |
| 1007 | if ((cipher->algorithm_ssl & SSL_TLSV1_2) && | 1007 | /* we did not say we would use this cipher */ |
| 1008 | s->s3->hs.negotiated_tls_version < TLS1_2_VERSION) { | ||
| 1009 | al = SSL_AD_ILLEGAL_PARAMETER; | 1008 | al = SSL_AD_ILLEGAL_PARAMETER; |
| 1010 | SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED); | 1009 | SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED); |
| 1011 | goto fatal_err; | 1010 | goto fatal_err; |
| 1012 | } | 1011 | } |
| 1013 | 1012 | ||
| 1014 | if (!ssl_cipher_in_list(SSL_get_ciphers(s), cipher)) { | 1013 | /* Require a ciphersuite that can be used with TLSv1.2. */ |
| 1015 | /* we did not say we would use this cipher */ | 1014 | if (cipher->algorithm_ssl != SSL_SSLV3 && |
| 1015 | cipher->algorithm_ssl != SSL_TLSV1 && | ||
| 1016 | cipher->algorithm_ssl != SSL_TLSV1_2) { | ||
| 1016 | al = SSL_AD_ILLEGAL_PARAMETER; | 1017 | al = SSL_AD_ILLEGAL_PARAMETER; |
| 1017 | SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED); | 1018 | SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED); |
| 1018 | goto fatal_err; | 1019 | goto fatal_err; |
| @@ -1034,13 +1035,6 @@ ssl3_get_server_hello(SSL *s) | |||
| 1034 | if (!tls1_transcript_hash_init(s)) | 1035 | if (!tls1_transcript_hash_init(s)) |
| 1035 | goto err; | 1036 | goto err; |
| 1036 | 1037 | ||
| 1037 | /* | ||
| 1038 | * Don't digest cached records if no sigalgs: we may need them for | ||
| 1039 | * client authentication. | ||
| 1040 | */ | ||
| 1041 | if (!SSL_USE_SIGALGS(s)) | ||
| 1042 | tls1_transcript_free(s); | ||
| 1043 | |||
| 1044 | if (!CBS_get_u8(&cbs, &compression_method)) | 1038 | if (!CBS_get_u8(&cbs, &compression_method)) |
| 1045 | goto decode_err; | 1039 | goto decode_err; |
| 1046 | 1040 | ||
| @@ -1384,10 +1378,9 @@ ssl3_get_server_key_exchange(SSL *s) | |||
| 1384 | goto fatal_err; | 1378 | goto fatal_err; |
| 1385 | } | 1379 | } |
| 1386 | 1380 | ||
| 1387 | if (SSL_USE_SIGALGS(s)) { | 1381 | if (!CBS_get_u16(&cbs, &sigalg_value)) |
| 1388 | if (!CBS_get_u16(&cbs, &sigalg_value)) | 1382 | goto decode_err; |
| 1389 | goto decode_err; | 1383 | |
| 1390 | } | ||
| 1391 | if (!CBS_get_u16_length_prefixed(&cbs, &signature)) | 1384 | if (!CBS_get_u16_length_prefixed(&cbs, &signature)) |
| 1392 | goto decode_err; | 1385 | goto decode_err; |
| 1393 | if (CBS_len(&signature) > EVP_PKEY_size(pkey)) { | 1386 | if (CBS_len(&signature) > EVP_PKEY_size(pkey)) { |
| @@ -1448,7 +1441,7 @@ ssl3_get_server_key_exchange(SSL *s) | |||
| 1448 | static int | 1441 | static int |
| 1449 | ssl3_get_certificate_request(SSL *s) | 1442 | ssl3_get_certificate_request(SSL *s) |
| 1450 | { | 1443 | { |
| 1451 | CBS cert_request, cert_types, rdn_list; | 1444 | CBS cert_request, cert_types, rdn_list, sigalgs; |
| 1452 | X509_NAME *xn = NULL; | 1445 | X509_NAME *xn = NULL; |
| 1453 | const unsigned char *q; | 1446 | const unsigned char *q; |
| 1454 | STACK_OF(X509_NAME) *ca_sk = NULL; | 1447 | STACK_OF(X509_NAME) *ca_sk = NULL; |
| @@ -1497,27 +1490,23 @@ ssl3_get_certificate_request(SSL *s) | |||
| 1497 | if (!CBS_get_u8_length_prefixed(&cert_request, &cert_types)) | 1490 | if (!CBS_get_u8_length_prefixed(&cert_request, &cert_types)) |
| 1498 | goto decode_err; | 1491 | goto decode_err; |
| 1499 | 1492 | ||
| 1500 | if (SSL_USE_SIGALGS(s)) { | 1493 | if (CBS_len(&cert_request) < 2) { |
| 1501 | CBS sigalgs; | 1494 | SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG); |
| 1502 | 1495 | goto err; | |
| 1503 | if (CBS_len(&cert_request) < 2) { | 1496 | } |
| 1504 | SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG); | 1497 | if (!CBS_get_u16_length_prefixed(&cert_request, &sigalgs)) { |
| 1505 | goto err; | 1498 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1506 | } | 1499 | SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG); |
| 1507 | if (!CBS_get_u16_length_prefixed(&cert_request, &sigalgs)) { | 1500 | goto err; |
| 1508 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); | 1501 | } |
| 1509 | SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG); | 1502 | if (CBS_len(&sigalgs) % 2 != 0 || CBS_len(&sigalgs) > 64) { |
| 1510 | goto err; | 1503 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
| 1511 | } | 1504 | SSLerror(s, SSL_R_SIGNATURE_ALGORITHMS_ERROR); |
| 1512 | if (CBS_len(&sigalgs) % 2 != 0 || CBS_len(&sigalgs) > 64) { | 1505 | goto err; |
| 1513 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); | ||
| 1514 | SSLerror(s, SSL_R_SIGNATURE_ALGORITHMS_ERROR); | ||
| 1515 | goto err; | ||
| 1516 | } | ||
| 1517 | if (!CBS_stow(&sigalgs, &s->s3->hs.sigalgs, | ||
| 1518 | &s->s3->hs.sigalgs_len)) | ||
| 1519 | goto err; | ||
| 1520 | } | 1506 | } |
| 1507 | if (!CBS_stow(&sigalgs, &s->s3->hs.sigalgs, | ||
| 1508 | &s->s3->hs.sigalgs_len)) | ||
| 1509 | goto err; | ||
| 1521 | 1510 | ||
| 1522 | /* get the CA RDNs */ | 1511 | /* get the CA RDNs */ |
| 1523 | if (CBS_len(&cert_request) < 2) { | 1512 | if (CBS_len(&cert_request) < 2) { |
| @@ -2035,77 +2024,6 @@ ssl3_send_client_verify_sigalgs(SSL *s, EVP_PKEY *pkey, | |||
| 2035 | } | 2024 | } |
| 2036 | 2025 | ||
| 2037 | static int | 2026 | static int |
| 2038 | ssl3_send_client_verify_rsa(SSL *s, EVP_PKEY *pkey, CBB *cert_verify) | ||
| 2039 | { | ||
| 2040 | CBB cbb_signature; | ||
| 2041 | RSA *rsa; | ||
| 2042 | unsigned char data[EVP_MAX_MD_SIZE]; | ||
| 2043 | unsigned char *signature = NULL; | ||
| 2044 | unsigned int signature_len; | ||
| 2045 | size_t data_len; | ||
| 2046 | int ret = 0; | ||
| 2047 | |||
| 2048 | if (!tls1_transcript_hash_value(s, data, sizeof(data), &data_len)) | ||
| 2049 | goto err; | ||
| 2050 | if ((signature = calloc(1, EVP_PKEY_size(pkey))) == NULL) | ||
| 2051 | goto err; | ||
| 2052 | if ((rsa = EVP_PKEY_get0_RSA(pkey)) == NULL) | ||
| 2053 | goto err; | ||
| 2054 | if (RSA_sign(NID_md5_sha1, data, data_len, signature, &signature_len, | ||
| 2055 | rsa) <= 0 ) { | ||
| 2056 | SSLerror(s, ERR_R_RSA_LIB); | ||
| 2057 | goto err; | ||
| 2058 | } | ||
| 2059 | |||
| 2060 | if (!CBB_add_u16_length_prefixed(cert_verify, &cbb_signature)) | ||
| 2061 | goto err; | ||
| 2062 | if (!CBB_add_bytes(&cbb_signature, signature, signature_len)) | ||
| 2063 | goto err; | ||
| 2064 | if (!CBB_flush(cert_verify)) | ||
| 2065 | goto err; | ||
| 2066 | |||
| 2067 | ret = 1; | ||
| 2068 | err: | ||
| 2069 | free(signature); | ||
| 2070 | return ret; | ||
| 2071 | } | ||
| 2072 | |||
| 2073 | static int | ||
| 2074 | ssl3_send_client_verify_ec(SSL *s, EVP_PKEY *pkey, CBB *cert_verify) | ||
| 2075 | { | ||
| 2076 | CBB cbb_signature; | ||
| 2077 | EC_KEY *eckey; | ||
| 2078 | unsigned char data[EVP_MAX_MD_SIZE]; | ||
| 2079 | unsigned char *signature = NULL; | ||
| 2080 | unsigned int signature_len; | ||
| 2081 | int ret = 0; | ||
| 2082 | |||
| 2083 | if (!tls1_transcript_hash_value(s, data, sizeof(data), NULL)) | ||
| 2084 | goto err; | ||
| 2085 | if ((signature = calloc(1, EVP_PKEY_size(pkey))) == NULL) | ||
| 2086 | goto err; | ||
| 2087 | if ((eckey = EVP_PKEY_get0_EC_KEY(pkey)) == NULL) | ||
| 2088 | goto err; | ||
| 2089 | if (!ECDSA_sign(0, &data[MD5_DIGEST_LENGTH], SHA_DIGEST_LENGTH, | ||
| 2090 | signature, &signature_len, eckey)) { | ||
| 2091 | SSLerror(s, ERR_R_ECDSA_LIB); | ||
| 2092 | goto err; | ||
| 2093 | } | ||
| 2094 | |||
| 2095 | if (!CBB_add_u16_length_prefixed(cert_verify, &cbb_signature)) | ||
| 2096 | goto err; | ||
| 2097 | if (!CBB_add_bytes(&cbb_signature, signature, signature_len)) | ||
| 2098 | goto err; | ||
| 2099 | if (!CBB_flush(cert_verify)) | ||
| 2100 | goto err; | ||
| 2101 | |||
| 2102 | ret = 1; | ||
| 2103 | err: | ||
| 2104 | free(signature); | ||
| 2105 | return ret; | ||
| 2106 | } | ||
| 2107 | |||
| 2108 | static int | ||
| 2109 | ssl3_send_client_verify(SSL *s) | 2027 | ssl3_send_client_verify(SSL *s) |
| 2110 | { | 2028 | { |
| 2111 | const struct ssl_sigalg *sigalg; | 2029 | const struct ssl_sigalg *sigalg; |
| @@ -2130,20 +2048,9 @@ ssl3_send_client_verify(SSL *s) | |||
| 2130 | * For TLS v1.2 send signature algorithm and signature using | 2048 | * For TLS v1.2 send signature algorithm and signature using |
| 2131 | * agreed digest and cached handshake records. | 2049 | * agreed digest and cached handshake records. |
| 2132 | */ | 2050 | */ |
| 2133 | if (SSL_USE_SIGALGS(s)) { | 2051 | if (!ssl3_send_client_verify_sigalgs(s, pkey, sigalg, |
| 2134 | if (!ssl3_send_client_verify_sigalgs(s, pkey, sigalg, | 2052 | &cert_verify)) |
| 2135 | &cert_verify)) | ||
| 2136 | goto err; | ||
| 2137 | } else if (EVP_PKEY_id(pkey) == EVP_PKEY_RSA) { | ||
| 2138 | if (!ssl3_send_client_verify_rsa(s, pkey, &cert_verify)) | ||
| 2139 | goto err; | ||
| 2140 | } else if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) { | ||
| 2141 | if (!ssl3_send_client_verify_ec(s, pkey, &cert_verify)) | ||
| 2142 | goto err; | ||
| 2143 | } else { | ||
| 2144 | SSLerror(s, ERR_R_INTERNAL_ERROR); | ||
| 2145 | goto err; | 2053 | goto err; |
| 2146 | } | ||
| 2147 | 2054 | ||
| 2148 | tls1_transcript_free(s); | 2055 | tls1_transcript_free(s); |
| 2149 | 2056 | ||
| @@ -2352,11 +2259,8 @@ ssl3_send_client_change_cipher_spec(SSL *s) | |||
| 2352 | s->init_off = 0; | 2259 | s->init_off = 0; |
| 2353 | 2260 | ||
| 2354 | if (SSL_is_dtls(s)) { | 2261 | if (SSL_is_dtls(s)) { |
| 2355 | s->d1->handshake_write_seq = | 2262 | if (!dtls12_ccs_built(s)) |
| 2356 | s->d1->next_handshake_write_seq; | 2263 | goto err; |
| 2357 | dtls1_set_message_header_int(s, SSL3_MT_CCS, 0, | ||
| 2358 | s->d1->handshake_write_seq, 0, 0); | ||
| 2359 | dtls1_buffer_message(s, 1); | ||
| 2360 | } | 2264 | } |
| 2361 | 2265 | ||
| 2362 | s->s3->hs.state = SSL3_ST_CW_CHANGE_B; | 2266 | s->s3->hs.state = SSL3_ST_CW_CHANGE_B; |
| @@ -2444,7 +2348,8 @@ ssl3_get_server_finished(SSL *s) | |||
| 2444 | goto fatal_err; | 2348 | goto fatal_err; |
| 2445 | } | 2349 | } |
| 2446 | 2350 | ||
| 2447 | if (!CBS_mem_equal(&cbs, s->s3->hs.peer_finished, CBS_len(&cbs))) { | 2351 | if (!CBS_mem_equal(&cbs, |
| 2352 | s->s3->hs.peer_finished, s->s3->hs.peer_finished_len)) { | ||
| 2448 | al = SSL_AD_DECRYPT_ERROR; | 2353 | al = SSL_AD_DECRYPT_ERROR; |
| 2449 | SSLerror(s, SSL_R_DIGEST_CHECK_FAILED); | 2354 | SSLerror(s, SSL_R_DIGEST_CHECK_FAILED); |
| 2450 | goto fatal_err; | 2355 | goto fatal_err; |
