Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Detailed Step by Step instructions I followed to achieve this</strong></p> <ul> <li>Download bouncycastle JAR from <a href="http://repo2.maven.org/maven2/org/bouncycastle/bcprov-ext-jdk15on/1.46/bcprov-ext-jdk15on-1.46.jar">http://repo2.maven.org/maven2/org/bouncycastle/bcprov-ext-jdk15on/1.46/bcprov-ext-jdk15on-1.46.jar</a> or take it from the "doc" folder.</li> <li>Configure BouncyCastle for PC using one of the below methods. <ul> <li>Adding the BC Provider Statically (Recommended) <ul> <li>Copy the bcprov-ext-jdk15on-1.46.jar to each <ul> <li>D:\tools\jdk1.5.0_09\jre\lib\ext (JDK (bundled JRE)</li> <li>D:\tools\jre1.5.0_09\lib\ext (JRE)</li> <li>C:\ (location to be used in env variable)</li> </ul></li> <li>Modify the java.security file under <ul> <li>D:\tools\jdk1.5.0_09\jre\lib\security</li> <li>D:\tools\jre1.5.0_09\lib\security</li> <li>and add the following entry <ul> <li>security.provider.7=org.bouncycastle.jce.provider.BouncyCastleProvider</li> </ul></li> </ul></li> <li>Add the following environment variable in "User Variables" section <ul> <li>CLASSPATH=%CLASSPATH%;c:\bcprov-ext-jdk15on-1.46.jar</li> </ul></li> </ul></li> <li>Add bcprov-ext-jdk15on-1.46.jar to CLASSPATH of your project and Add the following line in your code <ul> <li>Security.addProvider(new BouncyCastleProvider());</li> </ul></li> </ul></li> <li>Generate the Keystore using Bouncy Castle <ul> <li>Run the following command <ul> <li>keytool -genkey -alias myproject -keystore C:/myproject.keystore -storepass myproject -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider</li> </ul></li> <li>This generates the file C:\myproject.keystore</li> <li>Run the following command to check if it is properly generated or not <ul> <li>keytool -list -keystore C:\myproject.keystore -storetype BKS</li> </ul></li> </ul></li> <li><p>Configure BouncyCastle for TOMCAT</p> <ul> <li><p>Open D:\tools\apache-tomcat-6.0.35\conf\server.xml and add the following entry</p> <ul> <li>&lt;Connector port="8443" keystorePass="myproject" alias="myproject" keystore="c:/myproject.keystore" keystoreType="BKS" SSLEnabled="true" clientAuth="false" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS" sslImplementationName="org.bouncycastle.jce.provider.BouncyCastleProvider"/&gt;</li> </ul></li> <li><p>Restart the server after these changes.</p></li> </ul></li> <li>Configure BouncyCastle for Android Client <ul> <li>No need to configure since Android supports Bouncy Castle Version 1.46 internally in the provided "android.jar".</li> <li>Just implement your version of HTTP Client (MyHttpClient.java can be found below) and set the following in code <ul> <li>SSLSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);</li> </ul></li> <li>If you don't do this, it gives an exception as below <ul> <li>javax.net.ssl.SSLException: hostname in certificate didn't match: &lt;192.168.104.66> != </li> </ul></li> <li>In production mode, change the above code to <ul> <li>SSLSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);</li> </ul></li> </ul></li> </ul> <p><strong>MyHttpClient.java</strong></p> <pre><code>package com.arisglobal.aglite.network; import java.io.InputStream; import java.security.KeyStore; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.conn.SingleClientConnManager; import com.arisglobal.aglite.activity.R; import android.content.Context; public class MyHttpClient extends DefaultHttpClient { final Context context; public MyHttpClient(Context context) { this.context = context; } @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // Register for port 443 our SSLSocketFactory with our keystore to the ConnectionManager registry.register(new Scheme("https", newSslSocketFactory(), 443)); return new SingleClientConnManager(getParams(), registry); } private SSLSocketFactory newSslSocketFactory() { try { // Get an instance of the Bouncy Castle KeyStore format KeyStore trusted = KeyStore.getInstance("BKS"); // Get the raw resource, which contains the keystore with your trusted certificates (root and any intermediate certs) InputStream in = context.getResources().openRawResource(R.raw.aglite); try { // Initialize the keystore with the provided trusted certificates. // Also provide the password of the keystore trusted.load(in, "aglite".toCharArray()); } finally { in.close(); } // Pass the keystore to the SSLSocketFactory. The factory is responsible for the verification of the server certificate. SSLSocketFactory sf = new SSLSocketFactory(trusted); // Hostname verification from certificate // http://hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html#d4e506 sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return sf; } catch (Exception e) { throw new AssertionError(e); } } } </code></pre> <p>How to invoke the above code in your Activity class:</p> <pre><code>DefaultHttpClient client = new MyHttpClient(getApplicationContext()); HttpResponse response = client.execute(...); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload