Control: tags -1 +pending

I have made a patch that keeps Monkeysign from just crashing on those
keys. The right way to do this, of course, is to simply refuse signing
that keyid, but that's a harder fix that will have to wait.

The attached patch was applied to the 2.x branch, and should fix the bug
here.

A.

-- 
The value of a college education is not the learning of many facts but
the training of the mind to think.
                       - Albert Einstein

>From 76186ba6f1ebf3c58f699aecd29cbb648205d4e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= <anar...@debian.org>
Date: Thu, 1 Sep 2016 14:02:58 -0400
Subject: [PATCH] handle improperly encoded UIDs (Closes: #736629)

---
 monkeysign/gpg.py |  2 +-
 tests/test_gpg.py | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/monkeysign/gpg.py b/monkeysign/gpg.py
index 56d21a1..2c10fe9 100644
--- a/monkeysign/gpg.py
+++ b/monkeysign/gpg.py
@@ -735,7 +735,7 @@ def __str__(self):
         ret += u'    Fingerprint = ' + self.format_fpr() + "\n"
         i = 1
         for uid in self.uidslist:
-            ret += u"uid %d      [%s] %s\n" % (i, uid.get_trust(), uid.uid.decode('utf-8'))
+            ret += u"uid %d      [%s] %s\n" % (i, uid.get_trust(), uid.uid.decode('utf-8', 'replace'))
             i += 1
         for subkey in self.subkeys.values():
             ret += u"sub   " + subkey.length + u"R/" + subkey.keyid(8) + u" " + subkey.creation
diff --git a/tests/test_gpg.py b/tests/test_gpg.py
index 39fef0c..2aa76a0 100755
--- a/tests/test_gpg.py
+++ b/tests/test_gpg.py
@@ -342,6 +342,20 @@ def test_wrongly_place_sigs(self):
         self.gpg.context.call_command(['list-sigs', '6D866396'])
         self.assertRegexpMatches(self.gpg.context.stdout, 'sig:::1:86E4E70A96F47C6A:[^:]*::::Second Test Key <unitte...@monkeysphere.info>:10x:')
 
+    def test_broken_encoding(self):
+        """test some key that has a non-standard encoding
+
+        RFC4880 specifies that UIDs should be UTF-8, but someone this
+        one isn't.
+
+        see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=736629
+        """
+        self.assertTrue(self.gpg.import_data(open(os.path.dirname(__file__) +
+                                                  '/ECAA37C45C7E48CE.asc').read()))
+        key = self.gpg.get_keys('095D9EC8C995AB203DC260FEECAA37C45C7E48CE')
+        foo = key['095D9EC8C995AB203DC260FEECAA37C45C7E48CE'].__str__().encode('utf-8')
+
+
 class TestOpenPGPkey(unittest.TestCase):
     def setUp(self):
         self.key = OpenPGPkey("""tru::1:1343350431:0:3:1:5
-- 
2.1.4

Reply via email to