Skip to content

Commit 61120b7

Browse files
committed
Initialize certificate: default to SHA-1 when necessary
Make SHA-1 with RSA signature type the last option. SHA-1 signatures are deprecated as weak.
1 parent 1d363f3 commit 61120b7

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

tests/api/test_ossl_x509_crypto.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,12 @@ int test_wolfSSL_make_cert(void)
698698
cert.isCA = 1;
699699
#ifndef NO_SHA256
700700
cert.sigType = CTC_SHA256wRSA;
701+
#elif defined(WOLFSSL_SHA384)
702+
cert.sigType = CTC_SHA384wRSA;
703+
#elif defined(WOLFSSL_SHA512)
704+
cert.sigType = CTC_SHA512wRSA;
705+
#elif defined(WOLFSSL_SHA224)
706+
cert.sigType = CTC_SHA224wRSA;
701707
#else
702708
cert.sigType = CTC_SHAwRSA;
703709
#endif

wolfcrypt/src/asn.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24985,10 +24985,16 @@ int wc_InitCert_ex(Cert* cert, void* heap, int devId)
2498524985
XMEMSET(cert, 0, sizeof(Cert));
2498624986

2498724987
cert->version = 2; /* version 3 is hex 2 */
24988-
#ifndef NO_SHA
24989-
cert->sigType = CTC_SHAwRSA;
24990-
#elif !defined(NO_SHA256)
24988+
#if !defined(NO_SHA256)
2499124989
cert->sigType = CTC_SHA256wRSA;
24990+
#elif defined(WOLFSSL_SHA384)
24991+
cert->sigType = CTC_SHA384wRSA;
24992+
#elif defined(WOLFSSL_SHA512)
24993+
cert->sigType = CTC_SHA512wRSA;
24994+
#elif defined(WOLFSSL_SHA224)
24995+
cert->sigType = CTC_SHA224wRSA;
24996+
#elif !defined(NO_SHA)
24997+
cert->sigType = CTC_SHAwRSA;
2499224998
#else
2499324999
cert->sigType = 0;
2499425000
#endif

wolfcrypt/test/test.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24505,6 +24505,12 @@ static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng,
2450524505
myCert->isCA = 1;
2450624506
#ifndef NO_SHA256
2450724507
myCert->sigType = CTC_SHA256wRSA;
24508+
#elif defined(WOLFSSL_SHA384)
24509+
myCert->sigType = CTC_SHA384wRSA;
24510+
#elif defined(WOLFSSL_SHA512)
24511+
myCert->sigType = CTC_SHA512wRSA;
24512+
#elif defined(WOLFSSL_SHA224)
24513+
myCert->sigType = CTC_SHA224wRSA;
2450824514
#else
2450924515
myCert->sigType = CTC_SHAwRSA;
2451024516
#endif
@@ -24652,6 +24658,12 @@ static wc_test_ret_t rsa_certgen_test(RsaKey* key, RsaKey* keypub, WC_RNG* rng,
2465224658

2465324659
#ifndef NO_SHA256
2465424660
myCert->sigType = CTC_SHA256wRSA;
24661+
#elif defined(WOLFSSL_SHA384)
24662+
myCert->sigType = CTC_SHA384wRSA;
24663+
#elif defined(WOLFSSL_SHA512)
24664+
myCert->sigType = CTC_SHA512wRSA;
24665+
#elif defined(WOLFSSL_SHA224)
24666+
myCert->sigType = CTC_SHA224wRSA;
2465524667
#else
2465624668
myCert->sigType = CTC_SHAwRSA;
2465724669
#endif
@@ -24878,6 +24890,12 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
2487824890

2487924891
#ifndef NO_SHA256
2488024892
myCert->sigType = CTC_SHA256wRSA;
24893+
#elif defined(WOLFSSL_SHA384)
24894+
myCert->sigType = CTC_SHA384wRSA;
24895+
#elif defined(WOLFSSL_SHA512)
24896+
myCert->sigType = CTC_SHA512wRSA;
24897+
#elif defined(WOLFSSL_SHA224)
24898+
myCert->sigType = CTC_SHA224wRSA;
2488124899
#else
2488224900
myCert->sigType = CTC_SHAwRSA;
2488324901
#endif
@@ -25981,6 +25999,12 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
2598125999

2598226000
#ifndef NO_SHA256
2598326001
req->sigType = CTC_SHA256wRSA;
26002+
#elif defined(WOLFSSL_SHA384)
26003+
req->sigType = CTC_SHA384wRSA;
26004+
#elif defined(WOLFSSL_SHA512)
26005+
req->sigType = CTC_SHA512wRSA;
26006+
#elif defined(WOLFSSL_SHA224)
26007+
req->sigType = CTC_SHA224wRSA;
2598426008
#else
2598526009
req->sigType = CTC_SHAwRSA;
2598626010
#endif
@@ -37094,6 +37118,12 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
3709437118

3709537119
#ifndef NO_SHA256
3709637120
myCert->sigType = CTC_SHA256wECDSA;
37121+
#elif defined(WOLFSSL_SHA384)
37122+
myCert->sigType = CTC_SHA384wECDSA;
37123+
#elif defined(WOLFSSL_SHA512)
37124+
myCert->sigType = CTC_SHA512wECDSA;
37125+
#elif defined(WOLFSSL_SHA224)
37126+
myCert->sigType = CTC_SHA224wECDSA;
3709737127
#else
3709837128
myCert->sigType = CTC_SHAwECDSA;
3709937129
#endif

0 commit comments

Comments
 (0)