[tor-commits] [stem/master] Check for signing support in cryptography module
atagar at torproject.org
atagar at torproject.org
Mon Sep 4 20:09:24 UTC 2017
commit 33d41646b6de6a5a0327a95c8ef2c4c6b47e0b52
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Sep 4 12:11:02 2017 -0700
Check for signing support in cryptography module
Python 3.5.2 seems to have cryptography 1.2.3. This is highly out of date and
causes unit tests to fail with...
======================================================================
ERROR: test_descriptor_signing
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/atagar/Desktop/stem/test/require.py", line 58, in wrapped
return func(self, *args, **kwargs)
File "/home/atagar/Desktop/stem/test/unit/descriptor/extrainfo_descriptor.py", line 139, in test_descriptor_signing
RelayExtraInfoDescriptor.create(sign = True)
File "/home/atagar/Desktop/stem/stem/descriptor/extrainfo_descriptor.py", line 986, in create
return cls(cls.content(attr, exclude, sign, signing_key), validate = validate)
File "/home/atagar/Desktop/stem/stem/descriptor/extrainfo_descriptor.py", line 978, in content
return _append_router_signature(content, signing_key.private)
File "/home/atagar/Desktop/stem/stem/descriptor/__init__.py", line 1040, in _append_router_signature
signature = base64.b64encode(private_key.sign(content, padding.PKCS1v15(), hashes.SHA1()))
AttributeError: '_RSAPrivateKey' object has no attribute 'sign'
----------------------------------------------------------------------
Current version of cryptography is 2.0.3, and the sign method was added in
1.4...
https://cryptography.io/en/latest/hazmat/primitives/asymmetric/rsa/#cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey.sign
---
stem/prereq.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/stem/prereq.py b/stem/prereq.py
index e3d0051d..f09870cf 100644
--- a/stem/prereq.py
+++ b/stem/prereq.py
@@ -98,8 +98,13 @@ def is_crypto_available():
try:
from cryptography.utils import int_from_bytes, int_to_bytes
from cryptography.hazmat.backends import default_backend
- from cryptography.hazmat.primitives.serialization import load_der_public_key
+ from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
+ from cryptography.hazmat.primitives.serialization import load_der_public_key
+
+ if not hasattr(rsa.RSAPrivateKey, 'sign'):
+ raise ImportError()
+
return True
except ImportError:
log.log_once('stem.prereq.is_crypto_available', log.INFO, CRYPTO_UNAVAILABLE)
More information about the tor-commits
mailing list