@@ -45,8 +45,8 @@ static std::vector<std::string> get_subject_alt_names(const X509* x509) {
45
45
return list;
46
46
}
47
47
48
- // verify that the csms certificate's commonName matches the CSMS FQDN
49
- bool verify_csms_cn ( const std::string& hostname, bool preverified, boost::asio::ssl::verify_context& ctx) {
48
+ bool WebsocketTLS::verify_csms_cn ( const std::string& hostname, bool preverified,
49
+ boost::asio::ssl::verify_context& ctx) {
50
50
51
51
// Error depth gives the depth in the chain (with 0 = leaf certificate) where
52
52
// a potential (!) error occurred; error here means current error code and can also be "OK".
@@ -59,6 +59,8 @@ bool verify_csms_cn(const std::string& hostname, bool preverified, boost::asio::
59
59
int error = X509_STORE_CTX_get_error (ctx.native_handle ());
60
60
EVLOG_warning << " Invalid certificate error '" << X509_verify_cert_error_string (error) << " ' (at chain depth '"
61
61
<< depth << " ')" ;
62
+
63
+ this ->connection_failed_callback (ConnectionFailedReason::InvalidCSMSCertificate);
62
64
}
63
65
64
66
// only check for CSMS server certificate
@@ -71,6 +73,7 @@ bool verify_csms_cn(const std::string& hostname, bool preverified, boost::asio::
71
73
char common_name[256 ];
72
74
if (X509_NAME_get_text_by_NID (subject_name, NID_commonName, common_name, sizeof (common_name)) <= 0 ) {
73
75
EVLOG_error << " Could not extract CN from CSMS server certificate" ;
76
+ this ->connection_failed_callback (ConnectionFailedReason::InvalidCSMSCertificate);
74
77
return false ;
75
78
}
76
79
@@ -96,6 +99,7 @@ bool verify_csms_cn(const std::string& hostname, bool preverified, boost::asio::
96
99
s << " '" << alt_name << " '" ;
97
100
}
98
101
EVLOG_warning << s.str ();
102
+ this ->connection_failed_callback (ConnectionFailedReason::InvalidCSMSCertificate);
99
103
return false ;
100
104
}
101
105
@@ -289,8 +293,9 @@ tls_context WebsocketTLS::on_tls_init(std::string hostname, websocketpp::connect
289
293
290
294
context->set_verify_mode (boost::asio::ssl::verify_peer);
291
295
if (this ->connection_options .verify_csms_common_name ) {
292
- context->set_verify_callback (websocketpp::lib::bind (
293
- &verify_csms_cn, hostname, websocketpp::lib::placeholders::_1, websocketpp::lib::placeholders::_2));
296
+ context->set_verify_callback ([this , hostname](bool preverified, boost::asio::ssl::verify_context& ctx) {
297
+ return this ->verify_csms_cn (hostname, preverified, ctx);
298
+ });
294
299
295
300
} else {
296
301
EVLOG_warning << " Not verifying the CSMS certificates commonName with the Fully Qualified Domain Name "
@@ -424,8 +429,6 @@ void WebsocketTLS::on_fail_tls(tls_client* c, websocketpp::connection_hdl hdl) {
424
429
const auto ec = con->get_ec ();
425
430
this ->log_on_fail (ec, con->get_transport_ec (), con->get_response_code ());
426
431
427
- // TODO(piet): Trigger SecurityEvent in case InvalidCentralSystemCertificate
428
-
429
432
// -1 indicates to always attempt to reconnect
430
433
if (this ->connection_options .max_connection_attempts == -1 or
431
434
this ->connection_attempts <= this ->connection_options .max_connection_attempts ) {
0 commit comments