(params, record)
| 37 | return encrypt_fn(data, pubkey) |
| 38 | |
| 39 | def prep_security_data(params, record): |
| 40 | get_bw_obj = lambda rec: next( |
| 41 | iter(params.breach_watch_records.get(rec, {}).get('data_unencrypted', {}).get('passwords', [])), |
| 42 | {}) if params.breach_watch else None |
| 43 | |
| 44 | from .breachwatch import BreachWatch |
| 45 | score = get_security_score(record) |
| 46 | # Send empty object to remove old security data (when password and/or passkey are removed) |
| 47 | sec_data = b'' |
| 48 | if score is not None: |
| 49 | sec_data = {'strength': score} |
| 50 | password = _get_pass(record) |
| 51 | login_url = BreachWatch.extract_url(record) |
| 52 | parse_results = urllib.parse.urlparse(login_url) |
| 53 | domain = parse_results.hostname or parse_results.path |
| 54 | pw_obj = get_bw_obj(record.record_uid) |
| 55 | if pw_obj is not None and password: |
| 56 | status = pw_obj.get('status') |
| 57 | sec_data['bw_result'] = client_pb2.BWStatus.Value(status) if status \ |
| 58 | else client_pb2.BWStatus.GOOD if is_pw_strong(score) \ |
| 59 | else client_pb2.BWStatus.WEAK |
| 60 | if domain: |
| 61 | sec_data.update(dict(domain=domain)) |
| 62 | data_size = len(json.dumps(sec_data).encode('utf8')) |
| 63 | max_size = 244 |
| 64 | diff = max_size - data_size |
| 65 | # truncate domain string if needed to avoid reaching RSA encryption data size limitation |
| 66 | if diff < 0: |
| 67 | new_length = len(domain) + diff |
| 68 | sec_data.update(dict(domain=domain[:new_length])) |
| 69 | sec_data = encrypt_security_data(params, sec_data) |
| 70 | return sec_data |
| 71 | |
| 72 | def prep_security_data_update(params, record): # type: (KeeperParams, KeeperRecord) -> Optional[APIRequest_pb2.SecurityData] |
| 73 | sd = APIRequest_pb2.SecurityData() |
no test coverage detected