@@ -47811,6 +47811,62 @@ static int test_wolfSSL_PKCS7_SIGNED_new(void)
4781147811}
4781247812
4781347813#ifndef NO_BIO
47814+
47815+ static int test_wolfSSL_PEM_write_bio_encryptedKey(void)
47816+ {
47817+ EXPECT_DECLS;
47818+ #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)) && \
47819+ defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA) && \
47820+ defined(WOLFSSL_ENCRYPTED_KEYS) && \
47821+ (defined(WOLFSSL_PEM_TO_DER) || defined(WOLFSSL_DER_TO_PEM)) && \
47822+ !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && \
47823+ !defined(NO_DES3)
47824+ RSA* rsaKey = NULL;
47825+ RSA* retKey = NULL;
47826+ const EVP_CIPHER *cipher = NULL;
47827+ BIO* bio = NULL;
47828+ BIO* retbio = NULL;
47829+ byte* out;
47830+ const char* password = "wolfssl";
47831+ word32 passwordSz =(word32)XSTRLEN((char*)password);
47832+ int membufSz = 0;
47833+
47834+ #if defined(USE_CERT_BUFFERS_2048)
47835+ const byte* key = client_key_der_2048;
47836+ word32 keySz = sizeof_client_key_der_2048;
47837+ #elif defined(USE_CERT_BUFFERS_1024)
47838+ const byte* key = client_key_der_1024;
47839+ word32 keySz = sizeof_client_key_der_1024;
47840+ #endif
47841+ /* Import Rsa Key */
47842+ ExpectNotNull(rsaKey = wolfSSL_RSA_new());
47843+ ExpectIntEQ(wolfSSL_RSA_LoadDer_ex(rsaKey, key, keySz,
47844+ WOLFSSL_RSA_LOAD_PRIVATE), 1);
47845+
47846+ ExpectNotNull(cipher = EVP_des_ede3_cbc());
47847+ ExpectNotNull(bio = BIO_new(BIO_s_mem()));
47848+ ExpectIntEQ(PEM_write_bio_RSAPrivateKey(bio, rsaKey, cipher,
47849+ (byte*)password, passwordSz, NULL, NULL), 1);
47850+ ExpectIntGT((membufSz = BIO_get_mem_data(bio, &out)), 0);
47851+ ExpectNotNull(retbio = BIO_new_mem_buf(out, membufSz));
47852+ ExpectNotNull((retKey = PEM_read_bio_RSAPrivateKey(retbio, NULL,
47853+ NULL, (void*)password)));
47854+ if (bio != NULL) {
47855+ BIO_free(bio);
47856+ }
47857+ if (retbio != NULL) {
47858+ BIO_free(retbio);
47859+ }
47860+ if (retKey != NULL) {
47861+ RSA_free(retKey);
47862+ }
47863+ if (rsaKey != NULL) {
47864+ RSA_free(rsaKey);
47865+ }
47866+ #endif
47867+ return EXPECT_RESULT();
47868+ }
47869+
4781447870static int test_wolfSSL_PEM_write_bio_PKCS7(void)
4781547871{
4781647872 EXPECT_DECLS;
@@ -67974,6 +68030,7 @@ TEST_CASE testCases[] = {
6797468030 TEST_DECL(test_wolfSSL_PKCS7_SIGNED_new),
6797568031#ifndef NO_BIO
6797668032 TEST_DECL(test_wolfSSL_PEM_write_bio_PKCS7),
68033+ TEST_DECL(test_wolfSSL_PEM_write_bio_encryptedKey),
6797768034#ifdef HAVE_SMIME
6797868035 TEST_DECL(test_wolfSSL_SMIME_read_PKCS7),
6797968036 TEST_DECL(test_wolfSSL_SMIME_write_PKCS7),
0 commit comments