@@ -14,15 +14,14 @@ namespace Tls {
1414PlatformBridgeCertValidator::PlatformBridgeCertValidator (
1515 const Envoy::Ssl::CertificateValidationContextConfig* config, SslStats& stats,
1616 const envoy_cert_validator* platform_validator)
17- : config_(config), stats_(stats), platform_validator_(platform_validator) {
17+ : allow_untrusted_certificate_(config != nullptr &&
18+ config->trustChainVerification () ==
19+ envoy::extensions::transport_sockets::tls::v3::
20+ CertificateValidationContext::ACCEPT_UNTRUSTED),
21+ platform_validator_(platform_validator), stats_(stats) {
1822 ENVOY_BUG (config != nullptr && config->caCert ().empty () &&
1923 config->certificateRevocationList ().empty (),
2024 " Invalid certificate validation context config." );
21- if (config_ != nullptr ) {
22- allow_untrusted_certificate_ = config_->trustChainVerification () ==
23- envoy::extensions::transport_sockets::tls::v3::
24- CertificateValidationContext::ACCEPT_UNTRUSTED;
25- }
2625}
2726
2827PlatformBridgeCertValidator::~PlatformBridgeCertValidator () {
@@ -34,17 +33,12 @@ PlatformBridgeCertValidator::~PlatformBridgeCertValidator() {
3433 }
3534}
3635
37- int PlatformBridgeCertValidator::initializeSslContexts (std::vector<SSL_CTX*> /* contexts*/ ,
38- bool /* handshaker_provides_certificates*/ ) {
39- return SSL_VERIFY_PEER;
40- }
41-
4236ValidationResults PlatformBridgeCertValidator::doVerifyCertChain (
4337 STACK_OF (X509) & cert_chain, Ssl::ValidateResultCallbackPtr callback,
4438 Ssl::SslExtendedSocketInfo* ssl_extended_info,
4539 const Network::TransportSocketOptionsConstSharedPtr& transport_socket_options,
4640 SSL_CTX& /* ssl_ctx*/ , const CertValidator::ExtraValidationContext& /* validation_context*/ ,
47- bool is_server, absl::string_view host_name ) {
41+ bool is_server, absl::string_view hostname ) {
4842 ASSERT (!is_server);
4943 if (sk_X509_num (&cert_chain) == 0 ) {
5044 if (ssl_extended_info) {
@@ -78,10 +72,18 @@ ValidationResults PlatformBridgeCertValidator::doVerifyCertChain(
7872 !transport_socket_options->verifySubjectAltNameListOverride ().empty ()) {
7973 host = transport_socket_options->verifySubjectAltNameListOverride ()[0 ];
8074 } else {
81- host = host_name ;
75+ host = hostname ;
8276 }
77+
78+ std::vector<std::string> subject_alt_names;
79+ if (transport_socket_options != nullptr ) {
80+ subject_alt_names = transport_socket_options->verifySubjectAltNameListOverride ();
81+ } else {
82+ subject_alt_names = {std::string (hostname)};
83+ }
84+
8385 auto validation = std::make_unique<PendingValidation>(
84- *this , std::move (certs), host, std::move (transport_socket_options ), std::move (callback));
86+ *this , std::move (certs), host, std::move (subject_alt_names ), std::move (callback));
8587 PendingValidation* validation_ptr = validation.get ();
8688 validations_.insert (std::move (validation));
8789 std::thread verification_thread (&PendingValidation::verifyCertsByPlatform, validation_ptr);
@@ -91,16 +93,16 @@ ValidationResults PlatformBridgeCertValidator::doVerifyCertChain(
9193}
9294
9395void PlatformBridgeCertValidator::verifyCertChainByPlatform (
94- std::vector<envoy_data>& cert_chain, const std::string& host_name ,
96+ const std::vector<envoy_data>& cert_chain, const std::string& hostname ,
9597 const std::vector<std::string>& subject_alt_names, PendingValidation& pending_validation) {
9698 ASSERT (!cert_chain.empty ());
97- ENVOY_LOG (trace, " Start verifyCertChainByPlatform for host {}" , host_name );
99+ ENVOY_LOG (trace, " Start verifyCertChainByPlatform for host {}" , hostname );
98100 // This is running in a stand alone thread other than the engine thread.
99101 envoy_data leaf_cert_der = cert_chain[0 ];
100102 bssl::UniquePtr<X509> leaf_cert (d2i_X509 (
101103 nullptr , const_cast <const unsigned char **>(&leaf_cert_der.bytes ), leaf_cert_der.length ));
102104 envoy_cert_validation_result result =
103- platform_validator_->validate_cert (cert_chain.data (), cert_chain.size (), host_name .c_str ());
105+ platform_validator_->validate_cert (cert_chain.data (), cert_chain.size (), hostname .c_str ());
104106 bool success = result.result == ENVOY_SUCCESS;
105107 if (!success) {
106108 ENVOY_LOG (debug, result.error_details );
@@ -126,20 +128,15 @@ void PlatformBridgeCertValidator::verifyCertChainByPlatform(
126128}
127129
128130void PlatformBridgeCertValidator::PendingValidation::verifyCertsByPlatform () {
129- parent_.verifyCertChainByPlatform (
130- certs_, host_name_,
131- (transport_socket_options_ != nullptr
132- ? transport_socket_options_->verifySubjectAltNameListOverride ()
133- : std::vector<std::string>{host_name_}),
134- *this );
131+ parent_.verifyCertChainByPlatform (certs_, hostname_, subject_alt_names_, *this );
135132}
136133
137134void PlatformBridgeCertValidator::PendingValidation::postVerifyResultAndCleanUp (
138135 bool success, absl::string_view error_details, uint8_t tls_alert,
139136 OptRef<Stats::Counter> error_counter) {
140137 ENVOY_LOG (trace,
141138 " Finished platform cert validation for {}, post result callback to network thread" ,
142- host_name_ );
139+ hostname_ );
143140
144141 if (parent_.platform_validator_ ->validation_cleanup ) {
145142 parent_.platform_validator_ ->validation_cleanup ();
@@ -153,7 +150,7 @@ void PlatformBridgeCertValidator::PendingValidation::postVerifyResultAndCleanUp(
153150 if (weak_alive_indicator.expired ()) {
154151 return ;
155152 }
156- ENVOY_LOG (trace, " Got validation result for {} from platform" , host_name_ );
153+ ENVOY_LOG (trace, " Got validation result for {} from platform" , hostname_ );
157154 parent_.validation_threads_ [thread_id].join ();
158155 parent_.validation_threads_ .erase (thread_id);
159156 if (error_counter.has_value ()) {
0 commit comments