<s> import sys <EOL> import json <EOL> import requests <EOL> import base64 <EOL> import re <EOL> import getpass <EOL> import time <EOL> import os <EOL> from keepercommander import generator <EOL> import datetime <EOL> from keepercommander import plugin_manager , params <EOL> from keepercommander . record import Record <EOL> from keepercommander . error import AuthenticationError , CommunicationError , CryptoError <EOL> from Crypto import Random <EOL> from Crypto . Hash import SHA256 , HMAC , SHA <EOL> from Crypto . Protocol . KDF import PBKDF2 <EOL> from Crypto . PublicKey import RSA <EOL> from Crypto . Cipher import AES , PKCS1_v1_5 <EOL> CLIENT_VERSION = '<STR_LIT>' <EOL> current_milli_time = lambda : int ( round ( time . time ( ) * <NUM_LIT:1000> ) ) <EOL> BS = <NUM_LIT:16> <EOL> pad = lambda s : s + ( BS - len ( s ) % BS ) * chr ( BS - len ( s ) % BS ) <EOL> pad_binary = lambda s : s + ( ( BS - len ( s ) % BS ) * chr ( BS - len ( s ) % BS ) ) . encode ( ) <EOL> unpad_binary = lambda s : s [ <NUM_LIT:0> : - s [ - <NUM_LIT:1> ] ] <EOL> unpad_char = lambda s : s [ <NUM_LIT:0> : - ord ( s [ - <NUM_LIT:1> ] ) ] <EOL> def login ( params ) : <EOL> """<STR_LIT>""" <EOL> if not params . auth_verifier : <EOL> if params . debug : <EOL> print ( '<STR_LIT>' ) <EOL> payload = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : CLIENT_VERSION , <EOL> '<STR_LIT:username>' : params . user <EOL> } <EOL> try : <EOL> r = requests . post ( params . server , json = payload ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> raise CommunicationError ( sys . exc_info ( ) [ <NUM_LIT:0> ] ) <EOL> if params . debug : <EOL> debug_response ( params , payload , r ) <EOL> if not '<STR_LIT>' in r . json ( ) : <EOL> if r . json ( ) [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> raise AuthenticationError ( '<STR_LIT>' + str ( params . user ) + '<STR_LIT>' ) <EOL> if r . json ( ) [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> raise AuthenticationError ( '<STR_LIT>' ) <EOL> params . salt = base64 . urlsafe_b64decode ( r . json ( ) [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> params . iterations = r . json ( ) [ '<STR_LIT>' ] <EOL> prf = lambda p , s : HMAC . new ( p , s , SHA256 ) . digest ( ) <EOL> tmp_auth_verifier = base64 . urlsafe_b64encode ( <EOL> PBKDF2 ( params . password , params . salt , <EOL> <NUM_LIT:32> , params . iterations , prf ) ) <EOL> params . auth_verifier = tmp_auth_verifier . decode ( ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( params . auth_verifier ) + '<STR_LIT:]>' ) <EOL> success = False <EOL> while not success : <EOL> if params . mfa_token : <EOL> payload = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : params . auth_verifier , <EOL> '<STR_LIT>' : CLIENT_VERSION , <EOL> '<STR_LIT>' : params . mfa_token , <EOL> '<STR_LIT>' : params . mfa_type , <EOL> '<STR_LIT:username>' : params . user <EOL> } <EOL> else : <EOL> payload = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT:version>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : params . auth_verifier , <EOL> '<STR_LIT>' : CLIENT_VERSION , <EOL> '<STR_LIT:username>' : params . user <EOL> } <EOL> try : <EOL> r = requests . post ( params . server , json = payload ) <EOL> except : <EOL> raise CommunicationError ( sys . exc_info ( ) [ <NUM_LIT:0> ] ) <EOL> response_json = r . json ( ) <EOL> if params . debug : <EOL> debug_response ( params , payload , r ) <EOL> if ( <EOL> response_json [ '<STR_LIT>' ] == '<STR_LIT>' and <EOL> response_json [ '<STR_LIT:result>' ] == '<STR_LIT:success>' <EOL> ) : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in response_json : <EOL> params . session_token = response_json [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in response_json : <EOL> params . mfa_token = response_json [ '<STR_LIT>' ] <EOL> params . config [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> params . config [ '<STR_LIT>' ] = params . mfa_token <EOL> try : <EOL> with open ( params . config_filename , '<STR_LIT:w>' ) as f : <EOL> json . dump ( params . config , f , ensure_ascii = False ) <EOL> print ( '<STR_LIT>' + params . config_filename ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> if params . mfa_token : <EOL> params . mfa_type = '<STR_LIT>' <EOL> else : <EOL> params . mfa_type = '<STR_LIT>' <EOL> if '<STR_LIT>' in response_json : <EOL> if '<STR_LIT>' in response_json [ '<STR_LIT>' ] : <EOL> params . encrypted_private_key = response_json [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> else : <EOL> raise CommunicationError ( '<STR_LIT>' + '<STR_LIT>' ) <EOL> if '<STR_LIT>' in response_json [ '<STR_LIT>' ] : <EOL> params . encryption_params = response_json [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> decrypt_data_key ( params ) <EOL> decrypt_private_key ( params ) <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> success = True <EOL> elif ( response_json [ '<STR_LIT>' ] == '<STR_LIT>' or <EOL> response_json [ '<STR_LIT>' ] == '<STR_LIT>' or <EOL> response_json [ '<STR_LIT>' ] == '<STR_LIT>' ) : <EOL> try : <EOL> params . mfa_token = '<STR_LIT>' <EOL> params . mfa_type = '<STR_LIT>' <EOL> while not params . mfa_token : <EOL> try : <EOL> params . mfa_token = getpass . getpass ( <EOL> prompt = '<STR_LIT>' , stream = None ) <EOL> except ( KeyboardInterrupt ) : <EOL> print ( '<STR_LIT>' ) <EOL> raise <EOL> except ( EOFError , KeyboardInterrupt , SystemExit ) : <EOL> return <EOL> elif response_json [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> raise AuthenticationError ( '<STR_LIT>' ) <EOL> elif response_json [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> raise AuthenticationError ( response_json [ '<STR_LIT:message>' ] ) <EOL> elif response_json [ '<STR_LIT>' ] : <EOL> raise AuthenticationError ( response_json [ '<STR_LIT>' ] ) <EOL> else : <EOL> raise CommunicationError ( '<STR_LIT>' ) <EOL> def sync_down ( params ) : <EOL> """<STR_LIT>""" <EOL> if not params . server : <EOL> raise CommunicationError ( '<STR_LIT>' ) <EOL> if not params . user : <EOL> raise CommunicationError ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> def make_json ( params ) : <EOL> return { <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] , <EOL> '<STR_LIT>' : params . revision , <EOL> '<STR_LIT>' : current_milli_time ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : CLIENT_VERSION , <EOL> '<STR_LIT>' : params . mfa_token , <EOL> '<STR_LIT>' : params . mfa_type , <EOL> '<STR_LIT>' : params . session_token , <EOL> '<STR_LIT:username>' : params . user <EOL> } <EOL> if not params . session_token : <EOL> try : <EOL> login ( params ) <EOL> except : <EOL> raise <EOL> payload = make_json ( params ) <EOL> try : <EOL> r = requests . post ( params . server , json = payload ) <EOL> except : <EOL> raise CommunicationError ( sys . exc_info ( ) [ <NUM_LIT:0> ] ) <EOL> response_json = r . json ( ) <EOL> if response_json [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> try : <EOL> login ( params ) <EOL> except : <EOL> raise <EOL> payload = make_json ( params ) <EOL> try : <EOL> r = requests . post ( params . server , json = payload ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> raise CommunicationError ( sys . exc_info ( ) [ <NUM_LIT:0> ] ) <EOL> response_json = r . json ( ) <EOL> if params . debug : <EOL> debug_response ( params , payload , r ) <EOL> if response_json [ '<STR_LIT:result>' ] == '<STR_LIT:success>' : <EOL> if '<STR_LIT>' in response_json : <EOL> if response_json [ '<STR_LIT>' ] : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> params . record_cache = { } <EOL> params . meta_data_cache = { } <EOL> params . shared_folder_cache = { } <EOL> if '<STR_LIT>' in response_json : <EOL> params . revision = response_json [ '<STR_LIT>' ] <EOL> if params . debug : print ( '<STR_LIT>' + str ( params . revision ) ) <EOL> if '<STR_LIT>' in response_json : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> for uid in response_json [ '<STR_LIT>' ] : <EOL> del params . record_cache [ uid ] <EOL> if '<STR_LIT>' in response_json : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> for shared_folder in response_json [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in shared_folder : <EOL> for record in shared_folder [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in record : <EOL> record_uid = record [ '<STR_LIT>' ] <EOL> if record_uid in params . record_cache : <EOL> if not params . record_cache [ record_uid ] [ '<STR_LIT>' ] : <EOL> if num_folders_with_record ( record_uid ) == <NUM_LIT:1> : <EOL> del params . record_cache [ record_uid ] <EOL> for uid in response_json [ '<STR_LIT>' ] : <EOL> del params . shared_folder_cache [ uid ] <EOL> if '<STR_LIT>' in response_json : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> for meta_data in response_json [ '<STR_LIT>' ] : <EOL> if params . debug : print ( '<STR_LIT>' + str ( meta_data ) ) <EOL> if not '<STR_LIT>' in meta_data : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> unencrypted_key = os . urandom ( <NUM_LIT:32> ) <EOL> iv = os . urandom ( <NUM_LIT:16> ) <EOL> cipher = AES . new ( params . data_key , AES . MODE_CBC , iv ) <EOL> type1key = iv + cipher . encrypt ( pad_binary ( unencrypted_key ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( type1key ) ) <EOL> meta_data [ '<STR_LIT>' ] = ( base64 . urlsafe_b64encode ( <EOL> type1key ) . decode ( ) ) . rstrip ( '<STR_LIT>' ) <EOL> meta_data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> meta_data [ '<STR_LIT>' ] = True <EOL> if meta_data [ '<STR_LIT>' ] == <NUM_LIT:2> : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> decoded_key = base64 . urlsafe_b64decode ( <EOL> meta_data [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> dsize = SHA . digest_size <EOL> sentinel = Random . new ( ) . read ( <NUM_LIT:15> + dsize ) <EOL> cipher = PKCS1_v1_5 . new ( params . rsa_key ) <EOL> unencrypted_key = cipher . decrypt ( decoded_key , sentinel ) <EOL> if len ( unencrypted_key ) != <NUM_LIT:32> : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( meta_data [ '<STR_LIT>' ] ) ) <EOL> print ( '<STR_LIT>' + str ( unencrypted_key ) ) <EOL> iv = os . urandom ( <NUM_LIT:16> ) <EOL> cipher = AES . new ( params . data_key , AES . MODE_CBC , iv ) <EOL> type1key = iv + cipher . encrypt ( pad_binary ( unencrypted_key ) ) <EOL> meta_data [ '<STR_LIT>' ] = ( base64 . urlsafe_b64encode ( <EOL> type1key ) . decode ( ) ) . rstrip ( '<STR_LIT>' ) <EOL> meta_data [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( type1key ) ) <EOL> print ( '<STR_LIT>' + str ( meta_data [ '<STR_LIT>' ] ) ) <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> params . meta_data_cache [ meta_data [ '<STR_LIT>' ] ] = meta_data <EOL> if '<STR_LIT>' in response_json : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> for shared_folder in response_json [ '<STR_LIT>' ] : <EOL> decoded_key = base64 . urlsafe_b64decode ( <EOL> shared_folder [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> if shared_folder [ '<STR_LIT>' ] == <NUM_LIT:1> : <EOL> iv = decoded_key [ : <NUM_LIT:16> ] <EOL> ciphertext = decoded_key [ <NUM_LIT:16> : ] <EOL> cipher = AES . new ( params . data_key , AES . MODE_CBC , iv ) <EOL> unencrypted_key = unpad_binary ( cipher . decrypt ( ciphertext ) ) <EOL> if shared_folder [ '<STR_LIT>' ] == <NUM_LIT:2> : <EOL> dsize = SHA . digest_size <EOL> sentinel = Random . new ( ) . read ( <NUM_LIT:15> + dsize ) <EOL> cipher = PKCS1_v1_5 . new ( params . rsa_key ) <EOL> unencrypted_key = cipher . decrypt ( decoded_key , sentinel ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( shared_folder [ '<STR_LIT>' ] ) + '<STR_LIT>' + str ( unencrypted_key ) ) <EOL> if len ( unencrypted_key ) != <NUM_LIT:32> : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> shared_folder [ '<STR_LIT>' ] = unencrypted_key <EOL> decoded_folder_name = base64 . urlsafe_b64decode ( <EOL> shared_folder [ '<STR_LIT:name>' ] + '<STR_LIT>' ) <EOL> iv = decoded_folder_name [ : <NUM_LIT:16> ] <EOL> ciphertext = decoded_folder_name [ <NUM_LIT:16> : ] <EOL> cipher = AES . new ( unencrypted_key , AES . MODE_CBC , iv ) <EOL> folder_name = unpad_binary ( cipher . decrypt ( ciphertext ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( folder_name ) ) <EOL> shared_folder [ '<STR_LIT:name>' ] = folder_name <EOL> params . shared_folder_cache [ shared_folder [ '<STR_LIT>' ] ] = shared_folder <EOL> if '<STR_LIT>' in response_json : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> for record in response_json [ '<STR_LIT>' ] : <EOL> record_uid = record [ '<STR_LIT>' ] <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( record_uid ) ) <EOL> if record_uid in params . meta_data_cache : <EOL> record . update ( params . meta_data_cache [ record_uid ] ) <EOL> unencrypted_key = '<STR_LIT>' <EOL> if '<STR_LIT>' in record : <EOL> if params . debug : print ( '<STR_LIT>' + str ( record ) ) <EOL> record_key = record [ '<STR_LIT>' ] <EOL> decoded_key = base64 . urlsafe_b64decode ( record_key + '<STR_LIT>' ) <EOL> iv = decoded_key [ : <NUM_LIT:16> ] <EOL> ciphertext = decoded_key [ <NUM_LIT:16> : ] <EOL> cipher = AES . new ( params . data_key , AES . MODE_CBC , iv ) <EOL> unencrypted_key = cipher . decrypt ( ciphertext ) [ : <NUM_LIT:32> ] <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( unencrypted_key ) ) <EOL> else : <EOL> for shared_folder_uid in params . shared_folder_cache : <EOL> shared_folder = params . shared_folder_cache [ shared_folder_uid ] <EOL> sf_key = shared_folder [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in shared_folder : <EOL> sf_records = shared_folder [ '<STR_LIT>' ] <EOL> for sf_record in sf_records : <EOL> if '<STR_LIT>' in sf_record : <EOL> if sf_record [ '<STR_LIT>' ] == record_uid : <EOL> if '<STR_LIT>' in sf_record : <EOL> sf_rec_key = sf_record [ '<STR_LIT>' ] <EOL> record [ '<STR_LIT>' ] = sf_rec_key <EOL> decoded_key = base64 . urlsafe_b64decode ( <EOL> sf_rec_key + '<STR_LIT>' ) <EOL> iv = decoded_key [ : <NUM_LIT:16> ] <EOL> ciphertext = decoded_key [ <NUM_LIT:16> : ] <EOL> cipher = AES . new ( sf_key , AES . MODE_CBC , iv ) <EOL> unencrypted_key = cipher . decrypt ( ciphertext ) [ : <NUM_LIT:32> ] <EOL> if unencrypted_key : <EOL> if len ( unencrypted_key ) != <NUM_LIT:32> : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> record [ '<STR_LIT>' ] = unencrypted_key <EOL> else : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( unencrypted_key ) ) <EOL> '''<STR_LIT>''' <EOL> if ( '<STR_LIT>' in record ) and record [ '<STR_LIT>' ] : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> decoded_data = base64 . urlsafe_b64decode ( record [ '<STR_LIT:data>' ] + '<STR_LIT>' ) <EOL> iv = decoded_data [ : <NUM_LIT:16> ] <EOL> ciphertext = decoded_data [ <NUM_LIT:16> : ] <EOL> cipher = AES . new ( params . data_key , AES . MODE_CBC , iv ) <EOL> record [ '<STR_LIT:data>' ] = unpad_binary ( cipher . decrypt ( ciphertext ) ) <EOL> record [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> elif '<STR_LIT:data>' in record : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> decoded_data = base64 . urlsafe_b64decode ( record [ '<STR_LIT:data>' ] + '<STR_LIT>' ) <EOL> iv = decoded_data [ : <NUM_LIT:16> ] <EOL> ciphertext = decoded_data [ <NUM_LIT:16> : ] <EOL> cipher = AES . new ( record [ '<STR_LIT>' ] , AES . MODE_CBC , iv ) <EOL> record [ '<STR_LIT:data>' ] = unpad_binary ( cipher . decrypt ( ciphertext ) ) <EOL> else : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> record [ '<STR_LIT:data>' ] = b'<STR_LIT:{}>' <EOL> if '<STR_LIT>' in record : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> decoded_extra = base64 . urlsafe_b64decode ( record [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> iv = decoded_extra [ : <NUM_LIT:16> ] <EOL> ciphertext = decoded_extra [ <NUM_LIT:16> : ] <EOL> cipher = AES . new ( record [ '<STR_LIT>' ] , AES . MODE_CBC , iv ) <EOL> record [ '<STR_LIT>' ] = unpad_binary ( cipher . decrypt ( ciphertext ) ) <EOL> else : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> record [ '<STR_LIT>' ] = b'<STR_LIT:{}>' <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( isinstance ( record , dict ) ) ) <EOL> print ( '<STR_LIT>' + str ( isinstance ( params . record_cache , dict ) ) ) <EOL> print ( '<STR_LIT>' + str ( record ) ) <EOL> params . record_cache [ record_uid ] = record <EOL> if '<STR_LIT>' in response_json : <EOL> print ( '<STR_LIT>' ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( params . meta_data_cache ) ) <EOL> print ( '<STR_LIT>' + str ( params . record_cache ) ) <EOL> print ( '<STR_LIT>' + str ( params . shared_folder_cache ) ) <EOL> if len ( params . record_cache ) == <NUM_LIT:1> : <EOL> print ( '<STR_LIT>' ) <EOL> else : <EOL> print ( '<STR_LIT>' + str ( len ( params . record_cache ) ) + '<STR_LIT>' ) <EOL> else : <EOL> if response_json [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> raise CommunicationError ( '<STR_LIT>' + '<STR_LIT>' ) <EOL> else : <EOL> raise CommunicationError ( '<STR_LIT>' ) <EOL> def num_folders_with_record ( record_uid ) : <EOL> counter = <NUM_LIT:0> <EOL> for shared_folder in params . shared_folder_cache : <EOL> if '<STR_LIT>' in shared_folder : <EOL> for record in shared_folder [ '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in record : <EOL> if record [ '<STR_LIT>' ] == record_uid : <EOL> counter += <NUM_LIT:1> <EOL> return counter <EOL> def decrypt_data_key ( params ) : <EOL> """<STR_LIT>""" <EOL> if not params . encryption_params : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> decoded_encryption_params = base64 . urlsafe_b64decode ( <EOL> params . encryption_params + '<STR_LIT>' ) <EOL> if len ( decoded_encryption_params ) != <NUM_LIT:100> : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> version = int . from_bytes ( decoded_encryption_params [ <NUM_LIT:0> : <NUM_LIT:1> ] , <EOL> byteorder = '<STR_LIT>' , signed = False ) <EOL> iterations = int . from_bytes ( decoded_encryption_params [ <NUM_LIT:1> : <NUM_LIT:4> ] , <EOL> byteorder = '<STR_LIT>' , signed = False ) <EOL> salt = decoded_encryption_params [ <NUM_LIT:4> : <NUM_LIT:20> ] <EOL> encrypted_data_key = decoded_encryption_params [ <NUM_LIT:20> : <NUM_LIT:100> ] <EOL> iv = encrypted_data_key [ <NUM_LIT:0> : <NUM_LIT:16> ] <EOL> ciphertext = encrypted_data_key [ <NUM_LIT:16> : <NUM_LIT> ] <EOL> if iterations < <NUM_LIT:1000> : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> prf = lambda p , s : HMAC . new ( p , s , SHA256 ) . digest ( ) <EOL> key = PBKDF2 ( params . password , salt , <NUM_LIT:32> , iterations , prf ) <EOL> cipher = AES . new ( key , AES . MODE_CBC , iv ) <EOL> decrypted_data_key = cipher . decrypt ( ciphertext ) <EOL> if len ( decrypted_data_key ) != <NUM_LIT:64> : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> if decrypted_data_key [ : <NUM_LIT:32> ] != decrypted_data_key [ <NUM_LIT:32> : ] : <EOL> raise CryptoError ( '<STR_LIT>' ) <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> params . data_key = decrypted_data_key [ : <NUM_LIT:32> ] <EOL> def decrypt_private_key ( params ) : <EOL> """<STR_LIT>""" <EOL> decoded_private_key = base64 . urlsafe_b64decode ( <EOL> params . encrypted_private_key + '<STR_LIT>' ) <EOL> iv = decoded_private_key [ : <NUM_LIT:16> ] <EOL> ciphertext = decoded_private_key [ <NUM_LIT:16> : ] <EOL> cipher = AES . new ( params . data_key , AES . MODE_CBC , iv ) <EOL> decrypted_private_key = cipher . decrypt ( ciphertext ) <EOL> params . private_key = unpad_binary ( decrypted_private_key ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( decrypted_private_key ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( params . private_key ) ) <EOL> params . rsa_key = RSA . importKey ( params . private_key ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( params . private_key ) ) <EOL> def rotate_password ( params , record_uid ) : <EOL> """<STR_LIT>""" <EOL> record_uid = record_uid . strip ( ) <EOL> if not record_uid : <EOL> print ( '<STR_LIT>' ) <EOL> return False <EOL> if not params . record_cache : <EOL> print ( '<STR_LIT>' ) <EOL> return False <EOL> if not record_uid in params . record_cache : <EOL> print ( '<STR_LIT>' ) <EOL> return False <EOL> cached_rec = params . record_cache [ record_uid ] <EOL> if '<STR_LIT:data>' in cached_rec : <EOL> data = json . loads ( cached_rec [ '<STR_LIT:data>' ] . decode ( '<STR_LIT:utf-8>' ) ) <EOL> else : data = { } <EOL> if '<STR_LIT>' in cached_rec : <EOL> extra = json . loads ( cached_rec [ '<STR_LIT>' ] . decode ( '<STR_LIT:utf-8>' ) ) <EOL> else : extra = { } <EOL> can_edit = False <EOL> if '<STR_LIT>' in cached_rec : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> can_edit = True <EOL> found_shared_folder_uid = '<STR_LIT>' <EOL> if can_edit == False : <EOL> for shared_folder_uid in params . shared_folder_cache : <EOL> shared_folder = params . shared_folder_cache [ shared_folder_uid ] <EOL> sf_key = shared_folder [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in shared_folder : <EOL> sf_records = shared_folder [ '<STR_LIT>' ] <EOL> for sf_record in sf_records : <EOL> if '<STR_LIT>' in sf_record : <EOL> if sf_record [ '<STR_LIT>' ] == record_uid : <EOL> found_shared_folder_uid = shared_folder_uid <EOL> if '<STR_LIT>' in sf_record : <EOL> can_edit = True <EOL> if params . debug : <EOL> print ( '<STR_LIT>' ) <EOL> break <EOL> if not can_edit : <EOL> print ( '<STR_LIT>' ) <EOL> return False <EOL> if not params . server : <EOL> raise CommunicationError ( '<STR_LIT>' ) <EOL> if not params . user : <EOL> raise CommunicationError ( '<STR_LIT>' ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( data ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( extra ) ) <EOL> modified_time = int ( round ( time . time ( ) ) ) <EOL> modified_time_milli = modified_time * <NUM_LIT:1000> <EOL> datestamp = datetime . datetime . fromtimestamp ( <EOL> modified_time ) . strftime ( '<STR_LIT>' ) <EOL> custom_dict = { } <EOL> custom_dict [ '<STR_LIT:name>' ] = '<STR_LIT>' + str ( datestamp ) <EOL> custom_dict [ '<STR_LIT:value>' ] = data [ '<STR_LIT>' ] <EOL> custom_dict [ '<STR_LIT:type>' ] = '<STR_LIT:text>' <EOL> serialized = json . dumps ( custom_dict ) <EOL> custom_dict_json = json . loads ( serialized ) <EOL> data [ '<STR_LIT>' ] . append ( custom_dict_json ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( data [ '<STR_LIT>' ] ) ) <EOL> record_object = Record ( ) <EOL> record_object . load ( data ) <EOL> rules = record_object . get ( "<STR_LIT>" ) <EOL> if rules : <EOL> new_password = generator . generateFromRules ( rules ) <EOL> else : <EOL> new_password = generator . generate ( ) <EOL> plugin_name = record_object . get ( "<STR_LIT>" ) <EOL> if plugin_name : <EOL> plugin = plugin_manager . get_plugin ( plugin_name ) <EOL> if plugin : <EOL> if hasattr ( plugin , "<STR_LIT>" ) : <EOL> new_password = plugin . adjust ( new_password ) <EOL> print ( "<STR_LIT>" + str ( plugin_name ) ) <EOL> success = plugin . rotate ( record_object , new_password ) <EOL> if success : <EOL> if params . debug : <EOL> print ( "<STR_LIT>" . format ( plugin_name ) ) <EOL> else : <EOL> print ( "<STR_LIT>" . format ( plugin_name ) ) <EOL> return False <EOL> else : <EOL> return False <EOL> else : <EOL> return False <EOL> data [ '<STR_LIT>' ] = record_object . password <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( data [ '<STR_LIT>' ] ) ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( data ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( isinstance ( data , dict ) ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( isinstance ( params . record_cache , dict ) ) ) <EOL> params . record_cache [ record_uid ] [ '<STR_LIT:data>' ] = json . dumps ( data ) . encode ( ) <EOL> if params . debug : <EOL> print ( '<STR_LIT>' + str ( params . record_cache [ record_uid ] ) ) <EOL> print ( '<STR_LIT>' + str ( data ) ) <EOL> print ( '<STR_LIT>' + str ( extra ) ) <EOL> data_serialized = json . dumps ( data ) <EOL> extra_serialized = json . dumps ( extra ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( data_serialized ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( extra_serialized ) ) <EOL> if not '<STR_LIT>' in params . record_cache [ record_uid ] : <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> raise CryptoError ( '<STR_LIT>' + record_uid ) <EOL> if not '<STR_LIT>' in params . record_cache [ record_uid ] : <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> raise CryptoError ( '<STR_LIT>' + record_uid ) <EOL> record_key_unencrypted = params . record_cache [ record_uid ] [ '<STR_LIT>' ] <EOL> iv = os . urandom ( <NUM_LIT:16> ) <EOL> cipher = AES . new ( record_key_unencrypted , AES . MODE_CBC , iv ) <EOL> encrypted_data = iv + cipher . encrypt ( pad ( data_serialized ) ) <EOL> iv = os . urandom ( <NUM_LIT:16> ) <EOL> cipher = AES . new ( record_key_unencrypted , AES . MODE_CBC , iv ) <EOL> encrypted_extra = iv + cipher . encrypt ( pad ( extra_serialized ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encrypted_data ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encrypted_extra ) ) <EOL> encoded_data = base64 . urlsafe_b64encode ( encrypted_data ) . decode ( ) <EOL> encoded_extra = base64 . urlsafe_b64encode ( encrypted_extra ) . decode ( ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encoded_data ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encoded_extra ) ) <EOL> new_record = { } <EOL> new_record [ '<STR_LIT>' ] = record_uid <EOL> new_record [ '<STR_LIT:version>' ] = <NUM_LIT:2> <EOL> new_record [ '<STR_LIT:data>' ] = encoded_data <EOL> new_record [ '<STR_LIT>' ] = encoded_extra <EOL> new_record [ '<STR_LIT>' ] = modified_time_milli <EOL> new_record [ '<STR_LIT>' ] = params . record_cache [ record_uid ] [ '<STR_LIT>' ] <EOL> if found_shared_folder_uid : <EOL> new_record [ '<STR_LIT>' ] = found_shared_folder_uid <EOL> if '<STR_LIT>' in params . record_cache [ record_uid ] : <EOL> new_record [ '<STR_LIT>' ] = params . record_cache [ record_uid ] [ '<STR_LIT>' ] <EOL> if params . debug : print ( '<STR_LIT>' + str ( new_record ) ) <EOL> update_records = [ ] <EOL> update_records . append ( new_record ) <EOL> def make_json ( params , update_records ) : <EOL> return { <EOL> '<STR_LIT>' : current_milli_time ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : update_records , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : CLIENT_VERSION , <EOL> '<STR_LIT>' : params . mfa_token , <EOL> '<STR_LIT>' : params . mfa_type , <EOL> '<STR_LIT>' : params . session_token , <EOL> '<STR_LIT:username>' : params . user <EOL> } <EOL> if not params . session_token : <EOL> try : <EOL> login ( params ) <EOL> except : <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> raise <EOL> payload = make_json ( params , update_records ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( payload ) ) <EOL> try : <EOL> r = requests . post ( params . server , json = payload ) <EOL> except : <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> raise CommunicationError ( sys . exc_info ( ) [ <NUM_LIT:0> ] ) <EOL> response_json = r . json ( ) <EOL> if params . debug : <EOL> debug_response ( params , payload , r ) <EOL> if response_json [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> try : <EOL> login ( params ) <EOL> except : <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> raise <EOL> payload = make_json ( params , update_records ) <EOL> try : <EOL> r = requests . post ( params . server , json = payload ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> raise CommunicationError ( sys . exc_info ( ) [ <NUM_LIT:0> ] ) <EOL> response_json = r . json ( ) <EOL> if params . debug : <EOL> debug_response ( params , payload , r ) <EOL> if response_json [ '<STR_LIT:result>' ] == '<STR_LIT:success>' : <EOL> new_revision = <NUM_LIT:0> <EOL> if '<STR_LIT>' in response_json : <EOL> for info in response_json [ '<STR_LIT>' ] : <EOL> if info [ '<STR_LIT>' ] == record_uid : <EOL> if info [ '<STR_LIT:status>' ] == '<STR_LIT:success>' : <EOL> new_revision = response_json [ '<STR_LIT>' ] <EOL> if new_revision == <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' ) <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> return False <EOL> if new_revision == new_record [ '<STR_LIT>' ] : <EOL> print ( '<STR_LIT>' ) <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> return False <EOL> print ( '<STR_LIT>' + str ( new_record [ '<STR_LIT>' ] ) + '<STR_LIT>' + str ( new_record [ '<STR_LIT>' ] ) , '<STR_LIT>' + str ( new_revision ) ) <EOL> params . record_cache [ record_uid ] [ '<STR_LIT>' ] = new_revision <EOL> else : <EOL> if response_json [ '<STR_LIT>' ] : <EOL> if plugin_name : <EOL> print ( '<STR_LIT>' + new_password ) <EOL> raise CommunicationError ( '<STR_LIT>' + response_json [ '<STR_LIT>' ] ) <EOL> return True <EOL> def get_record ( params , record_uid ) : <EOL> """<STR_LIT>""" <EOL> record_uid = record_uid . strip ( ) <EOL> if not record_uid : <EOL> print ( '<STR_LIT>' ) <EOL> return <EOL> if not params . record_cache : <EOL> print ( '<STR_LIT>' ) <EOL> return <EOL> if not record_uid in params . record_cache : <EOL> print ( '<STR_LIT>' ) <EOL> return <EOL> cached_rec = params . record_cache [ record_uid ] <EOL> if params . debug : print ( '<STR_LIT>' + str ( cached_rec ) ) <EOL> data = json . loads ( cached_rec [ '<STR_LIT:data>' ] . decode ( '<STR_LIT:utf-8>' ) ) <EOL> rec = Record ( record_uid ) <EOL> rec . load ( data , cached_rec [ '<STR_LIT>' ] ) <EOL> return rec <EOL> def search_records ( params , searchstring ) : <EOL> """<STR_LIT>""" <EOL> if not params . record_cache : <EOL> print ( '<STR_LIT>' ) <EOL> return <EOL> if searchstring != '<STR_LIT>' : print ( '<STR_LIT>' + searchstring ) <EOL> p = re . compile ( searchstring . lower ( ) ) <EOL> search_results = [ ] <EOL> for record_uid in params . record_cache : <EOL> rec = get_record ( params , record_uid ) <EOL> target = rec . to_lowerstring ( ) <EOL> if p . search ( target ) : <EOL> search_results . append ( rec ) <EOL> return search_results <EOL> def prepare_record ( params , record , shared_folder_uid = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> if not record . record_uid : <EOL> record . record_uid = generate_record_uid ( ) <EOL> if params . debug : print ( '<STR_LIT>' + record . record_uid ) <EOL> if record . record_uid in params . record_cache : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> modified_time = int ( round ( time . time ( ) ) ) <EOL> modified_time_milli = modified_time * <NUM_LIT:1000> <EOL> datestamp = datetime . datetime . fromtimestamp ( <EOL> modified_time ) . strftime ( '<STR_LIT>' ) <EOL> data = { } <EOL> extra = { } <EOL> udata = [ ] <EOL> data [ '<STR_LIT:title>' ] = record . title <EOL> data [ '<STR_LIT>' ] = record . folder <EOL> data [ '<STR_LIT>' ] = record . login <EOL> data [ '<STR_LIT>' ] = record . password <EOL> data [ '<STR_LIT>' ] = record . login_url <EOL> data [ '<STR_LIT>' ] = record . notes <EOL> data [ '<STR_LIT>' ] = record . custom_fields <EOL> data_serialized = json . dumps ( data ) <EOL> extra_serialized = json . dumps ( extra ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( data ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( data_serialized ) ) <EOL> unencrypted_key = os . urandom ( <NUM_LIT:32> ) <EOL> iv = os . urandom ( <NUM_LIT:16> ) <EOL> cipher = AES . new ( params . data_key , AES . MODE_CBC , iv ) <EOL> type1key = iv + cipher . encrypt ( pad_binary ( unencrypted_key ) ) <EOL> encoded_type1key = ( base64 . urlsafe_b64encode ( <EOL> type1key ) . decode ( ) ) . rstrip ( '<STR_LIT>' ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( type1key ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encoded_type1key ) ) <EOL> iv = os . urandom ( <NUM_LIT:16> ) <EOL> cipher = AES . new ( unencrypted_key , AES . MODE_CBC , iv ) <EOL> encrypted_data = iv + cipher . encrypt ( pad ( data_serialized ) ) <EOL> iv = os . urandom ( <NUM_LIT:16> ) <EOL> cipher = AES . new ( unencrypted_key , AES . MODE_CBC , iv ) <EOL> encrypted_extra = iv + cipher . encrypt ( pad ( extra_serialized ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encrypted_data ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encrypted_extra ) ) <EOL> encoded_data = base64 . urlsafe_b64encode ( encrypted_data ) . decode ( ) <EOL> encoded_extra = base64 . urlsafe_b64encode ( encrypted_extra ) . decode ( ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encoded_data ) ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( encoded_extra ) ) <EOL> new_record = { } <EOL> new_record [ '<STR_LIT>' ] = record . record_uid <EOL> new_record [ '<STR_LIT:version>' ] = <NUM_LIT:2> <EOL> new_record [ '<STR_LIT:data>' ] = encoded_data <EOL> new_record [ '<STR_LIT>' ] = encoded_extra <EOL> new_record [ '<STR_LIT>' ] = udata <EOL> new_record [ '<STR_LIT>' ] = modified_time_milli <EOL> new_record [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> new_record [ '<STR_LIT>' ] = encoded_type1key <EOL> if shared_folder_uid : <EOL> new_record [ '<STR_LIT>' ] = shared_folder_uid <EOL> if params . debug : print ( '<STR_LIT>' + str ( new_record ) ) <EOL> return new_record <EOL> def make_request ( params , command ) : <EOL> return { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : command , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : CLIENT_VERSION , <EOL> } <EOL> def communicate ( params , request ) : <EOL> def authorize_request ( ) : <EOL> request [ '<STR_LIT>' ] = current_milli_time ( ) <EOL> request [ '<STR_LIT>' ] = params . mfa_token , <EOL> request [ '<STR_LIT>' ] = params . mfa_type <EOL> request [ '<STR_LIT>' ] = params . session_token <EOL> request [ '<STR_LIT:username>' ] = params . user <EOL> if not params . session_token : <EOL> try : <EOL> login ( params ) <EOL> except : <EOL> raise <EOL> authorize_request ( ) <EOL> if params . debug : print ( '<STR_LIT>' + str ( request ) ) <EOL> try : <EOL> r = requests . post ( params . server , json = request ) <EOL> except : <EOL> raise CommunicationError ( sys . exc_info ( ) [ <NUM_LIT:0> ] ) <EOL> response_json = r . json ( ) <EOL> if params . debug : <EOL> debug_response ( params , request , r ) <EOL> if response_json [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if params . debug : print ( '<STR_LIT>' ) <EOL> try : <EOL> login ( params ) <EOL> except : <EOL> raise <EOL> authorize_request ( ) <EOL> try : <EOL> r = requests . post ( params . server , json = request ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> raise CommunicationError ( sys . exc_info ( ) [ <NUM_LIT:0> ] ) <EOL> response_json = r . json ( ) <EOL> if params . debug : <EOL> debug_response ( params , request , r ) <EOL> if response_json [ '<STR_LIT:result>' ] != '<STR_LIT:success>' : <EOL> if response_json [ '<STR_LIT>' ] : <EOL> raise CommunicationError ( '<STR_LIT>' + response_json [ '<STR_LIT>' ] ) <EOL> return response_json <EOL> def add_record ( params ) : <EOL> """<STR_LIT>""" <EOL> record = Record ( ) <EOL> if not record . title : <EOL> while not record . title : <EOL> record . title = input ( "<STR_LIT>" ) <EOL> record . folder = input ( "<STR_LIT>" ) <EOL> record . login = input ( "<STR_LIT>" ) <EOL> record . password = input ( "<STR_LIT>" ) <EOL> record . login_url = input ( "<STR_LIT>" ) <EOL> record . notes = input ( "<STR_LIT>" ) <EOL> while True : <EOL> custom_dict = { } <EOL> custom_dict [ '<STR_LIT:name>' ] = input ( "<STR_LIT>" ) <EOL> if not custom_dict [ '<STR_LIT:name>' ] : <EOL> break <EOL> custom_dict [ '<STR_LIT:value>' ] = input ( "<STR_LIT>" ) <EOL> custom_dict [ '<STR_LIT:type>' ] = '<STR_LIT:text>' <EOL> record . custom_fields . append ( custom_dict ) <EOL> new_record = prepare_record ( params , record ) <EOL> request = make_request ( params , '<STR_LIT>' ) <EOL> request [ '<STR_LIT>' ] = [ new_record ] <EOL> response_json = communicate ( params , request ) <EOL> if response_json [ '<STR_LIT:result>' ] == '<STR_LIT:success>' : <EOL> new_revision = <NUM_LIT:0> <EOL> if '<STR_LIT>' in response_json : <EOL> for info in response_json [ '<STR_LIT>' ] : <EOL> if info [ '<STR_LIT>' ] == record . record_uid : <EOL> if info [ '<STR_LIT:status>' ] == '<STR_LIT:success>' : <EOL> new_revision = response_json [ '<STR_LIT>' ] <EOL> if new_revision == <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' ) <EOL> return False <EOL> if new_revision == new_record [ '<STR_LIT>' ] : <EOL> print ( '<STR_LIT>' ) <EOL> return False <EOL> print ( '<STR_LIT>' + str ( new_record [ '<STR_LIT>' ] ) + '<STR_LIT>' + str ( new_record [ '<STR_LIT>' ] ) , '<STR_LIT>' + str ( new_revision ) ) <EOL> new_record [ '<STR_LIT>' ] = new_revision <EOL> sync_down ( params ) <EOL> return True <EOL> def debug_response ( params , payload , response ) : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' + params . server + '<STR_LIT:]>' ) <EOL> print ( '<STR_LIT>' + str ( payload ) + '<STR_LIT:]>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' + str ( response . status_code ) + '<STR_LIT:]>' ) <EOL> print ( '<STR_LIT>' + str ( response . headers ) + '<STR_LIT:]>' ) <EOL> if response . text : <EOL> print ( '<STR_LIT>' + str ( response . text ) + '<STR_LIT:]>' ) <EOL> print ( '<STR_LIT>' + json . dumps ( response . json ( ) , <EOL> sort_keys = True , indent = <NUM_LIT:4> ) + '<STR_LIT:]>' ) <EOL> if params . session_token : <EOL> print ( '<STR_LIT>' + str ( params . session_token ) + '<STR_LIT:]>' ) <EOL> def generate_random_records ( params , num ) : <EOL> """<STR_LIT>""" <EOL> def generate_record_uid ( ) : <EOL> """<STR_LIT>""" <EOL> return base64 . urlsafe_b64encode ( <EOL> os . urandom ( <NUM_LIT:16> ) ) . decode ( ) . rstrip ( '<STR_LIT>' ) </s>
