Skip to content

Commit daf5582

Browse files
committed
reject crls with unrecognized critical entry extensions per rfc 5280 section 5.3
1 parent 353a379 commit daf5582

4 files changed

Lines changed: 241 additions & 47 deletions

File tree

tests/api/test_certman.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,147 @@ int test_wolfSSL_CRL_unknown_critical_ext(void)
24272427
return EXPECT_RESULT();
24282428
}
24292429

2430+
int test_wolfSSL_CRL_unknown_critical_entry_ext(void)
2431+
{
2432+
EXPECT_DECLS;
2433+
#if !defined(NO_CERTS) && defined(HAVE_CRL) && !defined(NO_RSA)
2434+
2435+
static const unsigned char ca_cert[] = {
2436+
0x30, 0x82, 0x03, 0x1b, 0x30, 0x82, 0x02, 0x03, 0xa0, 0x03, 0x02,
2437+
0x01, 0x02, 0x02, 0x14, 0x1e, 0x25, 0xc1, 0x5d, 0x6f, 0x02, 0x21,
2438+
0xa0, 0xf0, 0x14, 0x15, 0x9c, 0x3b, 0x4d, 0x1d, 0x73, 0x16, 0x00,
2439+
0xe4, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
2440+
0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30,
2441+
0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61,
2442+
0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x1e, 0x17, 0x0d,
2443+
0x32, 0x36, 0x30, 0x34, 0x31, 0x36, 0x31, 0x31, 0x33, 0x38, 0x35,
2444+
0x35, 0x5a, 0x17, 0x0d, 0x33, 0x36, 0x30, 0x34, 0x31, 0x33, 0x31,
2445+
0x31, 0x33, 0x38, 0x35, 0x35, 0x5a, 0x30, 0x15, 0x31, 0x13, 0x30,
2446+
0x11, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61,
2447+
0x69, 0x6d, 0x2d, 0x72, 0x6f, 0x6f, 0x74, 0x30, 0x82, 0x01, 0x22,
2448+
0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
2449+
0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82,
2450+
0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xba, 0x49, 0x8c, 0xb5,
2451+
0x17, 0xc1, 0x01, 0x24, 0x6f, 0x56, 0x1a, 0xa9, 0x3b, 0x03, 0xe2,
2452+
0x9f, 0x24, 0xb1, 0x25, 0x98, 0xfb, 0x38, 0x82, 0x78, 0x54, 0xa7,
2453+
0x1f, 0x69, 0x87, 0xe4, 0x96, 0x1b, 0x81, 0x18, 0x10, 0xb0, 0xc0,
2454+
0x5b, 0x4b, 0xbf, 0xb8, 0x1d, 0xf4, 0xee, 0x75, 0x0f, 0xb5, 0x45,
2455+
0x72, 0x70, 0xce, 0x65, 0x84, 0x44, 0x3e, 0x30, 0x78, 0xc4, 0xf3,
2456+
0xec, 0xba, 0x96, 0x78, 0xa4, 0x65, 0xfc, 0x62, 0x8d, 0xf5, 0x29,
2457+
0xf9, 0x7c, 0x3d, 0x78, 0x6c, 0x1d, 0x4a, 0x4c, 0xc9, 0x15, 0x2d,
2458+
0x22, 0x10, 0xea, 0x93, 0x26, 0xb8, 0xa6, 0x17, 0xd3, 0x0e, 0xbc,
2459+
0x0c, 0xab, 0x83, 0x63, 0xf6, 0x1c, 0xcc, 0x83, 0x73, 0x29, 0x7e,
2460+
0x7f, 0x83, 0x7f, 0xbd, 0x63, 0xaa, 0x8d, 0xfa, 0x78, 0x85, 0xd2,
2461+
0x3e, 0x60, 0x95, 0x5a, 0x8d, 0xfa, 0x8f, 0xcd, 0x94, 0x3f, 0x13,
2462+
0x28, 0xd9, 0xd0, 0x87, 0x28, 0x17, 0x78, 0xe2, 0x61, 0x8d, 0x79,
2463+
0x97, 0x01, 0xa9, 0x7c, 0x84, 0xc0, 0x1c, 0xbe, 0x5f, 0x5d, 0xca,
2464+
0x28, 0x6b, 0x5e, 0xdd, 0x83, 0xa5, 0x55, 0x34, 0x11, 0xba, 0xfa,
2465+
0x8b, 0x92, 0xa3, 0xde, 0xb6, 0xf3, 0xba, 0xab, 0x7f, 0x1a, 0x67,
2466+
0xfd, 0x6f, 0x20, 0x85, 0x4c, 0x77, 0xa7, 0x8e, 0xbe, 0xb8, 0xf8,
2467+
0x8f, 0x70, 0xe3, 0x5a, 0xd3, 0x77, 0xc9, 0x9e, 0x10, 0x60, 0xb4,
2468+
0xdb, 0x0c, 0xc5, 0x05, 0xe1, 0x1f, 0xbd, 0xe6, 0x79, 0xee, 0x82,
2469+
0x3f, 0x51, 0x76, 0xe2, 0x7f, 0x5c, 0x11, 0x6d, 0xd3, 0x21, 0x69,
2470+
0xec, 0x05, 0x11, 0x8b, 0xc8, 0x39, 0xb3, 0x2c, 0xa6, 0x83, 0xb4,
2471+
0x6f, 0xac, 0x19, 0xd6, 0x6a, 0x65, 0x0d, 0x08, 0x94, 0x58, 0xde,
2472+
0x3d, 0xc9, 0x0c, 0x54, 0x03, 0x73, 0x0c, 0x8d, 0x24, 0x09, 0xf3,
2473+
0xb1, 0x5d, 0xd2, 0xe3, 0xeb, 0x56, 0xd6, 0x28, 0x66, 0x5b, 0x02,
2474+
0x03, 0x01, 0x00, 0x01, 0xa3, 0x63, 0x30, 0x61, 0x30, 0x0f, 0x06,
2475+
0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03,
2476+
0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01,
2477+
0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06,
2478+
0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x52, 0x97, 0x58,
2479+
0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e,
2480+
0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x1f, 0x06, 0x03, 0x55,
2481+
0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x52, 0x97, 0x58,
2482+
0x47, 0x98, 0xca, 0xf8, 0x99, 0xa0, 0x7e, 0x8e, 0x1c, 0x38, 0x2e,
2483+
0xea, 0xbb, 0xea, 0x9b, 0x74, 0x30, 0x30, 0x0d, 0x06, 0x09, 0x2a,
2484+
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
2485+
0x82, 0x01, 0x01, 0x00, 0x7d, 0x30, 0xd4, 0x6a, 0x01, 0x89, 0x3b,
2486+
0x62, 0xed, 0x16, 0x46, 0x59, 0x0f, 0xf2, 0x3b, 0xb5, 0xde, 0x89,
2487+
0x08, 0x17, 0x68, 0xcb, 0x46, 0xdc, 0x39, 0xa6, 0xcb, 0x56, 0xb0,
2488+
0x91, 0xeb, 0x03, 0xb2, 0x15, 0xc4, 0x3b, 0x4d, 0x63, 0x55, 0x22,
2489+
0x0a, 0x26, 0xe6, 0x64, 0x46, 0xe8, 0x0f, 0xa8, 0xf3, 0xde, 0xe1,
2490+
0x43, 0x54, 0xe6, 0xd7, 0x8a, 0xf4, 0x4f, 0xab, 0x56, 0x93, 0x12,
2491+
0x71, 0x4b, 0x25, 0x71, 0x0a, 0x31, 0x18, 0x79, 0xee, 0x45, 0xa4,
2492+
0xf5, 0x72, 0x67, 0xfa, 0x41, 0xd9, 0x87, 0x97, 0x09, 0xef, 0x55,
2493+
0xad, 0x6f, 0x47, 0x1d, 0x5a, 0xb2, 0xe9, 0xf7, 0x22, 0x05, 0x2d,
2494+
0x5a, 0x81, 0xa8, 0xe8, 0x53, 0xb0, 0x94, 0xf6, 0x63, 0xff, 0x3f,
2495+
0x51, 0x7a, 0x08, 0xac, 0x27, 0x9a, 0x57, 0x11, 0x22, 0xa4, 0x00,
2496+
0x84, 0x70, 0x86, 0x76, 0x39, 0x0f, 0x4f, 0x57, 0xcf, 0x8e, 0x94,
2497+
0xd2, 0x8e, 0x43, 0xc0, 0xd5, 0x34, 0x7d, 0xf5, 0xa1, 0x45, 0x1e,
2498+
0xb7, 0xc8, 0x7e, 0x7c, 0xfe, 0x5d, 0x4d, 0x53, 0x43, 0x25, 0x15,
2499+
0x9e, 0x08, 0x01, 0x56, 0xa4, 0xff, 0x79, 0x59, 0x25, 0xc9, 0x23,
2500+
0x98, 0xaf, 0x05, 0xaf, 0xc1, 0x0b, 0x29, 0xf1, 0xe2, 0xc4, 0x36,
2501+
0x31, 0x91, 0xfa, 0xf2, 0xbb, 0x12, 0xe8, 0x67, 0xf9, 0xc7, 0xa1,
2502+
0x5e, 0x8c, 0xed, 0x92, 0x12, 0xa3, 0x2b, 0xe1, 0xc2, 0xe1, 0xa0,
2503+
0xb0, 0x0e, 0x12, 0xa7, 0xd0, 0xa2, 0xae, 0xd6, 0xfa, 0x30, 0x21,
2504+
0x0f, 0x73, 0xfe, 0x24, 0x21, 0x5f, 0x03, 0x86, 0x69, 0xcd, 0xec,
2505+
0x76, 0x18, 0xe1, 0xfd, 0xb6, 0x64, 0x90, 0xa6, 0x06, 0x2e, 0x19,
2506+
0x40, 0x93, 0x50, 0x37, 0xe4, 0x90, 0xe3, 0x1f, 0x07, 0xae, 0xfb,
2507+
0x89, 0xc3, 0xf6, 0xc4, 0x90, 0xab, 0x40, 0x67, 0x4c, 0x43, 0x2c,
2508+
0xa2, 0xb0, 0x3e, 0x61, 0x16, 0x69, 0x8f
2509+
};
2510+
2511+
/* CRL with one revoked entry that carries a critical unknown extension
2512+
* (OID 2.5.29.1, old X.509v2 AKI, permanently superseded).
2513+
* Per RFC 5280 Section 5.3, the CRL must not be used. */
2514+
static const unsigned char crl_entry_critical[] = {
2515+
0x30, 0x82, 0x01, 0x8c, 0x30, 0x76, 0x02, 0x01, 0x01, 0x30, 0x0d,
2516+
0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b,
2517+
0x05, 0x00, 0x30, 0x15, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55,
2518+
0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x2d, 0x72,
2519+
0x6f, 0x6f, 0x74, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x34, 0x32, 0x31,
2520+
0x31, 0x32, 0x33, 0x33, 0x34, 0x38, 0x5a, 0x17, 0x0d, 0x33, 0x36,
2521+
0x30, 0x34, 0x31, 0x38, 0x31, 0x32, 0x33, 0x33, 0x34, 0x38, 0x5a,
2522+
0x30, 0x2d, 0x30, 0x2b, 0x02, 0x02, 0x10, 0x00, 0x17, 0x0d, 0x32,
2523+
0x36, 0x30, 0x34, 0x32, 0x31, 0x31, 0x32, 0x33, 0x33, 0x34, 0x38,
2524+
0x5a, 0x30, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x1d, 0x01, 0x01,
2525+
0x01, 0xff, 0x04, 0x0a, 0x0c, 0x08, 0x6f, 0x62, 0x73, 0x6f, 0x6c,
2526+
0x65, 0x74, 0x65, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
2527+
0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01,
2528+
0x00, 0x3c, 0xf1, 0xb9, 0x6e, 0x87, 0x6b, 0x33, 0x68, 0xca, 0xfb,
2529+
0xa2, 0x9c, 0xa9, 0x18, 0x7d, 0xbc, 0x49, 0x16, 0x84, 0xbc, 0xb1,
2530+
0x0a, 0x42, 0x62, 0x8f, 0x5a, 0x26, 0xed, 0x1f, 0x01, 0x30, 0xee,
2531+
0x5b, 0xa6, 0xfc, 0x59, 0x14, 0xe4, 0xaa, 0x74, 0xdf, 0x46, 0xbc,
2532+
0x8a, 0x98, 0x00, 0xd6, 0x13, 0x64, 0xd4, 0x33, 0x65, 0x93, 0x9e,
2533+
0xaf, 0xd0, 0xd2, 0x5d, 0xcd, 0x48, 0xf4, 0x28, 0x5a, 0xd7, 0xbf,
2534+
0x5d, 0xc8, 0x69, 0xc1, 0xb1, 0x7d, 0xf7, 0x81, 0xe4, 0x9d, 0x84,
2535+
0x5f, 0x7d, 0x27, 0x10, 0x3f, 0x91, 0x95, 0x15, 0xca, 0x77, 0xce,
2536+
0x9f, 0x9e, 0x84, 0x97, 0xb8, 0xb2, 0xc2, 0x43, 0xd0, 0xc8, 0x4a,
2537+
0x6e, 0x63, 0xbb, 0x90, 0x41, 0x17, 0xdc, 0xa7, 0xb0, 0xfb, 0xb4,
2538+
0x6c, 0xfc, 0x4b, 0xb9, 0x8d, 0x84, 0xe3, 0x00, 0x79, 0xa3, 0x7e,
2539+
0x8d, 0x1d, 0x8f, 0xb2, 0x69, 0xfc, 0xab, 0x56, 0x1c, 0xdd, 0x6d,
2540+
0x35, 0xbf, 0x06, 0x19, 0xa2, 0xcd, 0xea, 0x8c, 0x71, 0xb5, 0xc4,
2541+
0x36, 0x7a, 0xf7, 0xb4, 0x15, 0x15, 0x7e, 0xad, 0x6e, 0x76, 0xde,
2542+
0xbb, 0xf8, 0x41, 0xb0, 0x5f, 0x3b, 0xa2, 0x20, 0x32, 0x09, 0xb5,
2543+
0xe7, 0x85, 0x14, 0x0e, 0xbe, 0xb5, 0x6c, 0x2a, 0xa8, 0xeb, 0x65,
2544+
0x71, 0xa4, 0x7d, 0x12, 0x9f, 0x27, 0x57, 0x5e, 0x1d, 0xcd, 0x6f,
2545+
0x5a, 0x08, 0xa8, 0xed, 0xf8, 0x6b, 0x03, 0x5f, 0xc7, 0x6f, 0x8b,
2546+
0x1d, 0x7d, 0x35, 0x99, 0x53, 0x0b, 0x5d, 0xb9, 0x34, 0x48, 0xf5,
2547+
0x5c, 0x9a, 0xc3, 0x52, 0x0b, 0xe3, 0x57, 0x7e, 0xd0, 0x4c, 0x5d,
2548+
0xcd, 0x3b, 0x21, 0x20, 0x76, 0xdd, 0x74, 0x1f, 0xdd, 0xc8, 0x1c,
2549+
0xab, 0x46, 0xa9, 0x48, 0xcc, 0x97, 0x5e, 0x8a, 0x28, 0x2d, 0x77,
2550+
0x51, 0x9c, 0x7f, 0x51, 0x18, 0x4a, 0x85, 0xa2, 0x57, 0xc5, 0xda,
2551+
0x8f, 0xd4, 0x85, 0x9e
2552+
};
2553+
2554+
WOLFSSL_CERT_MANAGER* cm = NULL;
2555+
2556+
ExpectNotNull(cm = wolfSSL_CertManagerNew());
2557+
ExpectIntEQ(wolfSSL_CertManagerLoadCABuffer(cm, ca_cert,
2558+
sizeof(ca_cert), WOLFSSL_FILETYPE_ASN1), WOLFSSL_SUCCESS);
2559+
ExpectIntEQ(wolfSSL_CertManagerEnableCRL(cm, WOLFSSL_CRL_CHECKALL),
2560+
WOLFSSL_SUCCESS);
2561+
2562+
ExpectIntNE(wolfSSL_CertManagerLoadCRLBuffer(cm, crl_entry_critical,
2563+
sizeof(crl_entry_critical), WOLFSSL_FILETYPE_ASN1),
2564+
WOLFSSL_SUCCESS);
2565+
2566+
wolfSSL_CertManagerFree(cm);
2567+
#endif
2568+
return EXPECT_RESULT();
2569+
}
2570+
24302571
int test_wolfSSL_CertManagerCheckOCSPResponse(void)
24312572
{
24322573
EXPECT_DECLS;

tests/api/test_certman.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int test_wolfSSL_CRL_static_revoked_list(void);
4242
int test_wolfSSL_CRL_duplicate_extensions(void);
4343
int test_wolfSSL_CRL_critical_idp(void);
4444
int test_wolfSSL_CRL_unknown_critical_ext(void);
45+
int test_wolfSSL_CRL_unknown_critical_entry_ext(void);
4546
int test_wolfSSL_CertManagerCheckOCSPResponse(void);
4647
int test_various_pathlen_chains(void);
4748
int test_wolfSSL_CertManagerRejectMD5Cert(void);
@@ -65,6 +66,7 @@ int test_wolfSSL_CertManagerRejectMD5Cert(void);
6566
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_duplicate_extensions), \
6667
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_critical_idp), \
6768
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_unknown_critical_ext), \
69+
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_unknown_critical_entry_ext), \
6870
TEST_DECL_GROUP("certman", test_wolfSSL_CertManagerCheckOCSPResponse), \
6971
TEST_DECL_GROUP("certman", test_various_pathlen_chains), \
7072
TEST_DECL_GROUP("certman", test_wolfSSL_CertManagerRejectMD5Cert)

wolfcrypt/src/asn.c

Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34108,38 +34108,58 @@ static const byte crlReasonOid[] = { 0x55, 0x1d, 0x15 };
3410834108

3410934109
/* Parse CRL entry extensions to extract the reason code.
3411034110
* Sets *reasonCode if found, otherwise leaves it unchanged. */
34111-
static void ParseCRL_ReasonCode(const byte* buff, word32 idx, word32 maxIdx,
34112-
int* reasonCode)
34111+
static int ParseCRL_ReasonCode(const byte* buff, word32 idx, word32 maxIdx,
34112+
int* reasonCode)
3411334113
{
3411434114
while (idx < maxIdx) {
3411534115
int len;
34116+
int oidLen;
3411634117
word32 end;
3411734118
word32 localIdx;
34119+
word32 oidContent;
3411834120
byte tag;
34121+
int critical = 0;
34122+
int isReasonOid = 0;
3411934123

3412034124
/* Each extension is a SEQUENCE */
3412134125
if (GetSequence(buff, &idx, &len, maxIdx) < 0) {
3412234126
break;
3412334127
}
3412434128
end = idx + (word32)len;
3412534129

34126-
/* Check for CRL Reason OID: 2.5.29.21 */
34127-
if (end - idx >= (word32)(2 + sizeof(crlReasonOid)) &&
34128-
buff[idx] == ASN_OBJECT_ID &&
34129-
buff[idx + 1] == sizeof(crlReasonOid) &&
34130-
XMEMCMP(buff + idx + 2, crlReasonOid,
34130+
/* Parse OID: tag, length (short or long form), content */
34131+
if (GetASNTag(buff, &idx, &tag, end) < 0 ||
34132+
tag != ASN_OBJECT_ID) {
34133+
break;
34134+
}
34135+
if (GetLength(buff, &idx, &oidLen, end) < 0) {
34136+
break;
34137+
}
34138+
oidContent = idx;
34139+
if (idx + (word32)oidLen > end) {
34140+
break;
34141+
}
34142+
34143+
/* Check if it's the CRL Reason OID: 2.5.29.21 */
34144+
if ((word32)oidLen == sizeof(crlReasonOid) &&
34145+
XMEMCMP(buff + oidContent, crlReasonOid,
3413134146
sizeof(crlReasonOid)) == 0) {
34132-
/* Skip past the OID */
34133-
idx += 2 + (word32)sizeof(crlReasonOid);
34134-
/* Skip optional critical BOOLEAN */
34135-
localIdx = idx;
34136-
if (GetASNTag(buff, &localIdx, &tag, end) == 0 &&
34137-
tag == ASN_BOOLEAN) {
34138-
/* Consume full BOOLEAN TLV (tag + length + value). */
34139-
if (GetBoolean(buff, &idx, end) < 0) {
34140-
break;
34141-
}
34147+
isReasonOid = 1;
34148+
}
34149+
idx = oidContent + (word32)oidLen;
34150+
34151+
/* Parse optional critical BOOLEAN */
34152+
localIdx = idx;
34153+
if (GetASNTag(buff, &localIdx, &tag, end) == 0 &&
34154+
tag == ASN_BOOLEAN) {
34155+
int ret = GetBoolean(buff, &idx, end);
34156+
if (ret < 0) {
34157+
break;
3414234158
}
34159+
critical = ret;
34160+
}
34161+
34162+
if (isReasonOid) {
3414334163
/* Get OCTET STRING wrapping the ENUMERATED */
3414434164
if (GetOctetString(buff, &idx, &len, end) >= 0) {
3414534165
/* Parse ENUMERATED reason value */
@@ -34155,8 +34175,15 @@ static void ParseCRL_ReasonCode(const byte* buff, word32 idx, word32 maxIdx,
3415534175
}
3415634176
}
3415734177
}
34178+
else if (critical) {
34179+
/* RFC 5280 Section 5.3: reject CRL with unknown critical
34180+
* entry extension. */
34181+
WOLFSSL_MSG("Unknown critical CRL entry extension");
34182+
return ASN_CRIT_EXT_E;
34183+
}
3415834184
idx = end;
3415934185
}
34186+
return 0;
3416034187
}
3416134188

3416234189
#ifdef HAVE_CRL
@@ -34169,8 +34196,7 @@ WOLFSSL_TEST_VIS int wc_ParseCRLReasonFromExtensions(const byte* ext,
3416934196
return BAD_FUNC_ARG;
3417034197
}
3417134198

34172-
ParseCRL_ReasonCode(ext, 0, extSz, reasonCode);
34173-
return 0;
34199+
return ParseCRL_ReasonCode(ext, 0, extSz, reasonCode);
3417434200
}
3417534201
#endif
3417634202

@@ -34232,40 +34258,43 @@ static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx,
3423234258

3423334259
/* Parse CRL entry extensions (v2 only) */
3423434260
if (dataASN[REVOKEDASN_IDX_TIME_EXT].length > 0) {
34261+
/* .offset points at the outer SEQUENCE tag. Re-parse the
34262+
* SEQUENCE header to locate the content start (list of
34263+
* Extension SEQUENCEs), which handles long-form length. */
3423534264
word32 extOff = dataASN[REVOKEDASN_IDX_TIME_EXT].offset;
34236-
word32 extLen = dataASN[REVOKEDASN_IDX_TIME_EXT].length;
34237-
word32 extEnd = extOff + extLen;
34238-
word32 extIdx2 = extOff;
34265+
word32 extTagEnd = extOff +
34266+
dataASN[REVOKEDASN_IDX_TIME_EXT].length + 6;
34267+
int extLen;
34268+
34269+
if (GetSequence(buff, &extOff, &extLen, extTagEnd) < 0) {
34270+
ret = ASN_PARSE_E;
34271+
}
34272+
else {
34273+
word32 extEnd = extOff + (word32)extLen;
3423934274

3424034275
#if defined(OPENSSL_EXTRA)
34241-
/* Store raw DER of extensions for OpenSSL compat API.
34242-
* Include the outer SEQUENCE tag+length. */
34243-
{
34244-
/* Back up to include the SEQUENCE header. We know the
34245-
* content starts at extOff, so the header is just before.
34246-
* Use the raw buffer start from before GetASN_Items. */
34247-
word32 seqHdrSz = 0;
34248-
/* The outer SEQUENCE header is at most 4 bytes before
34249-
* content. Rather than guess, store just the content. */
34250-
rc->extensions = (byte*)XMALLOC(extLen, dcrl->heap,
34276+
/* Store raw DER of extension contents for OpenSSL compat. */
34277+
rc->extensions = (byte*)XMALLOC((size_t)extLen, dcrl->heap,
3425134278
DYNAMIC_TYPE_REVOKED);
3425234279
if (rc->extensions != NULL) {
34253-
XMEMCPY(rc->extensions, buff + extOff, extLen);
34254-
rc->extensionsSz = extLen;
34280+
XMEMCPY(rc->extensions, buff + extOff, (size_t)extLen);
34281+
rc->extensionsSz = (word32)extLen;
3425534282
}
34256-
(void)seqHdrSz;
34257-
}
3425834283
#endif
3425934284

34260-
ParseCRL_ReasonCode(buff, extIdx2, extEnd, &rc->reasonCode);
34285+
ret = ParseCRL_ReasonCode(buff, extOff, extEnd,
34286+
&rc->reasonCode);
34287+
}
3426134288
}
3426234289

34263-
/* Add revoked certificate to chain. */
34290+
if (ret == 0) {
34291+
/* Add revoked certificate to chain. */
3426434292
#ifndef CRL_STATIC_REVOKED_LIST
34265-
rc->next = dcrl->certs;
34266-
dcrl->certs = rc;
34293+
rc->next = dcrl->certs;
34294+
dcrl->certs = rc;
3426734295
#endif
34268-
dcrl->totalCerts++;
34296+
dcrl->totalCerts++;
34297+
}
3426934298
}
3427034299

3427134300
FREE_ASNGETDATA(dataASN, dcrl->heap);
@@ -34299,7 +34328,13 @@ static int ParseCRL_RevokedCerts(RevokedCert* rcert, DecodedCRL* dcrl,
3429934328
/* Parse each revoked certificate. */
3430034329
while ((ret == 0) && (idx < maxIdx)) {
3430134330
/* Parse a revoked certificate. */
34302-
if (GetRevoked(rcert, buff, &idx, dcrl, maxIdx) < 0) {
34331+
int r = GetRevoked(rcert, buff, &idx, dcrl, maxIdx);
34332+
if (r == WC_NO_ERR_TRACE(ASN_CRIT_EXT_E)) {
34333+
/* Preserve the specific error so callers can distinguish a
34334+
* rejected critical extension from a generic parse failure. */
34335+
ret = r;
34336+
}
34337+
else if (r < 0) {
3430334338
ret = ASN_PARSE_E;
3430434339
}
3430534340
}

wolfcrypt/src/asn_orig.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9061,18 +9061,17 @@ static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx,
90619061
XFREE(rc, dcrl->heap, DYNAMIC_TYPE_REVOKED);
90629062
return ret;
90639063
}
9064-
/* add to list */
9065-
rc->next = dcrl->certs;
9066-
dcrl->certs = rc;
90679064

90689065
(void)rcert;
90699066
#endif /* CRL_STATIC_REVOKED_LIST */
9070-
dcrl->totalCerts++;
90719067
/* get date */
90729068
#ifndef NO_ASN_TIME
90739069
ret = GetBasicDate(buff, idx, rc->revDate, &rc->revDateFormat, maxIdx);
90749070
if (ret < 0) {
90759071
WOLFSSL_MSG("Expecting Date");
9072+
#ifndef CRL_STATIC_REVOKED_LIST
9073+
XFREE(rc, dcrl->heap, DYNAMIC_TYPE_REVOKED);
9074+
#endif
90769075
return ret;
90779076
}
90789077
#endif
@@ -9106,11 +9105,28 @@ static int GetRevoked(RevokedCert* rcert, const byte* buff, word32* idx,
91069105
}
91079106
#endif
91089107

9109-
ParseCRL_ReasonCode(buff, seqIdx, extEnd, &rc->reasonCode);
9108+
ret = ParseCRL_ReasonCode(buff, seqIdx, extEnd,
9109+
&rc->reasonCode);
9110+
if (ret != 0) {
9111+
#ifndef CRL_STATIC_REVOKED_LIST
9112+
#if defined(OPENSSL_EXTRA)
9113+
XFREE(rc->extensions, dcrl->heap, DYNAMIC_TYPE_REVOKED);
9114+
#endif
9115+
XFREE(rc, dcrl->heap, DYNAMIC_TYPE_REVOKED);
9116+
#endif
9117+
return ret;
9118+
}
91109119
}
91119120
}
91129121
}
91139122

9123+
#ifndef CRL_STATIC_REVOKED_LIST
9124+
/* add to list only after all parsing succeeded */
9125+
rc->next = dcrl->certs;
9126+
dcrl->certs = rc;
9127+
#endif
9128+
dcrl->totalCerts++;
9129+
91149130
*idx = end;
91159131

91169132
return 0;

0 commit comments

Comments
 (0)