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

Function load_team_keys

keepercommander/api.py:365–449  ·  view source on GitHub ↗
(params, team_uids)

Source from the content-addressed store, hash-verified

363
364
365def load_team_keys(params, team_uids): # type: (KeeperParams, List[str]) -> None
366 s = set(team_uids)
367 s.difference_update(params.key_cache.keys())
368 if not s:
369 return
370
371 if params.enterprise:
372 logging.debug('Resolve team keys shared with enterprise')
373 tree_key = params.enterprise['unencrypted_tree_key']
374 for t in params.enterprise.get('teams', []):
375 team_uid = t.get('team_uid')
376 if team_uid in s:
377 try:
378 encrypted_team_key = t.get('encrypted_team_key')
379 if encrypted_team_key:
380 team_key = crypto.decrypt_aes_v2(utils.base64_url_decode(encrypted_team_key), tree_key)
381 existing = params.key_cache.get(team_uid)
382 params.key_cache[team_uid] = PublicKeys(
383 aes=team_key,
384 rsa=getattr(existing, 'rsa', b'') or b'',
385 ec=getattr(existing, 'ec', b'') or b'')
386 # Still fetch asymmetric public keys via team_get_keys below.
387 except Exception as e:
388 logging.debug('Team UID \"%s\": Decrypt key error: %s', team_uid, str(e))
389
390 if not s:
391 return
392
393 logging.debug('Loading %d team keys', len(s))
394 uids_to_load = list(s)
395
396 while len(uids_to_load) > 0:
397 uids = uids_to_load[:90]
398 uids_to_load = uids_to_load[90:]
399 rq = {
400 'command': 'team_get_keys',
401 'teams': uids
402 }
403 rs = communicate(params, rq)
404 if 'keys' in rs:
405 merged = {} # team_uid -> PublicKeys fields
406 for tk in rs['keys']:
407 team_uid = tk.get('team_uid')
408 if not team_uid:
409 continue
410 if team_uid not in merged:
411 existing = params.key_cache.get(team_uid)
412 merged[team_uid] = {
413 'aes': getattr(existing, 'aes', b'') or b'',
414 'rsa': getattr(existing, 'rsa', b'') or b'',
415 'ec': getattr(existing, 'ec', b'') or b'',
416 }
417 # Read the symmetric/wrapped team key from the 'key' field
418 if 'key' in tk:
419 try:
420 encrypted_key = utils.base64_url_decode(tk['key'])
421 key_type = tk.get('type')
422 if key_type == 1:

Callers

nothing calls this directly

Calls 4

PublicKeysClass · 0.85
communicateFunction · 0.70
debugMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected