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