Author: subinacls Language: python
Description: ssl tls socket wrapped Timestamp: 2013-06-19 18:31:49 +0000
View raw paste Reply
  1. original socket:
  2.  
  3. try:
  4.         class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
  5.                 def handle(self):
  6.                         self.data = self.request.recv(1024).strip()
  7.                         print bcolors.OKBLUE + "Host: %s connected on port: %s\n" % (self.client_address[0],self.data) + bcolors.ENDC
  8.                         self.request.send(self.data)
  9.         class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
  10.                 pass
  11.         socketserver = ThreadedTCPServer(('', lowport), ThreadedTCPRequestHandler)
  12.         socketserver_thread = threading.Thread(target=socketserver.serve_forever)
  13.         socketserver_thread.setDaemon(False)
  14.         socketserver_thread.start()
  15.  
  16. tls_wrapped:
  17.  
  18.    try:
  19.     class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
  20.      def handle(self):
  21.       self.request = ssl.wrap_socket(self.request,
  22.         certfile=('ca.crt'),
  23.         keyfile=('ca.key'),
  24.         server_side=True,
  25.         cert_reqs=ssl.CERT_NONE,
  26.         ssl_version=ssl.PROTOCOL_TLSv1,
  27.         do_handshake_on_connect=True)
  28.       self.data = self.request.read(1024).strip()
  29.       print "Host: %s connected on port: %s\n" % (self.client_address[0],self.data)
  30.       self.request.send(self.data)
  31.     class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
  32.      pass
  33.     socketserver = ThreadedTCPServer(('', int(port) ), ThreadedTCPRequestHandler)
  34.     socketserver_thread = threading.Thread(target=socketserver.serve_forever)
  35.     socketserver_thread.setDaemon(False)
  36.     socketserver_thread.start()
  37.  
View raw paste Reply