| 8203 | } |
| 8204 | |
| 8205 | TSReturnCode |
| 8206 | TSSslClientCertUpdate(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 | } |
no test coverage detected