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

Function _fetch_server_key_from

keepercommander/rest_api.py:294–314  ·  view source on GitHub ↗
(context, url)

Source from the content-addressed store, hash-verified

292
293
294def _fetch_server_key_from(context, url): # type: (RestApiContext, str) -> SelfManagedServerKey
295 rs = requests.get(url, proxies=context.proxies, verify=context.certificate_check,
296 timeout=SERVER_KEY_FETCH_TIMEOUT)
297 rs.raise_for_status()
298 try:
299 server_key = rs.json()
300 except ValueError:
301 raise ValueError('did not return JSON')
302 if not isinstance(server_key, dict):
303 raise ValueError('did not return a server key')
304 public_key = server_key.get('serverPublicKey')
305 key_id = server_key.get('serverPublicKeyId')
306 if not public_key or not key_id:
307 raise ValueError(f'has no server key: {server_key.get("error") or "serverPublicKey is missing"}')
308 key = _make_server_key(key_id, public_key, f'fetched from {url}', fetched=True)
309 published = server_key.get('fingerprint')
310 if isinstance(published, str) and published:
311 if _fingerprint_matches(published, public_key) is False:
312 raise ValueError(f'the fingerprint it published ({published}) does not match its key '
313 f'({server_key_fingerprint(public_key)})')
314 return key
315
316
317def _fetch_server_key(context, host): # type: (RestApiContext, str) -> SelfManagedServerKey

Callers 1

_fetch_server_keyFunction · 0.85

Calls 6

_make_server_keyFunction · 0.85
_fingerprint_matchesFunction · 0.85
server_key_fingerprintFunction · 0.85
raise_for_statusMethod · 0.80
jsonMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected