From 4b48a82de6158b661d9ca629f5caf4f308190dc3 Mon Sep 17 00:00:00 2001 From: Scott Kitterman Date: Fri, 8 Nov 2019 23:12:31 -0500 Subject: [PATCH] - Support signature verification with SubjectPublicKeyInfo formatted keys since, although rare, they are RFC 6376 specified (LP: #1851862) --- ChangeLog | 2 ++ dkim/crypto.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd4c3fc..6c522bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,8 @@ Version 1.0.0 - Add new timeout parameter to enable DNS lookup timeouts to be adjusted - Add new DKIM.present function to allow applications to test if a DKIM signature is present without doing validation (LP: #1851141) + - Support signature verification with SubjectPublicKeyInfo formatted keys + since, although rare, they are RFC 6376 specified (LP: #1851862) - Drop usage of pymilter Milter.dns in dnsplug since it doesn't support havine a timeout passed to it diff --git a/dkim/crypto.py b/dkim/crypto.py index 144bbde..10e3e5a 100644 --- a/dkim/crypto.py +++ b/dkim/crypto.py @@ -118,8 +118,11 @@ def parse_public_key(data): # Not sure why the [1:] is necessary to skip a byte. x = asn1_parse(ASN1_Object, data) pkd = asn1_parse(ASN1_RSAPublicKey, x[0][1][1:]) - except ASN1FormatError as e: - raise UnparsableKeyError('Unparsable public key: ' + str(e)) + except ASN1FormatError as e_spki: + try: + pkd = asn1_parse(ASN1_RSAPublicKey, data) + except ASN1FormatError as e_rsa: + raise UnparsableKeyError('Unparsable public key; SubjectPublicKeyInfo: ' + str(e_spki) + '; RSAPublicKey: ' + str(e_rsa)) pk = { 'modulus': pkd[0][0], 'publicExponent': pkd[0][1],