From afb0e1c4ab6732727c5231ed330f42d7f8db71f1 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 29 Aug 2026 16:15:22 +0200 Subject: lib: Reject peer keys of another algorithm The openssl_dhe_derive() function decoded the peer public key from the wire with d2i_PUBKEY() and handed it straight to EVP_PKEY_derive_set_peer(). A peer offering a key of a type other than the one negotiated was only caught inside OpenSSL. This aborts in OpenSSL debug builds, which tripped integration. Now we check the decoded key type against the type of the local key pair first. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/crypt/openssl.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/crypt/openssl.c b/src/lib/crypt/openssl.c index 1ee2318e..9c488b9d 100644 --- a/src/lib/crypt/openssl.c +++ b/src/lib/crypt/openssl.c @@ -1057,8 +1057,9 @@ int openssl_dhe_derive(EVP_PKEY * pkp, int kdf, uint8_t * s) { - uint8_t * pos; - EVP_PKEY * pub; + uint8_t * pos; + EVP_PKEY * pub; + const char * name; assert(pkp != NULL); assert(pk.data != NULL); @@ -1070,6 +1071,11 @@ int openssl_dhe_derive(EVP_PKEY * pkp, if (pub == NULL) goto fail_decode; + /* A peer key of another type must not reach the derivation */ + name = EVP_PKEY_get0_type_name(pkp); + if (name == NULL || EVP_PKEY_is_a(pub, name) != 1) + goto fail_derive; + if (__openssl_dhe_derive(pkp, pub, pk, kdf, s) < 0) goto fail_derive; -- cgit v1.2.3