By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,812 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,812 IT Pros & Developers. It's quick & easy.

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

P: 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ź.
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply

P: 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(2048)
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(2048)
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.