[PATCH 19.07 v2 1/3] wolfssl: Fix OCSP request/response verification

Eneas U de Queiroz cotequeiroz at gmail.com
Mon Feb 14 13:19:08 PST 2022


In the case that the serial number in the OCSP request differs from the
serial number in the OCSP response the error from the comparison was not
resulting in a failed verification.

Signed-off-by: Eneas U de Queiroz <cotequeiroz at gmail.com>
---
 package/libs/wolfssl/Makefile                 |   2 +-
 .../patches/200-Fix-CompareOcspReqResp.patch  | 224 ++++++++++++++++++
 2 files changed, 225 insertions(+), 1 deletion(-)
 create mode 100644 package/libs/wolfssl/patches/200-Fix-CompareOcspReqResp.patch

diff --git a/package/libs/wolfssl/Makefile b/package/libs/wolfssl/Makefile
index 57fcaa03b2..631576a58e 100644
--- a/package/libs/wolfssl/Makefile
+++ b/package/libs/wolfssl/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=wolfssl
 PKG_VERSION:=4.7.0-stable
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=https://github.com/wolfSSL/wolfssl/archive/v$(PKG_VERSION)
diff --git a/package/libs/wolfssl/patches/200-Fix-CompareOcspReqResp.patch b/package/libs/wolfssl/patches/200-Fix-CompareOcspReqResp.patch
new file mode 100644
index 0000000000..9661a2b752
--- /dev/null
+++ b/package/libs/wolfssl/patches/200-Fix-CompareOcspReqResp.patch
@@ -0,0 +1,224 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Hayden Roche <hayden at wolfssl.com>
+Date: Tue, 27 Apr 2021 13:54:43 -0700
+Subject: [PATCH] Fix CompareOcspReqResp.
+
+There was a bug in this function that could cause a match to be reported even
+when the OCSP request and response in fact had a mismatch.
+
+(cherry picked from commit 73076940af8904f98eee085994c176fe1876b95a)
+
+diff --git a/src/ssl.c b/src/ssl.c
+index 14a160dc2..289ffb941 100644
+--- a/src/ssl.c
++++ b/src/ssl.c
+@@ -6503,7 +6503,7 @@ WOLFSSL_API int wolfSSL_CertManagerCheckOCSPResponse(WOLFSSL_CERT_MANAGER *cm,
+ {
+     int ret;
+ 
+-    WOLFSSL_ENTER("wolfSSL_CertManagerCheckOCSP_Staple");
++    WOLFSSL_ENTER("wolfSSL_CertManagerCheckOCSPResponse");
+     if (cm == NULL || response == NULL)
+         return BAD_FUNC_ARG;
+     if (cm->ocspEnabled == 0)
+diff --git a/tests/api.c b/tests/api.c
+index 6b3af3092..72bfc9aae 100644
+--- a/tests/api.c
++++ b/tests/api.c
+@@ -1091,6 +1091,170 @@ static int test_cm_load_ca_file(const char* ca_cert_file)
+ }
+ #endif /* !NO_FILESYSTEM && !NO_CERTS */
+ 
++static void test_wolfSSL_CertManagerCheckOCSPResponse(void)
++{
++#ifdef HAVE_OCSP
++/* Need one of these for wolfSSL_OCSP_REQUEST_new. */
++#if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || \
++    defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_APACHE_HTTPD) || \
++    defined(HAVE_LIGHTY)
++    WOLFSSL_CERT_MANAGER* cm = NULL;
++    /* Captured with Wireshark using ocsp.test. */
++    byte response[] = {
++        0x30, 0x82, 0x06, 0x3b, 0x0a, 0x01, 0x00, 0xa0, 0x82, 0x06, 0x34, 0x30, 0x82, 0x06, 0x30, 0x06,
++        0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01, 0x04, 0x82, 0x06, 0x21, 0x30, 0x82,
++        0x06, 0x1d, 0x30, 0x81, 0xbf, 0xa2, 0x16, 0x04, 0x14, 0x21, 0x29, 0x0a, 0x15, 0x08, 0xdd, 0x79,
++        0x01, 0x7c, 0xa3, 0xc6, 0x11, 0xe9, 0xbf, 0x8a, 0x33, 0x82, 0x53, 0xc4, 0x0c, 0x18, 0x0f, 0x32,
++        0x30, 0x32, 0x31, 0x30, 0x34, 0x32, 0x37, 0x32, 0x30, 0x32, 0x35, 0x35, 0x36, 0x5a, 0x30, 0x6f,
++        0x30, 0x6d, 0x30, 0x45, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04,
++        0x14, 0x9c, 0x4c, 0x71, 0x15, 0xc3, 0x02, 0x19, 0xca, 0x36, 0xdc, 0xb9, 0x8b, 0x21, 0x33, 0x00,
++        0x4c, 0xa4, 0xa7, 0x8e, 0xd3, 0x04, 0x14, 0xdd, 0xb3, 0xe7, 0x6d, 0xa8, 0x2e, 0xe8, 0xc5, 0x4e,
++        0x6e, 0xcf, 0x74, 0xe6, 0x75, 0x3c, 0x94, 0x15, 0xce, 0xe8, 0x1d, 0x02, 0x0c, 0x6f, 0x9c, 0x01,
++        0x78, 0x1c, 0x21, 0x80, 0x32, 0x25, 0x4a, 0x73, 0x2b, 0x80, 0x00, 0x18, 0x0f, 0x32, 0x30, 0x32,
++        0x31, 0x30, 0x34, 0x32, 0x37, 0x32, 0x30, 0x32, 0x35, 0x35, 0x36, 0x5a, 0xa0, 0x11, 0x18, 0x0f,
++        0x32, 0x30, 0x32, 0x31, 0x30, 0x35, 0x30, 0x31, 0x32, 0x30, 0x32, 0x35, 0x35, 0x36, 0x5a, 0xa1,
++        0x23, 0x30, 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x02,
++        0x04, 0x12, 0x04, 0x10, 0xc0, 0x42, 0x27, 0x55, 0xaf, 0xc4, 0x5c, 0x34, 0xe1, 0xc8, 0xef, 0x5b,
++        0x31, 0xb1, 0x78, 0xe9, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01,
++        0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x54, 0x1b, 0x9e, 0x10, 0x0f, 0x82, 0x2c, 0x8e,
++        0xd7, 0xdd, 0xf2, 0xec, 0x9c, 0x6c, 0x04, 0x5d, 0x57, 0x69, 0xcd, 0x30, 0x1b, 0xe8, 0xd4, 0x5d,
++        0xd4, 0x03, 0x97, 0xd1, 0x33, 0x78, 0x34, 0xdb, 0xc2, 0x4c, 0xc1, 0x8a, 0xee, 0xc7, 0x18, 0x6a,
++        0xe3, 0x6d, 0x59, 0x1b, 0xed, 0xf5, 0x87, 0xff, 0x9d, 0x11, 0xff, 0x5a, 0xa5, 0x12, 0x93, 0x0e,
++        0xc7, 0x67, 0xa4, 0x37, 0xb2, 0x8b, 0xba, 0xab, 0xe1, 0x29, 0x33, 0xe9, 0xf8, 0x10, 0x1d, 0xbf,
++        0x7c, 0x2b, 0x2e, 0x2e, 0x0b, 0x58, 0x5d, 0x8e, 0x0c, 0x44, 0xe2, 0x1d, 0x73, 0x2a, 0x8a, 0x6a,
++        0xc9, 0x4e, 0x2f, 0x7c, 0xa0, 0x94, 0x75, 0x50, 0xa7, 0x37, 0x77, 0xa3, 0xbf, 0x0e, 0xfc, 0x3a,
++        0x69, 0x58, 0x4d, 0x81, 0xee, 0x1c, 0x81, 0xdf, 0x4b, 0x94, 0x46, 0xcd, 0x55, 0xa4, 0xbf, 0xdb,
++        0xdc, 0x3e, 0xbd, 0xbb, 0x62, 0x74, 0x83, 0x48, 0xf8, 0x56, 0x19, 0xf5, 0xc0, 0x40, 0x3d, 0xca,
++        0x62, 0xd9, 0xa3, 0x31, 0x36, 0x1f, 0xd1, 0x84, 0xbd, 0x2c, 0x4b, 0xd5, 0x44, 0x2b, 0x96, 0x08,
++        0xb4, 0x44, 0x99, 0x03, 0x71, 0x56, 0xae, 0x1f, 0xd2, 0x6e, 0xce, 0xd4, 0x3d, 0x66, 0x48, 0xd6,
++        0x58, 0xde, 0x7a, 0x78, 0x48, 0x96, 0xfd, 0x56, 0x21, 0x1d, 0x6c, 0x40, 0x91, 0x9b, 0xd8, 0x25,
++        0xc7, 0x36, 0xc2, 0x8c, 0xd9, 0xd8, 0x47, 0xf0, 0x78, 0x45, 0x75, 0x37, 0x71, 0x08, 0xce, 0x05,
++        0xc3, 0xb5, 0xe3, 0xd1, 0xfb, 0xf1, 0x59, 0xf7, 0x77, 0x8d, 0x69, 0x14, 0xf4, 0xfc, 0xc6, 0x2e,
++        0x88, 0x9f, 0x8a, 0xfc, 0xc0, 0x65, 0x28, 0x02, 0xfa, 0x4f, 0xd4, 0x94, 0x8b, 0x06, 0xa1, 0xc1,
++        0x68, 0xc6, 0x77, 0x10, 0x1b, 0xc0, 0xae, 0x42, 0x98, 0x2e, 0x8d, 0xc2, 0xef, 0x61, 0x1d, 0x44,
++        0xc0, 0x51, 0xe9, 0x2d, 0x40, 0x6a, 0x14, 0xaa, 0xa0, 0x82, 0x04, 0x43, 0x30, 0x82, 0x04, 0x3f,
++        0x30, 0x82, 0x04, 0x3b, 0x30, 0x82, 0x03, 0x23, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0c, 0x50,
++        0xbe, 0xf6, 0x03, 0xdf, 0x09, 0x7f, 0x0d, 0x01, 0x2e, 0x9c, 0xf2, 0x30, 0x0d, 0x06, 0x09, 0x2a,
++        0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x62, 0x31, 0x0b, 0x30, 0x09,
++        0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x42, 0x45, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55,
++        0x04, 0x0a, 0x13, 0x10, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x6e,
++        0x76, 0x2d, 0x73, 0x61, 0x31, 0x38, 0x30, 0x36, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x2f, 0x47,
++        0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64,
++        0x65, 0x64, 0x20, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x43, 0x41,
++        0x20, 0x2d, 0x20, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36, 0x20, 0x2d, 0x20, 0x47, 0x33, 0x30, 0x1e,
++        0x17, 0x0d, 0x32, 0x31, 0x30, 0x32, 0x32, 0x31, 0x30, 0x35, 0x34, 0x34, 0x33, 0x30, 0x5a, 0x17,
++        0x0d, 0x32, 0x31, 0x30, 0x35, 0x32, 0x34, 0x30, 0x35, 0x34, 0x34, 0x32, 0x39, 0x5a, 0x30, 0x81,
++        0x8a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x53, 0x47, 0x31, 0x1b,
++        0x30, 0x19, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x12, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x53,
++        0x69, 0x67, 0x6e, 0x20, 0x50, 0x74, 0x65, 0x20, 0x4c, 0x74, 0x64, 0x31, 0x15, 0x30, 0x13, 0x06,
++        0x03, 0x55, 0x04, 0x05, 0x13, 0x0c, 0x32, 0x30, 0x31, 0x39, 0x30, 0x36, 0x31, 0x33, 0x30, 0x30,
++        0x30, 0x38, 0x31, 0x47, 0x30, 0x45, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x3e, 0x47, 0x6c, 0x6f,
++        0x62, 0x61, 0x6c, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x64, 0x65, 0x64,
++        0x20, 0x56, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x43, 0x41, 0x20, 0x2d,
++        0x20, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36, 0x20, 0x2d, 0x20, 0x47, 0x33, 0x20, 0x4f, 0x43, 0x53,
++        0x50, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, 0x65, 0x72, 0x30, 0x82, 0x01, 0x22, 0x30,
++        0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82,
++        0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xc1, 0x3b, 0xdb, 0x49,
++        0x41, 0x1a, 0xee, 0x2c, 0x9c, 0xda, 0x22, 0xd0, 0x20, 0x37, 0x8b, 0x3a, 0x2f, 0x66, 0x31, 0xe2,
++        0xc2, 0xab, 0x9b, 0x15, 0x61, 0xce, 0x5e, 0xf9, 0xc5, 0xe1, 0xc2, 0x77, 0x72, 0x4a, 0xeb, 0x96,
++        0x91, 0x05, 0x7d, 0xd6, 0x17, 0x2d, 0x9f, 0x9f, 0x1f, 0xeb, 0xcd, 0x2e, 0x3d, 0xff, 0x06, 0xfc,
++        0x26, 0xe1, 0x95, 0xae, 0x71, 0xc7, 0xad, 0xb2, 0x1e, 0x4d, 0x25, 0x48, 0x6d, 0xc5, 0xf6, 0x17,
++        0x42, 0xee, 0x2d, 0x63, 0xfc, 0xd0, 0x8c, 0x41, 0x57, 0x1b, 0x8e, 0xe4, 0x09, 0xb2, 0x11, 0x57,
++        0x8f, 0x42, 0xd1, 0xa2, 0x69, 0x99, 0xe4, 0xaf, 0xaa, 0x89, 0xe0, 0xd2, 0xa8, 0x42, 0xa1, 0x93,
++        0xa4, 0x06, 0xa9, 0x5b, 0x2f, 0x06, 0x80, 0xcf, 0x19, 0x82, 0x80, 0x53, 0x12, 0x35, 0xa3, 0x4c,
++        0x82, 0x5a, 0x96, 0xb2, 0x16, 0xca, 0x05, 0x90, 0xaf, 0x08, 0xaa, 0xed, 0x97, 0x55, 0xf6, 0x08,
++        0xbf, 0xf5, 0xd1, 0x9c, 0xa9, 0x63, 0xaf, 0x34, 0x47, 0xa9, 0xc4, 0x4d, 0x94, 0xc3, 0xc1, 0x98,
++        0x54, 0xa3, 0x9b, 0x76, 0xb8, 0x27, 0x49, 0x11, 0xbd, 0x9b, 0x77, 0x75, 0x52, 0x67, 0x6b, 0x25,
++        0x55, 0xa5, 0x6b, 0x38, 0xfe, 0xa1, 0x11, 0xaf, 0xf6, 0x3c, 0xb5, 0xac, 0x8f, 0xc4, 0xb3, 0xa4,
++        0x4f, 0xcd, 0x30, 0x00, 0x74, 0x72, 0x86, 0x80, 0xf2, 0x70, 0xdc, 0xb5, 0xf5, 0xcf, 0x8d, 0x39,
++        0x99, 0x80, 0xce, 0x22, 0xa7, 0xfe, 0x91, 0xee, 0x60, 0x9f, 0xa6, 0x9c, 0x86, 0x96, 0x02, 0x33,
++        0xc5, 0xe8, 0x08, 0xe4, 0x7d, 0x00, 0x01, 0x11, 0xcf, 0x4c, 0x18, 0xa5, 0xf6, 0xf6, 0x68, 0x36,
++        0x8c, 0x1b, 0x0c, 0x3b, 0x77, 0x2d, 0x1d, 0xb7, 0xa6, 0x71, 0xa0, 0x93, 0x54, 0xa2, 0x1c, 0x66,
++        0x32, 0xaf, 0xea, 0x08, 0x6a, 0x40, 0xb0, 0x42, 0x67, 0x4d, 0x33, 0x15, 0x02, 0x03, 0x01, 0x00,
++        0x01, 0xa3, 0x81, 0xc7, 0x30, 0x81, 0xc4, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18,
++        0x30, 0x16, 0x80, 0x14, 0xdd, 0xb3, 0xe7, 0x6d, 0xa8, 0x2e, 0xe8, 0xc5, 0x4e, 0x6e, 0xcf, 0x74,
++        0xe6, 0x75, 0x3c, 0x94, 0x15, 0xce, 0xe8, 0x1d, 0x30, 0x4c, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04,
++        0x45, 0x30, 0x43, 0x30, 0x41, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0xa0, 0x32, 0x01, 0x5f,
++        0x30, 0x34, 0x30, 0x32, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x26,
++        0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x67, 0x6c, 0x6f, 0x62,
++        0x61, 0x6c, 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x65, 0x70, 0x6f, 0x73,
++        0x69, 0x74, 0x6f, 0x72, 0x79, 0x2f, 0x30, 0x0f, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
++        0x30, 0x01, 0x05, 0x04, 0x02, 0x05, 0x00, 0x30, 0x13, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0c,
++        0x30, 0x0a, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x09, 0x30, 0x1d, 0x06, 0x03,
++        0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x21, 0x29, 0x0a, 0x15, 0x08, 0xdd, 0x79, 0x01, 0x7c,
++        0xa3, 0xc6, 0x11, 0xe9, 0xbf, 0x8a, 0x33, 0x82, 0x53, 0xc4, 0x0c, 0x30, 0x0e, 0x06, 0x03, 0x55,
++        0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x07, 0x80, 0x30, 0x0d, 0x06, 0x09, 0x2a,
++        0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x20,
++        0xe7, 0x5b, 0xa7, 0x87, 0xc2, 0x0c, 0xf4, 0xf4, 0x61, 0xb4, 0xe3, 0xd4, 0x10, 0xd5, 0xe8, 0x1f,
++        0x77, 0xe9, 0xff, 0x60, 0xda, 0xcb, 0x64, 0x3d, 0x16, 0x20, 0x8d, 0x25, 0xee, 0xf7, 0x23, 0x39,
++        0xaf, 0x59, 0x90, 0xe2, 0x1c, 0x33, 0xde, 0xeb, 0xad, 0xce, 0x09, 0x9f, 0x39, 0x71, 0xd4, 0x4f,
++        0x62, 0xca, 0x4b, 0x44, 0xae, 0xf3, 0x64, 0xa3, 0xe6, 0xc4, 0x74, 0x27, 0xda, 0xad, 0x18, 0x29,
++        0xad, 0x36, 0x28, 0xdc, 0x08, 0x2d, 0x9b, 0x0b, 0x0f, 0xea, 0x47, 0x78, 0x2b, 0xc6, 0x5d, 0xe0,
++        0x62, 0xb5, 0xcc, 0xf1, 0x40, 0x97, 0x23, 0xa9, 0x21, 0x05, 0x95, 0x5e, 0xef, 0x4f, 0xa4, 0x64,
++        0xcb, 0x6b, 0xa4, 0x13, 0x3a, 0x34, 0xbc, 0x47, 0x61, 0xd2, 0xc3, 0x31, 0x4e, 0x3d, 0x70, 0x97,
++        0x07, 0xc3, 0xcf, 0x8d, 0xb8, 0x71, 0x22, 0x3e, 0x17, 0xdd, 0xce, 0xd2, 0x2f, 0xa2, 0x73, 0x2e,
++        0x92, 0x29, 0xa9, 0xc1, 0xd2, 0xce, 0x65, 0xd7, 0xba, 0x88, 0x7b, 0x10, 0x1a, 0x3b, 0xb0, 0x2c,
++        0xa3, 0x33, 0xda, 0xb0, 0xc5, 0x2a, 0x32, 0x81, 0xd8, 0xa4, 0x7a, 0x75, 0xb9, 0xd2, 0xf6, 0xa9,
++        0x07, 0xc0, 0x5d, 0xcc, 0xfe, 0x95, 0xe7, 0x8c, 0x40, 0xc0, 0x40, 0xd7, 0xe4, 0xd2, 0xcb, 0x34,
++        0xa4, 0x75, 0x2c, 0x78, 0xe2, 0x78, 0x28, 0x69, 0x32, 0x7b, 0x79, 0x34, 0xfc, 0x70, 0x7d, 0x33,
++        0x4d, 0xc4, 0xfd, 0x45, 0x17, 0x81, 0xd5, 0xdb, 0xe6, 0x42, 0xc4, 0x65, 0x3c, 0xa9, 0x17, 0x47,
++        0xa8, 0x26, 0xad, 0x74, 0xb3, 0xd7, 0xb6, 0xa7, 0x6b, 0x18, 0xaf, 0x7b, 0x84, 0xf0, 0x5c, 0xd0,
++        0x1f, 0x39, 0xfa, 0xbf, 0x9c, 0x27, 0x34, 0x4e, 0x76, 0xec, 0x40, 0x11, 0x12, 0x8d, 0xc7, 0x24,
++        0x3b, 0xdd, 0x66, 0xba, 0x8e, 0x3f, 0x42, 0x50, 0x07, 0xf6, 0x7a, 0x56, 0x0e, 0x4d, 0x61
++    };
++    OcspEntry entry[1];
++    CertStatus status[1];
++    OcspRequest* request;
++    byte serial[] = {0x6f, 0x9c, 0x01, 0x78, 0x1c, 0x21, 0x80, 0x32, 0x25, 0x4a,
++                     0x73, 0x2b};
++    byte issuerHash[] = {0x9c, 0x4c, 0x71, 0x15, 0xc3, 0x02, 0x19, 0xca, 0x36,
++                         0xdc, 0xb9, 0x8b, 0x21, 0x33, 0x00, 0x4c, 0xa4, 0xa7,
++                         0x8e, 0xd3};
++    byte issuerKeyHash[] = {0xdd, 0xb3, 0xe7, 0x6d, 0xa8, 0x2e, 0xe8, 0xc5,
++                            0x4e, 0x6e, 0xcf, 0x74, 0xe6, 0x75, 0x3c, 0x94,
++                            0x15, 0xce, 0xe8, 0x1d};
++
++
++    printf(testingFmt, "wolfSSL_CertManagerCheckOCSPResponse()");
++
++    XMEMSET(entry, 0, sizeof(OcspEntry));
++    XMEMSET(status, 0, sizeof(CertStatus));
++
++    AssertNotNull(request = wolfSSL_OCSP_REQUEST_new());
++    request->serial = (byte*)XMALLOC(sizeof(serial), NULL,
++                                     DYNAMIC_TYPE_OCSP_REQUEST);
++    AssertNotNull(request->serial);
++
++    request->serialSz = sizeof(serial);
++    XMEMCPY(request->serial, serial, sizeof(serial));
++    XMEMCPY(request->issuerHash, issuerHash, sizeof(issuerHash));
++    XMEMCPY(request->issuerKeyHash, issuerKeyHash, sizeof(issuerKeyHash));
++
++    AssertNotNull(cm = wolfSSL_CertManagerNew_ex(NULL));
++    AssertIntEQ(wolfSSL_CertManagerEnableOCSP(cm, 0), WOLFSSL_SUCCESS);
++    AssertIntEQ(wolfSSL_CertManagerLoadCA(cm,
++        "./certs/external/ca-globalsign-root.pem", NULL), WOLFSSL_SUCCESS);
++
++    /* Response should be valid. */
++    AssertIntEQ(wolfSSL_CertManagerCheckOCSPResponse(cm, response,
++        sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
++
++    /* Flip a byte in the request serial number, response should be invalid
++     * now. */
++    request->serial[0] ^= request->serial[0];
++    AssertIntNE(wolfSSL_CertManagerCheckOCSPResponse(cm, response,
++        sizeof(response), NULL, status, entry, request), WOLFSSL_SUCCESS);
++
++
++    wolfSSL_OCSP_REQUEST_free(request);
++    wolfSSL_CertManagerFree(cm);
++
++    printf(resultFmt, passed);
++#endif /* OPENSSL_ALL || WOLFSSL_NGINX ||  WOLFSSL_HAPROXY ||
++        * WOLFSSL_APACHE_HTTPD || HAVE_LIGHTY */
++#endif /* HAVE_OCSP */
++}
++
+ static int test_wolfSSL_CertManagerLoadCABuffer(void)
+ {
+     int ret = 0;
+@@ -40273,6 +40437,7 @@ void ApiTest(void)
+     AssertIntEQ(test_wolfSSL_CTX_use_certificate_buffer(), WOLFSSL_SUCCESS);
+     test_wolfSSL_CTX_use_PrivateKey_file();
+     test_wolfSSL_CTX_load_verify_locations();
++    test_wolfSSL_CertManagerCheckOCSPResponse();
+     test_wolfSSL_CertManagerLoadCABuffer();
+     test_wolfSSL_CertManagerGetCerts();
+     test_wolfSSL_CertManagerSetVerify();
+diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c
+index fe2799478..bbf71e3c1 100644
+--- a/wolfcrypt/src/asn.c
++++ b/wolfcrypt/src/asn.c
+@@ -17950,9 +17950,10 @@ int CompareOcspReqResp(OcspRequest* req, OcspResponse* resp)
+     for (single = resp->single; single; single = next) {
+         cmp = req->serialSz - single->status->serialSz;
+         if (cmp == 0) {
+-            if ((XMEMCMP(req->serial, single->status->serial, req->serialSz) == 0)
+-             && (XMEMCMP(req->issuerHash, single->issuerHash, OCSP_DIGEST_SIZE) == 0)
+-             && (XMEMCMP(req->issuerKeyHash, single->issuerKeyHash, OCSP_DIGEST_SIZE) == 0)) {
++            cmp = XMEMCMP(req->serial, single->status->serial, req->serialSz)
++               || XMEMCMP(req->issuerHash, single->issuerHash, OCSP_DIGEST_SIZE)
++               || XMEMCMP(req->issuerKeyHash, single->issuerKeyHash, OCSP_DIGEST_SIZE);
++            if (cmp == 0) {
+                 /* match found */
+                 if (resp->single != single && prev) {
+                     /* move to top of list */



More information about the openwrt-devel mailing list