ur2cdanger
Lurker
I am trying to trust a Certificate Authority in my Android application.
I am doing this. Is this enough to trust the CA ? How can I check it ?
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 ?