I am writing a Java application for my own personal use for a BlackBerry 6.x system.
So I have hit a huge hurdle in my development. Basically, I need the application to connect to a specific webpage to retrieve some data. As I need to log into the site using plaintext credentials, I'd strongly prefer using HTTPS.
For some reason which I just cannot work out, the device just will not connect to the site I need to connect to, and many others.
Pages that the device is fully capable of loading include https://www.google.com.au, and https://www.youtube.com.
Pages that the device is unable to connect to include https://github.com, and https://duckduckgo.com.
Notable remarks:
- This issue occurs both in the BlackBerry emulator, and on a physical device. The physical device being used is a BlackBerry Curve 9300 running BlackBerryOS 6.3. The emulator is something similar. (The 9600 emulator shipped with the BlackBerry 7.x JDK also has the same issues.)
- The pages that cannot be accessed through Java code using HTTPS also cannot be accessed using the default browser in the system. Despite being able to connect to these sites fine using the 3rd party Opera Mini browser.
- The issue only seems to occur when trying to use a HttpsConnection instead of a HttpConnection. I am able to connect to the site if I use an insecure HttpConnection, though I wish not to use this.
Here is the overall gist of what I'm trying to run on the device:
public static final String SITE_URL = "https://duckduckgo.com";
HttpsConnection conn = null;
try {
// Create connection
conn = (HttpsConnection) Connector.open(SITE_URL + ";deviceside=true;interface=wifi", 3, true);
// Try print certificate information
Certificate c = conn.getSecurityInfo().getServerCertificate();
Dialog.alert("Issuer: " + c.getIssuer() + " subj:" + c.getSubject());
// Getting response code opens connection, sends request,
// and reads HTTP headers.
int rcode = conn.getResponseCode();
if (rcode != HttpsConnection.HTTP_OK) {
throw new IOException ("HTTP response: " + rcode);
}
Dialog.alert("Response: " + rcode);
} catch (ClassCastException e) {
throw new IllegalArgumentException("Not a HTTP URL");
} catch (IOException e) {
Dialog.alert("IOException: " + e.getMessage());
} finally {
// Close connection and stream.
if (is != null) { is.close(); }
if (conn != null) { conn.close(); }
}
If I change SITE_URL to something I know I can connect to (https://www.google.com.au, et al) then the code runs fine and I get a HTTP 200. When I try to connect to say, https://duckduckgo.com, the program simply throws an IOException. (Specifically it seems to be a TLSIOException, if I catch all of the relevant IOException subclasses) and returns null upon calling getMessage().
Thanks,
Any help or suggestions would be much appreciated.