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

Function prepare_record

keepercommander/api.py:591–672  ·  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 this record was conve

(params, record)

Source from the content-addressed store, hash-verified

589
590
591def prepare_record(params, record):
592 """ Prepares the Record() object to be sent to the Keeper Cloud API
593 by serializing and encrypting it in the proper JSON format used for
594 transmission. If the record has no UID, one is generated and the
595 encrypted record key is sent to the server. If this record was
596 converted from RSA to AES we send the new record key. If the record
597 is in a shared folder, must send shared folder UID for edit permission.
598 """
599
600 record_object = {
601 'version': 2,
602 'client_modified_time': current_milli_time()
603 } # type: Dict[str, Any]
604
605 if not record.record_uid:
606 logging.debug('Generated Record UID: %s', record.record_uid)
607 record.record_uid = generate_record_uid()
608
609 record_object['record_uid'] = record.record_uid
610
611 data = {}
612 extra = {}
613 udata = {}
614 unencrypted_key = None
615 if record.record_uid in params.record_cache:
616 path = resolve_record_write_path(params, record.record_uid)
617 if path:
618 record_object.update(path)
619 else:
620 logging.error('You do not have edit permissions on this record')
621 return None
622
623 rec = params.record_cache[record.record_uid]
624
625 data.update(json.loads(rec['data_unencrypted'].decode('utf-8')))
626 if data.get('secret2') != record.password:
627 params.queue_audit_event('record_password_change', record_uid=record.record_uid)
628
629 if 'extra' in rec:
630 extra.update(json.loads(rec['extra_unencrypted'].decode('utf-8')))
631 if 'udata' in rec:
632 udata.update(rec['udata'])
633 unencrypted_key = rec['record_key_unencrypted']
634 record_object['revision'] = rec['revision']
635 if record.record_uid in params.meta_data_cache and params.meta_data_cache[record.record_uid].get('is_converted_record_type'):
636 logging.debug('Converted record sends record key')
637 record_object['record_key'] = \
638 utils.base64_url_encode(crypto.encrypt_aes_v1(unencrypted_key, params.data_key))
639 else:
640 logging.debug('Generated record key')
641 unencrypted_key = os.urandom(32)
642 record_object['record_key'] = utils.base64_url_encode(crypto.encrypt_aes_v1(unencrypted_key, params.data_key))
643 record_object['revision'] = 0
644
645 data['title'] = record.title
646 data['folder'] = record.folder
647 data['secret1'] = record.login
648 data['secret2'] = record.password

Callers 2

update_recordFunction · 0.85
add_recordFunction · 0.85

Calls 10

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

Tested by

no test coverage detected