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.

Recommended Answers

All 2 Replies

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):
        dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.set_reuse_addr()
        self.bind(('', port))
        self.listen(5)

    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'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.