public static void checkCertificate(X509TrustManager x509TrustManager,
KeyManagerFactory keyManagerFactory, String alias)
throws GeneralSecurityException {
// get the certificate chain for the provided alias
X509KeyManager x509KeyManager = null;
KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
for (KeyManager keyManager : keyManagers) {
if (keyManager instanceof X509KeyManager) {
x509KeyManager = (X509KeyManager) keyManager;
}
}
if (x509KeyManager == null) {
throw new GeneralSecurityException("no x509KeyManager found");
}
X509Certificate[] serverCertificateChain =
x509KeyManager.getCertificateChain(alias);
if (serverCertificateChain == null) {
throw new GeneralSecurityException(
"no certificate chain found for alias \"" + alias + "\"");
}