From 031f334b56ed17c9e4b6756e35026a3ee2a1db20 Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Wed, 12 Jun 2024 10:12:38 -0400 Subject: [PATCH 1/3] Remove the OCSP nonce --- .../libs/System.Security.Cryptography.Native/pal_x509.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_x509.c b/src/native/libs/System.Security.Cryptography.Native/pal_x509.c index 04c6ba06cd5dc..9ad4b73b44a8e 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_x509.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_x509.c @@ -1181,8 +1181,9 @@ static OCSP_REQUEST* BuildOcspRequest(X509* subject, X509* issuer) // Ownership was successfully transferred to req certId = NULL; - // Add a random nonce. - OCSP_request_add1_nonce(req, NULL, -1); + // We return the request without setting a nonce on it. Most public CA OCSP responders ignore the nonce, and in some + // cases flat out error when presented with a nonce. + // This behavior also matches Windows and Apple platforms. return req; } From 98114a53af54c31503f0605c17891d9411abf72c Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Wed, 12 Jun 2024 10:17:23 -0400 Subject: [PATCH 2/3] Remove OCSP_request_add1_nonce from the shim --- .../libs/System.Security.Cryptography.Native/opensslshim.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/native/libs/System.Security.Cryptography.Native/opensslshim.h b/src/native/libs/System.Security.Cryptography.Native/opensslshim.h index f94ddc01274c4..57ba6a6809649 100644 --- a/src/native/libs/System.Security.Cryptography.Native/opensslshim.h +++ b/src/native/libs/System.Security.Cryptography.Native/opensslshim.h @@ -454,7 +454,6 @@ int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, unsigned char *md, size_t len); REQUIRED_FUNCTION(OCSP_cert_to_id) \ REQUIRED_FUNCTION(OCSP_check_nonce) \ REQUIRED_FUNCTION(OCSP_request_add0_id) \ - REQUIRED_FUNCTION(OCSP_request_add1_nonce) \ REQUIRED_FUNCTION(OCSP_REQUEST_free) \ REQUIRED_FUNCTION(OCSP_REQUEST_new) \ REQUIRED_FUNCTION(OCSP_resp_find_status) \ @@ -969,7 +968,6 @@ FOR_ALL_OPENSSL_FUNCTIONS #define OCSP_check_nonce OCSP_check_nonce_ptr #define OCSP_CERTID_free OCSP_CERTID_free_ptr #define OCSP_request_add0_id OCSP_request_add0_id_ptr -#define OCSP_request_add1_nonce OCSP_request_add1_nonce_ptr #define OCSP_REQUEST_free OCSP_REQUEST_free_ptr #define OCSP_REQUEST_new OCSP_REQUEST_new_ptr #define OCSP_resp_find_status OCSP_resp_find_status_ptr From 47afabc5169e496c41f7bb02b3273b3f611f7a9b Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Wed, 12 Jun 2024 11:54:20 -0400 Subject: [PATCH 3/3] Do not require nonces in the response --- src/native/libs/System.Security.Cryptography.Native/pal_x509.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_x509.c b/src/native/libs/System.Security.Cryptography.Native/pal_x509.c index 9ad4b73b44a8e..87791a45128ce 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_x509.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_x509.c @@ -948,7 +948,8 @@ static X509VerifyStatusCode CheckOcspGetExpiry(OCSP_REQUEST* req, int nonceCheck = req == NULL ? 1 : OCSP_check_nonce(req, basicResp); // Treat "response has no nonce" as success, since not all responders set the nonce. - if (nonceCheck == -1) + // Treat "neither has a nonce" as success, since we do not send nonces in our requests. + if (nonceCheck == -1 || nonceCheck == 2) { nonceCheck = 1; }