Blackberry and SSL

Discussion in 'Java' started by John Goche, Jan 19, 2006.

  1. John Goche

    John Goche Guest

    Hello,

    I am using the BlackBerry J2ME emulator to establish an
    SSL connection. While connected I accept the certificate,
    write some data, then read some data from the input stream
    as follows. However, after reading is.available() number of
    bytes (see code below), the input stream is starts returning
    garbage (not the bytes I see when I connect from my C++
    SSL library code).

    What am I supposed to do so that is.getBytes() does not
    return junk bytes after returning int is.available() number of
    bytes? Am I supposed to close() and then reopen() the input
    streams? Should I buffer them somehow using producer and
    consumer threads? I tried increasing the receive buffer size
    but it did not help. What should I do to fix this problem.
    Alternatively, anyone know of any good SSL libraries
    out there that work (given that I am not having much
    luck with the BlackBerry one?). What am I
    doing wrong?

    class Foo {

    private SecureConnection sc;
    private InputStream is;
    private OutputStream os;

    boolean open(String host, String port) {

    try {

    String str = "ssl://" + host + ":" + port;

    sc = (SecureConnection) Connector.open(str);

    //sc.setSocketOption(SocketConnection.LINGER, 5);
    //sc.setSocketOption(SocketConnection.KEEPALIVE, 1);
    sc.setSocketOption(SocketConnection.RCVBUF, 6000);

    is = sc.openInputStream();

    os = sc.openOutputStream();

    return true;

    } catch (IOException e) {

    Dialog.alert("Could not open secure connection.");

    }

    return false;

    }

    // ...

    private synchronized byte[] getBytes(int size) {

    if (size > 0) {

    byte[] bytes = new byte[size];

    int count = 0;

    int val;

    try {

    while (count < size) {

    if ((val = is.read(bytes, count, size - count)) == -1) {

    connectionClosed();

    }

    count += val;

    }

    } catch (IOException e) {

    networkReadError();

    }

    return bytes;

    }

    return null;

    }

    }

    --

    Thanks,

    JG
    John Goche, Jan 19, 2006
    #1
    1. Advertising

  2. John Goche

    John Goche Guest

    Hello,

    I am have done some more testing on this
    BlackBerry SecureConnection code with the
    4.1.10.170 JDE...

    sc = (SecureConnection) Connector.open(str);

    is = sc.openInputStream();

    is.available() returns 0

    I call is.read() to read X bytes.

    I call is.available() returns 2^14 + 4 - x.

    I call is.read() to read is.available() bytes.

    is.available() returns 0.

    I call is.read() and I read some junk.

    After the junk, I see the original X bytes
    I had originally read.

    After that, I get network read errors when
    trying to read more bytes.

    It is as though the SSL library is not decoding
    my data properly. So now I am going to try the
    Nokia API, the J2SE API, and look for addon
    Java SSL libraries which I might be able to
    include as alternative source code as part
    of my project if they only work properly.

    Any feedback welcome,

    Regards,

    JG
    John Goche, Jan 19, 2006
    #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. John Cosmas

    ASP.NET and BLACKBERRY

    John Cosmas, Jun 18, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    5,690
    Alex Feinman [MVP]
    Jun 18, 2005
  2. nzpcmad

    Blackberry and web services

    nzpcmad, Dec 6, 2004, in forum: Java
    Replies:
    1
    Views:
    380
    Darryl L. Pierce
    Dec 6, 2004
  3. dave

    blackberry emulator and browsing problem

    dave, May 12, 2004, in forum: ASP .Net Mobile
    Replies:
    7
    Views:
    143
    Yan-Hong Huang[MSFT]
    May 14, 2004
  4. Stefan Huber

    blackberry and browsercap

    Stefan Huber, Nov 14, 2005, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    137
    Stefan Huber
    Nov 14, 2005
  5. dave

    blackberry and linkbutton javascript error

    dave, Dec 22, 2005, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    132
Loading...

Share This Page