When running a SSL socket server in Python 2.5 or 2.6 (didn't try with newer versions), new connections are setup with "ssl.wrap_socket()". Everything works fine if I connect a client with SSL, but if I just telnet to the server it's not possible to close the socket anymore (receiving data works fine through the non-ssl socket though).
I get a SSL exception like this: "SSLError: [Errno 1] _ssl.c:480: error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol". After that I am not able to close the socket, but still can send data on the non-ssl-wrapped socket. How would I close this now open non-ssl socket?
Simplified code:
read_sockets,write_sockets,error_sockets = select.select(CONNECTION_LIST,[],[])
for sock in read_sockets:
if sock == server_socket:
newsock, addr = server_socket.accept()
# SSL Setup
try:
sslsock = ssl.wrap_socket(newsock, server_side=True, certfile="../cert.pem", keyfile="../cert.pem")
CONNECTION_LIST.append(sslsock)
except:
print "ssl handshake failed"
try:
newsock.send("bye\r\n") # succeeds
newsock.close() # doesn't work
|