#NEWLINE# def chrome_cookies( url , cookie_file = None ) : #NEWLINE# #INDENT# salt = b'saltysalt' #NEWLINE# iv = ( b' ' * 16 ) #NEWLINE# length = 16 #NEWLINE# def chrome_decrypt( encrypted_value , key = None ) : #NEWLINE# #INDENT# encrypted_value = encrypted_value [ 3 : ] #NEWLINE# def clean( x ) : #NEWLINE# #INDENT# last = x [ ( - 1 ) ] #NEWLINE# if isinstance ( last , int ) : #NEWLINE# #INDENT# return x [ : ( - last ) ] . decode ( 'utf8' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return x [ : ( - ord ( last ) ) ] . decode ( 'utf8' ) #NEWLINE# #UNINDENT# #UNINDENT# cipher = AES . new ( key , AES . MODE_CBC , IV = iv ) #NEWLINE# decrypted = cipher . decrypt ( encrypted_value ) #NEWLINE# return clean ( decrypted ) #NEWLINE# #UNINDENT# if ( sys . platform == 'darwin' ) : #NEWLINE# #INDENT# my_pass = keyring . get_password ( 'Chrome Safe Storage' , 'Chrome' ) #NEWLINE# my_pass = my_pass . encode ( 'utf8' ) #NEWLINE# iterations = 1003 #NEWLINE# cookie_file = ( cookie_file or os . path . expanduser ( '~/Library/Application Support/Google/Chrome/Default/Cookies' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if sys . platform . startswith ( 'linux' ) : #NEWLINE# #INDENT# my_pass = 'peanuts' . encode ( 'utf8' ) #NEWLINE# iterations = 1 #NEWLINE# cookie_file = ( cookie_file or os . path . expanduser ( '~/.config/chromium/Default/Cookies' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise OSError ( 'This script only works on OSX or Linux.' ) #NEWLINE# #UNINDENT# #UNINDENT# key = PBKDF2 ( my_pass , salt , length , iterations ) #NEWLINE# domain = urlparse ( url ) . netloc #NEWLINE# conn = sqlite3 . connect ( cookie_file ) #NEWLINE# sql = 'select name, value, encrypted_value from cookies where host_key like ?' #NEWLINE# cookies = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for host_key in generate_host_keys ( domain ) : #NEWLINE# #INDENT# cookies_list = [ ] #NEWLINE# for ( k , v , ev ) in conn . execute ( sql , ( host_key , ) ) : #NEWLINE# #INDENT# if ( v or ( ev [ : 3 ] != b'v10' ) ) : #NEWLINE# #INDENT# cookies_list . append ( ( k , v ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# decrypted_tuple = ( k , chrome_decrypt ( ev , key = key ) ) #NEWLINE# cookies_list . append ( decrypted_tuple ) #NEWLINE# #UNINDENT# #UNINDENT# cookies . update ( cookies_list ) #NEWLINE# #UNINDENT# conn . rollback ( ) #NEWLINE# return host_key