| 223 | } |
| 224 | |
| 225 | LoadedTLSConfig TLSConfig::loadSync() const { |
| 226 | LoadedTLSConfig loaded; |
| 227 | |
| 228 | const std::string certPath = getCertificatePathSync(); |
| 229 | if (certPath.size()) { |
| 230 | try { |
| 231 | loaded.tlsCertBytes = readFileBytes(certPath, FLOW_KNOBS->CERT_FILE_MAX_SIZE); |
| 232 | } catch (Error& e) { |
| 233 | fprintf(stderr, "Error reading TLS Certificate [%s]: %s\n", certPath.c_str(), e.what()); |
| 234 | throw; |
| 235 | } |
| 236 | } else { |
| 237 | loaded.tlsCertBytes = tlsCertBytes; |
| 238 | } |
| 239 | |
| 240 | const std::string keyPath = getKeyPathSync(); |
| 241 | if (keyPath.size()) { |
| 242 | try { |
| 243 | loaded.tlsKeyBytes = readFileBytes(keyPath, FLOW_KNOBS->CERT_FILE_MAX_SIZE); |
| 244 | } catch (Error& e) { |
| 245 | fprintf(stderr, "Error reading TLS Key [%s]: %s\n", keyPath.c_str(), e.what()); |
| 246 | throw; |
| 247 | } |
| 248 | } else { |
| 249 | loaded.tlsKeyBytes = tlsKeyBytes; |
| 250 | } |
| 251 | |
| 252 | const std::string CAPath = getCAPathSync(); |
| 253 | if (CAPath.size()) { |
| 254 | try { |
| 255 | loaded.tlsCABytes = readFileBytes(CAPath, FLOW_KNOBS->CERT_FILE_MAX_SIZE); |
| 256 | } catch (Error& e) { |
| 257 | fprintf(stderr, "Error reading TLS CA [%s]: %s\n", CAPath.c_str(), e.what()); |
| 258 | throw; |
| 259 | } |
| 260 | } else { |
| 261 | loaded.tlsCABytes = tlsCABytes; |
| 262 | } |
| 263 | |
| 264 | loaded.tlsPassword = tlsPassword; |
| 265 | loaded.tlsVerifyPeers = tlsVerifyPeers; |
| 266 | loaded.endpointType = endpointType; |
| 267 | |
| 268 | return loaded; |
| 269 | } |
| 270 | |
| 271 | TLSPolicy::TLSPolicy(const LoadedTLSConfig& loaded, std::function<void()> on_failure) |
| 272 | : rules(), on_failure(std::move(on_failure)), is_client(loaded.getEndpointType() == TLSEndpointType::CLIENT) { |