Hi, I have written a simple chat server and a client that can connect to it. To make it more secure, I would like to add SSL to the connection process. How would I go about doing this?

Thanks in advance.

Thanks for the links myle. Except I seem to be having a little trouble with my server (which uses the asyncore module). I'm not quite sure how I can implement ssl into my code:

class ChatServer(dispatcher):

    def __init__(self, port, name):
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.bind(('', port))

    def handle_accept(self):
        conn, addr = self.accept()

if __name__ == '__main__':
    s = ChatServer(PORT, NAME)
    try: asyncore.loop()
    except KeyboardInterrupt: pass

Now, if I add "self.ssl.wrap_socket(conn, server_side=True, certfile="servercert.pem", keyfile="serverkey.pem", ssl_version=ssl.PROTOCOL_SSLv3)" into my "__init__" method, I get the following error:

s = ChatServer(PORT, NAME)
File "chatserver.v0.3.py", line 854, in __init__
self.ssl.wrap_socket(conn, server_side=True, certfile="servercert.pem",
File "/usr/lib/python2.6/asyncore.py", line 391, in __getattr__
return getattr(self.socket, attr)
AttributeError: '_socketobject' object has no attribute 'ssl'

This article has been dead for over six months. Start a new discussion instead.