1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.jce.provider;
2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
36e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport java.io.IOException;
46e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport java.math.BigInteger;
56e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport java.security.cert.CRLException;
66e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport java.security.cert.X509CRLEntry;
76e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport java.util.Date;
86e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport java.util.Enumeration;
96e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport java.util.HashSet;
106e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport java.util.Set;
116e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom
126e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstromimport javax.security.auth.x500.X500Principal;
136e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom
144c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1Encoding;
1570c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstromimport org.bouncycastle.asn1.ASN1Enumerated;
16c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.ASN1InputStream;
174c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.ASN1ObjectIdentifier;
18c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.util.ASN1Dump;
194c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.x500.X500Name;
20c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.x509.CRLReason;
214c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.x509.Extension;
224c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstromimport org.bouncycastle.asn1.x509.Extensions;
23c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.x509.GeneralName;
24c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.x509.GeneralNames;
25c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.x509.TBSCertList;
26c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport org.bouncycastle.asn1.x509.X509Extension;
27c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom
28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam/**
29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * The following extensions are listed in RFC 2459 as relevant to CRL Entries
30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam *
31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * ReasonCode Hode Instruction Code Invalidity Date Certificate Issuer
32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * (critical)
33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */
34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class X509CRLEntryObject extends X509CRLEntry
35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{
36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    private TBSCertList.CRLEntry c;
37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
384c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom    private X500Name certificateIssuer;
39c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    private int           hashValue;
40c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    private boolean       isHashValueSet;
41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public X509CRLEntryObject(TBSCertList.CRLEntry c)
43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this.c = c;
454c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        this.certificateIssuer = null;
46b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
47b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
48b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
49b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Constructor for CRLEntries of indirect CRLs. If <code>isIndirect</code>
50b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * is <code>false</code> {@link #getCertificateIssuer()} will always
51b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * return <code>null</code>, <code>previousCertificateIssuer</code> is
52b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * ignored. If this <code>isIndirect</code> is specified and this CRLEntry
53b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * has no certificate issuer CRL entry extension
54b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * <code>previousCertificateIssuer</code> is returned by
55b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * {@link #getCertificateIssuer()}.
56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *
57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param c
58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *            TBSCertList.CRLEntry object.
59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param isIndirect
60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *            <code>true</code> if the corresponding CRL is a indirect
61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *            CRL.
62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * @param previousCertificateIssuer
63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     *            Certificate issuer of the previous CRLEntry.
64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public X509CRLEntryObject(
66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        TBSCertList.CRLEntry c,
67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        boolean isIndirect,
684c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        X500Name previousCertificateIssuer)
69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        this.c = c;
714c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        this.certificateIssuer = loadCertificateIssuer(isIndirect, previousCertificateIssuer);
72b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
73b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
74b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    /**
75b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     * Will return true if any extensions are present and marked as critical as
764c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom     * we currently don't handle any extensions!
77b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam     */
78b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public boolean hasUnsupportedCriticalExtension()
79b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
80b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        Set extns = getCriticalExtensionOIDs();
81b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
82c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        return extns != null && !extns.isEmpty();
83b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
84b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
854c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom    private X500Name loadCertificateIssuer(boolean isIndirect, X500Name previousCertificateIssuer)
86b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
87b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (!isIndirect)
88b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
89b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            return null;
90b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
91b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
9270c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom        Extension ext = getExtension(Extension.certificateIssuer);
93b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (ext == null)
94b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
95b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            return previousCertificateIssuer;
96b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
97b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
98b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        try
99b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
10070c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom            GeneralName[] names = GeneralNames.getInstance(ext.getParsedValue()).getNames();
101b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            for (int i = 0; i < names.length; i++)
102b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            {
103b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                if (names[i].getTagNo() == GeneralName.directoryName)
104b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                {
1054c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                    return X500Name.getInstance(names[i].getName());
106b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                }
107b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            }
108c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            return null;
109b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
11070c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom        catch (Exception e)
111b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
112c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            return null;
113b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
114b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
115b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
116c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    public X500Principal getCertificateIssuer()
117c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    {
1184c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        if (certificateIssuer == null)
1194c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        {
1204c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom            return null;
1214c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        }
1224c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        try
1234c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        {
1244c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom            return new X500Principal(certificateIssuer.getEncoded());
1254c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        }
1264c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        catch (IOException e)
1274c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        {
1284c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom            return null;
1294c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        }
130c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    }
131c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom
132b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    private Set getExtensionOIDs(boolean critical)
133b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
1344c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        Extensions extensions = c.getExtensions();
135b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
136b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (extensions != null)
137b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
138b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            Set set = new HashSet();
139b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            Enumeration e = extensions.oids();
140b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
141b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            while (e.hasMoreElements())
142b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            {
1434c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
1444c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                Extension ext = extensions.getExtension(oid);
145b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
146b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                if (critical == ext.isCritical())
147b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                {
148b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                    set.add(oid.getId());
149b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                }
150b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            }
151b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
152b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            return set;
153b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
154b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
155b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return null;
156b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
157b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
158b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public Set getCriticalExtensionOIDs()
159b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
160b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return getExtensionOIDs(true);
161b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
162b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
163b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public Set getNonCriticalExtensionOIDs()
164b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
165b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return getExtensionOIDs(false);
166b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
167b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
16870c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom    private Extension getExtension(ASN1ObjectIdentifier oid)
169b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
1704c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        Extensions exts = c.getExtensions();
171b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
172b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (exts != null)
173b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
17470c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom            return exts.getExtension(oid);
17570c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom        }
17670c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom
17770c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom        return null;
17870c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom    }
17970c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom
18070c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom    public byte[] getExtensionValue(String oid)
18170c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom    {
18270c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom        Extension ext = getExtension(new ASN1ObjectIdentifier(oid));
183b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
18470c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom        if (ext != null)
18570c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom        {
18670c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom            try
187b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            {
18870c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom                return ext.getExtnValue().getEncoded();
18970c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom            }
19070c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom            catch (Exception e)
19170c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom            {
19270c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom                throw new RuntimeException("error encoding " + e.toString());
193b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            }
194b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
195b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
196b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return null;
197b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
198b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
199c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    /**
200c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom     * Cache the hashCode value - calculating it with the standard method.
201c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom     * @return  calculated hashCode.
202c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom     */
203c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    public int hashCode()
204c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    {
205c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        if (!isHashValueSet)
206c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        {
207c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            hashValue = super.hashCode();
208c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom            isHashValueSet = true;
209c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        }
210c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom
211c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        return hashValue;
212c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom    }
213c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom
2145db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root    public boolean equals(Object o)
2155db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root    {
2165db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root        if (o == this)
2175db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root        {
2185db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root            return true;
2195db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root        }
2205db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root
2215db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root        if (o instanceof X509CRLEntryObject)
2225db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root        {
2235db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root            X509CRLEntryObject other = (X509CRLEntryObject)o;
2245db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root
2255db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root            return this.c.equals(other.c);
2265db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root        }
2275db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root
2285db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root        return super.equals(this);
2295db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root    }
2305db505e1f6a68c8d5dfdb0fed0b8607dea7bed96Kenny Root
231b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public byte[] getEncoded()
232b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        throws CRLException
233b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
234b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        try
235b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
2364c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom            return c.getEncoded(ASN1Encoding.DER);
237b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
238b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        catch (IOException e)
239b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
240b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            throw new CRLException(e.toString());
241b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
242b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
243b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
244b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public BigInteger getSerialNumber()
245b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
246b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return c.getUserCertificate().getValue();
247b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
248b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
249b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public Date getRevocationDate()
250b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
251b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return c.getRevocationDate().getDate();
252b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
253b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
254b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public boolean hasExtensions()
255b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
256b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return c.getExtensions() != null;
257b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
258b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
259b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    public String toString()
260b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    {
261b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        StringBuffer buf = new StringBuffer();
262b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        String nl = System.getProperty("line.separator");
263b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
264b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        buf.append("      userCertificate: ").append(this.getSerialNumber()).append(nl);
265b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        buf.append("       revocationDate: ").append(this.getRevocationDate()).append(nl);
266c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom        buf.append("       certificateIssuer: ").append(this.getCertificateIssuer()).append(nl);
267b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
2684c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom        Extensions extensions = c.getExtensions();
269b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
270b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        if (extensions != null)
271b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        {
272b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            Enumeration e = extensions.oids();
273b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            if (e.hasMoreElements())
274b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            {
275b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                buf.append("   crlEntryExtensions:").append(nl);
276b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
277b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                while (e.hasMoreElements())
278b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                {
2794c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                    ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier)e.nextElement();
2804c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                    Extension ext = extensions.getExtension(oid);
2814c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                    if (ext.getExtnValue() != null)
282c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                    {
2834c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                        byte[]                  octs = ext.getExtnValue().getOctets();
284c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        ASN1InputStream dIn = new ASN1InputStream(octs);
285c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        buf.append("                       critical(").append(ext.isCritical()).append(") ");
286c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        try
287c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        {
2884c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                            if (oid.equals(X509Extension.reasonCode))
289c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            {
29070c8287138e69a98c2f950036f9f703ee37228c8Brian Carlstrom                                buf.append(CRLReason.getInstance(ASN1Enumerated.getInstance(dIn.readObject()))).append(nl);
291c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            }
2924c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                            else if (oid.equals(X509Extension.certificateIssuer))
293c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            {
2944c111300c39cb2e27f07fc2ae3b00e23ed4443b2Brian Carlstrom                                buf.append("Certificate issuer: ").append(GeneralNames.getInstance(dIn.readObject())).append(nl);
295c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            }
296c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            else
297c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            {
298c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                                buf.append(oid.getId());
299c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                                buf.append(" value = ").append(ASN1Dump.dumpAsString(dIn.readObject())).append(nl);
300c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            }
301c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        }
302c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        catch (Exception ex)
303c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        {
304c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            buf.append(oid.getId());
305c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                            buf.append(" value = ").append("*****").append(nl);
306c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        }
307c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                    }
308c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                    else
309c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                    {
310c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                        buf.append(nl);
311c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom                    }
312b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam                }
313b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam            }
314b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        }
315b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam
316b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam        return buf.toString();
317b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam    }
318b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam}
319