Skip to content

Commit

Permalink
Changed a few bits following dquinn's recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-kisteleki committed Apr 4, 2017
1 parent f6fc10c commit e5ea902
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ to use sagan to say, parse traceroute or DNS results, then you can do the follow

$ SAGAN_WITHOUT_SSL=1 pip install ripe.atlas.sagan

More information can also be found `here`_.

If you *do* care about SSL and have to use a Mac, then `this issue`_ will likely
be of assistance. Essentially, you will need to uninstall Xcode (if it's
installed already), then attempt to use ``gcc``. This will trigger the OS to
Expand All @@ -87,4 +89,5 @@ when that's finished, install Sagan with this command:

$ CFLAGS="-I/usr/include" pip install ripe.atlas.sagan

.. _here: https://cryptography.io/en/latest/installation/
.. _this issue: https://github.com/RIPE-NCC/ripe.atlas.sagan/issues/52
24 changes: 15 additions & 9 deletions ripe/atlas/sagan/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
from .base import Result, ResultParseError, ParsingDict


OID_COUNTRY = "2.5.4.6"
OID_ORG = "2.5.4.10"
OID_COMMON_NAME = "2.5.4.3"
EXT_SAN = "subjectAltName"


class Certificate(ParsingDict):

def __init__(self, data, **kwargs):
Expand All @@ -57,7 +63,7 @@ def __init__(self, data, **kwargs):

self.extensions = {}

cert = x509.load_pem_x509_certificate(data.encode('ascii'), openssl.backend)
cert = x509.load_pem_x509_certificate(data.encode("ascii"), openssl.backend)

if cert:
self.checksum_md5 = self._colonify(cert.fingerprint(hashes.MD5()))
Expand All @@ -81,27 +87,27 @@ def __init__(self, data, **kwargs):

def _add_extensions(self, cert):
for ext in cert.extensions:
if ext.oid._name == 'subjectAltName':
self.extensions['subjectAltName'] = []
if ext.oid._name == EXT_SAN:
self.extensions[EXT_SAN] = []
for san in ext.value:
self.extensions['subjectAltName'].append(san.value)
self.extensions[EXT_SAN].append(san.value)

@staticmethod
def _colonify(bytes):
hex = codecs.getencoder('hex_codec')(bytes)[0].decode('ascii').upper()
return ':'.join(a+b for a,b in zip(hex[::2], hex[1::2]))
hex = codecs.getencoder("hex_codec")(bytes)[0].decode("ascii").upper()
return ":".join(a+b for a,b in zip(hex[::2], hex[1::2]))

@staticmethod
def _parse_x509_name(name):
cn = None
o = None
c = None
for attr in name:
if attr.oid.dotted_string == '2.5.4.6': # country
if attr.oid.dotted_string == OID_COUNTRY:
c = attr.value
elif attr.oid.dotted_string == '2.5.4.10': # organisation
elif attr.oid.dotted_string == OID_ORG:
o = attr.value
elif attr.oid.dotted_string == '2.5.4.3': # common name
elif attr.oid.dotted_string == OID_COMMON_NAME:
cn = attr.value
return cn, o, c

Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

name = "ripe.atlas.sagan"
install_requires = [
"IPy",
"python-dateutil",
"pytz",
]
Expand Down

0 comments on commit e5ea902

Please sign in to comment.