Skip to content

Commit

Permalink
be more strict on CSR version number allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Jun 18, 2024
1 parent eef20ce commit 07967ba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -31162,6 +31162,13 @@ static int MakeCertReq(Cert* cert, byte* derBuffer, word32 derSz,
DerCert der[1];
#endif

/* check that the cert. req. version matches rfc2986 sect. 4.1 */
if (cert->version != 0) {
WOLFSSL_MSG("Only version 0 for CSR supported");
WOLFSSL_ERROR_VERBOSE(ASN_VERSION_E);
return ASN_VERSION_E;
}

if (eccKey)
cert->keyType = ECC_KEY;
else if (rsaKey)
Expand Down Expand Up @@ -31249,6 +31256,13 @@ static int MakeCertReq(Cert* cert, byte* derBuffer, word32 derSz,
(void)dilithiumKey;
(void)sphincsKey;

/* check that the cert. req. version matches rfc2986 sect. 4.1 */
if (cert->version != 0) {
WOLFSSL_MSG("Only version 0 for CSR supported");
WOLFSSL_ERROR_VERBOSE(ASN_VERSION_E);
return ASN_VERSION_E;
}

CALLOC_ASNSETDATA(dataASN, certReqBodyASN_Length, ret, cert->heap);

if (ret == 0) {
Expand Down
7 changes: 7 additions & 0 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21820,6 +21820,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_test(void)
#endif /* WOLFSSL_EKU_OID */
#endif /* WOLFSSL_CERT_EXT */

req->version = 2; /* test bad version fails */
derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
if (derSz >= 0) {
ERROR_OUT(-7976, exit_rsa);
}

req->version = 0;
derSz = wc_MakeCertReq(req, der, FOURK_BUF, key, NULL);
if (derSz < 0) {
ERROR_OUT(WC_TEST_RET_ENC_EC(derSz), exit_rsa);
Expand Down

0 comments on commit 07967ba

Please sign in to comment.