Provide specialized error message when signing or verifying ed25519

signatures and pynacl is not installed (LP: #1854475)
This commit is contained in:
Scott Kitterman
2019-12-15 01:12:02 -05:00
parent 6c5f701131
commit 5a0824108d
3 changed files with 15 additions and 3 deletions
+8 -3
View File
@@ -184,7 +184,6 @@ class NaClNotFoundError(DKIMException):
""" Nacl package not installed, needed for ed25119 signatures """
pass
class UnknownKeyTypeError(DKIMException):
""" Key type (k tag) is not known (rsa/ed25519) """
@@ -443,7 +442,10 @@ def evaluate_pk(name, s):
pass
try:
if pub[b'k'] == b'ed25519':
pk = nacl.signing.VerifyKey(pub[b'p'], encoder=nacl.encoding.Base64Encoder)
try:
pk = nacl.signing.VerifyKey(pub[b'p'], encoder=nacl.encoding.Base64Encoder)
except NameError:
raise NaClNotFoundError('pynacl module required for ed25519 signing, see README.md')
keysize = 256
ktag = b'ed25519'
except KeyError:
@@ -826,7 +828,10 @@ class DKIM(DomainSigner):
except UnparsableKeyError as e:
raise KeyFormatError(str(e))
elif self.signature_algorithm == b'ed25519-sha256':
pk = nacl.signing.SigningKey(privkey, encoder=nacl.encoding.Base64Encoder)
try:
pk = nacl.signing.SigningKey(privkey, encoder=nacl.encoding.Base64Encoder)
except NameError:
raise NaClNotFoundError('pynacl module required for ed25519 signing, see README.md')
if identity is not None and not identity.endswith(domain):
raise ParameterError("identity must end with domain")