diff options
Diffstat (limited to 'src/lib/libssl/ssl_srvr.c')
-rw-r--r-- | src/lib/libssl/ssl_srvr.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c index 1f6753fdf4..0979750e22 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.136 2022/01/09 15:34:21 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_srvr.c,v 1.137 2022/01/09 15:40:13 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 | * |
@@ -1769,23 +1769,21 @@ ssl3_get_client_kex_ecdhe(SSL *s, CBS *cbs) | |||
1769 | static int | 1769 | static int |
1770 | ssl3_get_client_kex_gost(SSL *s, CBS *cbs) | 1770 | ssl3_get_client_kex_gost(SSL *s, CBS *cbs) |
1771 | { | 1771 | { |
1772 | EVP_PKEY_CTX *pkey_ctx; | ||
1773 | EVP_PKEY *client_pub_pkey = NULL, *pk = NULL; | ||
1774 | unsigned char premaster_secret[32]; | 1772 | unsigned char premaster_secret[32]; |
1775 | unsigned long alg_a; | 1773 | EVP_PKEY_CTX *pkey_ctx = NULL; |
1776 | size_t outlen = 32; | 1774 | EVP_PKEY *client_pubkey; |
1775 | EVP_PKEY *pkey = NULL; | ||
1776 | size_t outlen; | ||
1777 | CBS gostblob; | 1777 | CBS gostblob; |
1778 | int al; | ||
1779 | 1778 | ||
1780 | /* Get our certificate private key*/ | 1779 | /* Get our certificate private key*/ |
1781 | alg_a = S3I(s)->hs.cipher->algorithm_auth; | 1780 | if ((S3I(s)->hs.cipher->algorithm_auth & SSL_aGOST01) != 0) |
1782 | if (alg_a & SSL_aGOST01) | 1781 | pkey = s->cert->pkeys[SSL_PKEY_GOST01].privatekey; |
1783 | pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey; | ||
1784 | 1782 | ||
1785 | if ((pkey_ctx = EVP_PKEY_CTX_new(pk, NULL)) == NULL) | 1783 | if ((pkey_ctx = EVP_PKEY_CTX_new(pkey, NULL)) == NULL) |
1786 | goto err; | 1784 | goto err; |
1787 | if (EVP_PKEY_decrypt_init(pkey_ctx) <= 0) | 1785 | if (EVP_PKEY_decrypt_init(pkey_ctx) <= 0) |
1788 | goto gerr; | 1786 | goto err; |
1789 | 1787 | ||
1790 | /* | 1788 | /* |
1791 | * If client certificate is present and is of the same type, | 1789 | * If client certificate is present and is of the same type, |
@@ -1794,9 +1792,8 @@ ssl3_get_client_kex_gost(SSL *s, CBS *cbs) | |||
1794 | * it is completely valid to use a client certificate for | 1792 | * it is completely valid to use a client certificate for |
1795 | * authorization only. | 1793 | * authorization only. |
1796 | */ | 1794 | */ |
1797 | if ((client_pub_pkey = X509_get_pubkey(s->session->peer)) != NULL) { | 1795 | if ((client_pubkey = X509_get0_pubkey(s->session->peer)) != NULL) { |
1798 | if (EVP_PKEY_derive_set_peer(pkey_ctx, | 1796 | if (EVP_PKEY_derive_set_peer(pkey_ctx, client_pubkey) <= 0) |
1799 | client_pub_pkey) <= 0) | ||
1800 | ERR_clear_error(); | 1797 | ERR_clear_error(); |
1801 | } | 1798 | } |
1802 | 1799 | ||
@@ -1805,13 +1802,15 @@ ssl3_get_client_kex_gost(SSL *s, CBS *cbs) | |||
1805 | goto decode_err; | 1802 | goto decode_err; |
1806 | if (CBS_len(cbs) != 0) | 1803 | if (CBS_len(cbs) != 0) |
1807 | goto decode_err; | 1804 | goto decode_err; |
1805 | outlen = sizeof(premaster_secret); | ||
1808 | if (EVP_PKEY_decrypt(pkey_ctx, premaster_secret, &outlen, | 1806 | if (EVP_PKEY_decrypt(pkey_ctx, premaster_secret, &outlen, |
1809 | CBS_data(&gostblob), CBS_len(&gostblob)) <= 0) { | 1807 | CBS_data(&gostblob), CBS_len(&gostblob)) <= 0) { |
1810 | SSLerror(s, SSL_R_DECRYPTION_FAILED); | 1808 | SSLerror(s, SSL_R_DECRYPTION_FAILED); |
1811 | goto gerr; | 1809 | goto err; |
1812 | } | 1810 | } |
1813 | 1811 | ||
1814 | if (!tls12_derive_master_secret(s, premaster_secret, 32)) | 1812 | if (!tls12_derive_master_secret(s, premaster_secret, |
1813 | sizeof(premaster_secret))) | ||
1815 | goto err; | 1814 | goto err; |
1816 | 1815 | ||
1817 | /* Check if pubkey from client certificate was used */ | 1816 | /* Check if pubkey from client certificate was used */ |
@@ -1819,17 +1818,18 @@ ssl3_get_client_kex_gost(SSL *s, CBS *cbs) | |||
1819 | 2, NULL) > 0) | 1818 | 2, NULL) > 0) |
1820 | s->s3->flags |= TLS1_FLAGS_SKIP_CERT_VERIFY; | 1819 | s->s3->flags |= TLS1_FLAGS_SKIP_CERT_VERIFY; |
1821 | 1820 | ||
1822 | gerr: | 1821 | explicit_bzero(premaster_secret, sizeof(premaster_secret)); |
1823 | EVP_PKEY_free(client_pub_pkey); | ||
1824 | EVP_PKEY_CTX_free(pkey_ctx); | 1822 | EVP_PKEY_CTX_free(pkey_ctx); |
1825 | 1823 | ||
1826 | return 1; | 1824 | return 1; |
1827 | 1825 | ||
1828 | decode_err: | 1826 | decode_err: |
1829 | al = SSL_AD_DECODE_ERROR; | ||
1830 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); | 1827 | SSLerror(s, SSL_R_BAD_PACKET_LENGTH); |
1831 | ssl3_send_alert(s, SSL3_AL_FATAL, al); | 1828 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR); |
1832 | err: | 1829 | err: |
1830 | explicit_bzero(premaster_secret, sizeof(premaster_secret)); | ||
1831 | EVP_PKEY_CTX_free(pkey_ctx); | ||
1832 | |||
1833 | return 0; | 1833 | return 0; |
1834 | } | 1834 | } |
1835 | 1835 | ||