From 77b5e6762fbc13f31940680ea987019356a077ff Mon Sep 17 00:00:00 2001 From: Seth Grover Date: Thu, 31 Oct 2024 14:24:23 -0600 Subject: [PATCH] work in progress --- src/maltest/maltest.py | 18 ++++++++++++++---- src/maltest/utils.py | 10 ++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/maltest/maltest.py b/src/maltest/maltest.py index efedcab..270bc96 100755 --- a/src/maltest/maltest.py +++ b/src/maltest/maltest.py @@ -12,7 +12,13 @@ import signal import sys -from maltest.utils import MalcolmVM, MalcolmTestCollection, ShuttingDown, set_malcolm_vm_info +from maltest.utils import ( + MalcolmVM, + MalcolmTestCollection, + ShuttingDown, + set_malcolm_vm_info, + shakey_file_hash, +) ################################################################################################### script_name = os.path.basename(__file__) @@ -321,9 +327,13 @@ def main(): for pcapFile in pcaps: # TODO: would it be better to use SFTP for this? or even the upload interface? # TODO: Assuming the Malcolm directory like this might not be very robust - malcolmVm.CopyFile( - pcapFile, f'/home/{args.vmImageUsername}/Malcolm/pcap/upload/', tolerateFailure=True - ) + pcapFileParts = os.path.splitext(pcapFile) + if pcapHash := shakey_file_hash(pcapFile): + malcolmVm.CopyFile( + pcapFile, + f'/home/{args.vmImageUsername}/Malcolm/pcap/upload/{pcapHash}{pcapFileParts[1]}', + tolerateFailure=True, + ) # TODO: wait until all data has been processed (no new documents are being indexed for X amount of time) diff --git a/src/maltest/utils.py b/src/maltest/utils.py index 0a69433..3a0cb96 100644 --- a/src/maltest/utils.py +++ b/src/maltest/utils.py @@ -2,6 +2,7 @@ import ast import glob +import hashlib import json import mmguero import os @@ -31,6 +32,15 @@ ) +################################################################################################### +def shakey_file_hash(filename, digest_len=8): + try: + with open(filename, 'rb', buffering=0) as f: + return hashlib.file_digest(f, 'shake_256').hexdigest(digest_len) + except: + return None + + ################################################################################################### def set_malcolm_vm_info(info): global MalcolmVmInfo