M
M
Max2017-06-15 14:39:42
Python
Max, 2017-06-15 14:39:42

How to check SSL certificate level using Python?

Some sites have Extended Validation certificates. Such certificates have a so-called "green bar" - that is, when entering a site where such a certificate is installed, a green bar will appear in the address bar of the visitor's browser, which will indicate the name of the organization that received the certificate.
89d6dbbb56747fb0468a05fb9b81eb11.png
How to check if a domain has such a certificate? Preferably by sending requests via Python.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pcdesign, 2017-06-15
@pcdesign

https://stackoverflow.com/questions/30862099/how-c...

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import ssl, socket


hostname = sys.argv[1:][0]

ctx = ssl.create_default_context()
s = ctx.wrap_socket(socket.socket(), server_hostname=hostname)
s.connect((hostname, 443))
cert = s.getpeercert()

subject = dict(x[0] for x in cert['subject'])
issuer = dict(x[0] for x in cert['issuer'])

print(subject)
print(issuer)

# python check_sert.py thawte.com 
{'organizationalUnitName': u'Infrastructure Operations', 'organizationName': u'Thawte, Inc.', 'businessCategory': u'Private Organization', 'serialNumber': u'3898261', 'commonName': u'www.thawte.com', 'stateOrProvinceName': u'California', 'countryName': u'US', '1.3.6.1.4.1.311.60.2.1.2': u'Delaware', '1.3.6.1.4.1.311.60.2.1.3': u'US', 'localityName': u'Mountain View'}
{'countryName': u'US', 'commonName': u'thawte EV SSL CA - G3', 'organizationName': u'thawte, Inc.'}

# python check_sert.py toster.ru
{'organizationalUnitName': u'PositiveSSL', 'commonName': u'toster.ru'}
{'countryName': u'GB', 'commonName': u'COMODO RSA Domain Validation Secure Server CA', 'organizationName': u'COMODO CA Limited', 'localityName': u'Salford', 'stateOrProvinceName': u'Greater Manchester'}

C
chupasaurus, 2017-06-15
@chupasaurus

Wiki

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question