Skip to content

Instantly share code, notes, and snippets.

@miigotu
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save miigotu/f602d2182b1b7539b9af to your computer and use it in GitHub Desktop.

Select an option

Save miigotu/f602d2182b1b7539b9af to your computer and use it in GitHub Desktop.
Check for SNI capability over SSL
#From inside a virtualenv:
#!bin/python2.7
#For system wide site-packages, comment the previous and uncomment below:
##!/usr/bin/env python2.7
import sys
debug = False
info_strings = []
def InternalException(e, info='', exit=debug):
if debug:
print(e)
raise
sys.exit(1)
if len(info):
info_strings.append(info)
try:
import pyasn1
except ImportError as e:
InternalException(e, info='pyasn1')
try:
import ndg.httpsclient
except ImportError as e:
InternalException(e, info='ndg-httpsclient')
try:
import OpenSSL
from OpenSSL.version import __version__ as pyOpenSSL_Version
if debug:
print('pyOpenSSL Version: ' + pyOpenSSL_Version)
if int(pyOpenSSL_Version.replace('.', '')[:3]) > 13:
if debug:
print('OpenSSL is 0.14 or newer, checking for cryptography')
import cryptography
except ImportError as e:
InternalException(e, info='pyopenssl==0.13.1')
try:
import requests
assert int(requests.__version__.replace('.', '')[:3]) <= 260
except:
InternalException(sys.exc_info()[0], info='requests==2.6.0')
if len(info_strings):
output = 'Please run the following command, and run this script again:\n sudo pip2.7 install -U'
for mod in info_strings:
output += ' ' + mod
print(output)
sys.exit(1)
try:
from requests.packages.urllib3.contrib.pyopenssl import inject_into_urllib3
from requests.packages.urllib3 import disable_warnings
except ImportError as e:
InternalException(e, exit=True)
try:
disable_warnings()
inject_into_urllib3()
except:
InternalException(sys.exc_info()[0], exit=True)
try:
req = requests.get("https://sceneaccess.eu")
assert req.status_code == 200
except:
InternalException(sys.exc_info()[0], exit=True)
finally:
print('Success! SSL is working properly with SNI and shared hosting!')
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment