Skip to content

Commit a8bc825

Browse files
author
Serris Lew
committed
Additional logging
1 parent 264e35e commit a8bc825

2 files changed

Lines changed: 52 additions & 39 deletions

File tree

iocore/net/SSLConfig.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ SSLConfig::startup()
496496
void
497497
SSLConfig::reconfigure()
498498
{
499-
Debug("ssl", "Reload SSLConfig");
499+
Debug("ssl_load", "Reload SSLConfig");
500500
SSLConfigParams *params;
501501
params = new SSLConfigParams;
502502
// start loading the next config
@@ -538,8 +538,7 @@ SSLCertificateConfig::startup()
538538
// proxy.config.ssl.server.multicert.exit_on_load_fail is true
539539
SSLConfig::scoped_config params;
540540
if (!reconfigure() && params->configExitOnLoadError) {
541-
Fatal("failed to load SSL certificate file, %s",
542-
(!params->configFilePath || params->configFilePath[0] == '\0') ? "[empty file name]" : params->configFilePath);
541+
Fatal("failed to load SSL certificate file, %s", params->configFilePath);
543542
}
544543

545544
return true;
@@ -556,7 +555,7 @@ SSLCertificateConfig::reconfigure()
556555
// twice the healthcheck period to simulate a loading a large certificate set.
557556
if (is_action_tag_set("test.multicert.delay")) {
558557
const int secs = 60;
559-
Debug("ssl", "delaying certificate reload by %d secs", secs);
558+
Debug("ssl_load", "delaying certificate reload by %d secs", secs);
560559
ink_hrtime_sleep(HRTIME_SECONDS(secs));
561560
}
562561

@@ -632,7 +631,7 @@ SSLTicketParams::LoadTicket(bool &nochange)
632631
struct stat sdata;
633632
if (last_load_time && (stat(ticket_key_filename, &sdata) >= 0)) {
634633
if (sdata.st_mtime && sdata.st_mtime <= last_load_time) {
635-
Debug("ssl", "ticket key %s has not changed", ticket_key_filename);
634+
Debug("ssl_load", "ticket key %s has not changed", ticket_key_filename);
636635
// No updates since last load
637636
return true;
638637
}
@@ -654,7 +653,7 @@ SSLTicketParams::LoadTicket(bool &nochange)
654653
default_global_keyblock = keyblock;
655654
load_time = time(nullptr);
656655

657-
Debug("ssl", "ticket key reloaded from %s", ticket_key_filename);
656+
Debug("ssl_load", "ticket key reloaded from %s", ticket_key_filename);
658657
#endif
659658
return true;
660659
}
@@ -747,7 +746,7 @@ void
747746
SSLConfigParams::updateCTX(const std::string &cert_secret_name) const
748747
{
749748
// Clear the corresponding client CTXs. They will be lazy loaded later
750-
Debug("ssl", "Update cert %s", cert_secret_name.c_str());
749+
Debug("ssl_load", "Update cert %s", cert_secret_name.c_str());
751750
this->clearCTX(cert_secret_name);
752751

753752
// Update the server cert
@@ -763,7 +762,7 @@ SSLConfigParams::clearCTX(const std::string &client_cert) const
763762
auto ctx_iter = ctx_map_iter->second.find(client_cert);
764763
if (ctx_iter != ctx_map_iter->second.end()) {
765764
ctx_iter->second = nullptr;
766-
Debug("ssl", "Clear client cert %s %s", ctx_map_iter->first.c_str(), ctx_iter->first.c_str());
765+
Debug("ssl_load", "Clear client cert %s %s", ctx_map_iter->first.c_str(), ctx_iter->first.c_str());
767766
}
768767
}
769768
ink_mutex_release(&ctxMapLock);

iocore/net/SSLUtils.cc

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ SSL_locking_callback(int mode, int type, const char *file, int line)
135135
} else if (mode & CRYPTO_UNLOCK) {
136136
ink_mutex_release(&mutex_buf[type]);
137137
} else {
138-
Debug("ssl", "invalid SSL locking mode 0x%x", mode);
138+
Debug("ssl_load", "invalid SSL locking mode 0x%x", mode);
139139
ink_assert(0);
140140
}
141141
}
@@ -281,11 +281,11 @@ set_context_cert(SSL *ssl, void *arg)
281281
goto done;
282282
}
283283

284-
Debug("ssl", "set_context_cert ssl=%p server=%s handshake_complete=%d", ssl, servername, netvc->getSSLHandShakeComplete());
284+
Debug("ssl_load", "set_context_cert ssl=%p server=%s handshake_complete=%d", ssl, servername, netvc->getSSLHandShakeComplete());
285285

286286
// catch the client renegotiation early on
287287
if (SSLConfigParams::ssl_allow_client_renegotiation == false && netvc->getSSLHandShakeComplete()) {
288-
Debug("ssl", "set_context_cert trying to renegotiate from the client");
288+
Debug("ssl_load", "set_context_cert trying to renegotiate from the client");
289289
retval = 0; // Error
290290
goto done;
291291
}
@@ -362,7 +362,8 @@ set_context_cert(SSL *ssl, void *arg)
362362

363363
verify_ctx = SSL_get_SSL_CTX(ssl);
364364
// set_context_cert found SSL context for ...
365-
Debug("ssl", "ssl_cert_callback %s SSL context %p for requested name '%s'", found ? "found" : "using", verify_ctx, servername);
365+
Debug("ssl_load", "ssl_cert_callback %s SSL context %p for requested name '%s'", found ? "found" : "using", verify_ctx,
366+
servername);
366367

367368
if (verify_ctx == nullptr) {
368369
retval = 0;
@@ -821,7 +822,7 @@ ssl_private_key_passphrase_callback_exec(char *buf, int size, int rwflag, void *
821822
*buf = 0;
822823
passphrase_cb_userdata *ud = static_cast<passphrase_cb_userdata *>(userdata);
823824

824-
Debug("ssl", "ssl_private_key_passphrase_callback_exec rwflag=%d serverDialog=%s", rwflag, ud->_serverDialog);
825+
Debug("ssl_load", "ssl_private_key_passphrase_callback_exec rwflag=%d serverDialog=%s", rwflag, ud->_serverDialog);
825826

826827
// only respond to reading private keys, not writing them (does ats even do that?)
827828
if (0 == rwflag) {
@@ -855,7 +856,7 @@ ssl_private_key_passphrase_callback_builtin(char *buf, int size, int rwflag, voi
855856
*buf = 0;
856857
passphrase_cb_userdata *ud = static_cast<passphrase_cb_userdata *>(userdata);
857858

858-
Debug("ssl", "ssl_private_key_passphrase_callback rwflag=%d serverDialog=%s", rwflag, ud->_serverDialog);
859+
Debug("ssl_load", "ssl_private_key_passphrase_callback rwflag=%d serverDialog=%s", rwflag, ud->_serverDialog);
859860

860861
// only respond to reading private keys, not writing them (does ats even do that?)
861862
if (0 == rwflag) {
@@ -987,7 +988,7 @@ SSLInitializeLibrary()
987988
// After POST we don't have to lock for FIPS
988989
int mode = FIPS_mode();
989990
FIPS_mode_set(mode);
990-
Debug("ssl", "FIPS_mode: %d", mode);
991+
Debug("ssl_load", "FIPS_mode: %d", mode);
991992
#endif
992993

993994
mutex_buf = static_cast<ink_mutex *>(OPENSSL_malloc(CRYPTO_num_locks() * sizeof(ink_mutex)));
@@ -1039,7 +1040,7 @@ SSLPrivateKeyHandler(SSL_CTX *ctx, const SSLConfigParams *params, const char *ke
10391040
pkey = ENGINE_load_private_key(e, keyPath, nullptr, nullptr);
10401041
if (pkey) {
10411042
if (!SSL_CTX_use_PrivateKey(ctx, pkey)) {
1042-
Debug("ssl", "failed to load server private key from engine");
1043+
Debug("ssl_load", "failed to load server private key from engine");
10431044
EVP_PKEY_free(pkey);
10441045
return false;
10451046
}
@@ -1052,17 +1053,18 @@ SSLPrivateKeyHandler(SSL_CTX *ctx, const SSLConfigParams *params, const char *ke
10521053
scoped_BIO bio(BIO_new_mem_buf(secret_data, secret_data_len));
10531054
pkey = PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr);
10541055
if (nullptr == pkey) {
1055-
Debug("ssl", "failed to load server private key from %s", (!keyPath || keyPath[0] == '\0') ? "[empty key path]" : keyPath);
1056+
Debug("ssl_load", "failed to load server private key from %s",
1057+
(!keyPath || keyPath[0] == '\0') ? "[empty key path]" : keyPath);
10561058
return false;
10571059
}
10581060
if (!SSL_CTX_use_PrivateKey(ctx, pkey)) {
1059-
Debug("ssl", "failed to attach server private key loaded from %s",
1061+
Debug("ssl_load", "failed to attach server private key loaded from %s",
10601062
(!keyPath || keyPath[0] == '\0') ? "[empty key path]" : keyPath);
10611063
EVP_PKEY_free(pkey);
10621064
return false;
10631065
}
10641066
if (e == nullptr && !SSL_CTX_check_private_key(ctx)) {
1065-
Debug("ssl", "server private key does not match the certificate public key");
1067+
Debug("ssl_load", "server private key does not match the certificate public key");
10661068
return false;
10671069
}
10681070
}
@@ -1116,7 +1118,7 @@ SSLMultiCertConfigLoader::check_server_cert_now(X509 *cert, const char *certname
11161118
return -5;
11171119
}
11181120

1119-
Debug("ssl", "server certificate %s passed accessibility and date checks", certname);
1121+
Debug("ssl_load", "server certificate %s passed accessibility and date checks", certname);
11201122
return 0; // all good
11211123

11221124
} /* CheckServerCertNow() */
@@ -1137,7 +1139,7 @@ asn1_strdup(ASN1_STRING *s)
11371139
static void
11381140
ssl_callback_info(const SSL *ssl, int where, int ret)
11391141
{
1140-
Debug("ssl", "ssl_callback_info ssl: %p, where: %d, ret: %d, State: %s", ssl, where, ret, SSL_state_string_long(ssl));
1142+
Debug("ssl_load", "ssl_callback_info ssl: %p, where: %d, ret: %d, State: %s", ssl, where, ret, SSL_state_string_long(ssl));
11411143

11421144
SSLNetVConnection *netvc = SSLNetVCAccess(ssl);
11431145

@@ -1169,12 +1171,12 @@ ssl_callback_info(const SSL *ssl, int where, int ret)
11691171
#ifdef TLS1_3_VERSION
11701172
// TLSv1.3 has no renegotiation.
11711173
if (SSL_version(ssl) >= TLS1_3_VERSION) {
1172-
Debug("ssl", "TLSv1.3 has no renegotiation.");
1174+
Debug("ssl_load", "TLSv1.3 has no renegotiation.");
11731175
return;
11741176
}
11751177
#endif
11761178
netvc->setSSLClientRenegotiationAbort(true);
1177-
Debug("ssl", "ssl_callback_info trying to renegotiate from the client");
1179+
Debug("ssl_load", "ssl_callback_info trying to renegotiate from the client");
11781180
}
11791181
}
11801182
if (where & SSL_CB_HANDSHAKE_DONE) {
@@ -1254,7 +1256,7 @@ setClientCertLevel(SSL *ssl, uint8_t certLevel)
12541256
ink_release_assert(!"Invalid client verify level");
12551257
}
12561258

1257-
Debug("ssl", "setting cert level to %d", server_verify_client);
1259+
Debug("ssl_load", "setting cert level to %d", server_verify_client);
12581260
SSL_set_verify(ssl, server_verify_client, ssl_verify_client_callback);
12591261
SSL_set_verify_depth(ssl, params->verify_depth); // might want to make configurable at some point.
12601262
}
@@ -1329,7 +1331,8 @@ SSLMultiCertConfigLoader::init_server_ssl_ctx(CertLoadData const &data, const SS
13291331

13301332
ctx_type = (!generate_default_ctx && i < data.cert_type_list.size()) ? data.cert_type_list[i] : SSLCertContextType::GENERIC;
13311333

1332-
Debug("ssl", "Creating new context %p cert_count=%ld initial: %s", ctx, cert_names_list.size(), cert_names_list[0].c_str());
1334+
Debug("ssl_load", "Creating new context %p cert_count=%ld initial: %s", ctx, cert_names_list.size(),
1335+
cert_names_list[0].c_str());
13331336

13341337
// disable selected protocols
13351338
SSL_CTX_set_options(ctx, _params->ssl_ctx_options);
@@ -1339,7 +1342,7 @@ SSLMultiCertConfigLoader::init_server_ssl_ctx(CertLoadData const &data, const SS
13391342
}
13401343

13411344
#ifdef SSL_MODE_RELEASE_BUFFERS
1342-
Debug("ssl", "enabling SSL_MODE_RELEASE_BUFFERS");
1345+
Debug("ssl_load", "enabling SSL_MODE_RELEASE_BUFFERS");
13431346
SSL_CTX_set_mode(ctx, SSL_MODE_RELEASE_BUFFERS);
13441347
#endif
13451348

@@ -1552,13 +1555,13 @@ SSLMultiCertConfigLoader::_setup_session_ticket(SSL_CTX *ctx, const SSLMultiCert
15521555
// Session tickets are enabled by default. Disable if explicitly requested.
15531556
if (sslMultCertSettings->session_ticket_enabled == 0) {
15541557
SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET);
1555-
Debug("ssl", "ssl session ticket is disabled");
1558+
Debug("ssl_load", "ssl session ticket is disabled");
15561559
}
15571560
#endif
15581561
#if defined(TLS1_3_VERSION) && !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_IS_BORINGSSL)
15591562
if (!(this->_params->ssl_ctx_options & SSL_OP_NO_TLSv1_3)) {
15601563
SSL_CTX_set_num_tickets(ctx, sslMultCertSettings->session_ticket_number);
1561-
Debug("ssl", "ssl session ticket number set to %d", sslMultCertSettings->session_ticket_number);
1564+
Debug("ssl_load", "ssl session ticket number set to %d", sslMultCertSettings->session_ticket_number);
15621565
}
15631566
#endif
15641567
return true;
@@ -1908,7 +1911,7 @@ SSLMultiCertConfigLoader::_store_single_ssl_ctx(SSLCertLookup *lookup, const sha
19081911
// Index this certificate by the specified IP(v6) address. If the address is "*", make it the default context.
19091912
if (sslMultCertSettings->addr) {
19101913
if (strcmp(sslMultCertSettings->addr, "*") == 0) {
1911-
Debug("ssl", "Addr is '*'; setting %p to default", ctx.get());
1914+
Debug("ssl_load", "Addr is '*'; setting %p to default", ctx.get());
19121915
if (lookup->insert(sslMultCertSettings->addr, SSLCertContext(ctx, ctx_type, sslMultCertSettings, keyblock)) >= 0) {
19131916
inserted = true;
19141917
lookup->ssl_default = ctx;
@@ -1963,6 +1966,7 @@ ssl_extract_certificate(const matcher_line *line_info, SSLMultiCertConfigParams
19631966
if (label == nullptr) {
19641967
continue;
19651968
}
1969+
Debug("ssl_load", "Extracting certificate label: %s, value: %s", label, value);
19661970

19671971
if (strcasecmp(label, SSL_IP_TAG) == 0) {
19681972
sslMultCertSettings->addr = ats_strdup(value);
@@ -2069,7 +2073,7 @@ SSLMultiCertConfigLoader::load(SSLCertLookup *lookup)
20692073
const char *errPtr;
20702074

20712075
errPtr = parseConfigLine(line, &line_info, &sslCertTags);
2072-
Debug("ssl", "currently parsing %s at line %d from config file: %s", line, line_num, params->configFilePath);
2076+
Debug("ssl_load", "currently parsing %s at line %d from config file: %s", line, line_num, params->configFilePath);
20732077
if (errPtr != nullptr) {
20742078
RecSignalWarning(REC_SIGNAL_CONFIG_ERROR, "%s: discarding %s entry at line %d: %s", __func__, params->configFilePath,
20752079
line_num, errPtr);
@@ -2294,10 +2298,13 @@ SSLMultiCertConfigLoader::load_certs_and_cross_reference_names(
22942298
X509 *cert = nullptr;
22952299
if (bio) {
22962300
cert = PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr);
2301+
} else {
2302+
SSLError("failed to create bio for certificate secret %s of length %d", data.cert_names_list[i].c_str(), secret_data.size());
2303+
return false;
22972304
}
22982305
if (!bio || !cert) {
2299-
SSLError("failed to load certificate chain from %s with key path %s", data.cert_names_list[i].c_str(),
2300-
data.key_list.size() > i ? data.key_list[i].c_str() : "[empty key path]");
2306+
SSLError("failed to load certificate chain from %s of length %d with key path %s", data.cert_names_list[i].c_str(),
2307+
secret_data.size(), data.key_list.size() > i ? data.key_list[i].c_str() : "[empty key path]");
23012308
return false;
23022309
}
23032310

@@ -2343,9 +2350,12 @@ SSLMultiCertConfigLoader::load_certs_and_cross_reference_names(
23432350
ASN1_STRING *cn = X509_NAME_ENTRY_get_data(e);
23442351
subj_name = asn1_strdup(cn);
23452352

2346-
Debug("ssl", "subj '%s' in certificate %s %p", subj_name.get(), data.cert_names_list[i].c_str(), cert);
2353+
Debug("ssl_load", "subj '%s' in certificate %s %p", subj_name.get(), data.cert_names_list[i].c_str(), cert);
23472354
name_set.insert(subj_name.get());
23482355
}
2356+
if (name_set.empty()) {
2357+
Debug("ssl_load", "no subj name in certificate %s", data.cert_names_list[i].c_str());
2358+
}
23492359
}
23502360

23512361
// Traverse the subjectAltNames (if any) and insert additional keys for the SSL context.
@@ -2358,6 +2368,7 @@ SSLMultiCertConfigLoader::load_certs_and_cross_reference_names(
23582368
name = sk_GENERAL_NAME_value(names, i);
23592369
if (name->type == GEN_DNS) {
23602370
ats_scoped_str dns(asn1_strdup(name->d.dNSName));
2371+
Debug("ssl_load", "inserting dns '%s' in certificate: %s", dns.get(), data.cert_names_list[i].c_str());
23612372
name_set.insert(dns.get());
23622373
}
23632374
}
@@ -2419,10 +2430,10 @@ SSLMultiCertConfigLoader::load_certs(SSL_CTX *ctx, const std::vector<std::string
24192430
{
24202431
#if TS_USE_TLS_OCSP
24212432
if (SSLConfigParams::ssl_ocsp_enabled) {
2422-
Debug("ssl", "SSL OCSP Stapling is enabled");
2433+
Debug("ssl_load", "SSL OCSP Stapling is enabled");
24232434
SSL_CTX_set_tlsext_status_cb(ctx, ssl_callback_ocsp_stapling);
24242435
} else {
2425-
Debug("ssl", "SSL OCSP Stapling is disabled");
2436+
Debug("ssl_load", "SSL OCSP Stapling is disabled");
24262437
}
24272438
#else
24282439
if (SSLConfigParams::ssl_ocsp_enabled) {
@@ -2446,14 +2457,17 @@ SSLMultiCertConfigLoader::load_certs(SSL_CTX *ctx, const std::vector<std::string
24462457
X509 *cert = nullptr;
24472458
if (bio) {
24482459
cert = PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr);
2460+
} else {
2461+
SSLError("failed to create bio for certificate secret %s of length %d", data.cert_names_list[i].c_str(), secret_data.size());
2462+
return false;
24492463
}
24502464

24512465
if (!bio || !cert) {
24522466
SSLError("failed to load certificate chain from %s", cert_names_list[i].c_str());
24532467
return false;
24542468
}
24552469

2456-
Debug("ssl", "for ctx=%p, using certificate %s", ctx, cert_names_list[i].c_str());
2470+
Debug("ssl_load", "for ctx=%p, using certificate %s", ctx, cert_names_list[i].c_str());
24572471
if (!SSL_CTX_use_certificate(ctx, cert)) {
24582472
SSLError("Failed to assign cert from %s to SSL_CTX", cert_names_list[i].c_str());
24592473
X509_free(cert);
@@ -2462,14 +2476,14 @@ SSLMultiCertConfigLoader::load_certs(SSL_CTX *ctx, const std::vector<std::string
24622476

24632477
// Load up any additional chain certificates
24642478
if (!SSL_CTX_add_extra_chain_cert_bio(ctx, bio.get())) {
2465-
Debug("ssl", "couldn't add chain to %p", ctx);
2479+
Debug("ssl_load", "couldn't add chain to %p", ctx);
24662480
}
24672481

24682482
if (secret_key_data.empty()) {
24692483
secret_key_data = secret_data;
24702484
}
24712485
if (!SSLPrivateKeyHandler(ctx, params, keyPath.c_str(), secret_key_data.data(), secret_key_data.size())) {
2472-
SSLError("Failed to load private key: %s with key path: %s", cert_names_list[i].c_str(),
2486+
SSLError("failed to load certificate: %s of length %d with key path: %s", cert_names_list[i].c_str(), secret_key_data.size(),
24732487
keyPath.empty() ? "[empty key path]" : keyPath.c_str());
24742488
return false;
24752489
}
@@ -2548,7 +2562,7 @@ SSLMultiCertConfigLoader::set_session_id_context(SSL_CTX *ctx, const SSLConfigPa
25482562
}
25492563

25502564
if (nullptr != setting_cert) {
2551-
Debug("ssl", "Using '%s' in hash for session id context", sslMultCertSettings->cert.get());
2565+
Debug("ssl_load", "Using '%s' in hash for session id context", sslMultCertSettings->cert.get());
25522566
if (EVP_DigestUpdate(digest, sslMultCertSettings->cert, strlen(setting_cert)) == 0) {
25532567
SSLError("EVP_DigestUpdate failed using '%s' in hash for session id context", sslMultCertSettings->cert.get());
25542568
goto fail;

0 commit comments

Comments
 (0)