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