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)
| 564 | |
| 565 | |
| 566 | def prepare_record(params, record): |
| 567 | """ Prepares the Record() object to be sent to the Keeper Cloud API |
| 568 | by serializing and encrypting it in the proper JSON format used for |
| 569 | transmission. If the record has no UID, one is generated and the |
| 570 | encrypted record key is sent to the server. If this record was |
| 571 | converted from RSA to AES we send the new record key. If the record |
| 572 | is in a shared folder, must send shared folder UID for edit permission. |
| 573 | """ |
| 574 | |
| 575 | record_object = { |
| 576 | 'version': 2, |
| 577 | 'client_modified_time': current_milli_time() |
| 578 | } # type: Dict[str, Any] |
| 579 | |
| 580 | if not record.record_uid: |
| 581 | logging.debug('Generated Record UID: %s', record.record_uid) |
| 582 | record.record_uid = generate_record_uid() |
| 583 | |
| 584 | record_object['record_uid'] = record.record_uid |
| 585 | |
| 586 | data = {} |
| 587 | extra = {} |
| 588 | udata = {} |
| 589 | unencrypted_key = None |
| 590 | if record.record_uid in params.record_cache: |
| 591 | path = resolve_record_write_path(params, record.record_uid) |
| 592 | if path: |
| 593 | record_object.update(path) |
| 594 | else: |
| 595 | logging.error('You do not have edit permissions on this record') |
| 596 | return None |
| 597 | |
| 598 | rec = params.record_cache[record.record_uid] |
| 599 | |
| 600 | data.update(json.loads(rec['data_unencrypted'].decode('utf-8'))) |
| 601 | if data.get('secret2') != record.password: |
| 602 | params.queue_audit_event('record_password_change', record_uid=record.record_uid) |
| 603 | |
| 604 | if 'extra' in rec: |
| 605 | extra.update(json.loads(rec['extra_unencrypted'].decode('utf-8'))) |
| 606 | if 'udata' in rec: |
| 607 | udata.update(rec['udata']) |
| 608 | unencrypted_key = rec['record_key_unencrypted'] |
| 609 | record_object['revision'] = rec['revision'] |
| 610 | if record.record_uid in params.meta_data_cache and params.meta_data_cache[record.record_uid].get('is_converted_record_type'): |
| 611 | logging.debug('Converted record sends record key') |
| 612 | record_object['record_key'] = \ |
| 613 | utils.base64_url_encode(crypto.encrypt_aes_v1(unencrypted_key, params.data_key)) |
| 614 | else: |
| 615 | logging.debug('Generated record key') |
| 616 | unencrypted_key = os.urandom(32) |
| 617 | record_object['record_key'] = utils.base64_url_encode(crypto.encrypt_aes_v1(unencrypted_key, params.data_key)) |
| 618 | record_object['revision'] = 0 |
| 619 | |
| 620 | data['title'] = record.title |
| 621 | data['folder'] = record.folder |
| 622 | data['secret1'] = record.login |
| 623 | data['secret2'] = record.password |
no test coverage detected