Load certificates to SSL_CTX @static */
| 2312 | @static |
| 2313 | */ |
| 2314 | bool |
| 2315 | SSLMultiCertConfigLoader::load_certs(SSL_CTX *ctx, const std::vector<std::string> &cert_names_list, |
| 2316 | const std::vector<std::string> &key_list, CertLoadData const &data, |
| 2317 | const SSLConfigParams *params, const SSLMultiCertConfigParams *sslMultCertSettings) |
| 2318 | { |
| 2319 | if (SSLConfigParams::ssl_ocsp_enabled) { |
| 2320 | Dbg(dbg_ctl_ssl_load, "SSL OCSP Stapling is enabled"); |
| 2321 | SSL_CTX_set_tlsext_status_cb(ctx, ssl_callback_ocsp_stapling); |
| 2322 | } else { |
| 2323 | Dbg(dbg_ctl_ssl_load, "SSL OCSP Stapling is disabled"); |
| 2324 | } |
| 2325 | |
| 2326 | ink_assert(!cert_names_list.empty()); |
| 2327 | |
| 2328 | for (size_t i = 0; i < cert_names_list.size(); i++) { |
| 2329 | std::string keyPath = (i < key_list.size()) ? key_list[i] : ""; |
| 2330 | std::string secret_data; |
| 2331 | std::string secret_key_data; |
| 2332 | params->secrets.getOrLoadSecret(cert_names_list[i], keyPath, secret_data, secret_key_data); |
| 2333 | if (secret_data.empty()) { |
| 2334 | SSLError("failed to load certificate secret for %s with key path %s", cert_names_list[i].c_str(), |
| 2335 | keyPath.empty() ? "[empty key path]" : keyPath.c_str()); |
| 2336 | return false; |
| 2337 | } |
| 2338 | scoped_BIO bio(BIO_new_mem_buf(secret_data.data(), secret_data.size())); |
| 2339 | X509 *cert = nullptr; |
| 2340 | if (bio) { |
| 2341 | cert = PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr); |
| 2342 | } else { |
| 2343 | SSLError("failed to create bio for certificate secret %s of length %ld", data.cert_names_list[i].c_str(), secret_data.size()); |
| 2344 | return false; |
| 2345 | } |
| 2346 | |
| 2347 | if (!bio || !cert) { |
| 2348 | SSLError("failed to load certificate chain from %s", cert_names_list[i].c_str()); |
| 2349 | return false; |
| 2350 | } |
| 2351 | |
| 2352 | Dbg(dbg_ctl_ssl_load, "for ctx=%p, using certificate %s", ctx, cert_names_list[i].c_str()); |
| 2353 | if (!SSL_CTX_use_certificate(ctx, cert)) { |
| 2354 | SSLError("Failed to assign cert from %s to SSL_CTX", cert_names_list[i].c_str()); |
| 2355 | X509_free(cert); |
| 2356 | return false; |
| 2357 | } |
| 2358 | |
| 2359 | // Load up any additional chain certificates |
| 2360 | if (!SSL_CTX_add_extra_chain_cert_bio(ctx, bio.get())) { |
| 2361 | Dbg(dbg_ctl_ssl_load, "couldn't add chain to %p", ctx); |
| 2362 | SSLError("failed to load intermediate certificate chain from %s", cert_names_list[i].c_str()); |
| 2363 | return false; |
| 2364 | } |
| 2365 | |
| 2366 | if (secret_key_data.empty()) { |
| 2367 | Dbg(dbg_ctl_ssl_load, "empty private key for public key %s", cert_names_list[i].c_str()); |
| 2368 | secret_key_data = std::move(secret_data); |
| 2369 | } |
| 2370 | if (!SSLPrivateKeyHandler(ctx, keyPath.c_str(), secret_key_data.data(), secret_key_data.size())) { |
| 2371 | SSLError("failed to load certificate: %s of length %ld with key path: %s", cert_names_list[i].c_str(), secret_key_data.size(), |
nothing calls this directly
no test coverage detected