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

Function prepare_record_v3

keepercommander/api.py:650–731  ·  view source on GitHub ↗

Prepares the Record() object to be sent to the Keeper Cloud API by serializing and encrypting it in the proper JSON format used for transmission. If the record has no UID, one is generated and the encrypted record key is sent to the server. If the record is in a sh

(params, record)

Source from the content-addressed store, hash-verified

648
649
650def prepare_record_v3(params, record): # type: (KeeperParams, Record) -> Optional[Tuple[dict, Optional[bytes]]]
651 """ Prepares the Record() object to be sent to the Keeper Cloud API
652 by serializing and encrypting it in the proper JSON format used for
653 transmission. If the record has no UID, one is generated and the
654 encrypted record key is sent to the server. If the record is in a
655 shared folder, must send shared folder UID for edit permission.
656 """
657 if not record.record_uid:
658 logging.debug('Generated Record UID: %s', record.record_uid)
659 record.record_uid = generate_record_uid()
660
661 record_object = {
662 'record_uid': record.record_uid,
663 'client_modified_time': current_milli_time()
664 }
665
666 audit_data = None
667 data = ''
668 if record.record_uid in params.record_cache:
669 path = resolve_record_write_path(params, record.record_uid)
670 if path:
671 record_object.update(path)
672 else:
673 share_admins = get_share_admins_for_record(params, record.record_uid)
674 if not share_admins or params.user not in share_admins:
675 logging.error('You do not have edit permissions on this record')
676 return None
677 record_object['record_uid'] = record.record_uid
678
679 rec = params.record_cache[record.record_uid]
680
681 data = rec['data_unencrypted'].decode('utf-8') if isinstance(rec['data_unencrypted'], bytes) else rec['data_unencrypted']
682 try:
683 if params.enterprise_ec_key:
684 d = json.loads(data)
685 rt_name = d.get('type') or ''
686 fields = itertools.chain(d.get('fields') or [], (d.get('custom') or []))
687 url_field = next((u.get('value') for u in fields if u.get('type') == 'url' and u.get('value')), None)
688 url = ''
689 if url_field and isinstance(url_field, list):
690 url = utils.url_strip(url_field[0])
691
692 adata = {
693 'title': d.get('title', ''),
694 'record_type': rt_name,
695 }
696 if url:
697 adata['url'] = url # url will only be supplied if there is one on the record
698 audit_data = crypto.encrypt_ec(json.dumps(adata).encode('utf-8'), params.enterprise_ec_key)
699
700 except Exception as e:
701 logging.error(bcolors.FAIL + 'Invalid record type! Error: ' + str(e) + bcolors.ENDC)
702 return None
703
704 data = pad_aes_gcm(data)
705
706 unencrypted_key = rec['record_key_unencrypted']
707 record_object['revision'] = rec['revision']

Callers 1

get_pb2_record_updateFunction · 0.85

Calls 11

generate_record_uidFunction · 0.85
current_milli_timeFunction · 0.85
pad_aes_gcmFunction · 0.85
getMethod · 0.80
queue_audit_eventMethod · 0.80
get_recordFunction · 0.70
debugMethod · 0.45
updateMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected