Frage

I need implement whole process of sending data over HTTPS using PKI as described here http://upload.wikimedia.org/wikipedia/commons/9/96/Usage-of-Digital-Certificate.svg

How to sign (do I really have to do it?) my request with private key, and how to add certificate (which i received from webservice) to it?

I've my own keystore (http://nelenkov.blogspot.com/2011/12/using-custom-certificate-trust-store-on.html (really great blog!)) with webservice RootCA, private key used to create CSR file, and certificate signed by webservice (using csr).

I'm using robospice + square retrofit + square okHttp (or maybe use another HTTP client?) to execute requests and have my own SSLSocketFactory:

OkHttpClient client = new OkHttpClient();  
KeyStore keyStore = App.getInstance().getKeyStoreUtil().getKeyStore();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, AppConfig.KEYSTORE_PASSWORD);
SSLContext sslCtx = SSLContext.getInstance("TLS");
sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
client.setSslSocketFactory(sslCtx.getSocketFactory());

Since webservice is not implemented yet, I have no idea if it works, I'd really appreciate if someone could tell me whether I'm going right way or not.

War es hilfreich?

Lösung

Above code is working, but keep in mind that getting classes from App like App.getInstance.getKeyStoreUtil() is not really clean solution

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top