aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-17 22:43:14 +0100
committerAnders Broman <a.broman58@gmail.com>2018-11-20 05:13:37 +0000
commite2e0fd1dbdb07f2a1bd8822ab86bcd7144025f97 (patch)
tree5e27b55640158f83f9726c95d1976321d0bb7bb9 /test
parent52a667143929ace46929bfb6ad15b6a856cdbe77 (diff)
editcap: add --inject-secrets option
Add a new option to insert decryption secrets into a pcapng file. Change-Id: I0e024585cac9a8a328e88d32f9eb03d37d350e2a Ping-Bug: 15252 Reviewed-on: https://code.wireshark.org/review/30693 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixtures_ws.py5
-rw-r--r--test/suite_fileformats.py58
2 files changed, 63 insertions, 0 deletions
diff --git a/test/fixtures_ws.py b/test/fixtures_ws.py
index 053d89e0ce..df9b9149ac 100644
--- a/test/fixtures_ws.py
+++ b/test/fixtures_ws.py
@@ -112,6 +112,11 @@ def cmd_text2pcap(program):
@fixtures.fixture(scope='session')
+def cmd_editcap(program):
+ return program('editcap')
+
+
+@fixtures.fixture(scope='session')
def cmd_wireshark(program):
return program('wireshark')
diff --git a/test/suite_fileformats.py b/test/suite_fileformats.py
index 66c9880929..8bf341c1cd 100644
--- a/test/suite_fileformats.py
+++ b/test/suite_fileformats.py
@@ -157,6 +157,64 @@ class case_fileformat_pcapng_dsb(subprocesstest.SubprocessTestCase):
(0x544c534b, len(dsb2_contents), dsb2_contents),
))
+ def test_pcapng_dsb_2(self, cmd_editcap, dirs, capture_file, check_pcapng_dsb_fields):
+ '''Insert a single DSB into a pcapng file.'''
+ key_file = os.path.join(dirs.key_dir, 'dhe1_keylog.dat')
+ outfile = self.filename_from_id('dhe1-dsb.pcapng')
+ self.runProcess((cmd_editcap,
+ '--inject-secrets', 'tls,%s' % key_file,
+ capture_file('dhe1.pcapng.gz'), outfile
+ ))
+ with open(key_file, 'rb') as f:
+ keylog_contents = f.read()
+ check_pcapng_dsb_fields(outfile, (
+ (0x544c534b, len(keylog_contents), keylog_contents),
+ ))
+
+ def test_pcapng_dsb_3(self, cmd_editcap, dirs, capture_file, check_pcapng_dsb_fields):
+ '''Insert two DSBs into a pcapng file.'''
+ key_file1 = os.path.join(dirs.key_dir, 'dhe1_keylog.dat')
+ key_file2 = os.path.join(dirs.key_dir, 'http2-data-reassembly.keys')
+ outfile = self.filename_from_id('dhe1-dsb.pcapng')
+ self.runProcess((cmd_editcap,
+ '--inject-secrets', 'tls,%s' % key_file1,
+ '--inject-secrets', 'tls,%s' % key_file2,
+ capture_file('dhe1.pcapng.gz'), outfile
+ ))
+ with open(key_file1, 'rb') as f:
+ keylog1_contents = f.read()
+ with open(key_file2, 'rb') as f:
+ keylog2_contents = f.read()
+ check_pcapng_dsb_fields(outfile, (
+ (0x544c534b, len(keylog1_contents), keylog1_contents),
+ (0x544c534b, len(keylog2_contents), keylog2_contents),
+ ))
+
+ def test_pcapng_dsb_4(self, cmd_editcap, dirs, capture_file, check_pcapng_dsb_fields):
+ '''Insert a single DSB into a pcapng file with existing DSBs.'''
+ dsb_keys1 = os.path.join(dirs.key_dir, 'tls12-dsb-1.keys')
+ dsb_keys2 = os.path.join(dirs.key_dir, 'tls12-dsb-2.keys')
+ key_file = os.path.join(dirs.key_dir, 'dhe1_keylog.dat')
+ outfile = self.filename_from_id('tls12-dsb-extra.pcapng')
+ self.runProcess((cmd_editcap,
+ '--inject-secrets', 'tls,%s' % key_file,
+ capture_file('tls12-dsb.pcapng'), outfile
+ ))
+ with open(dsb_keys1, 'r') as f:
+ dsb1_contents = f.read().encode('utf8')
+ with open(dsb_keys2, 'r') as f:
+ dsb2_contents = f.read().encode('utf8')
+ with open(key_file, 'rb') as f:
+ keylog_contents = f.read()
+ # New DSBs are inserted before the first record. Due to the current
+ # implementation, this is inserted before other (existing) DSBs. This
+ # might change in the future if it is deemed more logical.
+ check_pcapng_dsb_fields(outfile, (
+ (0x544c534b, len(keylog_contents), keylog_contents),
+ (0x544c534b, len(dsb1_contents), dsb1_contents),
+ (0x544c534b, len(dsb2_contents), dsb2_contents),
+ ))
+
@fixtures.mark_usefixtures('test_env')
@fixtures.uses_fixtures