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