From f55cfd7ba736f3ff9e806ba1b6fd59340dcc13f2 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Sun, 26 Jan 2020 17:56:20 +0100 Subject: [PATCH] Fix missing wolfSSL_i2d_RSAPrivateKey references --- src/ssl.c | 6 ++++-- tests/api.c | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/ssl.c b/src/ssl.c index 61c76a514..f0aef5e57 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -42297,7 +42297,8 @@ int wolfSSL_BIO_new_bio_pair(WOLFSSL_BIO **bio1_p, size_t writebuf1, } -#if !defined(NO_RSA) +#if !defined(HAVE_FAST_RSA) && defined(WOLFSSL_KEY_GEN) && \ + !defined(NO_RSA) && !defined(HAVE_USER_RSA) /* Converts an rsa key from a bio buffer into an internal rsa structure. Returns a pointer to the new WOLFSSL_RSA structure. */ WOLFSSL_RSA* wolfSSL_d2i_RSAPrivateKey_bio(WOLFSSL_BIO *bio, WOLFSSL_RSA **out) @@ -42402,7 +42403,8 @@ int wolfSSL_CTX_use_certificate_ASN1(WOLFSSL_CTX *ctx, int derSz, } -#if !defined(NO_RSA) && !defined(HAVE_FAST_RSA) +#if !defined(HAVE_FAST_RSA) && defined(WOLFSSL_KEY_GEN) && \ + !defined(NO_RSA) && !defined(HAVE_USER_RSA) /* Adds the rsa private key to the user ctx. Returns WOLFSSL_SUCCESS if no error, returns WOLFSSL_FAILURE otherwise.*/ int wolfSSL_CTX_use_RSAPrivateKey(WOLFSSL_CTX* ctx, WOLFSSL_RSA* rsa) diff --git a/tests/api.c b/tests/api.c index aa98c0eed..ae97fcbbb 100644 --- a/tests/api.c +++ b/tests/api.c @@ -24196,7 +24196,6 @@ static void test_wolfSSL_d2i_PrivateKeys_bio(void) BIO* bio = NULL; EVP_PKEY* pkey = NULL; #ifndef NO_RSA - RSA* rsa = NULL; #endif WOLFSSL_CTX* ctx; @@ -24273,34 +24272,38 @@ static void test_wolfSSL_d2i_PrivateKeys_bio(void) AssertNotNull(ctx = SSL_CTX_new(wolfSSLv23_client_method())); #endif -#ifndef NO_RSA - /* Tests bad parameters */ - AssertNull(d2i_RSAPrivateKey_bio(NULL, NULL)); +#if !defined(HAVE_FAST_RSA) && defined(WOLFSSL_KEY_GEN) && \ + !defined(NO_RSA) && !defined(HAVE_USER_RSA) + { + RSA* rsa = NULL; + /* Tests bad parameters */ + AssertNull(d2i_RSAPrivateKey_bio(NULL, NULL)); - /* RSA not set yet, expecting to fail*/ - AssertIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), BAD_FUNC_ARG); + /* RSA not set yet, expecting to fail*/ + AssertIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), BAD_FUNC_ARG); #if defined(USE_CERT_BUFFERS_2048) && defined(WOLFSSL_KEY_GEN) - /* set RSA using bio*/ - AssertIntGT(BIO_write(bio, client_key_der_2048, - sizeof_client_key_der_2048), 0); - AssertNotNull(rsa = d2i_RSAPrivateKey_bio(bio, NULL)); + /* set RSA using bio*/ + AssertIntGT(BIO_write(bio, client_key_der_2048, + sizeof_client_key_der_2048), 0); + AssertNotNull(rsa = d2i_RSAPrivateKey_bio(bio, NULL)); - AssertIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WOLFSSL_SUCCESS); + AssertIntEQ(SSL_CTX_use_RSAPrivateKey(ctx, rsa), WOLFSSL_SUCCESS); - /*i2d RSAprivate key tests */ - AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), BAD_FUNC_ARG); - AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192); - AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr), - sizeof_client_key_der_2048); - bufPtr = NULL; - AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr), - sizeof_client_key_der_2048); - AssertNotNull(bufPtr); - XFREE(bufPtr, NULL, DYNAMIC_TYPE_OPENSSL); + /*i2d RSAprivate key tests */ + AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(NULL, NULL), BAD_FUNC_ARG); + AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, NULL), 1192); + AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr), + sizeof_client_key_der_2048); + bufPtr = NULL; + AssertIntEQ(wolfSSL_i2d_RSAPrivateKey(rsa, &bufPtr), + sizeof_client_key_der_2048); + AssertNotNull(bufPtr); + XFREE(bufPtr, NULL, DYNAMIC_TYPE_OPENSSL); #endif /* USE_CERT_BUFFERS_2048 WOLFSSL_KEY_GEN */ - RSA_free(rsa); -#endif /* NO_RSA */ + RSA_free(rsa); + } +#endif /* !HAVE_FAST_RSA && WOLFSSL_KEY_GEN && !NO_RSA && !HAVE_USER_RSA*/ SSL_CTX_free(ctx); ctx = NULL; BIO_free(bio);