mirror of https://github.com/wolfSSL/wolfssl.git
Merge pull request #5434 from satoshiyamaguchi/trial4
commit
e830a0f613
41
src/pk.c
41
src/pk.c
|
@ -1785,6 +1785,47 @@ WOLFSSL_RSA* wolfSSL_PEM_read_bio_RSAPrivateKey(WOLFSSL_BIO* bio,
|
|||
return rsa;
|
||||
}
|
||||
|
||||
/* Create an RSA private key by reading the PEM encoded data from the file
|
||||
* pointer.
|
||||
*
|
||||
* @param [in] fp File pointer to read from.
|
||||
* @param [out] out RSA key created.
|
||||
* @param [in] cb Password callback when PEM encrypted.
|
||||
* @param [in] pass NUL terminated string for passphrase when PEM encrypted.
|
||||
* @return RSA key on success.
|
||||
* @return NULL on failure.
|
||||
*/
|
||||
#ifndef NO_FILESYSTEM
|
||||
WOLFSSL_RSA* wolfSSL_PEM_read_RSAPrivateKey(XFILE fp, WOLFSSL_RSA** out,
|
||||
wc_pem_password_cb* cb, void* pass)
|
||||
{
|
||||
WOLFSSL_EVP_PKEY* pkey;
|
||||
WOLFSSL_RSA* rsa = NULL;
|
||||
|
||||
WOLFSSL_ENTER("PEM_read_RSAPrivateKey");
|
||||
|
||||
/* Read PEM encoded RSA private key from a file pointer. using generic EVP
|
||||
* function.
|
||||
*/
|
||||
pkey = wolfSSL_PEM_read_PrivateKey(fp, NULL, cb, pass);
|
||||
if (pkey != NULL) {
|
||||
/* Since the WOLFSSL_RSA structure is being taken from WOLFSSL_EVP_PKEY
|
||||
* the flag indicating that the WOLFSSL_RSA structure is owned should be
|
||||
* FALSE to avoid having it free'd. */
|
||||
pkey->ownRsa = 0;
|
||||
rsa = pkey->rsa;
|
||||
if (out != NULL) {
|
||||
/* Return WOLFSSL_RSA object through parameter too. */
|
||||
*out = rsa;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dispose of EVP_PKEY wrapper. */
|
||||
wolfSSL_EVP_PKEY_free(pkey);
|
||||
return rsa;
|
||||
}
|
||||
#endif /* !NO_FILESYSTEM */
|
||||
|
||||
#endif /* NO_BIO */
|
||||
|
||||
#if !defined(NO_FILESYSTEM)
|
||||
|
|
|
@ -32416,6 +32416,7 @@ static int test_wolfSSL_PEM_RSAPrivateKey(void)
|
|||
RSA* rsa = NULL;
|
||||
RSA* rsa_dup = NULL;
|
||||
BIO* bio = NULL;
|
||||
XFILE f = NULL;
|
||||
|
||||
printf(testingFmt, "wolfSSL_PEM_RSAPrivateKey()");
|
||||
|
||||
|
@ -32441,6 +32442,13 @@ static int test_wolfSSL_PEM_RSAPrivateKey(void)
|
|||
RSA_free(rsa);
|
||||
RSA_free(rsa_dup);
|
||||
|
||||
f = XFOPEN(svrKeyFile, "r");
|
||||
AssertTrue((f != XBADFILE));
|
||||
AssertNotNull((rsa = PEM_read_RSAPrivateKey(f, NULL, NULL, NULL)));
|
||||
AssertIntEQ(RSA_size(rsa), 256);
|
||||
RSA_free(rsa);
|
||||
XFCLOSE(f);
|
||||
|
||||
#ifdef HAVE_ECC
|
||||
AssertNotNull(bio = BIO_new_file(eccKeyFile, "rb"));
|
||||
AssertNull((rsa = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL)));
|
||||
|
|
|
@ -73,6 +73,11 @@ int wolfSSL_PEM_write_RSAPrivateKey(XFILE fp, WOLFSSL_RSA *rsa,
|
|||
const WOLFSSL_EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
wc_pem_password_cb *cb, void *u);
|
||||
|
||||
WOLFSSL_API
|
||||
WOLFSSL_RSA* wolfSSL_PEM_read_RSAPrivateKey(XFILE fp, WOLFSSL_RSA** rsa,
|
||||
wc_pem_password_cb* cb, void* pass);
|
||||
|
||||
WOLFSSL_API
|
||||
WOLFSSL_RSA *wolfSSL_PEM_read_RSAPublicKey(XFILE fp, WOLFSSL_RSA **x,
|
||||
wc_pem_password_cb *cb, void *u);
|
||||
|
@ -226,6 +231,7 @@ int wolfSSL_PEM_write_DHparams(XFILE fp, WOLFSSL_DH* dh);
|
|||
/* RSA */
|
||||
#define PEM_write_bio_RSAPrivateKey wolfSSL_PEM_write_bio_RSAPrivateKey
|
||||
#define PEM_read_bio_RSAPrivateKey wolfSSL_PEM_read_bio_RSAPrivateKey
|
||||
#define PEM_read_RSAPrivateKey wolfSSL_PEM_read_RSAPrivateKey
|
||||
#define PEM_write_bio_RSA_PUBKEY wolfSSL_PEM_write_bio_RSA_PUBKEY
|
||||
#define PEM_read_bio_RSA_PUBKEY wolfSSL_PEM_read_bio_RSA_PUBKEY
|
||||
#define PEM_read_bio_RSAPublicKey wolfSSL_PEM_read_bio_RSA_PUBKEY
|
||||
|
|
Loading…
Reference in New Issue