Hello,everyone!! I am writing a simple ssl client-server test program on my personal laptop. And I encounter some problems with my simple programs. Please give me some helps.-------------------------------------------------------------------------------------------------------------------------------------------------------- My server code: import socketimport sslbindsocket = socket.socket()bindsocket.bind(('127.0.0.1', 1234))bindsocket.listen(5)print 'server is waiting for connection...'newsocket, fromaddr = bindsocket.accept()print 'start ssl socket...'connstream = ssl.wrap_socket(newsocket, server_side=True, certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", ssl_version=ssl.PROTOCOL_SSLv23)data = connstream.read()print 'connected from address', fromaddrprint 'received data as', repr(data)connstream.close() My client code: import socketimport ssls = socket.socket(socket.AF_INET, socket.SOCK_STREAM)ssl_sock = ssl.wrap_socket(s, ca_certs="/home/ckyang/PHA/testsslsocket/myCA.crt", cert_reqs=ssl.CERT_REQUIRED)ssl_sock.connect(("127.0.0.1", 1234))ssl_sock.write("hello")ssl_sock.close() -----------------------------------------------------------------------------------------------------------------------------------------------------------Server side error: File "views.py", line 17, in <module>connstream = ssl.wrap_socket(newsocket, server_side=True, certfile="/etc/home/ckyang/PHA/testsslsocket/mypha.crt", keyfile="/etc/home/ckyang/PHA/testsslsocket/mypha.key", ssl_version=ssl.PROTOCOL_SSLv23) File "/usr/lib/python2.7/ssl.py", line 344, in wrap_socket ciphers=ciphers) File "/usr/lib/python2.7/ssl.py", line 119, in __init__ ciphers)ssl.SSLError: [Errno 336265218] _ssl.c:347: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib Client side error: File "client.py", line 10, in <module> ssl_sock.connect(("127.0.0.1", 1234)) File "/usr/lib/python2.7/ssl.py", line 299, in connect self.do_handshake() File "/usr/lib/python2.7/ssl.py", line 283, in do_handshake self._sslobj.do_handshake()socket.error: [Errno 104] Connection reset by peer ------------------------------------------------------------------------------------------------------------------------------------------------------------So what is wrong with my code? The codes are so simple and so much like python official site sample demonstration, but I still cant get it work, so frustrating. Seems the problem happened on server side then cause client side cant connect well, is that right? My platform is ubuntu, with openssl 0.9.8 and python 2.7. All certificates and keys self-signed by openssl for test convenience. This is the site for referrence : http://andyjeffries.co.uk/articles/x509-encrypted-authenticated-socket-ruby-client Or should I need a real certificate issued by a real CA to let things work? Any tips or suggestions welcomed, thank you very much~ Good day. Kay
-- http://mail.python.org/mailman/listinfo/python-list