From b53cc0e98c36a24890c03a7622c368bc47433fd4 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Wed, 28 Feb 2024 21:47:45 +1000 Subject: [PATCH 1/2] SSL: Loading bad private key Fix ProcessBufferTryDecodeRsa and ProcessBufferTryDecodeEcc to only clear error when key format isn't known. --- src/ssl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index aae12f0b2..06e0cec21 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -6543,7 +6543,10 @@ static int ProcessBufferTryDecodeRsa(WOLFSSL_CTX* ctx, WOLFSSL* ssl, "not enabled to try"); ret = WOLFSSL_BAD_FILE; #else - ret = 0; /* continue trying other algorithms */ + if (*keyFormat == 0) { + /* Format unknown so keep trying. */ + ret = 0; /* continue trying other algorithms */ + } #endif } else { @@ -6616,7 +6619,10 @@ static int ProcessBufferTryDecodeRsa(WOLFSSL_CTX* ctx, WOLFSSL* ssl, "not enabled to try"); ret = WOLFSSL_BAD_FILE; #else - ret = 0; /* continue trying other algorithms */ + if (*keyFormat == 0) { + /* Format unknown so keep trying. */ + ret = 0; /* continue trying other algorithms */ + } #endif } else { @@ -6728,7 +6734,7 @@ static int ProcessBufferTryDecodeEcc(WOLFSSL_CTX* ctx, WOLFSSL* ssl, *resetSuites = 1; } } - else { + else if (*keyFormat == 0) { ret = 0; /* continue trying other algorithms */ } @@ -6809,7 +6815,7 @@ static int ProcessBufferTryDecodeEd25519(WOLFSSL_CTX* ctx, WOLFSSL* ssl, } } } - else { + else if (*keyFormat == 0) { ret = 0; /* continue trying other algorithms */ } From 9addb3e45d4b723c5e1d613e3c221f2a6f0a48d4 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Thu, 29 Feb 2024 07:36:22 +1000 Subject: [PATCH 2/2] SSL: Change other ProcessBufferTryDecode*() Ed448, Falcon and Dilithium changed to return 0 when key format is 0. --- src/ssl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ssl.c b/src/ssl.c index 06e0cec21..584bf98ea 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -6893,6 +6893,9 @@ static int ProcessBufferTryDecodeEd448(WOLFSSL_CTX* ctx, WOLFSSL* ssl, } } } + else if (*keyFormat == 0) { + ret = 0; /* continue trying other algorithms */ + } wc_ed448_free(key); } @@ -6997,6 +7000,10 @@ static int ProcessBufferTryDecodeFalcon(WOLFSSL_CTX* ctx, WOLFSSL* ssl, *resetSuites = 1; } } + else if (*keyFormat == 0) { + ret = 0; /* continue trying other algorithms */ + } + wc_falcon_free(key); } XFREE(key, heap, DYNAMIC_TYPE_FALCON); @@ -7111,6 +7118,10 @@ static int ProcessBufferTryDecodeDilithium(WOLFSSL_CTX* ctx, WOLFSSL* ssl, *resetSuites = 1; } } + else if (*keyFormat == 0) { + ret = 0; /* continue trying other algorithms */ + } + wc_dilithium_free(key); } XFREE(key, heap, DYNAMIC_TYPE_DILITHIUM);