diff options
| author | tb <> | 2022-06-29 08:27:52 +0000 |
|---|---|---|
| committer | tb <> | 2022-06-29 08:27:52 +0000 |
| commit | d514ed3f0a5ed2d924983d4533a179823bf09ca0 (patch) | |
| tree | 737bede5c25ec5b6855578423751b08517e50653 /src | |
| parent | 24c464130eda826952b6d98e975e3dd7c8181b84 (diff) | |
| download | openbsd-d514ed3f0a5ed2d924983d4533a179823bf09ca0.tar.gz openbsd-d514ed3f0a5ed2d924983d4533a179823bf09ca0.tar.bz2 openbsd-d514ed3f0a5ed2d924983d4533a179823bf09ca0.zip | |
Check the security of DH key shares
ok beck, looks good to jsing
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libssl/ssl_clnt.c | 8 | ||||
| -rw-r--r-- | src/lib/libssl/ssl_locl.h | 3 | ||||
| -rw-r--r-- | src/lib/libssl/ssl_seclevel.c | 13 | ||||
| -rw-r--r-- | src/lib/libssl/ssl_srvr.c | 8 | ||||
| -rw-r--r-- | src/lib/libssl/tls_internal.h | 3 | ||||
| -rw-r--r-- | src/lib/libssl/tls_key_share.c | 13 |
6 files changed, 42 insertions, 6 deletions
diff --git a/src/lib/libssl/ssl_clnt.c b/src/lib/libssl/ssl_clnt.c index c509771cc3..5291175235 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.146 2022/06/07 17:45:13 tb Exp $ */ | 1 | /* $OpenBSD: ssl_clnt.c,v 1.147 2022/06/29 08:27:51 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 | * |
| @@ -1248,6 +1248,12 @@ ssl3_get_server_kex_dhe(SSL *s, CBS *cbs) | |||
| 1248 | goto err; | 1248 | goto err; |
| 1249 | } | 1249 | } |
| 1250 | 1250 | ||
| 1251 | if (!tls_key_share_peer_security(s, s->s3->hs.key_share)) { | ||
| 1252 | SSLerror(s, SSL_R_DH_KEY_TOO_SMALL); | ||
| 1253 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); | ||
| 1254 | return 0; | ||
| 1255 | } | ||
| 1256 | |||
| 1251 | return 1; | 1257 | return 1; |
| 1252 | 1258 | ||
| 1253 | err: | 1259 | err: |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index ed033abc91..f198c4b035 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ssl_locl.h,v 1.398 2022/06/29 07:59:14 tb Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.399 2022/06/29 08:27:51 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 | * |
| @@ -1290,6 +1290,7 @@ int ssl_security_dummy_cb(const SSL *ssl, const SSL_CTX *ctx, int op, | |||
| 1290 | int ssl_ctx_security(const SSL_CTX *ctx, int op, int bits, int nid, | 1290 | int ssl_ctx_security(const SSL_CTX *ctx, int op, int bits, int nid, |
| 1291 | void *other); | 1291 | void *other); |
| 1292 | int ssl_security(const SSL *ssl, int op, int bits, int nid, void * other); | 1292 | int ssl_security(const SSL *ssl, int op, int bits, int nid, void * other); |
| 1293 | int ssl_security_dh(const SSL *ssl, DH *dh); | ||
| 1293 | 1294 | ||
| 1294 | int ssl_get_new_session(SSL *s, int session); | 1295 | int ssl_get_new_session(SSL *s, int session); |
| 1295 | int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, | 1296 | int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, |
diff --git a/src/lib/libssl/ssl_seclevel.c b/src/lib/libssl/ssl_seclevel.c index 6c788c205d..34cea637e0 100644 --- a/src/lib/libssl/ssl_seclevel.c +++ b/src/lib/libssl/ssl_seclevel.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ssl_seclevel.c,v 1.5 2022/06/28 20:54:16 tb Exp $ */ | 1 | /* $OpenBSD: ssl_seclevel.c,v 1.6 2022/06/29 08:27:51 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2020 Theo Buehler <tb@openbsd.org> | 3 | * Copyright (c) 2020 Theo Buehler <tb@openbsd.org> |
| 4 | * | 4 | * |
| @@ -17,6 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | #include <stddef.h> | 18 | #include <stddef.h> |
| 19 | 19 | ||
| 20 | #include <openssl/dh.h> | ||
| 20 | #include <openssl/ossl_typ.h> | 21 | #include <openssl/ossl_typ.h> |
| 21 | #include <openssl/ssl.h> | 22 | #include <openssl/ssl.h> |
| 22 | #include <openssl/tls1.h> | 23 | #include <openssl/tls1.h> |
| @@ -225,3 +226,13 @@ ssl_security(const SSL *ssl, int op, int bits, int nid, void *other) | |||
| 225 | return ssl->cert->security_cb(ssl, NULL, op, bits, nid, other, | 226 | return ssl->cert->security_cb(ssl, NULL, op, bits, nid, other, |
| 226 | ssl->cert->security_ex_data); | 227 | ssl->cert->security_ex_data); |
| 227 | } | 228 | } |
| 229 | |||
| 230 | int | ||
| 231 | ssl_security_dh(const SSL *ssl, DH *dh) | ||
| 232 | { | ||
| 233 | #if defined(LIBRESSL_HAS_SECURITY_LEVEL) | ||
| 234 | return ssl_security(ssl, SSL_SECOP_TMP_DH, DH_security_bits(dh), 0, dh); | ||
| 235 | #else | ||
| 236 | return 1; | ||
| 237 | #endif | ||
| 238 | } | ||
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c index 97077a3380..e37f9cfdb7 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.144 2022/06/29 07:53:58 tb Exp $ */ | 1 | /* $OpenBSD: ssl_srvr.c,v 1.145 2022/06/29 08:27:51 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 | * |
| @@ -1355,6 +1355,12 @@ ssl3_send_server_kex_dhe(SSL *s, CBB *cbb) | |||
| 1355 | if (!tls_key_share_public(s->s3->hs.key_share, cbb)) | 1355 | if (!tls_key_share_public(s->s3->hs.key_share, cbb)) |
| 1356 | goto err; | 1356 | goto err; |
| 1357 | 1357 | ||
| 1358 | if (!tls_key_share_peer_security(s, s->s3->hs.key_share)) { | ||
| 1359 | SSLerror(s, SSL_R_DH_KEY_TOO_SMALL); | ||
| 1360 | ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); | ||
| 1361 | return 0; | ||
| 1362 | } | ||
| 1363 | |||
| 1358 | return 1; | 1364 | return 1; |
| 1359 | 1365 | ||
| 1360 | err: | 1366 | err: |
diff --git a/src/lib/libssl/tls_internal.h b/src/lib/libssl/tls_internal.h index a009635a05..0065f0f39f 100644 --- a/src/lib/libssl/tls_internal.h +++ b/src/lib/libssl/tls_internal.h | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_internal.h,v 1.5 2022/01/11 18:28:41 jsing Exp $ */ | 1 | /* $OpenBSD: tls_internal.h,v 1.6 2022/06/29 08:27:51 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2018, 2019, 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018, 2019, 2021 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -77,6 +77,7 @@ int tls_key_share_peer_public(struct tls_key_share *ks, CBS *cbs, | |||
| 77 | int *decode_error, int *invalid_key); | 77 | int *decode_error, int *invalid_key); |
| 78 | int tls_key_share_derive(struct tls_key_share *ks, uint8_t **shared_key, | 78 | int tls_key_share_derive(struct tls_key_share *ks, uint8_t **shared_key, |
| 79 | size_t *shared_key_len); | 79 | size_t *shared_key_len); |
| 80 | int tls_key_share_peer_security(const SSL *ssl, struct tls_key_share *ks); | ||
| 80 | 81 | ||
| 81 | __END_HIDDEN_DECLS | 82 | __END_HIDDEN_DECLS |
| 82 | 83 | ||
diff --git a/src/lib/libssl/tls_key_share.c b/src/lib/libssl/tls_key_share.c index e5e6c304b6..0b941d8b0d 100644 --- a/src/lib/libssl/tls_key_share.c +++ b/src/lib/libssl/tls_key_share.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: tls_key_share.c,v 1.4 2022/01/11 18:28:41 jsing Exp $ */ | 1 | /* $OpenBSD: tls_key_share.c,v 1.5 2022/06/29 08:27:52 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2020, 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2020, 2021 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -471,3 +471,14 @@ tls_key_share_derive(struct tls_key_share *ks, uint8_t **shared_key, | |||
| 471 | return tls_key_share_derive_ecdhe_ecp(ks, shared_key, | 471 | return tls_key_share_derive_ecdhe_ecp(ks, shared_key, |
| 472 | shared_key_len); | 472 | shared_key_len); |
| 473 | } | 473 | } |
| 474 | |||
| 475 | int | ||
| 476 | tls_key_share_peer_security(const SSL *ssl, struct tls_key_share *ks) | ||
| 477 | { | ||
| 478 | switch (ks->nid) { | ||
| 479 | case NID_dhKeyAgreement: | ||
| 480 | return ssl_security_dh(ssl, ks->dhe_peer); | ||
| 481 | default: | ||
| 482 | return 0; | ||
| 483 | } | ||
| 484 | } | ||
