Skip to content

Commit

Permalink
Added workaround for DSA public keys
Browse files Browse the repository at this point in the history
  • Loading branch information
moses-palmer committed Sep 14, 2016
1 parent 013a43a commit dd4ce6e
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/truepy/_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ def issue(self, certificate, key, digest='SHA1', **license_data):

return License(encoded, signature, 'with'.join((digest, encryption)))

def _verifier(self, certificate):
"""Returns a verifier for a certificate.
This function will attempt different factory methods, since the
argument lists differ.
:param cryptography.x509.Certificate certificate: The signer
certificate.
:return: a verifier
"""
public_key = certificate.public_key()
try:
return public_key.verifier(
base64.b64decode(self.signature),
padding.PKCS1v15(),
getattr(hashes, self._signature_digest)())
except TypeError:
return public_key.verifier(
base64.b64decode(self.signature),
getattr(hashes, self._signature_digest)())

def verify(self, certificate):
"""Verifies the signature of this certificate against a certificate.
Expand All @@ -185,10 +207,7 @@ def verify(self, certificate):
"""
certificate = self._certificate(certificate)

verifier = certificate.public_key().verifier(
base64.b64decode(self.signature),
padding.PKCS1v15(),
getattr(hashes, self._signature_digest)())
verifier = self._verifier(certificate)
verifier.update(self.encoded.encode('ascii'))
try:
verifier.verify()
Expand Down

0 comments on commit dd4ce6e

Please sign in to comment.