Skip to content

Commit 3532929

Browse files
authored
Merge pull request #10554 from gasbytes/ocsp-certid-serial-number-fix
OCSP_resp_find_status to require exact serial-length match
2 parents 12e7a1d + 53e1db4 commit 3532929

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/ocsp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,8 @@ int wolfSSL_OCSP_resp_find_status(WOLFSSL_OCSP_BASICRESP *bs,
776776
single = bs->single;
777777
while (single != NULL) {
778778
if (single->status != NULL && id->status != NULL &&
779-
(XMEMCMP(single->status->serial, id->status->serial,
779+
(single->status->serialSz == id->status->serialSz)
780+
&& (XMEMCMP(single->status->serial, id->status->serial,
780781
(size_t)single->status->serialSz) == 0)
781782
&& (XMEMCMP(single->issuerHash, id->issuerHash, OCSP_DIGEST_SIZE) == 0)
782783
&& (XMEMCMP(single->issuerKeyHash, id->issuerKeyHash, OCSP_DIGEST_SIZE) == 0)) {

tests/api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35023,6 +35023,7 @@ TEST_CASE testCases[] = {
3502335023
TEST_DECL(test_ocsp_response_parsing),
3502435024
TEST_DECL(test_ocsp_certid_enc_dec),
3502535025
TEST_DECL(test_ocsp_certid_dup),
35026+
TEST_DECL(test_ocsp_resp_find_status_serial_prefix),
3502635027
TEST_DECL(test_ocsp_tls_cert_cb),
3502735028
TEST_DECL(test_ocsp_cert_unknown_crl_fallback),
3502835029
TEST_DECL(test_ocsp_cert_unknown_crl_fallback_nonleaf),

tests/api/test_ocsp.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,63 @@ int test_ocsp_certid_dup(void)
774774
}
775775
#endif
776776

777+
int test_ocsp_resp_find_status_serial_prefix(void)
778+
{
779+
EXPECT_DECLS;
780+
#if defined(HAVE_OCSP) && defined(OPENSSL_EXTRA) && !defined(NO_SHA)
781+
OcspResponse response;
782+
OcspEntry single;
783+
CertStatus responseStatus;
784+
OcspEntry requestedId;
785+
CertStatus requestedStatus;
786+
int status;
787+
788+
XMEMSET(&response, 0, sizeof(response));
789+
XMEMSET(&single, 0, sizeof(single));
790+
XMEMSET(&responseStatus, 0, sizeof(responseStatus));
791+
XMEMSET(&requestedId, 0, sizeof(requestedId));
792+
XMEMSET(&requestedStatus, 0, sizeof(requestedStatus));
793+
794+
single.status = &responseStatus;
795+
requestedId.status = &requestedStatus;
796+
response.single = &single;
797+
798+
/* Matching issuer name and key hashes on both sides. */
799+
XMEMSET(single.issuerHash, 0x41, OCSP_DIGEST_SIZE);
800+
XMEMSET(single.issuerKeyHash, 0x42, OCSP_DIGEST_SIZE);
801+
XMEMCPY(requestedId.issuerHash, single.issuerHash, OCSP_DIGEST_SIZE);
802+
XMEMCPY(requestedId.issuerKeyHash, single.issuerKeyHash, OCSP_DIGEST_SIZE);
803+
804+
/* Response carries a CERT_GOOD status for serial 01:02 (2 bytes). */
805+
responseStatus.serial[0] = 0x01;
806+
responseStatus.serial[1] = 0x02;
807+
responseStatus.serialSz = 2;
808+
responseStatus.status = CERT_GOOD;
809+
810+
/* Sanity check: an exact serial match must be found and report CERT_GOOD. */
811+
requestedStatus.serial[0] = 0x01;
812+
requestedStatus.serial[1] = 0x02;
813+
requestedStatus.serialSz = 2;
814+
status = -1;
815+
ExpectIntEQ(wolfSSL_OCSP_resp_find_status(&response, &requestedId, &status,
816+
NULL, NULL, NULL, NULL), WOLFSSL_SUCCESS);
817+
ExpectIntEQ(status, CERT_GOOD);
818+
819+
/* Request serial 01:02:03 (3 bytes) shares the 01:02 prefix of the
820+
* response serial.
821+
* The lookup must not bind the good response to this longer and
822+
* differing serial. */
823+
requestedStatus.serial[0] = 0x01;
824+
requestedStatus.serial[1] = 0x02;
825+
requestedStatus.serial[2] = 0x03;
826+
requestedStatus.serialSz = 3;
827+
status = -1;
828+
ExpectIntEQ(wolfSSL_OCSP_resp_find_status(&response, &requestedId, &status,
829+
NULL, NULL, NULL, NULL), WOLFSSL_FAILURE);
830+
#endif
831+
return EXPECT_RESULT();
832+
}
833+
777834
#if defined(HAVE_OCSP) && defined(WOLFSSL_CERT_SETUP_CB) && \
778835
defined(HAVE_SSL_MEMIO_TESTS_DEPENDENCIES) && !defined(NO_RSA) && \
779836
(defined(HAVE_CERTIFICATE_STATUS_REQUEST) || \

tests/api/test_ocsp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
int test_ocsp_certid_enc_dec(void);
2626
int test_ocsp_certid_dup(void);
27+
int test_ocsp_resp_find_status_serial_prefix(void);
2728
int test_ocsp_status_callback(void);
2829
int test_ocsp_basic_verify(void);
2930
int test_ocsp_responder_keyhash_binding(void);

0 commit comments

Comments
 (0)