Perform protocol tests

This commit is contained in:
nemunaire 2015-02-01 18:09:19 +01:00 committed by nemunaire
parent 42a17bf15b
commit cd475317df
1 changed files with 40 additions and 0 deletions

40
eyespot/protocols.py Normal file
View File

@ -0,0 +1,40 @@
import socket
import ssl
def get():
"""Retrive a list of supported protocols by this Python version"""
protos = []
for p in ["PROTOCOL_SSLv2",
"PROTOCOL_SSLv3",
"PROTOCOL_TLSv1",
"PROTOCOL_TLSv1_1",
"PROTOCOL_TLSv1_2"]:
if hasattr(ssl, p):
protos.append(getattr(ssl, p))
return protos
def test(host, protocol):
"""Test if a service's host against the given protocol
Arguments:
host -- tuple (hostname, port) to test
protocol -- protocol to test
"""
context = ssl.SSLContext(protocol)
context.set_ciphers("ALL")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
ssl_sock = context.wrap_socket(s)
try:
ssl_sock.connect(host)
return True
except ssl.SSLError:
pass
except ConnectionResetError:
pass
return False