| 174 | } |
| 175 | |
| 176 | void CertificateReloader::tryLoadImpl(const Poco::Util::AbstractConfiguration & config, SSL_CTX * ctx, const std::string & prefix) |
| 177 | { |
| 178 | /// If at least one of the files is modified - recreate |
| 179 | std::string new_cert_path = config.getString(prefix + "certificateFile", ""); |
| 180 | std::string new_key_path = config.getString(prefix + "privateKeyFile", ""); |
| 181 | |
| 182 | if (config.has("acme") && prefix == Poco::Net::SSLManager::CFG_SERVER_PREFIX) |
| 183 | { |
| 184 | if (!new_cert_path.empty() || !new_key_path.empty()) |
| 185 | throw Exception(ErrorCodes::INVALID_CONFIG_PARAMETER, "Static TLS keys and ACME provider are enabled at the same time."); |
| 186 | |
| 187 | tryLoadACMECertificate(ctx, prefix); |
| 188 | |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | /// For empty paths (that means, that user doesn't want to use certificates) |
| 193 | /// no processing required |
| 194 | if (new_cert_path.empty() || new_key_path.empty()) |
| 195 | { |
| 196 | LOG_INFO(log, "One of paths is empty. Cannot apply new configuration for certificates. Fill all paths and try again."); |
| 197 | return; |
| 198 | } |
| 199 | |
| 200 | try |
| 201 | { |
| 202 | auto it = findOrInsert(ctx, prefix); |
| 203 | |
| 204 | bool cert_file_changed = it->cert_file.changeIfModified(std::move(new_cert_path), log); |
| 205 | bool key_file_changed = it->key_file.changeIfModified(std::move(new_key_path), log); |
| 206 | |
| 207 | if (cert_file_changed || key_file_changed) |
| 208 | { |
| 209 | LOG_DEBUG(log, "Reloading certificate ({}) and key ({}).", it->cert_file.path, it->key_file.path); |
| 210 | |
| 211 | std::string pass_phrase = config.getString(prefix + "privateKeyPassphraseHandler.options.password", ""); |
| 212 | it->data.set(std::make_unique<const Data>(it->cert_file.path, it->key_file.path, pass_phrase)); |
| 213 | |
| 214 | LOG_INFO(log, "Reloaded certificate ({}) and key ({}).", it->cert_file.path, it->key_file.path); |
| 215 | } |
| 216 | |
| 217 | /// If callback is not set yet |
| 218 | if (!it->initialized) |
| 219 | init(&*it); |
| 220 | } |
| 221 | catch (...) |
| 222 | { |
| 223 | LOG_ERROR(log, getCurrentExceptionMessageAndPattern(/* with_stacktrace */ false)); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | |
| 228 | void CertificateReloader::tryReloadAll(const Poco::Util::AbstractConfiguration & config) |
nothing calls this directly
no test coverage detected