Skip to content

Commit 0407ea1

Browse files
authored
Merge pull request #8970 from miyazakh/qt_jenkins_encryptedKey4PBKDF1
Fix Qt nightly Jenkins failure
2 parents f44178c + ee8be22 commit 0407ea1

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

src/pk.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,10 @@ static int der_to_enc_pem_alloc(unsigned char* der, int derSz,
507507
byte* cipherInfo = NULL;
508508
int pemSz = 0;
509509
int hashType = WC_HASH_TYPE_NONE;
510-
#if !defined(NO_SHA256)
511-
hashType = WC_SHA256;
510+
#if !defined(NO_MD5)
511+
hashType = WC_MD5;
512512
#elif !defined(NO_SHA)
513513
hashType = WC_SHA;
514-
#elif !defined(NO_MD5)
515-
hashType = WC_MD5;
516514
#endif
517515

518516
/* Macro doesn't always use it. */

tests/api.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
4781447870
static 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),

wolfcrypt/src/asn.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26848,6 +26848,14 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
2684826848
#ifdef OPENSSL_EXTRA
2684926849
char beginBuf[PEM_LINE_LEN + 1]; /* add 1 for null terminator */
2685026850
char endBuf[PEM_LINE_LEN + 1]; /* add 1 for null terminator */
26851+
#endif
26852+
#ifdef WOLFSSL_ENCRYPTED_KEYS
26853+
int hashType = WC_HASH_TYPE_NONE;
26854+
#if !defined(NO_MD5)
26855+
hashType = WC_MD5;
26856+
#elif !defined(NO_SHA)
26857+
hashType = WC_SHA;
26858+
#endif
2685126859
#endif
2685226860

2685326861
WOLFSSL_ENTER("PemToDer");
@@ -27214,7 +27222,7 @@ int PemToDer(const unsigned char* buff, long longSz, int type,
2721427222
#endif
2721527223

2721627224
ret = wc_BufferKeyDecrypt(info, der->buffer, der->length,
27217-
(byte*)password, passwordSz, WC_MD5);
27225+
(byte*)password, passwordSz, hashType);
2721827226

2721927227
#ifndef NO_WOLFSSL_SKIP_TRAILING_PAD
2722027228
#ifndef NO_DES3

0 commit comments

Comments
 (0)