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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Krzysztof Pa¼

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

    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¼

    #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 ObjectInputStre am(client.getIn putStream
    ()); - where client is client socket,
    JavaException: java.io.StreamC orruptedExcepti on: invalid stream header
    at
    java.io.ObjectI nputStream.read StreamHeader(Ob jectInputStream .java:737)
    at java.io.ObjectI nputStream.<ini t>(ObjectInputS tream.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_subjec t()
    return ok

    s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
    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((HOS T, PORT))
    print 'Writing query to server...'
    ss.send("GET_VE R")
    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\Pyt hon\conn.py", line 24, in ?
    data = ss.recv(2048)
    SSL.ZeroReturnE rror
    ===


    Comment

    Working...