Changeset 120


Ignore:
Timestamp:
03/01/17 19:03:44 (7 years ago)
Author:
tim
Message:

hooks and extensions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bletchley/ssltls.py

    r115 r120  
    5555
    5656
    57 def startSSLTLS(sock, mode='client', handshake=SSL.TLSv1_METHOD, key=None, certChain=[], cipher_list=None):
     57def startSSLTLS(sock, mode='client', protocol=SSL.TLSv1_METHOD, key=None, certChain=[], cipher_list=None):
    5858    '''
    5959    cipher_list example:  b'DH-DSS-AES256-GCM-SHA384:DHE-DSS-AES256-GCM-SHA384:DH-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA256:DH-RSA-AES256-SHA256:DH-DSS-AES256-SHA256:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DH-RSA-AES256-SHA:DH-DSS-AES256-SHA:DHE-RSA-CAMELLIA256-SHA:DHE-DSS-CAMELLIA256-SHA:DH-RSA-CAMELLIA256-SHA:DH-DSS-CAMELLIA256-SHA:ADH-AES256-GCM-SHA384:ADH-AES256-SHA256:ADH-AES256-SHA:ADH-CAMELLIA256-SHA:DH-DSS-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:DH-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-DSS-AES128-SHA256:DH-RSA-AES128-SHA256:DH-DSS-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:DH-RSA-AES128-SHA:DH-DSS-AES128-SHA:DHE-RSA-SEED-SHA:DHE-DSS-SEED-SHA:DH-RSA-SEED-SHA:DH-DSS-SEED-SHA:DHE-RSA-CAMELLIA128-SHA:DHE-DSS-CAMELLIA128-SHA:DH-RSA-CAMELLIA128-SHA:DH-DSS-CAMELLIA128-SHA:ADH-AES128-GCM-SHA256:ADH-AES128-SHA256:ADH-AES128-SHA:ADH-SEED-SHA:ADH-CAMELLIA128-SHA:ADH-RC4-MD5:EDH-RSA-DES-CBC3-SHA:EDH-DSS-DES-CBC3-SHA:DH-RSA-DES-CBC3-SHA:DH-DSS-DES-CBC3-SHA:ADH-DES-CBC3-SHA'
    6060    '''
    6161   
    62     context = createContext(handshake, key=key, certChain=certChain)
     62    context = createContext(protocol, key=key, certChain=certChain)
    6363    if cipher_list:
    6464        context.set_cipher_list(cipher_list)
     
    6666    #context.set_options(OpenSSL.SSL.OP_SINGLE_DH_USE)
    6767    #context.set_options(OpenSSL.SSL.OP_EPHEMERAL_RSA)
    68        
     68   
    6969    conn = SSL.Connection(context, sock)
    7070    if mode == 'client':
     
    7777
    7878
    79 def ConnectSSLTLS(host, port):
     79def ConnectSSLTLS(host, port, cipher_list=None, handshake_callback=None):
    8080    protocols = [("SSL 2/3", SSL.SSLv23_METHOD),
    8181                 ("TLS 1.0", SSL.TLSv1_METHOD),
     
    9191       
    9292        try:
    93             conn = startSSLTLS(serverSock, mode='client', handshake=p)
     93            if handshake_callback:
     94                if not handshake_callback(serverSock):
     95                    return None
     96        except Exception as e:
     97            traceback.print_exc(file=sys.stderr)
     98            return None
     99           
     100        try:
     101            conn = startSSLTLS(serverSock, mode='client', protocol=p, cipher_list=cipher_list)
    94102            break
    95103        except ValueError as e:
    96             sys.stderr.write("%s handshake not supported by your openssl library, trying others...\n" % pname)
     104            sys.stderr.write("%s protocol not supported by your openssl library, trying others...\n" % pname)
    97105        except SSL.Error as e:
    98106            sys.stderr.write("Exception during %s handshake with server." % pname)
Note: See TracChangeset for help on using the changeset viewer.