Skip to content

Commit bc71f91

Browse files
committed
Remove fixed DH ciphersuites.
Remove all fixed DH ciphersuites and associated logic. Reviewed-by: Matt Caswell <matt@openssl.org>
1 parent 74a62e9 commit bc71f91

10 files changed

+64
-656
lines changed

ssl/s3_lib.c

+1-399
Large diffs are not rendered by default.

ssl/ssl_ciph.c

+2-21
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,9 @@ static const SSL_CIPHER cipher_aliases[] = {
306306
*/
307307
{0, SSL_TXT_kRSA, 0, SSL_kRSA, 0, 0, 0, 0, 0, 0, 0, 0},
308308

309-
{0, SSL_TXT_kDHr, 0, SSL_kDHr, 0, 0, 0, 0, 0, 0, 0, 0},
310-
{0, SSL_TXT_kDHd, 0, SSL_kDHd, 0, 0, 0, 0, 0, 0, 0, 0},
311-
{0, SSL_TXT_kDH, 0, SSL_kDHr | SSL_kDHd, 0, 0, 0, 0, 0, 0, 0, 0},
312309
{0, SSL_TXT_kEDH, 0, SSL_kDHE, 0, 0, 0, 0, 0, 0, 0, 0},
313310
{0, SSL_TXT_kDHE, 0, SSL_kDHE, 0, 0, 0, 0, 0, 0, 0, 0},
314-
{0, SSL_TXT_DH, 0, SSL_kDHr | SSL_kDHd | SSL_kDHE, 0, 0, 0, 0, 0, 0, 0,
311+
{0, SSL_TXT_DH, 0, SSL_kDHE, 0, 0, 0, 0, 0, 0, 0,
315312
0},
316313

317314
{0, SSL_TXT_kECDHr, 0, SSL_kECDHr, 0, 0, 0, 0, 0, 0, 0, 0},
@@ -334,8 +331,6 @@ static const SSL_CIPHER cipher_aliases[] = {
334331
{0, SSL_TXT_aDSS, 0, 0, SSL_aDSS, 0, 0, 0, 0, 0, 0, 0},
335332
{0, SSL_TXT_DSS, 0, 0, SSL_aDSS, 0, 0, 0, 0, 0, 0, 0},
336333
{0, SSL_TXT_aNULL, 0, 0, SSL_aNULL, 0, 0, 0, 0, 0, 0, 0},
337-
/* no such ciphersuites supported! */
338-
{0, SSL_TXT_aDH, 0, 0, SSL_aDH, 0, 0, 0, 0, 0, 0, 0},
339334
{0, SSL_TXT_aECDH, 0, 0, SSL_aECDH, 0, 0, 0, 0, 0, 0, 0},
340335
{0, SSL_TXT_aECDSA, 0, 0, SSL_aECDSA, 0, 0, 0, 0, 0, 0, 0},
341336
{0, SSL_TXT_ECDSA, 0, 0, SSL_aECDSA, 0, 0, 0, 0, 0, 0, 0},
@@ -506,8 +501,7 @@ void ssl_load_ciphers(void)
506501
disabled_auth_mask |= SSL_aDSS;
507502
#endif
508503
#ifdef OPENSSL_NO_DH
509-
disabled_mkey_mask |= SSL_kDHr | SSL_kDHd | SSL_kDHE | SSL_kDHEPSK;
510-
disabled_auth_mask |= SSL_aDH;
504+
disabled_mkey_mask |= SSL_kDHE | SSL_kDHEPSK;
511505
#endif
512506
#ifdef OPENSSL_NO_EC
513507
disabled_mkey_mask |= SSL_kECDHe | SSL_kECDHr | SSL_kECDHEPSK;
@@ -1614,12 +1608,6 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
16141608
case SSL_kRSA:
16151609
kx = "RSA";
16161610
break;
1617-
case SSL_kDHr:
1618-
kx = "DH/RSA";
1619-
break;
1620-
case SSL_kDHd:
1621-
kx = "DH/DSS";
1622-
break;
16231611
case SSL_kDHE:
16241612
kx = "DH";
16251613
break;
@@ -1661,9 +1649,6 @@ char *SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
16611649
case SSL_aDSS:
16621650
au = "DSS";
16631651
break;
1664-
case SSL_aDH:
1665-
au = "DH";
1666-
break;
16671652
case SSL_aECDH:
16681653
au = "ECDH";
16691654
break;
@@ -1980,10 +1965,6 @@ int ssl_cipher_get_cert_index(const SSL_CIPHER *c)
19801965
return SSL_PKEY_ECC;
19811966
} else if (alg_a & SSL_aECDSA)
19821967
return SSL_PKEY_ECC;
1983-
else if (alg_k & SSL_kDHr)
1984-
return SSL_PKEY_DH_RSA;
1985-
else if (alg_k & SSL_kDHd)
1986-
return SSL_PKEY_DH_DSA;
19871968
else if (alg_a & SSL_aDSS)
19881969
return SSL_PKEY_DSA_SIGN;
19891970
else if (alg_a & SSL_aRSA)

ssl/ssl_lib.c

+1-12
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,7 @@ void ssl_set_masks(SSL *s, const SSL_CIPHER *cipher)
20062006
#endif
20072007
CERT *c = s->cert;
20082008
uint32_t *pvalid = s->s3->tmp.valid_flags;
2009-
int rsa_enc, rsa_sign, dh_tmp, dh_rsa, dh_dsa, dsa_sign;
2009+
int rsa_enc, rsa_sign, dh_tmp, dsa_sign;
20102010
unsigned long mask_k, mask_a;
20112011
#ifndef OPENSSL_NO_EC
20122012
int have_ecc_cert, ecdsa_ok;
@@ -2026,8 +2026,6 @@ void ssl_set_masks(SSL *s, const SSL_CIPHER *cipher)
20262026
rsa_enc = pvalid[SSL_PKEY_RSA_ENC] & CERT_PKEY_VALID;
20272027
rsa_sign = pvalid[SSL_PKEY_RSA_SIGN] & CERT_PKEY_SIGN;
20282028
dsa_sign = pvalid[SSL_PKEY_DSA_SIGN] & CERT_PKEY_SIGN;
2029-
dh_rsa = pvalid[SSL_PKEY_DH_RSA] & CERT_PKEY_VALID;
2030-
dh_dsa = pvalid[SSL_PKEY_DH_DSA] & CERT_PKEY_VALID;
20312029
#ifndef OPENSSL_NO_EC
20322030
have_ecc_cert = pvalid[SSL_PKEY_ECC] & CERT_PKEY_VALID;
20332031
#endif
@@ -2064,15 +2062,6 @@ void ssl_set_masks(SSL *s, const SSL_CIPHER *cipher)
20642062
if (dh_tmp)
20652063
mask_k |= SSL_kDHE;
20662064

2067-
if (dh_rsa)
2068-
mask_k |= SSL_kDHr;
2069-
2070-
if (dh_dsa)
2071-
mask_k |= SSL_kDHd;
2072-
2073-
if (mask_k & (SSL_kDHr | SSL_kDHd))
2074-
mask_a |= SSL_aDH;
2075-
20762065
if (rsa_enc || rsa_sign) {
20772066
mask_a |= SSL_aRSA;
20782067
}

ssl/ssl_locl.h

+21-29
Original file line numberDiff line numberDiff line change
@@ -295,32 +295,28 @@
295295
/* Bits for algorithm_mkey (key exchange algorithm) */
296296
/* RSA key exchange */
297297
# define SSL_kRSA 0x00000001U
298-
/* DH cert, RSA CA cert */
299-
# define SSL_kDHr 0x00000002U
300-
/* DH cert, DSA CA cert */
301-
# define SSL_kDHd 0x00000004U
302298
/* tmp DH key no DH cert */
303-
# define SSL_kDHE 0x00000008U
299+
# define SSL_kDHE 0x00000002U
304300
/* synonym */
305301
# define SSL_kEDH SSL_kDHE
306302
/* ECDH cert, RSA CA cert */
307-
# define SSL_kECDHr 0x00000020U
303+
# define SSL_kECDHr 0x00000004U
308304
/* ECDH cert, ECDSA CA cert */
309-
# define SSL_kECDHe 0x00000040U
305+
# define SSL_kECDHe 0x00000008U
310306
/* ephemeral ECDH */
311-
# define SSL_kECDHE 0x00000080U
307+
# define SSL_kECDHE 0x00000010U
312308
/* synonym */
313309
# define SSL_kEECDH SSL_kECDHE
314310
/* PSK */
315-
# define SSL_kPSK 0x00000100U
311+
# define SSL_kPSK 0x00000020U
316312
/* GOST key exchange */
317-
# define SSL_kGOST 0x00000200U
313+
# define SSL_kGOST 0x00000040U
318314
/* SRP */
319-
# define SSL_kSRP 0x00000400U
315+
# define SSL_kSRP 0x00000080U
320316

321-
# define SSL_kRSAPSK 0x00000800U
322-
# define SSL_kECDHEPSK 0x00001000U
323-
# define SSL_kDHEPSK 0x00002000U
317+
# define SSL_kRSAPSK 0x00000100U
318+
# define SSL_kECDHEPSK 0x00000200U
319+
# define SSL_kDHEPSK 0x00000400U
324320

325321
/* all PSK */
326322

@@ -333,20 +329,18 @@
333329
# define SSL_aDSS 0x00000002U
334330
/* no auth (i.e. use ADH or AECDH) */
335331
# define SSL_aNULL 0x00000004U
336-
/* Fixed DH auth (kDHd or kDHr) */
337-
# define SSL_aDH 0x00000008U
338332
/* Fixed ECDH auth (kECDHe or kECDHr) */
339-
# define SSL_aECDH 0x00000010U
333+
# define SSL_aECDH 0x00000008U
340334
/* ECDSA auth*/
341-
# define SSL_aECDSA 0x00000040U
335+
# define SSL_aECDSA 0x00000010U
342336
/* PSK auth */
343-
# define SSL_aPSK 0x00000080U
337+
# define SSL_aPSK 0x00000020U
344338
/* GOST R 34.10-2001 signature auth */
345-
# define SSL_aGOST01 0x00000200U
339+
# define SSL_aGOST01 0x00000040U
346340
/* SRP auth */
347-
# define SSL_aSRP 0x00000400U
341+
# define SSL_aSRP 0x00000080U
348342
/* GOST R 34.10-2012 signature auth */
349-
# define SSL_aGOST12 0x00000800U
343+
# define SSL_aGOST12 0x00000100U
350344

351345
/* Bits for algorithm_enc (symmetric encryption) */
352346
# define SSL_DES 0x00000001U
@@ -485,13 +479,11 @@
485479
# define SSL_PKEY_RSA_ENC 0
486480
# define SSL_PKEY_RSA_SIGN 1
487481
# define SSL_PKEY_DSA_SIGN 2
488-
# define SSL_PKEY_DH_RSA 3
489-
# define SSL_PKEY_DH_DSA 4
490-
# define SSL_PKEY_ECC 5
491-
# define SSL_PKEY_GOST01 7
492-
# define SSL_PKEY_GOST12_256 8
493-
# define SSL_PKEY_GOST12_512 9
494-
# define SSL_PKEY_NUM 10
482+
# define SSL_PKEY_ECC 3
483+
# define SSL_PKEY_GOST01 4
484+
# define SSL_PKEY_GOST12_256 5
485+
# define SSL_PKEY_GOST12_512 6
486+
# define SSL_PKEY_NUM 7
495487
/*
496488
* Pseudo-constant. GOST cipher suites can use different certs for 1
497489
* SSL_CIPHER. So let's see which one we have in fact.

ssl/ssl_rsa.c

+1-16
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,7 @@ int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa)
171171
static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey)
172172
{
173173
int i;
174-
/*
175-
* Special case for DH: check two DH certificate types for a match. This
176-
* means for DH certificates we must set the certificate first.
177-
*/
178-
if (pkey->type == EVP_PKEY_DH) {
179-
X509 *x;
180-
i = -1;
181-
x = c->pkeys[SSL_PKEY_DH_RSA].x509;
182-
if (x && X509_check_private_key(x, pkey))
183-
i = SSL_PKEY_DH_RSA;
184-
x = c->pkeys[SSL_PKEY_DH_DSA].x509;
185-
if (i == -1 && x && X509_check_private_key(x, pkey))
186-
i = SSL_PKEY_DH_DSA;
187-
ERR_clear_error();
188-
} else
189-
i = ssl_cert_type(NULL, pkey);
174+
i = ssl_cert_type(NULL, pkey);
190175
if (i < 0) {
191176
SSLerr(SSL_F_SSL_SET_PKEY, SSL_R_UNKNOWN_CERTIFICATE_TYPE);
192177
return (0);

ssl/statem/statem_clnt.c

+20-82
Original file line numberDiff line numberDiff line change
@@ -2390,47 +2390,23 @@ int tls_construct_client_key_exchange(SSL *s)
23902390
}
23912391
#endif
23922392
#ifndef OPENSSL_NO_DH
2393-
else if (alg_k & (SSL_kDHE | SSL_kDHr | SSL_kDHd | SSL_kDHEPSK)) {
2393+
else if (alg_k & (SSL_kDHE | SSL_kDHEPSK)) {
23942394
DH *dh_srvr, *dh_clnt;
2395-
if (s->s3->peer_dh_tmp != NULL)
2396-
dh_srvr = s->s3->peer_dh_tmp;
2397-
else {
2398-
/* we get them from the cert */
2399-
EVP_PKEY *spkey = NULL;
2400-
dh_srvr = NULL;
2401-
spkey = X509_get_pubkey(s->session->peer);
2402-
if (spkey) {
2403-
dh_srvr = EVP_PKEY_get1_DH(spkey);
2404-
EVP_PKEY_free(spkey);
2405-
}
2406-
if (dh_srvr == NULL) {
2407-
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE,
2408-
ERR_R_INTERNAL_ERROR);
2409-
goto err;
2410-
}
2395+
if (s->s3->peer_dh_tmp == NULL) {
2396+
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE,
2397+
ERR_R_INTERNAL_ERROR);
2398+
goto err;
24112399
}
2412-
if (s->s3->flags & TLS1_FLAGS_SKIP_CERT_VERIFY) {
2413-
/* Use client certificate key */
2414-
EVP_PKEY *clkey = s->cert->key->privatekey;
2415-
dh_clnt = NULL;
2416-
if (clkey)
2417-
dh_clnt = EVP_PKEY_get1_DH(clkey);
2418-
if (dh_clnt == NULL) {
2419-
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE,
2420-
ERR_R_INTERNAL_ERROR);
2421-
goto err;
2422-
}
2423-
} else {
2424-
/* generate a new random key */
2425-
if ((dh_clnt = DHparams_dup(dh_srvr)) == NULL) {
2426-
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE, ERR_R_DH_LIB);
2427-
goto err;
2428-
}
2429-
if (!DH_generate_key(dh_clnt)) {
2430-
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE, ERR_R_DH_LIB);
2431-
DH_free(dh_clnt);
2432-
goto err;
2433-
}
2400+
dh_srvr = s->s3->peer_dh_tmp;
2401+
/* generate a new random key */
2402+
if ((dh_clnt = DHparams_dup(dh_srvr)) == NULL) {
2403+
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE, ERR_R_DH_LIB);
2404+
goto err;
2405+
}
2406+
if (!DH_generate_key(dh_clnt)) {
2407+
SSLerr(SSL_F_TLS_CONSTRUCT_CLIENT_KEY_EXCHANGE, ERR_R_DH_LIB);
2408+
DH_free(dh_clnt);
2409+
goto err;
24342410
}
24352411

24362412
pmslen = DH_size(dh_clnt);
@@ -2454,15 +2430,11 @@ int tls_construct_client_key_exchange(SSL *s)
24542430
}
24552431
pmslen = n;
24562432

2457-
if (s->s3->flags & TLS1_FLAGS_SKIP_CERT_VERIFY)
2458-
n = 0;
2459-
else {
2460-
/* send off the data */
2461-
n = BN_num_bytes(dh_clnt->pub_key);
2462-
s2n(n, p);
2463-
BN_bn2bin(dh_clnt->pub_key, p);
2464-
n += 2;
2465-
}
2433+
/* send off the data */
2434+
n = BN_num_bytes(dh_clnt->pub_key);
2435+
s2n(n, p);
2436+
BN_bn2bin(dh_clnt->pub_key, p);
2437+
n += 2;
24662438

24672439
DH_free(dh_clnt);
24682440
}
@@ -2841,7 +2813,6 @@ int tls_construct_client_verify(SSL *s)
28412813
*/
28422814
static int ssl3_check_client_certificate(SSL *s)
28432815
{
2844-
unsigned long alg_k;
28452816
if (!s->cert || !s->cert->key->x509 || !s->cert->key->privatekey)
28462817
return 0;
28472818
/* If no suitable signature algorithm can't use certificate */
@@ -2854,26 +2825,6 @@ static int ssl3_check_client_certificate(SSL *s)
28542825
if (s->cert->cert_flags & SSL_CERT_FLAGS_CHECK_TLS_STRICT &&
28552826
!tls1_check_chain(s, NULL, NULL, NULL, -2))
28562827
return 0;
2857-
alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
2858-
/* See if we can use client certificate for fixed DH */
2859-
if (alg_k & (SSL_kDHr | SSL_kDHd)) {
2860-
int i = s->session->peer_type;
2861-
EVP_PKEY *clkey = NULL, *spkey = NULL;
2862-
clkey = s->cert->key->privatekey;
2863-
/* If client key not DH assume it can be used */
2864-
if (EVP_PKEY_id(clkey) != EVP_PKEY_DH)
2865-
return 1;
2866-
if (i >= 0)
2867-
spkey = X509_get_pubkey(s->session->peer);
2868-
if (spkey) {
2869-
/* Compare server and client parameters */
2870-
i = EVP_PKEY_cmp_parameters(clkey, spkey);
2871-
EVP_PKEY_free(spkey);
2872-
if (i != 1)
2873-
return 0;
2874-
}
2875-
s->s3->flags |= TLS1_FLAGS_SKIP_CERT_VERIFY;
2876-
}
28772828
return 1;
28782829
}
28792830

@@ -3042,20 +2993,7 @@ int ssl3_check_cert_and_algorithm(SSL *s)
30422993
al = SSL_AD_INTERNAL_ERROR;
30432994
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM, ERR_R_INTERNAL_ERROR);
30442995
goto f_err;
3045-
} else if ((alg_k & SSL_kDHr) && !SSL_USE_SIGALGS(s) &&
3046-
!has_bits(i, EVP_PK_DH | EVP_PKS_RSA)) {
3047-
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
3048-
SSL_R_MISSING_DH_RSA_CERT);
3049-
goto f_err;
30502996
}
3051-
# ifndef OPENSSL_NO_DSA
3052-
else if ((alg_k & SSL_kDHd) && !SSL_USE_SIGALGS(s) &&
3053-
!has_bits(i, EVP_PK_DH | EVP_PKS_DSA)) {
3054-
SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,
3055-
SSL_R_MISSING_DH_DSA_CERT);
3056-
goto f_err;
3057-
}
3058-
# endif
30592997
#endif
30602998

30612999
return (1);

ssl/statem/statem_lib.c

-11
Original file line numberDiff line numberDiff line change
@@ -632,17 +632,6 @@ int ssl_cert_type(X509 *x, EVP_PKEY *pkey)
632632
ret = SSL_PKEY_GOST12_512;
633633
}
634634
#endif
635-
else if (x && (i == EVP_PKEY_DH || i == EVP_PKEY_DHX)) {
636-
/*
637-
* For DH two cases: DH certificate signed with RSA and DH
638-
* certificate signed with DSA.
639-
*/
640-
i = X509_certificate_type(x, pk);
641-
if (i & EVP_PKS_RSA)
642-
ret = SSL_PKEY_DH_RSA;
643-
else if (i & EVP_PKS_DSA)
644-
ret = SSL_PKEY_DH_DSA;
645-
}
646635

647636
err:
648637
if (!pkey)

0 commit comments

Comments
 (0)