mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 03:34:39 +02:00
Merge pull request #1376 from JacobBarthelmeh/Compatibility-Layer
add wolfSSL_PEM_read_bio_RSAPrivateKey function
This commit is contained in:
37
src/ssl.c
37
src/ssl.c
@@ -27586,6 +27586,43 @@ WOLFSSL_EVP_PKEY* wolfSSL_PEM_read_bio_PrivateKey(WOLFSSL_BIO* bio,
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_RSA
|
||||
/* Uses the same format of input as wolfSSL_PEM_read_bio_PrivateKey but expects
|
||||
* the results to be an RSA key.
|
||||
*
|
||||
* bio structure to read RSA private key from
|
||||
* rsa if not null is then set to the result
|
||||
* cb password callback for reading PEM
|
||||
* pass password string
|
||||
*
|
||||
* returns a pointer to a new WOLFSSL_RSA structure on success and NULL on fail
|
||||
*/
|
||||
WOLFSSL_RSA* wolfSSL_PEM_read_bio_RSAPrivateKey(WOLFSSL_BIO* bio,
|
||||
WOLFSSL_RSA** rsa, pem_password_cb* cb, void* pass)
|
||||
{
|
||||
WOLFSSL_EVP_PKEY* pkey;
|
||||
WOLFSSL_RSA* local;
|
||||
|
||||
pkey = wolfSSL_PEM_read_bio_PrivateKey(bio, NULL, cb, pass);
|
||||
if (pkey == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Since the WOLFSSL_RSA structure is being taken from WOLFSSL_EVP_PEKY the
|
||||
* flag indicating that the WOLFSSL_RSA structure is owned should be FALSE
|
||||
* to avoid having it free'd */
|
||||
pkey->ownRsa = 0;
|
||||
local = pkey->rsa;
|
||||
if (rsa != NULL) {
|
||||
*rsa = local;
|
||||
}
|
||||
|
||||
wolfSSL_EVP_PKEY_free(pkey);
|
||||
return local;
|
||||
}
|
||||
#endif /* !NO_RSA */
|
||||
|
||||
|
||||
/* return of pkey->type which will be EVP_PKEY_RSA for example.
|
||||
*
|
||||
* type type of EVP_PKEY
|
||||
|
29
tests/api.c
29
tests/api.c
@@ -14109,6 +14109,34 @@ static void test_wolfSSL_PEM_PrivateKey(void)
|
||||
}
|
||||
|
||||
|
||||
static void test_wolfSSL_PEM_RSAPrivateKey(void)
|
||||
{
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
|
||||
!defined(NO_FILESYSTEM) && !defined(NO_RSA)
|
||||
RSA* rsa = NULL;
|
||||
BIO* bio = NULL;
|
||||
|
||||
printf(testingFmt, "wolfSSL_PEM_RSAPrivateKey()");
|
||||
|
||||
AssertNotNull(bio = BIO_new_file(svrKeyFile, "rb"));
|
||||
AssertNotNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
|
||||
AssertIntEQ(RSA_size(rsa), 256);
|
||||
|
||||
BIO_free(bio);
|
||||
RSA_free(rsa);
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
AssertNotNull(bio = BIO_new_file(eccKeyFile, "rb"));
|
||||
AssertNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
|
||||
|
||||
BIO_free(bio);
|
||||
#endif /* HAVE_ECC */
|
||||
|
||||
printf(resultFmt, passed);
|
||||
#endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
|
||||
}
|
||||
|
||||
|
||||
static void test_wolfSSL_tmp_dh(void)
|
||||
{
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
|
||||
@@ -17225,6 +17253,7 @@ void ApiTest(void)
|
||||
test_wolfSSL_ASN1_TIME_print();
|
||||
test_wolfSSL_private_keys();
|
||||
test_wolfSSL_PEM_PrivateKey();
|
||||
test_wolfSSL_PEM_RSAPrivateKey();
|
||||
test_wolfSSL_tmp_dh();
|
||||
test_wolfSSL_ctrl();
|
||||
test_wolfSSL_EVP_PKEY_new_mac_key();
|
||||
|
@@ -34,9 +34,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PEM_write_bio_PrivateKey wolfSSL_PEM_write_bio_PrivateKey
|
||||
#define PEM_write_bio_RSAPrivateKey wolfSSL_PEM_write_bio_RSAPrivateKey
|
||||
|
||||
/* RSA */
|
||||
WOLFSSL_API
|
||||
int wolfSSL_PEM_write_bio_RSAPrivateKey(WOLFSSL_BIO* bio, WOLFSSL_RSA* rsa,
|
||||
@@ -44,6 +41,11 @@ int wolfSSL_PEM_write_bio_RSAPrivateKey(WOLFSSL_BIO* bio, WOLFSSL_RSA* rsa,
|
||||
unsigned char* passwd, int len,
|
||||
pem_password_cb* cb, void* arg);
|
||||
WOLFSSL_API
|
||||
WOLFSSL_RSA* wolfSSL_PEM_read_bio_RSAPrivateKey(WOLFSSL_BIO* bio,
|
||||
WOLFSSL_RSA**,
|
||||
pem_password_cb* cb,
|
||||
void* arg);
|
||||
WOLFSSL_API
|
||||
int wolfSSL_PEM_write_mem_RSAPrivateKey(RSA* rsa, const EVP_CIPHER* cipher,
|
||||
unsigned char* passwd, int len,
|
||||
unsigned char **pem, int *plen);
|
||||
@@ -141,6 +143,7 @@ WOLFSSL_EVP_PKEY *wolfSSL_PEM_read_PrivateKey(FILE *fp, WOLFSSL_EVP_PKEY **x,
|
||||
#define PEM_write_bio_PrivateKey wolfSSL_PEM_write_bio_PrivateKey
|
||||
/* RSA */
|
||||
#define PEM_write_bio_RSAPrivateKey wolfSSL_PEM_write_bio_RSAPrivateKey
|
||||
#define PEM_read_bio_RSAPrivateKey wolfSSL_PEM_read_bio_RSAPrivateKey
|
||||
#define PEM_write_RSAPrivateKey wolfSSL_PEM_write_RSAPrivateKey
|
||||
#define PEM_write_RSA_PUBKEY wolfSSL_PEM_write_RSA_PUBKEY
|
||||
#define PEM_write_RSAPublicKey wolfSSL_PEM_write_RSAPublicKey
|
||||
|
Reference in New Issue
Block a user