MCPcopy Create free account
hub / github.com/apache/trafficserver / TSSslClientCertUpdate

Function TSSslClientCertUpdate

src/api/InkAPI.cc:8205–8265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8203}
8204
8205TSReturnCode
8206TSSslClientCertUpdate(const char *cert_path, const char *key_path)
8207{
8208 if (nullptr == cert_path) {
8209 return TS_ERROR;
8210 }
8211
8212 std::string key;
8213 shared_SSL_CTX client_ctx = nullptr;
8214 SSLConfigParams *params = SSLConfig::acquire();
8215
8216 // Generate second level key for client context lookup
8217 swoc::bwprint(key, "{}:{}", cert_path, key_path);
8218 Dbg(dbg_ctl_ssl_cert_update, "TSSslClientCertUpdate(): Use %.*s as key for lookup", static_cast<int>(key.size()), key.data());
8219
8220 if (nullptr != params) {
8221 // Try to update client contexts maps
8222 auto &ca_paths_map = params->top_level_ctx_map;
8223 auto &map_lock = params->ctxMapLock;
8224 std::string ca_paths_key;
8225 // First try to locate the client context and its CA path (by top level)
8226 ink_mutex_acquire(&map_lock);
8227 for (auto &ca_paths_pair : ca_paths_map) {
8228 auto &ctx_map = ca_paths_pair.second;
8229 auto iter = ctx_map.find(key);
8230 if (iter != ctx_map.end() && iter->second != nullptr) {
8231 ca_paths_key = ca_paths_pair.first;
8232 break;
8233 }
8234 }
8235 ink_mutex_release(&map_lock);
8236
8237 // Only update on existing
8238 if (ca_paths_key.empty()) {
8239 return TS_ERROR;
8240 }
8241
8242 // Extract CA related paths
8243 size_t sep = ca_paths_key.find(':');
8244 std::string ca_bundle_file = ca_paths_key.substr(0, sep);
8245 std::string ca_bundle_path = ca_paths_key.substr(sep + 1);
8246
8247 // Build new client context
8248 client_ctx =
8249 shared_SSL_CTX(SSLCreateClientContext(params, ca_bundle_path.empty() ? nullptr : ca_bundle_path.c_str(),
8250 ca_bundle_file.empty() ? nullptr : ca_bundle_file.c_str(), cert_path, key_path),
8251 SSL_CTX_free);
8252
8253 // Successfully generates a client context, update in the map
8254 ink_mutex_acquire(&map_lock);
8255 auto iter = ca_paths_map.find(ca_paths_key);
8256 if (iter != ca_paths_map.end() && iter->second.count(key)) {
8257 iter->second[key] = client_ctx;
8258 } else {
8259 client_ctx = nullptr;
8260 }
8261 ink_mutex_release(&map_lock);
8262 }

Callers 1

CB_cert_updateFunction · 0.85

Calls 12

acquireFunction · 0.85
ink_mutex_acquireFunction · 0.85
ink_mutex_releaseFunction · 0.85
SSLCreateClientContextFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45
findMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
substrMethod · 0.45
c_strMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected