#NEWLINE# @ flow . StateHandler ( next_state = 'CheckHash' ) #NEWLINE# def ReceiveFileHash( self , responses ) : #NEWLINE# #INDENT# 'Add hash digest to tracker and check with filestore.' #NEWLINE# if ( ( not responses . success ) and ( responses . request . request . name == 'HashFile' ) ) : #NEWLINE# #INDENT# logging . debug ( 'HashFile action not available, falling back to FingerprintFile.' ) #NEWLINE# self . CallClient ( 'FingerprintFile' , responses . request . request . payload , next_state = 'ReceiveFileHash' , request_data = responses . request_data ) #NEWLINE# return #NEWLINE# #UNINDENT# index = responses . request_data [ 'index' ] #NEWLINE# if ( not responses . success ) : #NEWLINE# #INDENT# self . Log ( 'Failed to hash file: %s' , responses . status ) #NEWLINE# self . state . pending_hashes . pop ( index , None ) #NEWLINE# self . FileFetchFailed ( responses . request . request . payload . pathspec , responses . request . request . name , request_data = responses . request_data ) #NEWLINE# return #NEWLINE# #UNINDENT# self . state . files_hashed += 1 #NEWLINE# response = responses . First ( ) #NEWLINE# if response . HasField ( 'hash' ) : #NEWLINE# #INDENT# hash_obj = response . hash #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# hash_obj = rdf_crypto . Hash ( ) #NEWLINE# if ( ( len ( response . results ) < 1 ) or ( response . results [ 0 ] [ 'name' ] != 'generic' ) ) : #NEWLINE# #INDENT# self . Log ( 'Failed to hash file: %s' , self . state . indexed_pathspecs [ index ] ) #NEWLINE# self . state . pending_hashes . pop ( index , None ) #NEWLINE# return #NEWLINE# #UNINDENT# result = response . results [ 0 ] #NEWLINE# try : #NEWLINE# #INDENT# for hash_type in [ 'md5' , 'sha1' , 'sha256' ] : #NEWLINE# #INDENT# value = result . GetItem ( hash_type ) #NEWLINE# setattr ( hash_obj , hash_type , value ) #NEWLINE# #UNINDENT# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# self . Log ( 'Failed to hash file: %s' , self . state . indexed_pathspecs [ index ] ) #NEWLINE# self . state . pending_hashes . pop ( index , None ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# tracker = self . state . pending_hashes [ index ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# self . Error ( ( "Couldn't stat the file, but got the hash (%s): %s" % ( utils . SmartStr ( index ) , utils . SmartStr ( response . pathspec ) ) ) ) #NEWLINE# return #NEWLINE# #UNINDENT# tracker . hash_obj = hash_obj #NEWLINE# tracker . bytes_read = response . bytes_read #NEWLINE# self . state . files_hashed_since_check += 1 #NEWLINE# if ( self . state . files_hashed_since_check >= self . MIN_CALL_TO_FILE_STORE ) : #NEWLINE# #INDENT# self . _CheckHashesWithFileStore ( )