I am having problems in connecting server using ssl from android emulater. I have created public key using portecle(bks).When i used to connect server,authentication is not taking place.Logcat is not showing any error but ssl connection is not working.
My Source Code:
import android.content.Context;
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.myclinicmyway.*;
import java.io.InputStream;
import java.security.KeyStore;
public class MyHttpClient extends DefaultHttpClient {
public final Context context;
public MyHttpClient(Context context) {
this.context = context;
}
//"http", PlainSocketFactory.getSocketFactory(), 80
@Override protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", newSslSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);
}// end of client connection
private SSLSocketFactory newSslSocketFactory() {
try {
KeyStore trusted = KeyStore.getInstance("BKS");
InputStream in = context.getResources().openRawResource(R.raw.docinbangalorefinals);
try {
trusted.load(in, "docinbangalore".toCharArray());
} finally {
in.close();
}
return new SSLSocketFactory(trusted);
}
catch (Exception e) {
throw new AssertionError(e);
}// end of catch
}// end of ssl socket
}// end of clas
I got the solution.Following code worked for me.