Module to control SSL handshake in python?

Viewed 3515

Is there a module to control the SSL handshake in python, Both client side and server? The python default SSL module is great but does the handshake automatic. I was wondering if there is a module that will allow me to do it manual similar to this:

import SSLManuel
import socket

s = socket.socket()
s.connect(("server.com",9999))

ClientHello = SSLManuel.generateClientHelloMessage(ssl=TLSv1_2, cipher="ECDHE-RSA-AES128-GCM-SHA256", server="www.server.com")
s.send(ClientHello)
ServerHello = s.recv()#this would receive the server hello
#This would verify the certificate of the server
if SSLManuel.check_cert(ServerHello) == true:
    Pre-Master-Key = SSLManuel.generatePreMasterKey()
    ClientKeyExchange = SSLManuel.generateClientKeyExchange(Pre-Master-Key)
    ChangeCiherSpec = SSLManuel.generateChangeCipherSpec()
    ClientFinished = SSLManuel.generateClientFinished()
    Sessionkey = SSLManuel.generateMasterKey(Pre-Master-Key)
    s.send(ClientKeyExchange)
    s.send(ChangeCiherSpec)
    s.send(ClientFinished)
    ServerFinished = s.recv()
    #This will check if the server is ready to communicate securely. 
    if SSLManuel.checkServerFinshed(ServerFinished) == true:
        #I can now use the SessionKey to encrypt data to and from the server
        s.send(SSLManuel.encrypt(SessionKey, "GET / HTTP/1.0\n\n"))
        response = s.recv()
        print(SSLManuel.decrypt(SessionKey, response))

I hope the naming conventions used in this example can help you understand what I'm trying to accomplish. Most of my knowledge of SSL comes from This Article. I have tried to write my own but have failed and I can't seem to find any module that will allow me to do this.

1 Answers
Related