Skip to content

Commit ee8be22

Browse files
committed
Fix Qt nightly jenkins failure
PBKDF1 encrpted key
1 parent a40b56c commit ee8be22

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
@@ -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+
4780847864
static 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),

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)