This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat-native.git
commit 0a7187ebd868a5d827e8c50807cd6502696f24aa Author: Mark Thomas <[email protected]> AuthorDate: Thu Dec 11 15:49:06 2025 +0000 Add the ability to control the OCSP verification flags. --- native/include/ssl_private.h | 2 ++ native/src/sslconf.c | 25 ++++++++++++++++++++++++- native/src/sslutils.c | 19 ++++++++++--------- xdocs/miscellaneous/changelog.xml | 3 +++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/native/include/ssl_private.h b/native/include/ssl_private.h index f55874178..caf503be5 100644 --- a/native/include/ssl_private.h +++ b/native/include/ssl_private.h @@ -312,6 +312,7 @@ struct tcn_ssl_ctxt_t { int no_ocsp_check; int ocsp_soft_fail; int ocsp_timeout; + int ocsp_verify_flags; }; #ifdef HAVE_SSL_CONF_CMD @@ -323,6 +324,7 @@ struct tcn_ssl_conf_ctxt_t { int no_ocsp_check; int ocsp_soft_fail; int ocsp_timeout; + int ocsp_verify_flags; }; #endif diff --git a/native/src/sslconf.c b/native/src/sslconf.c index 0dd853cb7..159179341 100644 --- a/native/src/sslconf.c +++ b/native/src/sslconf.c @@ -186,6 +186,18 @@ TCN_IMPLEMENT_CALL(jint, SSLConf, check)(TCN_STDARGS, jlong cctx, return 1; } + if (!strcmp(J2S(cmd), "OCSP_VERIFY_FLAGS")) { + int i; + errno = 0; + i = (int) strtol(J2S(value), NULL, 10); + if (!errno) { + c->ocsp_verify_flags = i; + } + TCN_FREE_CSTRING(cmd); + TCN_FREE_CSTRING(value); + return 1; + } + SSL_ERR_clear(); value_type = SSL_CONF_cmd_value_type(c->cctx, J2S(cmd)); ec = SSL_ERR_get(); @@ -242,7 +254,7 @@ TCN_IMPLEMENT_CALL(void, SSLConf, assign)(TCN_STDARGS, jlong cctx, sc->no_ocsp_check = c->no_ocsp_check; sc->ocsp_soft_fail = c->ocsp_soft_fail; sc->ocsp_timeout = c->ocsp_timeout; - // TODO verify + sc->ocsp_verify_flags = c->ocsp_verify_flags; } /* Apply a command to an SSL_CONF context */ @@ -312,6 +324,17 @@ TCN_IMPLEMENT_CALL(jint, SSLConf, apply)(TCN_STDARGS, jlong cctx, TCN_FREE_CSTRING(value); return 1; } + if (!strcmp(J2S(cmd), "OCSP_VERIFY_FLAGS")) { + int i; + errno = 0; + i = (int) strtol(J2S(value), NULL, 10); + if (!errno) { + c->ocsp_verify_flags = i; + } + TCN_FREE_CSTRING(cmd); + TCN_FREE_CSTRING(value); + return 1; + } SSL_ERR_clear(); rc = SSL_CONF_cmd(c->cctx, J2S(cmd), buf != NULL ? buf : J2S(value)); ec = SSL_ERR_get(); diff --git a/native/src/sslutils.c b/native/src/sslutils.c index 4bb68f60e..79741d0ac 100644 --- a/native/src/sslutils.c +++ b/native/src/sslutils.c @@ -33,8 +33,8 @@ extern int WIN32_SSL_password_prompt(tcn_pass_cb_t *data); #define ASN1_SEQUENCE 0x30 #define ASN1_OID 0x06 #define ASN1_STRING 0x86 -static int ssl_verify_OCSP(X509_STORE_CTX *ctx, int timeout); -static int ssl_ocsp_request(X509 *cert, X509 *issuer, X509_STORE_CTX *ctx, int timeout); +static int ssl_verify_OCSP(X509_STORE_CTX *ctx, int timeout, int verifyFlags); +static int ssl_ocsp_request(X509 *cert, X509 *issuer, X509_STORE_CTX *ctx, int timeout, int verifyFlags); #endif /* _________________________________________________________________ @@ -306,6 +306,7 @@ int SSL_callback_SSL_verify(int ok, X509_STORE_CTX *ctx) int ocsp_check_type = con->ctx->no_ocsp_check; int ocsp_soft_fail = con->ctx->ocsp_soft_fail; int ocsp_timeout = con->ctx->ocsp_timeout; + int ocsp_verify_flags = con->ctx->ocsp_verify_flags; #if defined(SSL_OP_NO_TLSv1_3) con->pha_state = PHA_COMPLETE; @@ -351,7 +352,7 @@ int SSL_callback_SSL_verify(int ok, X509_STORE_CTX *ctx) ok = 0; } else { - int ocsp_response = ssl_verify_OCSP(ctx, ocsp_timeout); + int ocsp_response = ssl_verify_OCSP(ctx, ocsp_timeout, ocsp_verify_flags); if (ocsp_response == OCSP_STATUS_REVOKED) { ok = 0 ; errnum = X509_STORE_CTX_get_error(ctx); @@ -494,7 +495,7 @@ int SSL_callback_alpn_select_proto(SSL* ssl, const unsigned char **out, unsigned #ifdef HAVE_OCSP /* Function that is used to do the OCSP verification */ -static int ssl_verify_OCSP(X509_STORE_CTX *ctx, int timeout) +static int ssl_verify_OCSP(X509_STORE_CTX *ctx, int timeout, int verifyFlags) { X509 *cert, *issuer; int r = OCSP_STATUS_UNKNOWN; @@ -519,7 +520,7 @@ static int ssl_verify_OCSP(X509_STORE_CTX *ctx, int timeout) /* if we can't get the issuer, we cannot perform OCSP verification */ issuer = X509_STORE_CTX_get0_current_issuer(ctx); if (issuer != NULL) { - r = ssl_ocsp_request(cert, issuer, ctx, timeout); + r = ssl_ocsp_request(cert, issuer, ctx, timeout, verifyFlags); switch (r) { case OCSP_STATUS_OK: X509_STORE_CTX_set_error(ctx, X509_V_OK); @@ -1014,7 +1015,7 @@ end: answer according to the status. */ static int process_ocsp_response(OCSP_REQUEST *ocsp_req, OCSP_RESPONSE *ocsp_resp, X509 *cert, X509 *issuer, - X509_STORE_CTX *ctx) + X509_STORE_CTX *ctx, int verifyFlags) { int r, o = V_OCSP_CERTSTATUS_UNKNOWN, i; OCSP_BASICRESP *bs; @@ -1038,7 +1039,7 @@ static int process_ocsp_response(OCSP_REQUEST *ocsp_req, OCSP_RESPONSE *ocsp_res } certStack = OCSP_resp_get0_certs(bs); - if (OCSP_basic_verify(bs, certStack, X509_STORE_CTX_get0_store(ctx), 0) <= 0) { + if (OCSP_basic_verify(bs, certStack, X509_STORE_CTX_get0_store(ctx), verifyFlags) <= 0) { X509_STORE_CTX_set_error(ctx, X509_V_ERR_OCSP_SIGNATURE_FAILURE); o = OCSP_STATUS_UNKNOWN; goto clean_bs; @@ -1078,7 +1079,7 @@ clean_bs: return o; } -static int ssl_ocsp_request(X509 *cert, X509 *issuer, X509_STORE_CTX *ctx, int timeout) +static int ssl_ocsp_request(X509 *cert, X509 *issuer, X509_STORE_CTX *ctx, int timeout, int verifyFlags) { char **ocsp_urls = NULL; int nid; @@ -1109,7 +1110,7 @@ static int ssl_ocsp_request(X509 *cert, X509 *issuer, X509_STORE_CTX *ctx, int t if (req != NULL) { resp = get_ocsp_response(p, ocsp_urls[0], req, timeout); if (resp != NULL) { - rv = process_ocsp_response(req, resp, cert, issuer, ctx); + rv = process_ocsp_response(req, resp, cert, issuer, ctx, verifyFlags); } else { /* Unable to send request / receive response. */ X509_STORE_CTX_set_error(ctx, X509_V_ERR_UNABLE_TO_GET_CRL); diff --git a/xdocs/miscellaneous/changelog.xml b/xdocs/miscellaneous/changelog.xml index a6ef70a93..633316592 100644 --- a/xdocs/miscellaneous/changelog.xml +++ b/xdocs/miscellaneous/changelog.xml @@ -53,6 +53,9 @@ Add a configurable timeout to the writing of OCSP requests and reading of OCSP responses. (markt) </add> + <add> + Add the ability to control the OCSP verification flags. (markt) + </add> </changelog> </section> <section name="Changes in 2.0.9"> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
