[diffoscope] 02/02: Add support for PGP files via pgpdump. (Closes: #859034)

Chris Lamb chris at chris-lamb.co.uk
Wed Mar 29 20:10:20 CEST 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch experimental
in repository diffoscope.

commit 05b3d02fd7874a2e1e4c7ba38fa6de899dc79ee6
Author: Chris Lamb <lamby at debian.org>
Date:   Wed Mar 29 19:10:03 2017 +0100

    Add support for PGP files via pgpdump. (Closes: #859034)
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 debian/control                     |  1 +
 diffoscope/comparators/__init__.py |  1 +
 diffoscope/comparators/pgp.py      | 52 ++++++++++++++++++++++++++++++++++++
 diffoscope/external_tools.py       |  3 +++
 tests/comparators/test_pgp.py      | 54 ++++++++++++++++++++++++++++++++++++++
 tests/data/pgp_expected_diff       | 14 ++++++++++
 tests/data/test1.pgp               | 17 ++++++++++++
 tests/data/test2.pgp               | 17 ++++++++++++
 8 files changed, 159 insertions(+)

diff --git a/debian/control b/debian/control
index 0578d7e..29259b8 100644
--- a/debian/control
+++ b/debian/control
@@ -35,6 +35,7 @@ Build-Depends:
  mono-utils <!nocheck>,
  openssh-client <!nocheck>,
  pdftk <!nocheck>,
+ pgpdump <!nocheck>,
  poppler-utils <!nocheck>,
  python-argcomplete,
  python3-all,
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 222d193..56fa166 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -79,6 +79,7 @@ class ComparatorManager(object):
         ('openssh.PublicKeyFile',),
         ('gif.GifFile',),
         ('pcap.PcapFile',),
+        ('pgp.PgpFile',),
     )
 
     _singleton = {}
diff --git a/diffoscope/comparators/pgp.py b/diffoscope/comparators/pgp.py
new file mode 100644
index 0000000..77b6911
--- /dev/null
+++ b/diffoscope/comparators/pgp.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2017 Chris Lamb <lamby at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import re
+
+from diffoscope.tools import tool_required
+from diffoscope.difference import Difference
+
+from .utils.file import File
+from .utils.command import Command
+
+
+class Pgpdump(Command):
+    @tool_required('pgpdump')
+    def cmdline(self):
+        return (
+            'pgpdump',
+            '-i',  # Dump integer packets
+            '-l',  # Dump literal packets
+            '-m',  # Dump marker packets
+            '-p',  # Dump private packets
+            '-u',  # Display UTC time
+            self.path,
+        )
+
+
+class PgpFile(File):
+    RE_FILE_TYPE = re.compile(r'^PGP message\b')
+
+    def compare_details(self, other, source=None):
+        return [Difference.from_command(
+            Pgpdump,
+            self.path,
+            other.path,
+            source='pgpdump',
+       )]
diff --git a/diffoscope/external_tools.py b/diffoscope/external_tools.py
index 28f2ce7..ad4f968 100644
--- a/diffoscope/external_tools.py
+++ b/diffoscope/external_tools.py
@@ -136,6 +136,9 @@ EXTERNAL_TOOLS = {
         'debian': 'binutils-multiarch',
         'arch': 'binutils',
     },
+    'pgpdump': {
+        'debian': 'pgpdump',
+    },
     'pdftk': {
         'debian': 'pdftk',
         'FreeBSD': 'pdftk',
diff --git a/tests/comparators/test_pgp.py b/tests/comparators/test_pgp.py
new file mode 100644
index 0000000..096898b
--- /dev/null
+++ b/tests/comparators/test_pgp.py
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2017 Chris Lamb <lamby at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+
+from diffoscope.comparators.pgp import PgpFile
+
+from utils.data import load_fixture, get_data
+from utils.tools import skip_unless_tools_exist
+from utils.nonexisting import assert_non_existing
+
+pgp1 = load_fixture('test1.pgp')
+pgp2 = load_fixture('test2.pgp')
+
+
+def test_identification(pgp1):
+    assert isinstance(pgp1, PgpFile)
+
+
+def test_no_differences(pgp1):
+    difference = pgp1.compare(pgp1)
+    assert difference is None
+
+
+ at pytest.fixture
+def differences(pgp1, pgp2):
+    return pgp1.compare(pgp2).details
+
+
+ at skip_unless_tools_exist('pgpdump')
+def test_diff(differences):
+    expected_diff = get_data('pgp_expected_diff')
+    assert differences[0].unified_diff == expected_diff
+
+
+ at skip_unless_tools_exist('pgpdump')
+def test_compare_non_existing(monkeypatch, pgp1):
+    assert_non_existing(monkeypatch, pgp1, has_null_source=False)
diff --git a/tests/data/pgp_expected_diff b/tests/data/pgp_expected_diff
new file mode 100644
index 0000000..78d2bfc
--- /dev/null
+++ b/tests/data/pgp_expected_diff
@@ -0,0 +1,14 @@
+@@ -1,11 +1,11 @@
+ Old: Public-Key Encrypted Session Key Packet(tag 1)(526 bytes)
+ 	New version(3)
+ 	Key ID - 0xF956ADF011DACB92
+ 	Pub alg - ElGamal Encrypt-Only(pub 16)
+-	ElGamal g^k mod p(2047 bits) - 49 47 8d 67 f1 be 15 11 ea 42 bc c9 4b c4 56 4f 3c 36 9d c5 a7 ad d1 6e a4 3c 04 36 5e bb dc 05 bb 2a 5e ab 5d a0 8f 0f 2b 2a 29 23 be c5 3f 86 1b 55 51 7b ec ca 91 78 25 df 4c c2 6c d0 63 b0 b9 37 b9 ba 88 e3 ab af 88 b3 e4 57 ae 87 fe 49 7e 38 38 b0 4b 35 36 7b d6 68 ae 2a c8 f0 05 33 6d 07 db 04 b4 5e 6c 3c a5 d1 ca b1 6a 23 96 0f ae cf 2a 39 ce cd 4b 14 fe 34 81 9d 43 52 c9 f5 1c a1 a7 0f 50 89 54 5e 2e 2d 57 e7 87 35 38 60 53 f8 e9 29 36 db b0 57 5a  [...]
+-	ElGamal m * y^k mod p(2046 bits) - 3f 37 5a ea 82 f1 f0 43 06 2f 4d 08 a2 0f ba 11 14 ab 7a b6 9a a6 ae 14 ca 7c a8 af eb 3c 57 b4 1b 02 09 a6 f5 b4 e5 44 34 bf b5 f3 a7 09 02 ec e0 6b 43 ec 9b 28 b2 fe 2b 58 26 8a 0c 04 c1 c7 2b b0 f2 90 b9 0e f6 14 40 63 31 b1 3f 6f ec 6e 5b 5c c8 b4 2e c6 58 73 3b 09 24 38 66 2e 99 cf 74 f1 40 07 af 09 91 fa 72 54 08 cc f7 9e 65 83 d3 5d 13 6f f6 96 be 9d 02 6a 37 b1 0a 3b c0 c8 58 60 4e fb f9 6d 39 c6 30 a8 70 db eb 3a 3d 42 b1 1d 2f 13 4a 0a 15 ef [...]
++	ElGamal g^k mod p(2048 bits) - 8a ea 29 42 74 8d 02 48 47 8c 17 27 59 49 0b 02 97 25 4b d5 11 39 fa 84 1d 45 f4 5f 96 9e fa 17 2f 5e 64 c8 7c 25 d4 8a d2 47 f4 4c fc a3 53 3c 86 95 5a 34 4c 74 15 ff 45 98 20 55 17 73 b1 5e a1 fa a9 14 bd 95 5b e4 93 d9 5f 5a 28 56 18 94 38 e8 43 57 fd 50 ff c2 39 94 6e a8 5c 41 47 5f 7b d1 16 01 e9 dc 32 3b 70 c4 ef 82 cd 4e d1 e3 22 d1 d9 75 1b b9 21 48 c2 71 cf d4 33 bf 7c 51 5a 5a 10 c8 7d cb c7 19 16 74 23 47 72 d0 d8 27 d5 17 04 83 72 a0 c7 83 4d  [...]
++	ElGamal m * y^k mod p(2044 bits) - 0c 48 0c 47 66 45 5c 02 1a 3b 8a 00 25 95 24 1e 7d 38 af 29 4a 0f 69 cb c9 c6 57 1b d2 6c 8d f8 d4 ac de 0f dc 84 4d 82 1b 72 b6 22 ea 5a 53 61 82 75 d3 52 52 39 6d 49 c9 72 2a 9f b0 90 59 26 eb 85 0b 9b 65 b1 1a 30 f9 35 5e 51 0d 45 77 e0 64 da 87 07 c6 fc 9f a2 0a 18 46 80 05 28 36 91 b2 a8 58 23 db 2b b1 50 35 51 31 29 68 14 87 d7 b5 a8 49 6e ec b5 eb 3f 6a 65 de bb c0 90 6d 3f 86 85 d5 39 3b 48 43 be 85 84 12 25 4f 74 14 2d db 7b 9f 1e 1b 94 21 70 [...]
+ 		-> m = sym alg(1 byte) + checksum(2 bytes) + PKCS-1 block type 02
+ New: Symmetrically Encrypted and MDC Packet(tag 18)(61 bytes)
+ 	Ver 1
+ 	Encrypted data [sym alg is specified in pub-key encrypted session key]
+ 		(plain text + MDC SHA1(20 bytes))
diff --git a/tests/data/test1.pgp b/tests/data/test1.pgp
new file mode 100644
index 0000000..34b7fe8
--- /dev/null
+++ b/tests/data/test1.pgp
@@ -0,0 +1,17 @@
+-----BEGIN PGP MESSAGE-----
+
+hQIOA/lWrfAR2suSEAf/SUeNZ/G+FRHqQrzJS8RWTzw2ncWnrdFupDwENl673AW7
+Kl6rXaCPDysqKSO+xT+GG1VRe+zKkXgl30zCbNBjsLk3ubqI46uviLPkV66H/kl+
+ODiwSzU2e9ZorirI8AUzbQfbBLRebDyl0cqxaiOWD67PKjnOzUsU/jSBnUNSyfUc
+oacPUIlUXi4tV+eHNThgU/jpKTbbsFdag9FfJ8xZeE1VAokRwOj5/zWpG+1vLfCA
+J4/dahY4+Qe2x68YN0S9USpYiHQglIpEfq2HGtJB36NDlMiZVKRwyWjmMhIekSKj
+ZED1N0W0E60lZSMmtQIcuCJmtFN0NF99M+Eo0ze2ZAf+Pzda6oLx8EMGL00Iog+6
+ERSreraapq4Uynyor+s8V7QbAgmm9bTlRDS/tfOnCQLs4GtD7Jsosv4rWCaKDATB
+xyuw8pC5DvYUQGMxsT9v7G5bXMi0LsZYczsJJDhmLpnPdPFAB68JkfpyVAjM955l
+g9NdE2/2lr6dAmo3sQo7wMhYYE77+W05xjCocNvrOj1CsR0vE0oKFe/MEBuIDX6l
+A9ZnGClePJkjJSL26+mBPUE9KAhmk/F+yVyUo+s2/aT+CGtREH0rh6PkYfZNO6hE
+OMkxM4/P13dLFmqQsL3628qK6q+WPIQDE0AjSJFXRETwIbn1bEgDqguREPW+Wkpc
+/dI9Ad3/VTFGUZ6VolwBXzE3vl16ooM4QZW1BqY6yK9iY4neoKq7DrSH0YvvbqGc
+bVfsZ5d1wfrKO9vctydgDw==
+=p4W1
+-----END PGP MESSAGE-----
diff --git a/tests/data/test2.pgp b/tests/data/test2.pgp
new file mode 100644
index 0000000..d62f5e1
--- /dev/null
+++ b/tests/data/test2.pgp
@@ -0,0 +1,17 @@
+-----BEGIN PGP MESSAGE-----
+
+hQIOA/lWrfAR2suSEAgAiuopQnSNAkhHjBcnWUkLApclS9UROfqEHUX0X5ae+hcv
+XmTIfCXUitJH9Ez8o1M8hpVaNEx0Ff9FmCBVF3OxXqH6qRS9lVvkk9lfWihWGJQ4
+6ENX/VD/wjmUbqhcQUdfe9EWAencMjtwxO+CzU7R4yLR2XUbuSFIwnHP1DO/fFFa
+WhDIfcvHGRZ0I0dy0Ngn1RcEg3Kgx4NNA7xdxcCdMQD+LmbX5g3CH6t0Bw4lzRr/
+f6euLB14y+59sAhj+ZC+Unp4TyqmtXXfGNySv/IEmD5CM5PUj0u7XmM8ETRJYxns
+pQuaJSM7/rwpUxu9z1krjSCoRvrt7BkRtT4tpsK/9wf8DEgMR2ZFXAIaO4oAJZUk
+Hn04rylKD2nLycZXG9JsjfjUrN4P3IRNghtytiLqWlNhgnXTUlI5bUnJciqfsJBZ
+JuuFC5tlsRow+TVeUQ1Fd+Bk2ocHxvyfogoYRoAFKDaRsqhYI9srsVA1UTEpaBSH
+17WoSW7stes/amXeu8CQbT+GhdU5O0hDvoWEEiVPdBQt23ufHhuUIXDAcewcqnWv
+wB6vOi/qRIFoShMxfo+0YF+DbGP6Brcq0IGYVH2j40UtBdEMH30FP0IqAQPVwrUb
+1iwPoLkQ49PT1nAUTt/L1v5hc+plnZYk85kq/3EiUQPTZnPjH1B8KWWW1/aMP26b
+V9I9AcNefSTHXkwXArx0n3l6Gy4ui5a++vsL6uq6Krw9R+uKF4Puytdh4kZMi4Oh
+Xrh4qwzrfT0P8c63wLtrLQ==
+=Lc/2
+-----END PGP MESSAGE-----

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list