Surya Kumar Selvam
- Forum posts: 1
Feb 16, 2015, 4:52:22 PM via Website
Feb 16, 2015 4:52:22 PM via Website
I am trying to trust a Certificate Authority in my Android application.
certData = Base64.decode(Base64EncodedCACert);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
InputStream in = new ByteArrayInputStream(certData);
X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in);
//Create a KeyStore containing trusted CA
KeyStore 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 TrustManager
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, tmf.getTrustManagers(), null);
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
Is this enough to trust the CA ? How can I check it ?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.