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

K

Krzysztof Pa¼

Hi,
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.
 
K

Krzysztof Pa¼

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
think.

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: java.io.StreamCorruptedException: invalid stream header
at
java.io_ObjectInputStream.readStreamHeader(ObjectInputStream.java:737)
at java.io_ObjectInputStream.<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 ?

Kris.

PS.
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...'
ss.send("GET_VER")
print 'Reading response from server...'
data = ss.recv(2048)
s.close()
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\conn.py", line 24, in ?
data = ss.recv(2048)
SSL.ZeroReturnError
===
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top