Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python SSL Socket Client to Java SSL Server. HELP me PLEASE.

Thread Tools

Python SSL Socket Client to Java SSL Server. HELP me PLEASE.

Krzysztof Paź
Posts: n/a
I want to make simple client in phyton, which would be able to communicate
with Java server using SSL sockets.
There is the Java clients, which is doing this - so I'm pretty sure, that
Java server works OK.

I've heard, that P2.3 has SSL support included in himself and also, I was
trying P2.2 with pyOpenSSL wrappers and extensions, but unsuccesfuly...

So, could you give me a few lines of python code which makes such things:
1. Importing nessesary libraries,
2. Connects to specified server and port with SSL socket (no cert.
validation is needed - just using server cert. to encrypt transmission),
3. Sends some string to server (something like command "GET_VER"),
4. Reads answer from server (it could be something similar to Java
Object... - Java strings, arrays of bytes, etc),
5. Prints this answer in human readable manner in console,
6. Disconnect from server.

It would be nice, if this code will use only opensource or freeavailable
soft/libs and Python 2.2 or 2.3.

Greetings from Poland,
Krzysztof Paź.

Reply With Quote
Krzysztof Paź
Posts: n/a
On the Java server side I'm using ObjectInput/OutputStream classes to
provide efficient communication.

After accepting incoming connection, SSL handshake is done properly - I

Next, while server is creating streams for reading and writing data with
client I've got such exception in Java Server Code - during call of code:
JavaCode: datain = new ObjectInputStream(client.getInputStream
()); - where client is client socket,
JavaException: invalid stream header
at<init>(ObjectInputStream .java:253)
So, what is the problem ?

If there is any possibility to read/write data with SSLsockets from Python
to Java ObjectInput/Output Streams or not ?

Any ideas ?


Main part of my test python client code:
def verify_cb(conn, cert, errnum, depth, ok):
print 'Got certificate: %s' % cert.get_subject()
return ok

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ctx = SSL.Context(SSL.SSLv3_METHOD)
ctx.set_verify(SSL.VERIFY_NONE, verify_cb)
ss = SSL.Connection(ctx,s)
print 'Python socket client. Connecting to: ', `HOST`, `PORT`, '.'
ss.connect((HOST, PORT))
print 'Writing query to server...'
print 'Reading response from server...'
data = ss.recv(204
print 'Received', `data`
this code make such output:
Python socket client. Connecting to: [my server...].
Writing query to server...
Got certificate: <...[cert data - ok]...>
Reading response from server...
Traceback (most recent call last):
File "D:\Install\Python\", line 24, in ?
data = ss.recv(204

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM
IO::Socket::SSL : $sock is not defined if client is not SSL (crash) Perl Misc 1 12-19-2005 07:36 PM
Client socket disconnection event not received on Server socket java .nio Avizz Java 3 09-29-2003 10:47 AM