Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Blackberry and SSL

Reply
Thread Tools

Blackberry and SSL

 
 
John Goche
Guest
Posts: n/a
 
      01-19-2006
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

 
Reply With Quote
 
 
 
 
John Goche
Guest
Posts: n/a
 
      01-19-2006

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SSL and OpenSSL::SSL::SSLServer accept() born in USSR Ruby 2 09-27-2009 01:46 AM
Maintain session between an SSL page and Non SSL page John Smith Java 0 10-05-2006 12:03 PM
webrick, ssl and non-ssl on the same port Pavel Smerk Ruby 3 08-15-2006 05:51 PM
Blackberry and XP and Office 2003 The bud Computer Support 1 03-22-2005 05:48 PM
SSL with backend SSL on CSS 11500 Olivier PELERIN Cisco 0 08-30-2004 08:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57