java.security.cert.Certificate issuerCert = null;
X509Certificate sCert = null;
KeyStore ks = null;
try {
// In 1.2 beta 4, we need an argument for the following method
ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new FileInputStream(System.getProperty("user.home") + File.separator + ".keystore"), null);
} catch (Exception e) {
throw new CertificateException("Invalid keystore");
}
// In 1.2 beta 4, we must handle a KeyStoreException
try {
String signer = ks.getCertificateAlias(c);
if (signer != null) {
System.out.println("We know the signer as " + signer);
return;
}
for (Enumeration alias = ks.aliases(); alias.hasMoreElements(); ) {
String s = (String) alias.nextElement();
try {
sCert = (X509Certificate) ks.getCertificate(s);
} catch (Exception e) {
continue;
}
if (name.equals(sCert.getSubjectDN().getName())) {
issuerCert = sCert;
break;
}
}
} catch (KeyStoreException kse) {
throw new CertificateException("Invalid keystore");
}
if (issuerCert == null) {
throw new CertificateException("No such certificate");
}
try {
c.verify(issuerCert.getPublicKey());
} catch (Exception e) {
System.out.println("EX" + e);
throw new CertificateException(e.toString());
}