Skip to content

Commit

Permalink
Removed pyasn1 dependencies
Browse files Browse the repository at this point in the history
Note that get_ext_by_oid() still returns the raw bytes of the extension.
I'm still undecided on whether keeping this behaviour is the right thing
to do or not.

References Yubico#19
  • Loading branch information
moreati committed Feb 26, 2016
1 parent 2612333 commit 5210329
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
maintainer='Yubico Open Source Maintainers',
maintainer_email='ossmaint@yubico.com',
url='https://github.com/Yubico/python-u2flib-server',
install_requires=['cryptography>=1.2', 'pyasn1>=0.1.7', 'pyasn1-modules'],
install_requires=[
'cryptography>=1.2',
],
test_suite='test',
tests_require=[],
extras_require={
Expand Down
23 changes: 12 additions & 11 deletions u2flib_server/attestation/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from cryptography.x509 import (
ExtensionNotFound, ObjectIdentifier
)


__all__ = [
'DeviceMatcher',
'FingerprintMatcher',
'ExtensionMatcher',
'DEFAULT_MATCHERS'
]

from cryptography.hazmat.primitives.serialization import Encoding


class DeviceMatcher(object):
selector_type = None
Expand All @@ -50,16 +53,14 @@ def matches(self, certificate, parameters=[]):
return certificate.get_fingerprint('sha1').lower() in fingerprints


# This is needed since older versions of M2Crypto don't have a way of getting
# extensions by their OID.
def get_ext_by_oid(cert, oid):
from pyasn1.codec.der import decoder
from pyasn1_modules import rfc2459
cert, _ = decoder.decode(cert.public_bytes(Encoding.DER), asn1Spec=rfc2459.Certificate())
for ext in cert['tbsCertificate']['extensions']:
if ext['extnID'].prettyPrint() == oid:
return decoder.decode(ext['extnValue'])[0].asOctets()
return None
oid = ObjectIdentifier(oid)
try:
extension = cert.extensions.get_extension_for_oid(oid)
except ExtensionNotFound:
return None

return extension.value.value


class ExtensionMatcher(DeviceMatcher):
Expand Down

0 comments on commit 5210329

Please sign in to comment.