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

Function prepare_record

keepercommander/api.py:627–708  ·  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

625
626
627def prepare_record(params, record):
628 """ Prepares the Record() object to be sent to the Keeper Cloud API
629 by serializing and encrypting it in the proper JSON format used for
630 transmission. If the record has no UID, one is generated and the
631 encrypted record key is sent to the server. If this record was
632 converted from RSA to AES we send the new record key. If the record
633 is in a shared folder, must send shared folder UID for edit permission.
634 """
635
636 record_object = {
637 'version': 2,
638 'client_modified_time': current_milli_time()
639 } # type: Dict[str, Any]
640
641 if not record.record_uid:
642 logging.debug('Generated Record UID: %s', record.record_uid)
643 record.record_uid = generate_record_uid()
644
645 record_object['record_uid'] = record.record_uid
646
647 data = {}
648 extra = {}
649 udata = {}
650 unencrypted_key = None
651 if record.record_uid in params.record_cache:
652 path = resolve_record_write_path(params, record.record_uid)
653 if path:
654 record_object.update(path)
655 else:
656 logging.error('You do not have edit permissions on this record')
657 return None
658
659 rec = params.record_cache[record.record_uid]
660
661 data.update(json.loads(rec['data_unencrypted'].decode('utf-8')))
662 if data.get('secret2') != record.password:
663 params.queue_audit_event('record_password_change', record_uid=record.record_uid)
664
665 if 'extra' in rec:
666 extra.update(json.loads(rec['extra_unencrypted'].decode('utf-8')))
667 if 'udata' in rec:
668 udata.update(rec['udata'])
669 unencrypted_key = rec['record_key_unencrypted']
670 record_object['revision'] = rec['revision']
671 if record.record_uid in params.meta_data_cache and params.meta_data_cache[record.record_uid].get('is_converted_record_type'):
672 logging.debug('Converted record sends record key')
673 record_object['record_key'] = \
674 utils.base64_url_encode(crypto.encrypt_aes_v1(unencrypted_key, params.data_key))
675 else:
676 logging.debug('Generated record key')
677 unencrypted_key = os.urandom(32)
678 record_object['record_key'] = utils.base64_url_encode(crypto.encrypt_aes_v1(unencrypted_key, params.data_key))
679 record_object['revision'] = 0
680
681 data['title'] = record.title
682 data['folder'] = record.folder
683 data['secret1'] = record.login
684 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
queue_audit_eventMethod · 0.80
validate_record_dataMethod · 0.80
get_recordFunction · 0.70
debugMethod · 0.45
updateMethod · 0.45
errorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected