• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Trust Certificate Authority in Android

I am trying to trust a Certificate Authority in my Android application.

Code:
certData =Base64.decode(Base64EncodedCACert);

CertificateFactory certFactory =CertificateFactory.getInstance("X.509");InputStream in =newByteArrayInputStream(certData);
X509Certificate cert =(X509Certificate)certFactory.generateCertificate(in);

//Create a KeyStore containing trusted CAKeyStore keyStore =KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null,null);
keyStore.setCertificateEntry("CA", cert);

//Create a TrustManager that trusts the CA in our KeyStore TrustManagerFactory tmf =TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);

//Create an SSLContext that use the TrustManagerSSLContext context =SSLContext.getInstance("SSL");
context.init(null, tmf.getTrustManagers(),null);

HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());

I am doing this. Is this enough to trust the CA ? How can I check it ?
 
Back
Top Bottom