My application connects to an SSL web service which uses a certificate to verify its identity. Recently, this certificate changed and since it is not signed by a trusted authority, part of my application failed. The service's advice to protect against this situation in the future is that I should start trusting the existing certificate's signing authority, instead of the individual certificates.
How may this be achieved in Java?
Currently I'm adding the certificate they provide into a keystore using keytool and composing it into a TrustManagerFactory something like:
public static TrustManager[] getTrustManagers() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
KeyStore tks = KeyStore.getInstance(KeyStore.getDefaultType());
tks.load(StarTrustManagerFactory.class.getResourceAsStream("webservice.ks"), "password".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(tks);
return tmf.getTrustManagers();
};
Is there a way of adapting this approach to return a TrustManager
which trusts the signing authority of the certificates I have? Additionally, how can I extract the information regarding the signer of the certificate from the certificate I have?
Thanks, Dan.