Monday, February 25, 2008

Technical: MDlet HTTPS

Brief introduction on the needs of a HTTPS connection. To ensure a secure channel between the server and client. The server and client both derive a session key from this secret value, which is used to encrypt all subsequent traffic sent between them.
Actually it's very simple to do HTTPS connections.

MISLEADING SOLUTION:
Previously, instead of the ContentConnection Class, we changed to the HttpsConnection Class:
HttpsConnection hc = (HttpsConnection)Connector.open(url);

We got errors like:


SOLUTION:
Based on the article here, we realised that it's the issue of "Unknown Certificates". This is because the certificates are created by us, thus it is not represented in the keystore of the J2ME Wireless Toolkit.

The J2ME Wireless Toolkit contains a tool called MEKeyTool, purpose is to manage the public keys of certificate authorities. It is found in the "installation_dir/bin".

To list keys in the default keystore:
mekeytool -list

Now, we gotta import the keystore used in tomcat into the Wireless Toolkit:
mekeytool -import -alias tomcat -keystore "z:\.keystore" -storepass changeit

Now we do a -list, you can observe it is in our keystore. Pointers to take note, when creating the certificate in tomcat, you MUST key in the "url_used" when they prompt you for FIRST NAME. I used the IP 10.211.55.2, so FIRST NAME is 10.211.55.2. Or else you will get the "Certificate does not contain the correct site name" error.

Since we now know that it's the configuration portion that causes us the problem, not the problem with the code. All we have to do is construct a HTTPS Connection String. So instead of this:
String url = "http://localhost:8080/"
ContentConnection connection = (ContentConnection) Connector.open(url);

we change it to this:
String url = "https://localhost:8443/"
ContentConnection connection = (ContentConnection) Connector.open(url);

WA LA!!

No comments: