src/java.base/share/classes/sun/security/x509/AuthorityKeyIdentifierExtension.java
author igerasim
Tue, 02 Oct 2018 10:19:07 -0700
changeset 51986 c1db377f6300
parent 47216 71c04702a3d5
permissions -rw-r--r--
8200381: Typos in javadoc - missing verb "be" and alike Reviewed-by: lancea, darcy, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2067
diff changeset
     2
 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2067
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2067
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2067
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2067
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2067
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.x509;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This class represents the Authority Key Identifier Extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>The authority key identifier extension provides a means of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * identifying the particular public key used to sign a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This extension would be used where an issuer has multiple signing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * keys (either due to multiple concurrent key pairs or due to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * changeover).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The ASN.1 syntax for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * AuthorityKeyIdentifier ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *    keyIdentifier             [0] KeyIdentifier           OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *    authorityCertIssuer       [1] GeneralNames            OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *    authorityCertSerialNumber [2] CertificateSerialNumber OPTIONAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * KeyIdentifier ::= OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see CertAttrSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class AuthorityKeyIdentifierExtension extends Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
implements CertAttrSet<String> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Identifier for this attribute, to be used with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * get, set, delete methods of Certificate, x509 type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static final String IDENT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                         "x509.info.extensions.AuthorityKeyIdentifier";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Attribute names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static final String NAME = "AuthorityKeyIdentifier";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final String KEY_ID = "key_id";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public static final String AUTH_NAME = "auth_name";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public static final String SERIAL_NUMBER = "serial_number";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // Private data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final byte TAG_ID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final byte TAG_NAMES = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static final byte TAG_SERIAL_NUM = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private KeyIdentifier       id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private GeneralNames        names = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private SerialNumber        serialNum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    // Encode only the extension value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private void encodeThis() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (id == null && names == null && serialNum == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            this.extensionValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        DerOutputStream seq = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (id != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            DerOutputStream tmp1 = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            id.encode(tmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                              false, TAG_ID), tmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            if (names != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                DerOutputStream tmp1 = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                names.encode(tmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                  true, TAG_NAMES), tmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            throw new IOException(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (serialNum != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            DerOutputStream tmp1 = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            serialNum.encode(tmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                              false, TAG_SERIAL_NUM), tmp1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        seq.write(DerValue.tag_Sequence, tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this.extensionValue = seq.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * The default constructor for this extension.  Null parameters make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * the element optional (not present).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   120
     * @param kid the KeyIdentifier associated with this extension.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param names the GeneralNames associated with this extension
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   122
     * @param sn the CertificateSerialNumber associated with
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   123
     *        this extension.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   126
    public AuthorityKeyIdentifierExtension(KeyIdentifier kid, GeneralNames names,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                           SerialNumber sn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this.id = kid;
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 25859
diff changeset
   130
        this.names = names;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.serialNum = sn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        this.extensionId = PKIXExtensions.AuthorityKey_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        this.critical = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * Create the extension from the passed DER encoded value of the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param critical true if the extension is to be treated as critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param value an array of DER encoded bytes of the actual value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @exception ClassCastException if value is not an array of bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public AuthorityKeyIdentifierExtension(Boolean critical, Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        this.extensionId = PKIXExtensions.AuthorityKey_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        this.critical = critical.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        this.extensionValue = (byte[]) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        DerValue val = new DerValue(this.extensionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            throw new IOException("Invalid encoding for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                  "AuthorityKeyIdentifierExtension.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        // Note that all the fields in AuthorityKeyIdentifier are defined as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // being OPTIONAL, i.e., there could be an empty SEQUENCE, resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // in val.data being null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        while ((val.data != null) && (val.data.available() != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            DerValue opt = val.data.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            // NB. this is always encoded with the IMPLICIT tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            // The checks only make sense if we assume implicit tagging,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            // with explicit tagging the form is always constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            if (opt.isContextSpecific(TAG_ID) && !opt.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                if (id != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    throw new IOException("Duplicate KeyIdentifier in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                          "AuthorityKeyIdentifier.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                opt.resetTag(DerValue.tag_OctetString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                id = new KeyIdentifier(opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            } else if (opt.isContextSpecific(TAG_NAMES) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                       opt.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                if (names != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    throw new IOException("Duplicate GeneralNames in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                          "AuthorityKeyIdentifier.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                opt.resetTag(DerValue.tag_Sequence);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                names = new GeneralNames(opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            } else if (opt.isContextSpecific(TAG_SERIAL_NUM) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                       !opt.isConstructed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                if (serialNum != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    throw new IOException("Duplicate SerialNumber in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                          "AuthorityKeyIdentifier.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                opt.resetTag(DerValue.tag_Integer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                serialNum = new SerialNumber(opt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                throw new IOException("Invalid encoding of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                      "AuthorityKeyIdentifierExtension.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
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 the object as a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public String toString() {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   199
        StringBuilder sb = new StringBuilder();
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   200
        sb.append(super.toString())
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   201
            .append("AuthorityKeyIdentifier [\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (id != null) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   203
            sb.append(id);       // id already has a newline
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (names != null) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   206
            sb.append(names).append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        if (serialNum != null) {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   209
            sb.append(serialNum).append('\n');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        }
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   211
        sb.append("]\n");
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 30374
diff changeset
   212
        return sb.toString();
2
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
     * Write the extension to the OutputStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param out the OutputStream to write the extension to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void encode(OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (this.extensionValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            extensionId = PKIXExtensions.AuthorityKey_Id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            critical = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        super.encode(tmp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        out.write(tmp.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Set the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void set(String name, Object obj) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (name.equalsIgnoreCase(KEY_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            if (!(obj instanceof KeyIdentifier)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
              throw new IOException("Attribute value should be of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                                    "type KeyIdentifier.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            id = (KeyIdentifier)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } else if (name.equalsIgnoreCase(AUTH_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (!(obj instanceof GeneralNames)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
              throw new IOException("Attribute value should be of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                    "type GeneralNames.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            names = (GeneralNames)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        } else if (name.equalsIgnoreCase(SERIAL_NUMBER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (!(obj instanceof SerialNumber)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
              throw new IOException("Attribute value should be of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                    "type SerialNumber.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            serialNum = (SerialNumber)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        "CertAttrSet:AuthorityKeyIdentifier.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        encodeThis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Get the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public Object get(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (name.equalsIgnoreCase(KEY_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return (id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        } else if (name.equalsIgnoreCase(AUTH_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return (names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        } else if (name.equalsIgnoreCase(SERIAL_NUMBER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            return (serialNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                        "CertAttrSet:AuthorityKeyIdentifier.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Delete the attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void delete(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (name.equalsIgnoreCase(KEY_ID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            id = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        } else if (name.equalsIgnoreCase(AUTH_NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            names = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } else if (name.equalsIgnoreCase(SERIAL_NUMBER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            serialNum = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
          throw new IOException("Attribute name not recognized by " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        "CertAttrSet:AuthorityKeyIdentifier.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        encodeThis();
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
     * Return an enumeration of names of attributes existing within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public Enumeration<String> getElements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        AttributeNameEnumeration elements = new AttributeNameEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        elements.addElement(KEY_ID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        elements.addElement(AUTH_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        elements.addElement(SERIAL_NUMBER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return (elements.elements());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Return the name of this attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return (NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
33820
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   313
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   314
    /**
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   315
     * Return the encoded key identifier, or null if not specified.
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   316
     */
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   317
    public byte[] getEncodedKeyIdentifier() throws IOException {
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   318
        if (id != null) {
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   319
            DerOutputStream derOut = new DerOutputStream();
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   320
            id.encode(derOut);
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   321
            return derOut.toByteArray();
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   322
        }
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   323
        return null;
be91931ea4b2 8072463: Remove requirement that AKID and SKID have to match when building certificate chain
mullan
parents: 30649
diff changeset
   324
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}