Skip to content

Commit 83b9523

Browse files
committed
wc_CheckPrivateKey() returns NOT_COMPILED_IN for certain gating flags
1 parent 22b25dc commit 83b9523

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20743,6 +20743,23 @@ static int test_EccSigFailure_cm(void)
2074320743
#endif /* !NO_RSA || HAVE_ECC */
2074420744
#endif /* NO_CERTS */
2074520745

20746+
static int test_wc_CheckPrivateKey_RSA_pub_only(void)
20747+
{
20748+
EXPECT_DECLS;
20749+
#if !defined(NO_RSA) && !defined(NO_ASN_CRYPT) && \
20750+
!defined(NO_CHECK_PRIVATE_KEY) && \
20751+
(defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY))
20752+
/* With RSA public-only or verify-only, wc_CheckPrivateKey should return
20753+
* NOT_COMPILED_IN for RSA key types since private key operations are not
20754+
* available. */
20755+
ExpectIntEQ(wc_CheckPrivateKey(server_key_der_2048,
20756+
sizeof_server_key_der_2048, server_cert_der_2048,
20757+
sizeof_server_cert_der_2048, RSAk, NULL),
20758+
WC_NO_ERR_TRACE(NOT_COMPILED_IN));
20759+
#endif
20760+
return EXPECT_RESULT();
20761+
}
20762+
2074620763
#if defined(HAVE_PK_CALLBACKS) && !defined(WOLFSSL_NO_TLS12)
2074720764
#if !defined(NO_FILESYSTEM) && !defined(NO_DH) && \
2074820765
!defined(NO_AES) && defined(HAVE_AES_CBC) && \
@@ -31782,6 +31799,7 @@ TEST_CASE testCases[] = {
3178231799
TEST_DECL(test_EccSigFailure_cm),
3178331800
TEST_DECL(test_RsaSigFailure_cm),
3178431801
#endif
31802+
TEST_DECL(test_wc_CheckPrivateKey_RSA_pub_only),
3178531803

3178631804
/* PKCS8 testing */
3178731805
TEST_DECL(test_wolfSSL_no_password_cb),

wolfcrypt/src/asn.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8565,6 +8565,9 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
85658565
|| ks == RSAPSSk
85668566
#endif
85678567
) {
8568+
#if defined(WOLFSSL_RSA_PUBLIC_ONLY) || defined(WOLFSSL_RSA_VERIFY_ONLY)
8569+
ret = NOT_COMPILED_IN;
8570+
#else
85688571
#ifdef WOLFSSL_SMALL_STACK
85698572
RsaKey* a;
85708573
RsaKey* b = NULL;
@@ -8619,6 +8622,7 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
86198622
wc_FreeRsaKey(a);
86208623
WC_FREE_VAR_EX(b, NULL, DYNAMIC_TYPE_RSA);
86218624
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_RSA);
8625+
#endif /* !WOLFSSL_RSA_PUBLIC_ONLY && !WOLFSSL_RSA_VERIFY_ONLY */
86228626
}
86238627
else
86248628
#endif /* !NO_RSA && !NO_ASN_CRYPT */

0 commit comments

Comments
 (0)