Skip to content

Commit

Permalink
TLS: in OpenSSL verify_callback_server(), set fine-grained alert erro…
Browse files Browse the repository at this point in the history
…r codes

For example, early rejection of common name will call
X509_STORE_CTX_set_error with X509_V_ERR_CERT_REJECTED.

This, in turn, will alert the client:

  EVENT: TLS_ALERT_MISC OpenSSLContext::SSL::read_cleartext:
  BIO_read failed, cap=2640 status=0: error:14094412:
  SSL routines:ssl3_read_bytes:sslv3 alert bad certificate[bad certificate]
  [FATAL-ERR]

Signed-off-by: James Yonan <[email protected]>
  • Loading branch information
jamesyonan authored and Jenkins-dev committed Jan 10, 2025
1 parent a96c32c commit cdd7852
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions openvpn/openssl/ssl/sslctx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,7 @@ class OpenSSLContext : public SSLFactoryAPI
self_ssl->authcert->add_fail(depth,
AuthCert::Fail::BAD_CERT_TYPE,
"bad peer-fingerprint in leaf certificate");
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_SIGNATURE_FAILURE);
preverify_ok = false;
}

Expand All @@ -1987,6 +1988,7 @@ class OpenSSLContext : public SSLFactoryAPI
self_ssl->authcert->add_fail(depth,
AuthCert::Fail::BAD_CERT_TYPE,
"bad ns-cert-type in leaf certificate");
X509_STORE_CTX_set_error(ctx, X509_V_ERR_INVALID_PURPOSE);
preverify_ok = false;
}

Expand All @@ -1998,6 +2000,7 @@ class OpenSSLContext : public SSLFactoryAPI
self_ssl->authcert->add_fail(depth,
AuthCert::Fail::BAD_CERT_TYPE,
"bad X509 key usage in leaf certificate");
X509_STORE_CTX_set_error(ctx, X509_V_ERR_INVALID_PURPOSE);
preverify_ok = false;
}

Expand All @@ -2009,6 +2012,7 @@ class OpenSSLContext : public SSLFactoryAPI
self_ssl->authcert->add_fail(depth,
AuthCert::Fail::BAD_CERT_TYPE,
"bad X509 extended key usage in leaf certificate");
X509_STORE_CTX_set_error(ctx, X509_V_ERR_INVALID_PURPOSE);
preverify_ok = false;
}

Expand All @@ -2023,12 +2027,14 @@ class OpenSSLContext : public SSLFactoryAPI
if (self->config->cn_reject_handler->reject(cn))
{
OVPN_LOG_INFO("VERIFY FAIL -- early rejection of leaf cert Common Name");
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REJECTED);
preverify_ok = false;
}
}
catch (const std::exception &e)
{
OVPN_LOG_INFO("VERIFY FAIL -- early rejection of leaf cert Common Name due to handler exception: " << e.what());
X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REJECTED);
preverify_ok = false;
}
}
Expand Down

0 comments on commit cdd7852

Please sign in to comment.