ssl - Android: opending a keystore as an asset to make an SSLSocketFactory -
have bouncy castle keystore, i'd use connect sslsocketfactory. doing in "desktop" java easy, how do on android.
it doesn't seem make difference whether put in assets or res/raw - problem comes when trying open , instantiate instance of keystore (java.security.keystore in case) pass sslsocketfactorys constructor.
has had success before? what's best way of "reading" , opening it? pointers or code snippets welcome.
many thanks
don
this should do:
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 java.io.inputstream; import java.security.keystore; 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)); registry.register(new scheme("https", newsslsocketfactory(), 443)); return new singleclientconnmanager(getparams(), registry); } private sslsocketfactory newsslsocketfactory() { try { keystore trusted = keystore.getinstance("bks"); inputstream in = context.getresources().openrawresource(r.raw.mystore); try { trusted.load(in, "ez24get".tochararray()); } { in.close(); } return new sslsocketfactory(trusted); } catch (exception e) { throw new assertionerror(e); } } }
ez24get password keystore.
Comments
Post a Comment