MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / get_self_managed_server_key

Function get_self_managed_server_key

keepercommander/rest_api.py:345–376  ·  view source on GitHub ↗

This host's own server key, or None for a Keeper cloud host or when it cannot be found.

(context)

Source from the content-addressed store, hash-verified

343
344
345def 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
379def refetch_server_key(context): # type: (RestApiContext) -> Optional[SelfManagedServerKey]

Callers 3

refetch_server_keyFunction · 0.85
get_server_public_keyFunction · 0.85
execute_restFunction · 0.85

Calls 9

server_hostFunction · 0.85
is_keeper_cloud_hostFunction · 0.85
_environment_server_keyFunction · 0.85
_unverified_reasonFunction · 0.85
_fetch_server_keyFunction · 0.85
server_key_fingerprintFunction · 0.85
warningMethod · 0.80
getMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected