[tor-commits] [bridgedb/develop] Fix libgpgme signing error due to Python2.7 buffer() interface changes.
isis at torproject.org
isis at torproject.org
Thu May 1 01:13:56 UTC 2014
commit 64ca16285a5dcaccf285343d754bb62898d9e9cd
Author: Isis Lovecruft <isis at torproject.org>
Date: Wed Apr 23 05:08:10 2014 +0000
Fix libgpgme signing error due to Python2.7 buffer() interface changes.
See https://mail.python.org/pipermail/python-dev/2010-October/104917.html
https://docs.python.org/2/c-api/buffer.html
https://github.com/SoftwareIntrospectionLab/MininGit/issues/101#issuecomment-1602514
We have to test if our Python2.7 version has the new or old builtin
buffer() interface.
(cherry picked from commit 3debed96a8e04894b0064e8075ffd8c1dd4ce10b)
From branch: hotfix/11522-gpg-signing
Backport reason: Part of the fix for #11664.
Signed-off-by: Isis Lovecruft <isis at torproject.org>
Conflicts:
lib/bridgedb/crypto.py
---
lib/bridgedb/crypto.py | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/lib/bridgedb/crypto.py b/lib/bridgedb/crypto.py
index ebab733..3b43628 100644
--- a/lib/bridgedb/crypto.py
+++ b/lib/bridgedb/crypto.py
@@ -49,6 +49,24 @@ from twisted.internet import ssl
#: The hash digest to use for HMACs.
DIGESTMOD = hashlib.sha1
+# Test to see if we have the old or new style buffer() interface. Trying
+# to use an old-style buffer on Python2.7 prior to version 2.7.5 will produce:
+#
+# TypeError: 'buffer' does not have the buffer interface
+#
+#: ``True`` if we have the new-style
+#: `buffer <https://docs.python.org/2/c-api/buffer.html>` interface.
+NEW_BUFFER_INTERFACE = False
+try:
+ io.BytesIO(buffer('test'))
+except TypeError:
+ logging.warn(
+ "This Python version is too old! "\
+ "It doesn't support new-style buffer interfaces: "\
+ "https://mail.python.org/pipermail/python-dev/2010-October/104917.html")
+else:
+ NEW_BUFFER_INTERFACE = True
+
class RSAKeyGenerationError(Exception):
"""Raised when there was an error creating an RSA keypair."""
@@ -365,8 +383,13 @@ def gpgSignMessage(gpgmeCtx, messageString, mode=None):
if not mode:
mode = gpgme.SIG_MODE_CLEAR
- msgFile = io.StringIO(unicode(messageString))
- sigFile = io.StringIO()
+ if NEW_BUFFER_INTERFACE:
+ msgFile = io.BytesIO(buffer(messageString))
+ sigFile = io.BytesIO()
+ else:
+ msgFile = io.StringIO(unicode(messageString))
+ sigFile = io.StringIO()
+
sigList = gpgmeCtx.sign(msgFile, sigFile, mode)
sigFile.seek(0)
signature = sigFile.read()
More information about the tor-commits
mailing list