First we can start by downloading the apk file for android and the jar file for your computer (server) along with the correct secure certificate and another certificate to test that other certificates will not work. Download link: http://ece301-examples.googlecode.com/files/ssl_sockets.zip
First I will go through the steps so you can see a working example before looking at the code.
The easiest way to test this:
1. First, make sure that you are using Wifi and that your laptop and your android device are both connected to the same Wifi.
2. From a terminal, run sslsocket.jar with the port number and the whole path of the certificate. In my case:
java -jar sslsocket.jar 9998 /home/juan/testserverkeys
3. Install the APK file in your android device. The certificate is inside the assets folder. When the screen comes up, you need to specify the IP address of your computer, the port number (I used 9998) and a message you like to send over. Then press the SEND button. Look at the image at the start of this article. Should look like that
In your server side you should see the following
Now if you use the wrong certificate:
java -jar sslsocket.jar 9998 /home/juan/testserverWrongKey
The rest of this article is available for $.99 cents. It has all the source code available to create the apk and jar file and it explains how to create the android SSL certificate as well as the server side certificate.
This article is exclusive, use Cleeng to view it in full.