ArrayList<java.security.cert.X509Certificate> chain = new ArrayList<java.security.cert.X509Certificate>();
if (ctx.extraChainCert != null) {
chain.addAll(ctx.extraChainCert);
} else if (ctx.cert != null) {
StoreContext storeCtx = ctx.createStoreContext(null);
X509AuxCertificate x = ctx.cert;
while (true) {
chain.add(x);
if (x.getIssuerDN().equals(x.getSubjectDN())) {
break;
}
try {
Name xn = new Name(x.getIssuerX500Principal());
X509Object[] s_obj = new X509Object[1];
if (storeCtx.getBySubject(X509Utils.X509_LU_X509, xn, s_obj) <= 0) {
break;
}
x = ((Certificate) s_obj[0]).x509;