Module for managing SSL communication in python?

Is there a module for managing SSL communication in python, both on the client side and on the server? The default SSL module for python is great, but the handshake is automatic. I was wondering if there is a module that will allow me to do this manually, 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 that 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 tried to write my own, but failed, and I cannot find any module that will allow me to do this.

+4
source share

All Articles