|
37 | 37 | import threading |
38 | 38 | from datetime import timedelta |
39 | 39 |
|
| 40 | +import _hashlib |
| 41 | + |
40 | 42 | from elasticapm.conf.constants import BASE_SANITIZE_FIELD_NAMES, TRACE_CONTINUATION_STRATEGY |
41 | 43 | from elasticapm.utils import compat, starmatch_to_regex |
42 | 44 | from elasticapm.utils.logging import get_logger |
@@ -373,6 +375,30 @@ def __call__(self, value, field_name): |
373 | 375 | return value |
374 | 376 |
|
375 | 377 |
|
| 378 | +def _in_fips_mode(): |
| 379 | + try: |
| 380 | + return _hashlib.get_fips_mode() == 1 |
| 381 | + except AttributeError: |
| 382 | + # versions older of Python3.9 does not have the helper |
| 383 | + return False |
| 384 | + |
| 385 | + |
| 386 | +class SupportedValueInFipsModeValidator(object): |
| 387 | + """If FIPS mode is enabled only supported_value is accepted""" |
| 388 | + |
| 389 | + def __init__(self, supported_value) -> None: |
| 390 | + self.supported_value = supported_value |
| 391 | + |
| 392 | + def __call__(self, value, field_name): |
| 393 | + if _in_fips_mode(): |
| 394 | + if value != self.supported_value: |
| 395 | + raise ConfigurationError( |
| 396 | + "{}={} must be set to {} if FIPS mode is enabled".format(field_name, value, self.supported_value), |
| 397 | + field_name, |
| 398 | + ) |
| 399 | + return value |
| 400 | + |
| 401 | + |
376 | 402 | class EnumerationValidator(object): |
377 | 403 | """ |
378 | 404 | Validator which ensures that a given config value is chosen from a list |
@@ -579,7 +605,9 @@ class Config(_ConfigBase): |
579 | 605 | server_url = _ConfigValue("SERVER_URL", default="http://127.0.0.1:8200", required=True) |
580 | 606 | server_cert = _ConfigValue("SERVER_CERT", validators=[FileIsReadableValidator()]) |
581 | 607 | server_ca_cert_file = _ConfigValue("SERVER_CA_CERT_FILE", validators=[FileIsReadableValidator()]) |
582 | | - verify_server_cert = _BoolConfigValue("VERIFY_SERVER_CERT", default=True) |
| 608 | + verify_server_cert = _BoolConfigValue( |
| 609 | + "VERIFY_SERVER_CERT", default=True, validators=[SupportedValueInFipsModeValidator(supported_value=True)] |
| 610 | + ) |
583 | 611 | use_certifi = _BoolConfigValue("USE_CERTIFI", default=True) |
584 | 612 | include_paths = _ListConfigValue("INCLUDE_PATHS") |
585 | 613 | exclude_paths = _ListConfigValue("EXCLUDE_PATHS", default=compat.get_default_library_patters()) |
|
0 commit comments