diff options
author | Geoffrey Thomas <geofft@ldpreload.com> | 2015-04-13 17:37:13 -0400 |
---|---|---|
committer | Geoffrey Thomas <geofft@ldpreload.com> | 2015-04-13 20:28:25 -0400 |
commit | c2d903bb0a14898e94446dc49517ef9f354463a5 (patch) | |
tree | 32d2e37f8b3d75c56f8addac87955fe0b256df33 /src | |
parent | 249bbd0064d42d78ff51e9a0203db4492453418f (diff) | |
download | cryptography-c2d903bb0a14898e94446dc49517ef9f354463a5.tar.gz cryptography-c2d903bb0a14898e94446dc49517ef9f354463a5.tar.bz2 cryptography-c2d903bb0a14898e94446dc49517ef9f354463a5.zip |
Work around pyasn1's willingness to return endOfOctets in DER parsing
See #1838 for discussion.
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/primitives/asymmetric/utils.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/primitives/asymmetric/utils.py b/src/cryptography/hazmat/primitives/asymmetric/utils.py index 71f4ff8e..f04eb66e 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/utils.py +++ b/src/cryptography/hazmat/primitives/asymmetric/utils.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, division, print_function +from pyasn1.codec.ber import eoo from pyasn1.codec.der import decoder, encoder from pyasn1.error import PyAsn1Error from pyasn1.type import namedtype, univ @@ -28,6 +29,12 @@ def decode_rfc6979_signature(signature): raise ValueError( "The signature contains bytes after the end of the ASN.1 sequence." ) + # pyasn1 can erroneously return this from top-level DER decoding. + # It's intended as a sentinel in recursive BER decoding, so it's + # returned even though an asn1Spec is provided. + if data == eoo.endOfOctets: + raise ValueError("Invalid signature data. Unable to decode ASN.1") + r = int(data.getComponentByName('r')) s = int(data.getComponentByName('s')) return (r, s) |