7 changed files with 122 additions and 54 deletions
@ -1,36 +1,72 @@ |
|||||
import ssl |
|
||||
import logging |
|
||||
|
|
||||
def sslversion(): |
_ALL_PROTOCOLS = ('t12', 't11', 't1', 'v23', 'v3', 'v2') |
||||
try: |
_SSL_PROTOCOLS = {} |
||||
return ssl.OPENSSL_VERSION |
|
||||
except: |
def ssl_potential(): |
||||
logging.info("ssl.OPENSSL_VERSION not defined") |
''' Return a list of potentially supported SSL protocols''' |
||||
return None |
|
||||
|
|
||||
def sslversioninfo(): |
|
||||
try: |
try: |
||||
return ssl.OPENSSL_VERSION_INFO |
import ssl |
||||
except: |
except ImportError: |
||||
logging.info("ssl.OPENSSL_VERSION_INFO not defined") |
return [] |
||||
return None |
return [p[9:] for p in dir(ssl) if p.startswith('PROTOCOL_')] |
||||
|
|
||||
def sslprotocols(): |
try: |
||||
protocollist = [] |
from OpenSSL import SSL |
||||
|
|
||||
|
_potential = ssl_potential() |
||||
try: |
try: |
||||
for i in dir(ssl): |
if 'TLSv1_2' in _potential: |
||||
if i.find('PROTOCOL_') == 0: |
_SSL_PROTOCOLS['t12'] = SSL.TLSv1_2_METHOD |
||||
protocollist.append(i[9:]) |
except AttributeError: |
||||
return protocollist |
pass |
||||
except: |
try: |
||||
return None |
if 'TLSv1_1' in _potential: |
||||
|
_SSL_PROTOCOLS['t11'] = SSL.TLSv1_1_METHOD |
||||
|
except AttributeError: |
||||
|
pass |
||||
|
try: |
||||
|
if 'TLSv1' in _potential: |
||||
|
_SSL_PROTOCOLS['t1'] = SSL.TLSv1_METHOD |
||||
|
except AttributeError: |
||||
|
pass |
||||
|
try: |
||||
|
if 'SSLv23' in _potential: |
||||
|
_SSL_PROTOCOLS['v23'] = SSL.SSLv23_METHOD |
||||
|
except AttributeError: |
||||
|
pass |
||||
|
try: |
||||
|
if 'SSLv3' in _potential: |
||||
|
_SSL_PROTOCOLS['v3'] = SSL.SSLv3_METHOD |
||||
|
except AttributeError: |
||||
|
pass |
||||
|
try: |
||||
|
if 'SSLv2' in _potential: |
||||
|
_SSL_PROTOCOLS['v2'] = SSL.SSLv2_METHOD |
||||
|
except AttributeError: |
||||
|
pass |
||||
|
except ImportError: |
||||
|
SSL = None |
||||
|
|
||||
if __name__ == '__main__': |
def ssl_method(method): |
||||
|
''' Translate SSL acronym to a method value ''' |
||||
|
if method in _SSL_PROTOCOLS: |
||||
|
return _SSL_PROTOCOLS[method] |
||||
|
else: |
||||
|
return _SSL_PROTOCOLS[0] |
||||
|
|
||||
logger = logging.getLogger('') |
def ssl_protocols(): |
||||
logger.setLevel(logging.INFO) |
''' Return acronyms for SSL protocols, highest quality first ''' |
||||
|
return [p for p in _ALL_PROTOCOLS if p in _SSL_PROTOCOLS] |
||||
|
|
||||
print sslversion() |
def ssl_version(): |
||||
print sslversioninfo() |
if SSL: |
||||
print sslprotocols() |
return SSL.SSLeay_version(SSL.SSLEAY_VERSION) |
||||
|
else: |
||||
|
return None |
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
|
||||
|
print 'SSL version: %s' % ssl_version() |
||||
|
print 'Potentials: %s' % ssl_potential() |
||||
|
print 'Actuals: %s' % ssl_protocols() |
||||
|
Loading…
Reference in new issue