public static Collection<Certificate> getCACertChain(Admin admin, String cAName, boolean checkRevokation, CAAdminSession caAdminSession) throws ConfigurationException{
try{
CAInfo cainfo = caAdminSession.getCAInfo(admin, cAName);
if(cainfo == null){
log.error("Misconfigured CA Name in RAService");
throw new ConfigurationException("Misconfigured CA Name in RAService");
}
if(checkRevokation){
if(cainfo.getStatus()==SecConst.CA_REVOKED){
throw new ConfigurationException("CA " + cainfo.getName() + " Have been revoked");
}
Iterator<Certificate> iter = cainfo.getCertificateChain().iterator();
iter.next(); // Throw away the first one.
while(iter.hasNext()){
X509Certificate cacert = (X509Certificate) iter.next();
CAInfo cainfo2 = caAdminSession.getCAInfo(admin,CertTools.stringToBCDNString(cacert.getSubjectDN().toString()).hashCode());
// This CA may be an external CA, so we don't bother if we can not find it.
if ((cainfo2 != null) && (cainfo2.getStatus()==SecConst.CA_REVOKED) ) {
throw new ConfigurationException("CA " + cainfo2.getName() + " Have been revoked");
}
}
}
return cainfo.getCertificateChain();
}catch(Exception e){
if (e instanceof ConfigurationException) {
throw (ConfigurationException)e;
}
log.error("Exception getting CA cert chain: ", e);
throw new ConfigurationException("Couldn't instantiate CAAdminSessionBean");
}
}