def testMultiGetFileSetsFileHashAttributeWhenMultipleChunksDownloaded(self): client_mock = action_mocks.MultiGetFileClientMock() pathspec = rdf_paths.PathSpec( pathtype=rdf_paths.PathSpec.PathType.OS, path=os.path.join(self.base_path, "test_img.dd")) args = transfer.MultiGetFileArgs(pathspecs=[pathspec]) flow_test_lib.TestFlowHelper( transfer.MultiGetFile.__name__, client_mock, token=self.token, client_id=self.client_id, args=args) # Fix path for Windows testing. pathspec.path = pathspec.path.replace("\\", "/") # Test the AFF4 file that was created. urn = pathspec.AFF4Path(self.client_id) fd_hash = data_store_utils.GetUrnHashEntry(urn) self.assertTrue(fd_hash) h = hashlib.sha256() with open(os.path.join(self.base_path, "test_img.dd"), "rb") as model_fd: h.update(model_fd.read()) self.assertEqual(fd_hash.sha256, h.digest())
def _SetupNSRLFiles(self): urn1 = self.AddFile("/Ext2IFS_1_10b.exe") urn2 = self.AddFile("/idea.dll") self.hashes1 = data_store_utils.GetUrnHashEntry(urn1) self.hashes2 = data_store_utils.GetUrnHashEntry(urn2) # Pretend this file is part of the NSRL. nsrl_fs = aff4.FACTORY.Open("aff4:/files/nsrl", token=self.token) nsrl_fs.AddHash("e1f7e62b3909263f3a2518bbae6a9ee36d5b502b", "bb0a15eefe63fd41f8dc9dee01c5cf9a", None, "idea.dll", 100, None, None, "M") self.sha1_hash = filestore.FileStoreHash( fingerprint_type="generic", hash_type="sha1", hash_value="e1f7e62b3909263f3a2518bbae6a9ee36d5b502b") return nsrl_fs
def testMultiGetFileSetsFileHashAttributeWhenMultipleChunksDownloaded( self): client_mock = action_mocks.MultiGetFileClientMock() pathspec = rdf_paths.PathSpec(pathtype=rdf_paths.PathSpec.PathType.OS, path=os.path.join( self.base_path, "test_img.dd")) args = transfer.MultiGetFileArgs(pathspecs=[pathspec]) flow_test_lib.TestFlowHelper(transfer.MultiGetFile.__name__, client_mock, token=self.token, client_id=self.client_id, args=args) h = hashlib.sha256() with open(os.path.join(self.base_path, "test_img.dd"), "rb") as model_fd: h.update(model_fd.read()) if not data_store.RelationalDBReadEnabled(): # Fix path for Windows testing. pathspec.path = pathspec.path.replace("\\", "/") # Test the AFF4 file that was created. urn = pathspec.AFF4Path(self.client_id) fd_hash = data_store_utils.GetUrnHashEntry(urn) self.assertTrue(fd_hash) self.assertEqual(fd_hash.sha256, h.digest()) if data_store.RelationalDBReadEnabled(): cp = db.ClientPath.FromPathSpec(self.client_id.Basename(), pathspec) fd_rel_db = file_store.OpenFile(cp) self.assertEqual(fd_rel_db.hash_id.AsBytes(), h.digest()) # Check that SHA256 hash of the file matches the contents # hash and that MD5 and SHA1 are set. history = data_store.REL_DB.ReadPathInfoHistory( cp.client_id, cp.path_type, cp.components) self.assertEqual(history[-1].hash_entry.sha256, fd_rel_db.hash_id.AsBytes()) self.assertIsNotNone(history[-1].hash_entry.sha1) self.assertIsNotNone(history[-1].hash_entry.md5)