jdk/src/share/classes/sun/security/x509/X509CRLEntryImpl.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.x509;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.cert.CRLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.CRLReason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.cert.X509CRLEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.misc.HexDumpEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>Abstract class for a revoked certificate in a CRL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * This class is for each entry in the <code>revokedCertificates</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * so it deals with the inner <em>SEQUENCE</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * revokedCertificates    SEQUENCE OF SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *     userCertificate    CertificateSerialNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *     revocationDate     ChoiceOfTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *     crlEntryExtensions Extensions OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *                        -- if present, must be v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * }  OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * CertificateSerialNumber  ::=  INTEGER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Extension  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *     extnId        OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *     critical      BOOLEAN DEFAULT FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *     extnValue     OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *                   -- contains a DER encoding of a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *                   -- of the type registered for use with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *                   -- the extnId object identifier value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
public class X509CRLEntryImpl extends X509CRLEntry {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private SerialNumber serialNumber = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private Date revocationDate = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private CRLExtensions extensions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private byte[] revokedCert = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private X500Principal certIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private final static boolean isExplicit = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final long YR_2050 = 2524636800000L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Constructs a revoked certificate entry using the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * serial number and revocation date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param num the serial number of the revoked certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param date the Date on which revocation took place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public X509CRLEntryImpl(BigInteger num, Date date) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        this.serialNumber = new SerialNumber(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.revocationDate = date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Constructs a revoked certificate entry using the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * serial number, revocation date and the entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param num the serial number of the revoked certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param date the Date on which revocation took place.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param crlEntryExts the extensions for this entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public X509CRLEntryImpl(BigInteger num, Date date,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                           CRLExtensions crlEntryExts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.serialNumber = new SerialNumber(num);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this.revocationDate = date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        this.extensions = crlEntryExts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Unmarshals a revoked certificate from its encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param revokedCert the encoded bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public X509CRLEntryImpl(byte[] revokedCert) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            parse(new DerValue(revokedCert));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            this.revokedCert = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            throw new CRLException("Parsing error: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Unmarshals a revoked certificate from its encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @param derVal the DER value containing the revoked certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public X509CRLEntryImpl(DerValue derValue) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            parse(derValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            revokedCert = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new CRLException("Parsing error: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Returns true if this revoked certificate entry has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * extensions, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @return true if this CRL entry has extensions, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public boolean hasExtensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return (extensions != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Encodes the revoked certificate to an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param outStrm an output stream to which the encoded revoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * certificate is written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @exception CRLException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void encode(DerOutputStream outStrm) throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (revokedCert == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                // sequence { serialNumber, revocationDate, extensions }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                serialNumber.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                if (revocationDate.getTime() < YR_2050) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    tmp.putUTCTime(revocationDate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    tmp.putGeneralizedTime(revocationDate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                if (extensions != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    extensions.encode(tmp, isExplicit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                DerOutputStream seq = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                seq.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                revokedCert = seq.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            outStrm.write(revokedCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
             throw new CRLException("Encoding error: " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Returns the ASN.1 DER-encoded form of this CRL Entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * which corresponds to the inner SEQUENCE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @exception CRLException if an encoding error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public byte[] getEncoded() throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (revokedCert == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            this.encode(new DerOutputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return revokedCert.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public X500Principal getCertificateIssuer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return certIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    void setCertificateIssuer(X500Principal crlIssuer, X500Principal certIssuer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (crlIssuer.equals(certIssuer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            this.certIssuer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            this.certIssuer = certIssuer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Gets the serial number from this X509CRLEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * i.e. the <em>userCertificate</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return the serial number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public BigInteger getSerialNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return serialNumber.getNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Gets the revocation date from this X509CRLEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * the <em>revocationDate</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @return the revocation date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public Date getRevocationDate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return new Date(revocationDate.getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * This method is the overridden implementation of the getRevocationReason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * method in X509CRLEntry. It is better performance-wise since it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * cached values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public CRLReason getRevocationReason() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Extension ext = getExtension(PKIXExtensions.ReasonCode_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (ext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        CRLReasonCodeExtension rcExt = (CRLReasonCodeExtension) ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return rcExt.getReasonCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * This static method is the default implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * getRevocationReason method in X509CRLEntry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public static CRLReason getRevocationReason(X509CRLEntry crlEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            byte[] ext = crlEntry.getExtensionValue("2.5.29.21");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (ext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            DerValue val = new DerValue(ext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            byte[] data = val.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            CRLReasonCodeExtension rcExt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                new CRLReasonCodeExtension(Boolean.FALSE, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return rcExt.getReasonCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * get Reason Code from CRL entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @returns Integer or null, if no such extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @throws IOException on error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public Integer getReasonCode() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        Object obj = getExtension(PKIXExtensions.ReasonCode_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (obj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        CRLReasonCodeExtension reasonCode = (CRLReasonCodeExtension)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return (Integer)(reasonCode.get(reasonCode.REASON));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Returns a printable string of this revoked certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @return value of this revoked certificate in a printable form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        sb.append(serialNumber.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        sb.append("  On: " + revocationDate.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (certIssuer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            sb.append("\n    Certificate issuer: " + certIssuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (extensions != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            Collection allEntryExts = extensions.getAllExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            Object[] objs = allEntryExts.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            sb.append("\n    CRL Entry Extensions: " + objs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            for (int i = 0; i < objs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                sb.append("\n    [" + (i+1) + "]: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                Extension ext = (Extension)objs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    if (OIDMap.getClass(ext.getExtensionId()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        sb.append(ext.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        byte[] extValue = ext.getExtensionValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                        if (extValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                            out.putOctetString(extValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                            extValue = out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                            HexDumpEncoder enc = new HexDumpEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                            sb.append("Extension unknown: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                      + "DER encoded OCTET string =\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                      + enc.encodeBuffer(extValue) + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                        sb.append(ext.toString()); //sub-class exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    sb.append(", Error parsing this extension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        sb.append("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Return true if a critical extension is found that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * not supported, otherwise return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public boolean hasUnsupportedCriticalExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return extensions.hasUnsupportedCriticalExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * Gets a Set of the extension(s) marked CRITICAL in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * X509CRLEntry.  In the returned set, each extension is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * represented by its OID string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @return a set of the extension oid strings in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * Object that are marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public Set<String> getCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        Set<String> extSet = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        for (Extension ex : extensions.getAllExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (ex.isCritical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                extSet.add(ex.getExtensionId().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return extSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Gets a Set of the extension(s) marked NON-CRITICAL in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * X509CRLEntry. In the returned set, each extension is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * represented by its OID string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @return a set of the extension oid strings in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Object that are marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public Set<String> getNonCriticalExtensionOIDs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        Set<String> extSet = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        for (Extension ex : extensions.getAllExtensions()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (!ex.isCritical()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                extSet.add(ex.getExtensionId().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return extSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Gets the DER encoded OCTET string for the extension value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * (<em>extnValue</em>) identified by the passed in oid String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * The <code>oid</code> string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * represented by a set of positive whole number separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * by ".", that means,<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * &lt;positive whole number&gt;.&lt;positive whole number&gt;.&lt;positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * whole number&gt;.&lt;...&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param oid the Object Identifier value for the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @return the DER encoded octet string of the extension value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public byte[] getExtensionValue(String oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            String extAlias = OIDMap.getName(new ObjectIdentifier(oid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            Extension crlExt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            if (extAlias == null) { // may be unknown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                ObjectIdentifier findOID = new ObjectIdentifier(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                Extension ex = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                ObjectIdentifier inCertOID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                for (Enumeration<Extension> e = extensions.getElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                                 e.hasMoreElements();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    ex = e.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    inCertOID = ex.getExtensionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    if (inCertOID.equals(findOID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                        crlExt = ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                crlExt = extensions.get(extAlias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            if (crlExt == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            byte[] extData = crlExt.getExtensionValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            if (extData == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            out.putOctetString(extData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            return out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * get an extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @param oid ObjectIdentifier of extension desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @returns Extension of type <extension> or null, if not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public Extension getExtension(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        // following returns null if no such OID in map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        //XXX consider cloning this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return extensions.get(OIDMap.getName(oid));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    private void parse(DerValue derVal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    throws CRLException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (derVal.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            throw new CRLException("Invalid encoded RevokedCertificate, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                  "starting sequence tag missing.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (derVal.data.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            throw new CRLException("No data encoded for RevokedCertificates");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        revokedCert = derVal.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        // serial number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        DerInputStream in = derVal.toDerInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        DerValue val = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        this.serialNumber = new SerialNumber(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        // revocationDate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        int nextByte = derVal.data.peekByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        if ((byte)nextByte == DerValue.tag_UtcTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            this.revocationDate = derVal.data.getUTCTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        } else if ((byte)nextByte == DerValue.tag_GeneralizedTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            this.revocationDate = derVal.data.getGeneralizedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            throw new CRLException("Invalid encoding for revocation date");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (derVal.data.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            return;  // no extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        // crlEntryExtensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        this.extensions = new CRLExtensions(derVal.toDerInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Utility method to convert an arbitrary instance of X509CRLEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * to a X509CRLEntryImpl. Does a cast if possible, otherwise reparses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * the encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public static X509CRLEntryImpl toImpl(X509CRLEntry entry)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (entry instanceof X509CRLEntryImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            return (X509CRLEntryImpl)entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return new X509CRLEntryImpl(entry.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * Returns the CertificateIssuerExtension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @return the CertificateIssuerExtension, or null if it does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    CertificateIssuerExtension getCertificateIssuerExtension() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return (CertificateIssuerExtension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            getExtension(PKIXExtensions.CertificateIssuer_Id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public Map<String, java.security.cert.Extension> getExtensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        Collection<Extension> exts = extensions.getAllExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        HashMap<String, java.security.cert.Extension> map =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            new HashMap<String, java.security.cert.Extension>(exts.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        for (Extension ext : exts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            map.put(ext.getId(), ext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
}