@@ -47805,6 +47805,62 @@ static int test_wolfSSL_PKCS7_SIGNED_new(void)
4780547805}
4780647806
4780747807#ifndef NO_BIO
47808+
47809+ static int test_wolfSSL_PEM_write_bio_encryptedKey(void)
47810+ {
47811+ EXPECT_DECLS;
47812+ #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
47813+ defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
47814+ defined(WOLFSSL_ENCRYPTED_KEYS) && \
47815+ (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)) && \
47816+ !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
47817+ !defined(NO_DES3)
47818+ RSA* rsaKey = NULL;
47819+ RSA* retKey = NULL;
47820+ const EVP_CIPHER *cipher = NULL;
47821+ BIO* bio = NULL;
47822+ BIO* retbio = NULL;
47823+ byte* out;
47824+ const char* password = "wolfssl";
47825+ word32 passwordSz =(word32)XSTRLEN((char*)password);
47826+ int membufSz = 0;
47827+
47828+ #if defined(USE_CERT_BUFFERS_2048)
47829+ const byte* key = client_key_der_2048;
47830+ word32 keySz = sizeof_client_key_der_2048;
47831+ #elif defined(USE_CERT_BUFFERS_1024)
47832+ const byte* key = client_key_der_1024;
47833+ word32 keySz = sizeof_client_key_der_1024;
47834+ #endif
47835+ /* Import Rsa Key */
47836+ ExpectNotNull(rsaKey = wolfSSL_RSA_new());
47837+ ExpectIntEQ(wolfSSL_RSA_LoadDer_ex(rsaKey, key, keySz,
47838+ WOLFSSL_RSA_LOAD_PRIVATE), 1);
47839+
47840+ ExpectNotNull(cipher = EVP_des_ede3_cbc());
47841+ ExpectNotNull(bio = BIO_new(BIO_s_mem()));
47842+ ExpectIntEQ(PEM_write_bio_RSAPrivateKey(bio, rsaKey, cipher,
47843+ (byte*)password, passwordSz, NULL, NULL), 1);
47844+ ExpectIntGT((membufSz = BIO_get_mem_data(bio, &out)), 0);
47845+ ExpectNotNull(retbio = BIO_new_mem_buf(out, membufSz));
47846+ ExpectNotNull((retKey = PEM_read_bio_RSAPrivateKey(retbio, NULL,
47847+ NULL, (void*)password)));
47848+ if (bio != NULL) {
47849+ BIO_free(bio);
47850+ }
47851+ if (retbio != NULL) {
47852+ BIO_free(retbio);
47853+ }
47854+ if (retKey != NULL) {
47855+ RSA_free(retKey);
47856+ }
47857+ if (rsaKey != NULL) {
47858+ RSA_free(rsaKey);
47859+ }
47860+ #endif
47861+ return EXPECT_RESULT();
47862+ }
47863+
4780847864static int test_wolfSSL_PEM_write_bio_PKCS7(void)
4780947865{
4781047866 EXPECT_DECLS;
@@ -67968,6 +68024,7 @@ TEST_CASE testCases[] = {
6796868024 TEST_DECL(test_wolfSSL_PKCS7_SIGNED_new),
6796968025#ifndef NO_BIO
6797068026 TEST_DECL(test_wolfSSL_PEM_write_bio_PKCS7),
68027+ TEST_DECL(test_wolfSSL_PEM_write_bio_encryptedKey),
6797168028#ifdef HAVE_SMIME
6797268029 TEST_DECL(test_wolfSSL_SMIME_read_PKCS7),
6797368030 TEST_DECL(test_wolfSSL_SMIME_write_PKCS7),
0 commit comments