Skip to content

Instantly share code, notes, and snippets.

@stevommmm
Created January 13, 2015 03:22
Show Gist options
  • Select an option

  • Save stevommmm/956f0204309d832e15dc to your computer and use it in GitHub Desktop.

Select an option

Save stevommmm/956f0204309d832e15dc to your computer and use it in GitHub Desktop.
sslablesockets
class SmartServerSocket:
def __init__( self, sock ):
self.sock = sock
# delegate methods as needed
_delegate_methods = [ "fileno" ]
for method in _delegate_methods:
setattr( self, method, getattr( sock, method ) )
def accept( self ):
(conn, addr) = self.sock.accept()
if conn.recv( 1, socket.MSG_PEEK ) == "\x16":
return (ssl.wrap_socket( conn, certfile='cert.pem', server_side=True ), addr)
else:
return (conn, addr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment