Friday, September 30, 2011

Android Https support

For providing https support in your android App.

Requirements :
JDK 1.6 (keytool), bcprov-jdk16-146.jar, open ssl.

Steps :

1. Generate the key store first.

2. Copy paste the following

 a. export CLASSPATH with the following.
    export CLASSPATH=$CLASSPATH:/home/name/Downloads/bcprov-jdk16-146.jar

b. Generate the keystore. mystore.bks will get generated at /home/uname/workspace/

keytool \
      -importcert \
      -v \
      -trustcacerts \
      -alias 0 \
      -file <(openssl x509 -in /home/uname/workspace/contentstore.net.crt) \
      -keystore /home/uname/workspace/mystore.bks \
      -storetype BKS \
      -provider org.bouncycastle.jce.provider.BouncyCastleProvider \
      -providerpath /home/uname/Downloads/bcprov-jdk16-146.jar \
      -storepass psswd
3. I will provide more detailed instructions for using the keystore in your android app, for now i will give summary of how it can be done.
   use the generated keystore file in your android app as a raw resource. Then override the createClientConnectionManager method of DefaultHttpClient that you were using.

 You can find how to override at various places in the net. Just Google Https support for Android.

4. If you are directly using the DefaultHttpClient, you are good to go. But if you  are using a restTemplate from Spring, then all that you need to do is:


RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(new MyHttpClient());



No comments:

Post a Comment