}  if (!engineIsKeyEntry(alias)) { return null;
    public Certificate[] engineGetCertificateChain(        String alias)     {        if (alias == null)        {            throw new IllegalArgumentException("null alias passed to getCertificateChain.");        }                Certificate c = engineGetCertificate(alias);        if (c != null)        {            Vector  cs = new Vector();            while (c != null)            {                X509Certificate     x509c = (X509Certificate)c;                Certificate         nextC = null;                byte[]  bytes = x509c.getExtensionValue(X509Extensions.AuthorityKeyIdentifier.getId());                if (bytes != null)                {                    try                    {                        ByteArrayInputStream    bIn = new ByteArrayInputStream(bytes);                        ASN1InputStream         aIn = new ASN1InputStream(bIn);                        bIn = new ByteArrayInputStream(((ASN1OctetString)aIn.readObject()).getOctets());                        aIn = new ASN1InputStream(bIn);                        AuthorityKeyIdentifier id = new AuthorityKeyIdentifier((ASN1Sequence)aIn.readObject());                        if (id.getKeyIdentifier() != null)                        {                            nextC = (Certificate)chainCerts.get(new CertId(id.getKeyIdentifier()));                        }                                            }                    catch (IOException e)                    {                        throw new RuntimeException(e.toString());                    }                }                if (nextC == null)                {                    //                    // no authority key id, try the Issuer DN                    //                    Principal  i = x509c.getIssuerDN();                    Principal  s = x509c.getSubjectDN();                    if (!i.equals(s))                    {                        Enumeration e = chainCerts.keys();                        while (e.hasMoreElements())                        {                            X509Certificate crt = (X509Certificate)chainCerts.get(e.nextElement());                            Principal  sub = crt.getSubjectDN();                            if (sub.equals(i))                            {                                try                                {                                    x509c.verify(crt.getPublicKey());                                    nextC = crt;                                    break;                                }                                catch (Exception ex)                                {                                    // continue                                }                            }                        }                    }                }                cs.addElement(c);                if (nextC != c)     // self signed - end of the chain                {                    c = nextC;                }                else                {                    c = null;                }            }            Certificate[]   certChain = new Certificate[cs.size()];            for (int i = 0; i != certChain.length; i++)            {                certChain[i] = (Certificate)cs.elementAt(i);            }            return certChain;        }        return null;    }