commit b9c54575d18fe09834b9f99c1953b50202273957 Author: Damian Johnson atagar@torproject.org Date: Mon Feb 27 15:52:34 2017 -0800
Make prereq module's is_nacl_available private
Public methods need to be kept around for backward compatability. Hope is to eventually drop our nacl usage if functionality we need is merged into cryptography...
https://github.com/pyca/cryptography/issues/2968
Making this private lets us drop the function later at will. --- stem/descriptor/certificate.py | 4 ++-- stem/descriptor/server_descriptor.py | 9 +++------ stem/prereq.py | 5 ++--- test/unit/descriptor/certificate.py | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/stem/descriptor/certificate.py b/stem/descriptor/certificate.py index 03b3781..c298e99 100644 --- a/stem/descriptor/certificate.py +++ b/stem/descriptor/certificate.py @@ -157,7 +157,7 @@ class Ed25519KeyCertificate(Certificate): raise ValueError('Expired Ed25519KeyCertificate')
def verify_descriptor_signature(self, descriptor, signature): - if not stem.prereq.is_nacl_available(): + if not stem.prereq._is_nacl_available(): raise ValueError('Certificate validation requires the nacl module')
import nacl.signing @@ -177,7 +177,7 @@ class Ed25519KeyCertificate(Certificate): raise ValueError('Descriptor Ed25519 certificate signature invalid')
def _verify_signature(self): - if not stem.prereq.is_nacl_available(): + if not stem.prereq._is_nacl_available(): raise ValueError('Certificate validation requires the nacl module')
import nacl.signing diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py index a8a1ba2..84148d2 100644 --- a/stem/descriptor/server_descriptor.py +++ b/stem/descriptor/server_descriptor.py @@ -766,16 +766,13 @@ class RelayDescriptor(ServerDescriptor): if onion_key_crosscert_digest != self.onion_key_crosscert_digest(): raise ValueError('Decrypted onion-key-crosscert digest does not match local digest (calculated: %s, local: %s)' % (onion_key_crosscert_digest, self.onion_key_crosscert_digest()))
- if stem.prereq.is_nacl_available() and self.ed25519_certificate: - self.certificate = _parse_certificate(_bytes_for_block(self.ed25519_certificate), - self.ed25519_master_key, - validate) + if stem.prereq._is_nacl_available() and self.ed25519_certificate: + self.certificate = _parse_certificate(_bytes_for_block(self.ed25519_certificate), self.ed25519_master_key, validate)
if self.certificate.identity_key != self.ed25519_master_key: raise ValueError('master-key-ed25519 does not match ed25519 certificate identity key')
- self.certificate.verify_descriptor_signature(raw_contents, - self.ed25519_signature) + self.certificate.verify_descriptor_signature(raw_contents, self.ed25519_signature)
@lru_cache() def digest(self): diff --git a/stem/prereq.py b/stem/prereq.py index 5d6e80a..9f265e6 100644 --- a/stem/prereq.py +++ b/stem/prereq.py @@ -15,7 +15,6 @@ Checks for stem dependencies. We require python 2.6 or greater (including the check_requirements - checks for minimum requirements for running stem is_python_3 - checks if python 3.0 or later is available is_crypto_available - checks if the cryptography module is available - is_nacl_available - checks if the pynacl module is available """
import inspect @@ -151,7 +150,7 @@ def is_mock_available():
@lru_cache() -def is_nacl_available(): +def _is_nacl_available(): """ Checks if the pynacl functions we use are available. This is used for verifying ed25519 certificates in relay descriptor signatures. @@ -166,5 +165,5 @@ def is_nacl_available(): from nacl import signing return True except ImportError: - log.log_once('stem.prereq.is_nacl_available', log.INFO, NACL_UNAVAILABLE) + log.log_once('stem.prereq._is_nacl_available', log.INFO, NACL_UNAVAILABLE) return False diff --git a/test/unit/descriptor/certificate.py b/test/unit/descriptor/certificate.py index 24a5a7e..160b320 100644 --- a/test/unit/descriptor/certificate.py +++ b/test/unit/descriptor/certificate.py @@ -87,7 +87,7 @@ class TestCertificate(unittest.TestCase): )
def test_certificate_with_invalid_signature(self): - if not stem.prereq.is_nacl_available(): + if not stem.prereq._is_nacl_available(): test.runner.skip(self, '(require nacl module)') return