Verified Commit 47084a1b authored by Sebastian Endres's avatar Sebastian Endres
Browse files

Add --clean to inject_secrets

parent 3cdf0b44
...@@ -21,6 +21,11 @@ def parse_args(): ...@@ -21,6 +21,11 @@ def parse_args():
type=Path, type=Path,
help="quic-interop-runner log dirs or result.json files", help="quic-interop-runner log dirs or result.json files",
) )
parser.add_argument(
"--clean",
action="store_true",
help="Delete plain pcap files after injecting the secrets into pcapng file.",
)
parser.add_argument( parser.add_argument(
"--debug", "--debug",
action="store_true", action="store_true",
...@@ -31,7 +36,7 @@ def parse_args(): ...@@ -31,7 +36,7 @@ def parse_args():
class SecretsInjector: class SecretsInjector:
def __init__(self, specs: list[Union[Path, Result]], debug=False): def __init__(self, specs: list[Union[Path, Result]], clean=False, debug=False):
self.specs = specs self.specs = specs
self.num_injected = 0 self.num_injected = 0
self.num_already_injected = 0 self.num_already_injected = 0
...@@ -39,6 +44,7 @@ class SecretsInjector: ...@@ -39,6 +44,7 @@ class SecretsInjector:
self.num_failed = 0 self.num_failed = 0
self._max_log_str_len = 0 self._max_log_str_len = 0
self.debug = debug self.debug = debug
self.clean = clean
self._spinner: Optional[YaspinWrapper] = None self._spinner: Optional[YaspinWrapper] = None
def find_keylog_file(self, test_case_path: Path) -> Optional[Path]: def find_keylog_file(self, test_case_path: Path) -> Optional[Path]:
...@@ -62,20 +68,20 @@ class SecretsInjector: ...@@ -62,20 +68,20 @@ class SecretsInjector:
return results[0] return results[0]
def inject(self, pcap_path: Path, pcap_ng_path: Path, keylog_file: Path): def inject(self, pcap_path: Path, pcap_ng_path: Path, keylog_file: Path):
if not pcap_path.is_file(): if pcap_ng_path.is_file() and pcap_ng_path.stat().st_size > 0:
self.log( self.log(
f"⨯ Raw pcap file {pcap_path} not found. Skipping.", f" {pcap_ng_path} already exists. Skipping.",
color="red", color="grey",
) )
self.num_already_injected += 1
return return
if pcap_ng_path.is_file() and pcap_ng_path.stat().st_size > 0: if not pcap_path.is_file():
self.log( self.log(
f" {pcap_ng_path} already exists. Skipping.", f"⨯ Raw pcap file {pcap_path} not found. Skipping.",
color="grey", color="red",
) )
self.num_already_injected += 1
return return
...@@ -94,6 +100,9 @@ class SecretsInjector: ...@@ -94,6 +100,9 @@ class SecretsInjector:
] ]
) )
self.num_injected += 1 self.num_injected += 1
if self.clean:
pcap_path.unlink()
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
self.log( self.log(
f"⨯ Failed to inject secrets {keylog_file} into {pcap_path}.", f"⨯ Failed to inject secrets {keylog_file} into {pcap_path}.",
...@@ -128,20 +137,27 @@ class SecretsInjector: ...@@ -128,20 +137,27 @@ class SecretsInjector:
pcap_ng_path=pcap_ng_path, pcap_ng_path=pcap_ng_path,
keylog_file=keylog_file, keylog_file=keylog_file,
) )
self.log() self.log()
def inject_in_result(self, result: Result): def inject_in_result(self, result: Result):
"""Inject secrets in result log dir.""" """Inject secrets in result log dir."""
for test_result in result.all_test_results: for test_result in result.all_test_results:
if test_result.result == "unsupported":
continue
self.inject_in_test_repetition_run_dir(test_result.log_dir_for_test) self.inject_in_test_repetition_run_dir(test_result.log_dir_for_test)
for meas_result in result.all_measurement_results: for meas_result in result.all_measurement_results:
if meas_result.result == "unsupported":
continue
for repetition_log_dir in meas_result.repetition_log_dirs: for repetition_log_dir in meas_result.repetition_log_dirs:
self.inject_in_test_repetition_run_dir(repetition_log_dir) self.inject_in_test_repetition_run_dir(repetition_log_dir)
def inject_in_log_dir(self, log_dir: Path): def inject_in_log_dir(self, log_dir: Path):
"""Inject Secrets""" """Inject secrets."""
for combination in log_dir.iterdir(): for combination in log_dir.iterdir():
if not combination.is_dir(): if not combination.is_dir():
...@@ -176,10 +192,10 @@ class SecretsInjector: ...@@ -176,10 +192,10 @@ class SecretsInjector:
log_str = ", ".join( log_str = ", ".join(
( (
colored(f"injected: {self.num_injected}, ", color="green"), colored(f"injected: {self.num_injected}", color="green"),
colored(f"failed: {self.num_failed}, ", color="red"), colored(f"failed: {self.num_failed}", color="red"),
colored( colored(
f"already injected: {self.num_already_injected}, ", color="yellow" f"already injected: {self.num_already_injected}", color="yellow"
), ),
colored( colored(
f"no keylog file found: {self.num_no_secret_found}", color="red" f"no keylog file found: {self.num_no_secret_found}", color="red"
...@@ -216,6 +232,7 @@ def main(): ...@@ -216,6 +232,7 @@ def main():
args = parse_args() args = parse_args()
cli = SecretsInjector( cli = SecretsInjector(
specs=[Result(spec) if spec.is_file() else spec for spec in args.spec], specs=[Result(spec) if spec.is_file() else spec for spec in args.spec],
clean=args.clean,
debug=args.debug, debug=args.debug,
) )
cli.run() cli.run()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment