This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cryptography import x509 | |
from cryptography.hazmat.backends import default_backend | |
from cryptography.hazmat.primitives import hashes, serialization | |
from cryptography.hazmat.primitives.asymmetric import rsa | |
from cryptography.x509.oid import NameOID | |
import datetime | |
import uuid | |
one_day = datetime.timedelta(1, 0, 0) | |
private_key = rsa.generate_private_key( | |
public_exponent=65537, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.6's urllib2 does not allow you to select the TLS dialect, | |
# and by default uses a SSLv23 compatibility negotiation implementation. | |
# Besides being vulnerable to POODLE, the OSX implementation doesn't | |
# work correctly, failing to connect to servers that respond only to | |
# TLS1.0+. These classes help set up TLS support for urllib2. | |
class TLS1Connection(httplib.HTTPSConnection): | |
"""Like HTTPSConnection but more specific""" | |
def __init__(self, host, **kwargs): | |
httplib.HTTPSConnection.__init__(self, host, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""SSL client/server certificates verification for `urllib2`. | |
It works on Python 2.6, 2.7, 3.1, 3.2 | |
It also works on Python 2.4, 2.5 if `ssl` is installed (``pip install ssl``) | |
Example:: | |
>>> import urllib2, urllib2_ssl | |
>>> opener = urllib2.build_opener(urllib2_ssl.HTTPSHandler( | |
... key_file='clientkey.pem', |