unknown protocol error when connecting to an server via ssl

christian_stengel christian_stengel at yahoo.de
Wed Jan 26 11:29:31 EST 2005


Hi *,

I have just started to learn python and I am having a problem with 
an python client connecting to a perl server using ssl (I tried this 
with pyOpenSSL and with the build in SSL Module).

I don't want to check a cerificate, so i simply tried a

from OpenSSL import SSL

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("127.0.0.1", 2000)

s.sendall("100 Hello\n")

ctx = SSL.Context(SSL.SSLv23_METHOD)
ctx.set_verify(SSL_VERIFY_NONE,self.verify_cb)
ss = SSL.Connection(ctx,s)
ss.set_connect_state()

ss.sendall("101 User\n")

when writeing the 101 I'll get an SSL23_GET_SERVER_HELLO 
unknown protocol error. If I don't do the ssl stuff, everything 
works.

I also tried this with the socket.ssl(s,None, None) to get a secure 
socket - but I got the same error.

The server is not written by me - so I can't change that to python.  
The problem is, that there is first an unencrypted socket, that is 
converted to a secure socket.

the perl (server) code is something like this:

# creating a socket
$socket = IO::Socket::INET->new(Listen => 5,
  LocalPort => 2000,
  Timeout => 15,
  Resue => 1,
  Proto => 'tcp');

# some more code

# accepting a remote connection
$session = $socket->accept;

# some more code

# convert the Socket to an ssl socket
$sslsocket = IO::Socket::SSL::socket_to_SSL($session,
  SSL_verify_mode => 0x00)

# some more code

 Does anybody know, where the UNKNOWN PROTOCOL error 
comes from? I have changed the connection Mode to 
SSLv2_METHOD but this gave me an GET_SERVER_HELLO 
read wrong packet type error.

I have done this with python 2.3.4 under linux - and the perl stuff 
is done via the IO-Socket-SSL package.

Thx,

Chris






More information about the Python-list mailing list