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

Discussion in 'Python' started by Krzysztof Pa¼, Sep 26, 2003.

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

    --
    Greetings from Poland,
    Krzysztof Pa¼.
     
    Krzysztof Pa¼, Sep 26, 2003
    #1
    1. Advertising

  2. UPDATED: Python SSL Socket Client to Java SSL Server. HELP me PLEASE.

    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
    ===
     
    Krzysztof Pa¼, Sep 26, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Avizz
    Replies:
    3
    Views:
    13,827
    Andy Fish
    Sep 29, 2003
  2. greatestmclarenfan
    Replies:
    2
    Views:
    587
    Steve Horsley
    Feb 16, 2006
  3. KK
    Replies:
    2
    Views:
    596
    Big Brian
    Oct 14, 2003
  4. Replies:
    0
    Views:
    696
  5. Replies:
    1
    Views:
    284
Loading...

Share This Page