/* Keep track of progress; remove entry when check is done */
Map progress = new HashMap(serverPrincipals.size());
for (Iterator i = serverPrincipals.iterator(); i.hasNext(); ) {
X500Principal p = (X500Principal) i.next();
if (!principals.contains(p)) {
throw new UnsupportedConstraintException(
"Missing principal: " + p);
}
progress.put(p, X500Principal.class);
}
X500PrivateCredential[] privateCredentials =
(X500PrivateCredential[]) AccessController.doPrivileged(
new SubjectCredentials.GetAllPrivateCredentialsAction(
serverSubject));
List certPaths =
SubjectCredentials.getCertificateChains(serverSubject);
if (certPaths != null) {
for (int i = certPaths.size(); --i >= 0; ) {
CertPath chain = (CertPath) certPaths.get(i);
X509Certificate firstCert = firstX509Cert(chain);
X500Principal p = firstCert.getSubjectX500Principal();
if (progress.containsKey(p)) {
try {
checkValidity(chain, null);
} catch (CertificateException e) {
progress.put(p, e);
continue;
}
progress.put(p, CertPath.class);
for (int j = privateCredentials.length; --j >= 0; ) {
X509Certificate cert =
privateCredentials[j].getCertificate();
if (firstCert.equals(cert)) {
progress.remove(p);
break;
}
}
}
}
}
if (!progress.isEmpty()) {
X500Principal p =
(X500Principal) progress.keySet().iterator().next();
Object result = progress.get(p);
if (result == X500Principal.class) {
throw new UnsupportedConstraintException(
"Missing public credentials: " + p);
} else if (result == CertPath.class) {
throw new UnsupportedConstraintException(
"Missing private credentials: " + p);
} else {
throw new UnsupportedConstraintException(
"Problem with certificates: " + p + "\n" + result,
(CertificateException) result);
}
}
}