summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2018-05-19 14:17:55 +0000
committerjsing <>2018-05-19 14:17:55 +0000
commitd404c2a1e5706326d4083e7a61f5050dc8cee8f3 (patch)
treec590f5b52b44abb1962d30b563ca77e1c76f890c /src
parent4ebb5ac1e53c979d397ecd492fe6929b1d0f3a7c (diff)
downloadopenbsd-d404c2a1e5706326d4083e7a61f5050dc8cee8f3.tar.gz
openbsd-d404c2a1e5706326d4083e7a61f5050dc8cee8f3.tar.bz2
openbsd-d404c2a1e5706326d4083e7a61f5050dc8cee8f3.zip
Convert ssl3_get_client_kex_gost() to CBS.
ok beck@ tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/ssl_srvr.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c
index 3da9cacd7d..94e263ad3c 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.30 2018/05/13 15:51:29 jsing Exp $ */ 1/* $OpenBSD: ssl_srvr.c,v 1.31 2018/05/19 14:17:55 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 *
@@ -2073,24 +2073,30 @@ ssl3_get_client_kex_ecdhe(SSL *s, unsigned char *p, long n)
2073static int 2073static int
2074ssl3_get_client_kex_gost(SSL *s, unsigned char *p, long n) 2074ssl3_get_client_kex_gost(SSL *s, unsigned char *p, long n)
2075{ 2075{
2076
2077 EVP_PKEY_CTX *pkey_ctx; 2076 EVP_PKEY_CTX *pkey_ctx;
2078 EVP_PKEY *client_pub_pkey = NULL, *pk = NULL; 2077 EVP_PKEY *client_pub_pkey = NULL, *pk = NULL;
2079 unsigned char premaster_secret[32], *start; 2078 unsigned char premaster_secret[32];
2080 size_t outlen = 32, inlen;
2081 unsigned long alg_a; 2079 unsigned long alg_a;
2082 int Ttag, Tclass; 2080 size_t outlen = 32;
2083 long Tlen; 2081 CBS cbs, gostblob;
2084 int al; 2082 int al;
2085 int ret = 0; 2083 int ret = 0;
2086 2084
2085 if (n < 0)
2086 goto err;
2087
2088 CBS_init(&cbs, p, n);
2089
2087 /* Get our certificate private key*/ 2090 /* Get our certificate private key*/
2088 alg_a = S3I(s)->hs.new_cipher->algorithm_auth; 2091 alg_a = S3I(s)->hs.new_cipher->algorithm_auth;
2089 if (alg_a & SSL_aGOST01) 2092 if (alg_a & SSL_aGOST01)
2090 pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey; 2093 pk = s->cert->pkeys[SSL_PKEY_GOST01].privatekey;
2091 2094
2092 pkey_ctx = EVP_PKEY_CTX_new(pk, NULL); 2095 if ((pkey_ctx = EVP_PKEY_CTX_new(pk, NULL)) == NULL)
2093 EVP_PKEY_decrypt_init(pkey_ctx); 2096 goto err;
2097 if (EVP_PKEY_decrypt_init(pkey_ctx) <= 0)
2098 goto gerr;
2099
2094 /* 2100 /*
2095 * If client certificate is present and is of the same type, 2101 * If client certificate is present and is of the same type,
2096 * maybe use it for key exchange. 2102 * maybe use it for key exchange.
@@ -2098,32 +2104,28 @@ ssl3_get_client_kex_gost(SSL *s, unsigned char *p, long n)
2098 * it is completely valid to use a client certificate for 2104 * it is completely valid to use a client certificate for
2099 * authorization only. 2105 * authorization only.
2100 */ 2106 */
2101 client_pub_pkey = X509_get_pubkey(s->session->peer); 2107 if ((client_pub_pkey = X509_get_pubkey(s->session->peer)) != NULL) {
2102 if (client_pub_pkey) {
2103 if (EVP_PKEY_derive_set_peer(pkey_ctx, 2108 if (EVP_PKEY_derive_set_peer(pkey_ctx,
2104 client_pub_pkey) <= 0) 2109 client_pub_pkey) <= 0)
2105 ERR_clear_error(); 2110 ERR_clear_error();
2106 } 2111 }
2107 if (2 > n) 2112
2108 goto truncated;
2109 /* Decrypt session key */ 2113 /* Decrypt session key */
2110 if (ASN1_get_object((const unsigned char **)&p, &Tlen, &Ttag, 2114 if (!CBS_get_asn1(&cbs, &gostblob, CBS_ASN1_SEQUENCE))
2111 &Tclass, n) != V_ASN1_CONSTRUCTED || 2115 goto truncated;
2112 Ttag != V_ASN1_SEQUENCE || Tclass != V_ASN1_UNIVERSAL) { 2116 if (CBS_len(&cbs) != 0)
2113 SSLerror(s, SSL_R_DECRYPTION_FAILED); 2117 goto truncated;
2114 goto gerr;
2115 }
2116 start = p;
2117 inlen = Tlen;
2118 if (EVP_PKEY_decrypt(pkey_ctx, premaster_secret, &outlen, 2118 if (EVP_PKEY_decrypt(pkey_ctx, premaster_secret, &outlen,
2119 start, inlen) <=0) { 2119 CBS_data(&gostblob), CBS_len(&gostblob)) <= 0) {
2120 SSLerror(s, SSL_R_DECRYPTION_FAILED); 2120 SSLerror(s, SSL_R_DECRYPTION_FAILED);
2121 goto gerr; 2121 goto gerr;
2122 } 2122 }
2123
2123 /* Generate master secret */ 2124 /* Generate master secret */
2124 s->session->master_key_length = 2125 s->session->master_key_length =
2125 tls1_generate_master_secret( 2126 tls1_generate_master_secret(
2126 s, s->session->master_key, premaster_secret, 32); 2127 s, s->session->master_key, premaster_secret, 32);
2128
2127 /* Check if pubkey from client certificate was used */ 2129 /* Check if pubkey from client certificate was used */
2128 if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, -1, 2130 if (EVP_PKEY_CTX_ctrl(pkey_ctx, -1, -1,
2129 EVP_PKEY_CTRL_PEER_KEY, 2, NULL) > 0) 2131 EVP_PKEY_CTRL_PEER_KEY, 2, NULL) > 0)