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

Function prepare_record

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

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

Callers 2

update_recordFunction · 0.85
add_recordFunction · 0.85

Calls 11

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
encodeMethod · 0.45

Tested by

no test coverage detected