jdk/src/share/classes/sun/security/x509/X509CertInfo.java
author mullan
Fri, 07 Sep 2012 12:49:04 -0400
changeset 13789 639c51fe428c
parent 10336 0bb1999251f8
child 14342 8435a30053c1
permissions -rw-r--r--
4647343: IDENT variable in sun.security.x509 classes not used Reviewed-by: mullan Contributed-by: jason.uh@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.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.misc.HexDumpEncoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The X509CertInfo class represents X.509 certificate information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <P>X.509 certificates have several base data elements, including:<UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <LI>The <em>Subject Name</em>, an X.500 Distinguished Name for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *      the entity (subject) for which the certificate was issued.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <LI>The <em>Subject Public Key</em>, the public key of the subject.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      This is one of the most important parts of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <LI>The <em>Validity Period</em>, a time period (e.g. six months)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *      within which the certificate is valid (unless revoked).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <LI>The <em>Issuer Name</em>, an X.500 Distinguished Name for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      Certificate Authority (CA) which issued the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <LI>A <em>Serial Number</em> assigned by the CA, for use in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      certificate revocation and other applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @see CertAttrSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see X509CertImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class X509CertInfo implements CertAttrSet<String> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Identifier for this attribute, to be used with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * get, set, delete methods of Certificate, x509 type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static final String IDENT = "x509.info";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    // Certificate attribute names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static final String NAME = "info";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final String VERSION = CertificateVersion.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final String SERIAL_NUMBER = CertificateSerialNumber.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static final String ALGORITHM_ID = CertificateAlgorithmId.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final String ISSUER = CertificateIssuerName.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final String VALIDITY = CertificateValidity.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public static final String SUBJECT = CertificateSubjectName.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final String KEY = CertificateX509Key.NAME;
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
    78
    public static final String ISSUER_ID = "issuerID";
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
    79
    public static final String SUBJECT_ID = "subjectID";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final String EXTENSIONS = CertificateExtensions.NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // X509.v1 data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected CertificateVersion version = new CertificateVersion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    protected CertificateSerialNumber   serialNum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected CertificateAlgorithmId    algId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    protected CertificateIssuerName     issuer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    protected CertificateValidity       interval = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected CertificateSubjectName    subject = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    protected CertificateX509Key        pubKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // X509.v2 & v3 extensions
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
    92
    protected UniqueIdentity   issuerUniqueId = null;
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
    93
    protected UniqueIdentity  subjectUniqueId = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // X509.v3 extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected CertificateExtensions     extensions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    // Attribute numbers for internal manipulation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final int ATTR_VERSION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static final int ATTR_SERIAL = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private static final int ATTR_ALGORITHM = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static final int ATTR_ISSUER = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static final int ATTR_VALIDITY = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final int ATTR_SUBJECT = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static final int ATTR_KEY = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static final int ATTR_ISSUER_ID = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static final int ATTR_SUBJECT_ID = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static final int ATTR_EXTENSIONS = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // DER encoded CertificateInfo data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private byte[]      rawCertInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // The certificate attribute name to integer mapping stored here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static final Map<String,Integer> map = new HashMap<String,Integer>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        map.put(VERSION, Integer.valueOf(ATTR_VERSION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        map.put(SERIAL_NUMBER, Integer.valueOf(ATTR_SERIAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        map.put(ALGORITHM_ID, Integer.valueOf(ATTR_ALGORITHM));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        map.put(ISSUER, Integer.valueOf(ATTR_ISSUER));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        map.put(VALIDITY, Integer.valueOf(ATTR_VALIDITY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        map.put(SUBJECT, Integer.valueOf(ATTR_SUBJECT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        map.put(KEY, Integer.valueOf(ATTR_KEY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        map.put(ISSUER_ID, Integer.valueOf(ATTR_ISSUER_ID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        map.put(SUBJECT_ID, Integer.valueOf(ATTR_SUBJECT_ID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        map.put(EXTENSIONS, Integer.valueOf(ATTR_EXTENSIONS));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Construct an uninitialized X509CertInfo on which <a href="#decode">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * decode</a> must later be called (or which may be deserialized).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public X509CertInfo() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Unmarshals a certificate from its encoded form, parsing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * encoded bytes.  This form of constructor is used by agents which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * need to examine and use certificate contents.  That is, this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * one of the more commonly used constructors.  Note that the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * must include only a certificate, and no "garbage" may be left at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * the end.  If you need to ignore data at the end of a certificate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * use another constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param cert the encoded bytes, with no trailing data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @exception CertificateParsingException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public X509CertInfo(byte[] cert) throws CertificateParsingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            DerValue    in = new DerValue(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            parse(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        } catch (IOException e) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   152
            throw new CertificateParsingException(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
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
     * Unmarshal a certificate from its encoded form, parsing a DER value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * This form of constructor is used by agents which need to examine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * and use certificate contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param derVal the der value containing the encoded cert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @exception CertificateParsingException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public X509CertInfo(DerValue derVal) throws CertificateParsingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            parse(derVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        } catch (IOException e) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   168
            throw new CertificateParsingException(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Appends the certificate to an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param out an output stream to which the certificate is appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @exception CertificateException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @exception IOException on other errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void encode(OutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    throws CertificateException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (rawCertInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            emit(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            rawCertInfo = tmp.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        out.write(rawCertInfo.clone());
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
     * Return an enumeration of names of attributes existing within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public Enumeration<String> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        AttributeNameEnumeration elements = new AttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        elements.addElement(VERSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        elements.addElement(SERIAL_NUMBER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        elements.addElement(ALGORITHM_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        elements.addElement(ISSUER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        elements.addElement(VALIDITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        elements.addElement(SUBJECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        elements.addElement(KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        elements.addElement(ISSUER_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        elements.addElement(SUBJECT_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        elements.addElement(EXTENSIONS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        return elements.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Return the name of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return(NAME);
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
     * Returns the encoded certificate info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @exception CertificateEncodingException on encoding information errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public byte[] getEncodedInfo() throws CertificateEncodingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (rawCertInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                emit(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                rawCertInfo = tmp.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            return rawCertInfo.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            throw new CertificateEncodingException(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            throw new CertificateEncodingException(e.toString());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Compares two X509CertInfo objects.  This is false if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * certificates are not both X.509 certs, otherwise it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * compares them as binary data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param other the object being compared with this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @return true iff the certificates are equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (other instanceof X509CertInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return equals((X509CertInfo) other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
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
     * Compares two certificates, returning false if any data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * differs between the two.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @param other the object being compared with this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @return true iff the certificates are equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public boolean equals(X509CertInfo other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            return(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        } else if (rawCertInfo == null || other.rawCertInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            return(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        } else if (rawCertInfo.length != other.rawCertInfo.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        for (int i = 0; i < rawCertInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (rawCertInfo[i] != other.rawCertInfo[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                return(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Calculates a hash code value for the object.  Objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * which are equal will also have the same hashcode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        int     retval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        for (int i = 1; i < rawCertInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            retval += rawCertInfo[i] * i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return(retval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Returns a printable representation of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (subject == null || pubKey == null || interval == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            || issuer == null || algId == null || serialNum == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                throw new NullPointerException("X.509 cert is incomplete");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        sb.append("[\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        sb.append("  " + version.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        sb.append("  Subject: " + subject.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        sb.append("  Signature Algorithm: " + algId.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        sb.append("  Key:  " + pubKey.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        sb.append("  " + interval.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        sb.append("  Issuer: " + issuer.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        sb.append("  " + serialNum.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // optional v2, v3 extras
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (issuerUniqueId != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            sb.append("  Issuer Id:\n" + issuerUniqueId.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (subjectUniqueId != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            sb.append("  Subject Id:\n" + subjectUniqueId.toString() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (extensions != null) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   316
            Collection<Extension> allExts = extensions.getAllExtensions();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   317
            Extension[] exts = allExts.toArray(new Extension[0]);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   318
            sb.append("\nCertificate Extensions: " + exts.length);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   319
            for (int i = 0; i < exts.length; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                sb.append("\n[" + (i+1) + "]: ");
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   321
                Extension ext = exts[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    if (OIDMap.getClass(ext.getExtensionId()) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        sb.append(ext.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        byte[] extValue = ext.getExtensionValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                        if (extValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                            DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                            out.putOctetString(extValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                            extValue = out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                            HexDumpEncoder enc = new HexDumpEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                            sb.append("Extension unknown: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                      + "DER encoded OCTET string =\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                      + enc.encodeBuffer(extValue) + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        sb.append(ext.toString()); //sub-class exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    sb.append(", Error parsing this extension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            Map<String,Extension> invalid = extensions.getUnparseableExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            if (invalid.isEmpty() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                sb.append("\nUnparseable certificate extensions: " + invalid.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                int i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                for (Extension ext : invalid.values()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    sb.append("\n[" + (i++) + "]: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    sb.append(ext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        sb.append("\n]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Set the certificate attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @params name the name of the Certificate attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @params val the value of the Certificate attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @exception CertificateException on invalid attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @exception IOException on other errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public void set(String name, Object val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    throws CertificateException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        X509AttributeName attrName = new X509AttributeName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        int attr = attributeMap(attrName.getPrefix());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        if (attr == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            throw new CertificateException("Attribute name not recognized: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                           + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        // set rawCertInfo to null, so that we are forced to re-encode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        rawCertInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        String suffix = attrName.getSuffix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        switch (attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        case ATTR_VERSION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                setVersion(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                version.set(suffix, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        case ATTR_SERIAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                setSerialNumber(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                serialNum.set(suffix, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        case ATTR_ALGORITHM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                setAlgorithmId(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                algId.set(suffix, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        case ATTR_ISSUER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                setIssuer(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                issuer.set(suffix, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        case ATTR_VALIDITY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                setValidity(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                interval.set(suffix, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        case ATTR_SUBJECT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                setSubject(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                subject.set(suffix, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        case ATTR_KEY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                setKey(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                pubKey.set(suffix, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        case ATTR_ISSUER_ID:
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   434
            setIssuerUniqueId(val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        case ATTR_SUBJECT_ID:
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   438
            setSubjectUniqueId(val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        case ATTR_EXTENSIONS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                setExtensions(val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (extensions == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    extensions = new CertificateExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                extensions.set(suffix, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Delete the certificate attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @params name the name of the Certificate attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @exception CertificateException on invalid attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @exception IOException on other errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public void delete(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    throws CertificateException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        X509AttributeName attrName = new X509AttributeName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        int attr = attributeMap(attrName.getPrefix());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (attr == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            throw new CertificateException("Attribute name not recognized: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                           + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        // set rawCertInfo to null, so that we are forced to re-encode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        rawCertInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        String suffix = attrName.getSuffix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        switch (attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        case ATTR_VERSION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                version = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                version.delete(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        case (ATTR_SERIAL):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                serialNum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                serialNum.delete(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        case (ATTR_ALGORITHM):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                algId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                algId.delete(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        case (ATTR_ISSUER):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                issuer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                issuer.delete(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        case (ATTR_VALIDITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                interval = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                interval.delete(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        case (ATTR_SUBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                subject = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                subject.delete(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        case (ATTR_KEY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                pubKey = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                pubKey.delete(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        case (ATTR_ISSUER_ID):
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   524
            issuerUniqueId = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        case (ATTR_SUBJECT_ID):
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   527
            subjectUniqueId = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        case (ATTR_EXTENSIONS):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                extensions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                if (extensions != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                   extensions.delete(suffix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * Get the certificate attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @params name the name of the Certificate attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @exception CertificateException on invalid attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @exception IOException on other errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public Object get(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    throws CertificateException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        X509AttributeName attrName = new X509AttributeName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        int attr = attributeMap(attrName.getPrefix());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (attr == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            throw new CertificateParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                          "Attribute name not recognized: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        String suffix = attrName.getSuffix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        switch (attr) { // frequently used attributes first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        case (ATTR_EXTENSIONS):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                return(extensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    return(extensions.get(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        case (ATTR_SUBJECT):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                return(subject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                return(subject.get(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        case (ATTR_ISSUER):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                return(issuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                return(issuer.get(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        case (ATTR_KEY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                return(pubKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                return(pubKey.get(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        case (ATTR_ALGORITHM):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                return(algId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                return(algId.get(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        case (ATTR_VALIDITY):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                return(interval);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                return(interval.get(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        case (ATTR_VERSION):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                return(version);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                return(version.get(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        case (ATTR_SERIAL):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (suffix == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                return(serialNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                return(serialNum.get(suffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        case (ATTR_ISSUER_ID):
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   613
            return(issuerUniqueId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        case (ATTR_SUBJECT_ID):
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   615
            return(subjectUniqueId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * This routine unmarshals the certificate information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    private void parse(DerValue val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    throws CertificateParsingException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        DerInputStream  in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        DerValue        tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            throw new CertificateParsingException("signed fields invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        rawCertInfo = val.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        in = val.data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        // Version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        tmp = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        if (tmp.isContextSpecific((byte)0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            version = new CertificateVersion(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            tmp = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        // Serial number ... an integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        serialNum = new CertificateSerialNumber(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        // Algorithm Identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        algId = new CertificateAlgorithmId(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        // Issuer name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        issuer = new CertificateIssuerName(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        X500Name issuerDN = (X500Name)issuer.get(CertificateIssuerName.DN_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        if (issuerDN.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            throw new CertificateParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                "Empty issuer DN not allowed in X509Certificates");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        // validity:  SEQUENCE { start date, end date }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        interval = new CertificateValidity(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        // subject name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        subject = new CertificateSubjectName(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        X500Name subjectDN = (X500Name)subject.get(CertificateSubjectName.DN_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        if ((version.compare(CertificateVersion.V1) == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                subjectDN.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            throw new CertificateParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                      "Empty subject DN not allowed in v1 certificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        // public key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        pubKey = new CertificateX509Key(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        // If more data available, make sure version is not v1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        if (in.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            if (version.compare(CertificateVersion.V1) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                throw new CertificateParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                          "no more data allowed for version 1 certificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        // Get the issuerUniqueId if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        tmp = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        if (tmp.isContextSpecific((byte)1)) {
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   684
            issuerUniqueId = new UniqueIdentity(tmp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            if (in.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            tmp = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        // Get the subjectUniqueId if present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if (tmp.isContextSpecific((byte)2)) {
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   692
            subjectUniqueId = new UniqueIdentity(tmp);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            if (in.available() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            tmp = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        // Get the extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        if (version.compare(CertificateVersion.V3) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            throw new CertificateParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                      "Extensions not allowed in v2 certificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        if (tmp.isConstructed() && tmp.isContextSpecific((byte)3)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            extensions = new CertificateExtensions(tmp.data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        // verify X.509 V3 Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        verifyCert(subject, extensions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * Verify if X.509 V3 Certificate is compliant with RFC 3280.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    private void verifyCert(CertificateSubjectName subject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        CertificateExtensions extensions)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        throws CertificateParsingException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        // if SubjectName is empty, check for SubjectAlternativeNameExtension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        X500Name subjectDN = (X500Name)subject.get(CertificateSubjectName.DN_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        if (subjectDN.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            if (extensions == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                throw new CertificateParsingException("X.509 Certificate is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                        "incomplete: subject field is empty, and certificate " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                        "has no extensions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            SubjectAlternativeNameExtension subjectAltNameExt = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            SubjectAlternativeNameExtension extValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            GeneralNames names = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                subjectAltNameExt = (SubjectAlternativeNameExtension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                        extensions.get(SubjectAlternativeNameExtension.NAME);
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   733
                names = subjectAltNameExt.get(
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   734
                        SubjectAlternativeNameExtension.SUBJECT_NAME);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                throw new CertificateParsingException("X.509 Certificate is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                        "incomplete: subject field is empty, and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                        "SubjectAlternativeName extension is absent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            // SubjectAlternativeName extension is empty or not marked critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            if (names == null || names.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                throw new CertificateParsingException("X.509 Certificate is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                        "incomplete: subject field is empty, and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                        "SubjectAlternativeName extension is empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            } else if (subjectAltNameExt.isCritical() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                throw new CertificateParsingException("X.509 Certificate is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                        "incomplete: SubjectAlternativeName extension MUST " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                        "be marked critical when subject field is empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * Marshal the contents of a "raw" certificate into a DER sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    private void emit(DerOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    throws CertificateException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        // version number, iff not V1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        version.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        // Encode serial number, issuer signing algorithm, issuer name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        // and validity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        serialNum.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        algId.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        if ((version.compare(CertificateVersion.V1) == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            (issuer.toString() == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            throw new CertificateParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                      "Null issuer DN not allowed in v1 certificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        issuer.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        interval.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        // Encode subject (principal) and associated key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        if ((version.compare(CertificateVersion.V1) == 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            (subject.toString() == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            throw new CertificateParsingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                      "Null subject DN not allowed in v1 certificate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        subject.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        pubKey.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        // Encode issuerUniqueId & subjectUniqueId.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if (issuerUniqueId != null) {
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   787
            issuerUniqueId.encode(tmp, DerValue.createTag(DerValue.TAG_CONTEXT,
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   788
                                                          false,(byte)1));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if (subjectUniqueId != null) {
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   791
            subjectUniqueId.encode(tmp, DerValue.createTag(DerValue.TAG_CONTEXT,
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   792
                                                           false,(byte)2));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        // Write all the extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        if (extensions != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            extensions.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        // Wrap the data; encoding of the "raw" cert is now complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        out.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * Returns the integer attribute number for the passed attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    private int attributeMap(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        Integer num = map.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        if (num == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        return num.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * Set the version number of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @params val the Object class value for the Extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @exception CertificateException on invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    private void setVersion(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        if (!(val instanceof CertificateVersion)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            throw new CertificateException("Version class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        version = (CertificateVersion)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * Set the serial number of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @params val the Object class value for the CertificateSerialNumber
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @exception CertificateException on invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    private void setSerialNumber(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        if (!(val instanceof CertificateSerialNumber)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            throw new CertificateException("SerialNumber class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        serialNum = (CertificateSerialNumber)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * Set the algorithm id of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @params val the Object class value for the AlgorithmId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @exception CertificateException on invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    private void setAlgorithmId(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        if (!(val instanceof CertificateAlgorithmId)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                             "AlgorithmId class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        algId = (CertificateAlgorithmId)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * Set the issuer name of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @params val the Object class value for the issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @exception CertificateException on invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    private void setIssuer(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        if (!(val instanceof CertificateIssuerName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                             "Issuer class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        issuer = (CertificateIssuerName)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * Set the validity interval of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * @params val the Object class value for the CertificateValidity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @exception CertificateException on invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    private void setValidity(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        if (!(val instanceof CertificateValidity)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                             "CertificateValidity class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        interval = (CertificateValidity)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * Set the subject name of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @params val the Object class value for the Subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @exception CertificateException on invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    private void setSubject(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        if (!(val instanceof CertificateSubjectName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                             "Subject class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        subject = (CertificateSubjectName)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * Set the public key in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @params val the Object class value for the PublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @exception CertificateException on invalid data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    private void setKey(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        if (!(val instanceof CertificateX509Key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                             "Key class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        pubKey = (CertificateX509Key)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * Set the Issuer Unique Identity in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @params val the Object class value for the IssuerUniqueId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @exception CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    private void setIssuerUniqueId(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        if (version.compare(CertificateVersion.V2) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            throw new CertificateException("Invalid version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        }
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   921
        if (!(val instanceof UniqueIdentity)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                             "IssuerUniqueId class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   925
        issuerUniqueId = (UniqueIdentity)val;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * Set the Subject Unique Identity in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * @params val the Object class value for the SubjectUniqueId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @exception CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    private void setSubjectUniqueId(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if (version.compare(CertificateVersion.V2) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            throw new CertificateException("Invalid version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        }
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   938
        if (!(val instanceof UniqueIdentity)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                             "SubjectUniqueId class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
13789
639c51fe428c 4647343: IDENT variable in sun.security.x509 classes not used
mullan
parents: 10336
diff changeset
   942
        subjectUniqueId = (UniqueIdentity)val;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * Set the extensions in the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * @params val the Object class value for the Extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @exception CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    private void setExtensions(Object val) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        if (version.compare(CertificateVersion.V3) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            throw new CertificateException("Invalid version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        if (!(val instanceof CertificateExtensions)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
          throw new CertificateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                             "Extensions class type invalid.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        extensions = (CertificateExtensions)val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
}