| 8265 | } |
| 8266 | |
| 8267 | TSReturnCode |
| 8268 | TSSslServerCertUpdate(const char *cert_path, const char *key_path) |
| 8269 | { |
| 8270 | if (nullptr == cert_path) { |
| 8271 | return TS_ERROR; |
| 8272 | } |
| 8273 | |
| 8274 | if (!key_path || key_path[0] == '\0') { |
| 8275 | key_path = cert_path; |
| 8276 | } |
| 8277 | |
| 8278 | SSLCertContext *cc = nullptr; |
| 8279 | shared_SSL_CTX test_ctx = nullptr; |
| 8280 | std::shared_ptr<X509> cert = nullptr; |
| 8281 | |
| 8282 | SSLConfig::scoped_config config; |
| 8283 | SSLCertificateConfig::scoped_config lookup; |
| 8284 | |
| 8285 | if (lookup && config) { |
| 8286 | // Read cert from path to extract lookup key (common name) |
| 8287 | scoped_BIO bio(BIO_new_file(cert_path, "r")); |
| 8288 | if (bio) { |
| 8289 | cert = std::shared_ptr<X509>(PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr), X509_free); |
| 8290 | } |
| 8291 | if (!bio || !cert) { |
| 8292 | SSLError("Failed to load certificate/key from %s", cert_path); |
| 8293 | return TS_ERROR; |
| 8294 | } |
| 8295 | |
| 8296 | // Extract common name |
| 8297 | int pos = X509_NAME_get_index_by_NID(X509_get_subject_name(cert.get()), NID_commonName, -1); |
| 8298 | X509_NAME_ENTRY *common_name = X509_NAME_get_entry(X509_get_subject_name(cert.get()), pos); |
| 8299 | ASN1_STRING *common_name_asn1 = X509_NAME_ENTRY_get_data(common_name); |
| 8300 | char *common_name_str = reinterpret_cast<char *>(const_cast<unsigned char *>(ASN1_STRING_get0_data(common_name_asn1))); |
| 8301 | if (ASN1_STRING_length(common_name_asn1) != static_cast<int>(strlen(common_name_str))) { |
| 8302 | // Embedded null char |
| 8303 | return TS_ERROR; |
| 8304 | } |
| 8305 | Dbg(dbg_ctl_ssl_cert_update, "Updating from %s with common name %s", cert_path, common_name_str); |
| 8306 | |
| 8307 | // Update context to use cert |
| 8308 | cc = lookup->find(common_name_str); |
| 8309 | if (cc && cc->getCtx()) { |
| 8310 | test_ctx = shared_SSL_CTX(SSLCreateServerContext(config, cc->userconfig.get(), cert_path, key_path), SSLReleaseContext); |
| 8311 | if (!test_ctx) { |
| 8312 | return TS_ERROR; |
| 8313 | } |
| 8314 | // Atomic Swap |
| 8315 | cc->setCtx(test_ctx); |
| 8316 | return TS_SUCCESS; |
| 8317 | } |
| 8318 | } |
| 8319 | |
| 8320 | return TS_ERROR; |
| 8321 | } |
| 8322 | |
| 8323 | TSReturnCode |
| 8324 | TSSslTicketKeyUpdate(char *ticketData, int ticketDataLen) |
no test coverage detected