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