Beispiel #1
0
 def setup(self):
     conn = TLSConnection(self.request)
     conn.closeSocket = True
     conn.handshakeServer(certChain=self.owner.creds.cert,
                          privateKey=self.owner.creds.pkey,
                          checker=self.owner.creds.checker,
                          reqCert=True)
     self.rfile = conn.makefile('rb', self.rbufsize)
     self.wfile = conn.makefile('wb', self.wbufsize)
     self.owner.conn = conn
Beispiel #2
0
class RevTLSClient:
    def __init__(self, address, credentials):
        self.address = address
        self.__creds = credentials
        self.conn = None
        self.connect()

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.close()

    def connect(self):
        if self.conn:
            return

        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(self.address)

        self.conn = TLSConnection(sock)
        self.conn.handshakeClientCert(self.__creds.cert,
                                      self.__creds.pkey,
                                      checker=self.__creds.checker)
        self.fconn = self.conn.makefile()

    def sendall(self, data):
        _write_with_length(self.fconn, data)

    def recvall(self):
        return _read_with_length(self.fconn)

    def close(self):
        self.fconn.close()
        self.fconn = None
        self.conn.close()
        self.conn = None