This host's own server key, or None for a Keeper cloud host or when it cannot be found.
(context)
| 343 | |
| 344 | |
| 345 | def get_self_managed_server_key(context): # type: (RestApiContext) -> Optional[SelfManagedServerKey] |
| 346 | """This host's own server key, or None for a Keeper cloud host or when it cannot be found.""" |
| 347 | server_base = getattr(context, 'server_base', None) |
| 348 | if not isinstance(server_base, str): |
| 349 | return None |
| 350 | host = server_host(server_base) |
| 351 | if is_keeper_cloud_host(host): |
| 352 | return None |
| 353 | if host in _resolved_server_keys: |
| 354 | return _resolved_server_keys[host] |
| 355 | |
| 356 | key = _configured_server_keys.get(host) or _environment_server_key() |
| 357 | reason = _unverified_reason(context) |
| 358 | if key is None: |
| 359 | if reason: |
| 360 | # Anyone between Commander and the server could replace a key fetched |
| 361 | # over this connection. Keep the built-in keys and explain if they fail. |
| 362 | _server_key_errors[host] = (f'the connection is not verified ({reason}), ' |
| 363 | f'so Commander does not fetch the key') |
| 364 | else: |
| 365 | try: |
| 366 | key = _fetch_server_key(context, host) |
| 367 | except Exception as e: |
| 368 | # Not a self-managed deployment, or not reachable. Keep the built-in keys, |
| 369 | # and explain if the server rejects them. |
| 370 | _server_key_errors[host] = str(e) |
| 371 | logging.debug('Server key of %s could not be fetched: %s', host, e) |
| 372 | elif reason: |
| 373 | logging.warning('The connection to %s is not verified (%s). Using the server key %s: key ID %d, %s', |
| 374 | host, reason, key.source, key.key_id, server_key_fingerprint(key.public_key)) |
| 375 | _resolved_server_keys[host] = key |
| 376 | return key |
| 377 | |
| 378 | |
| 379 | def refetch_server_key(context): # type: (RestApiContext) -> Optional[SelfManagedServerKey] |
no test coverage detected