src/java.base/share/classes/sun/security/x509/AlgorithmId.java
author darcy
Wed, 09 Oct 2019 09:57:41 -0700
changeset 58519 6e017b301287
parent 57950 4612a3cfb927
child 58679 9c3209ff7550
permissions -rw-r--r--
8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes Reviewed-by: mullan, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
     2
 * Copyright (c) 1996, 2019, 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: 4152
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: 4152
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: 4152
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4152
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4152
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.*;
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
    29
import java.security.spec.AlgorithmParameterSpec;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
    30
import java.security.spec.InvalidParameterSpecException;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
    31
import java.security.spec.MGF1ParameterSpec;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
    32
import java.security.spec.PSSParameterSpec;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
    36
import sun.security.rsa.PSSParameters;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This class identifies algorithms, such as cryptographic transforms, each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * of which may be associated with parameters.  Instances of this base class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * are used when this runtime environment has no special knowledge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * algorithm type, and may also be used in other cases.  Equivalence is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * defined according to OID and (where relevant) parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
    47
 * <P>Subclasses may be used, for example when the algorithm ID has
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * associated parameters which some code (e.g. code using public keys) needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * to have parsed.  Two examples of such algorithms are Diffie-Hellman key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * exchange, and the Digital Signature Standard Algorithm (DSS/DSA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <P>The OID constants defined in this class correspond to some widely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * used algorithms, for which conventional string names have been defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * This class is not a general repository for OIDs, or for such string names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Note that the mappings between algorithm IDs and algorithm names is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * not one-to-one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author Amit Kapoor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class AlgorithmId implements Serializable, DerEncoder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /** use serialVersionUID from JDK 1.1. for interoperability */
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 57895
diff changeset
    66
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private static final long serialVersionUID = 7205873507486557157L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * The object identitifer being used for this algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private ObjectIdentifier algid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // The (parsed) parameters
58519
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
    75
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private AlgorithmParameters algParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private boolean constructedFromDer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Parameters for this algorithm.  These are stored in unparsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * DER-encoded form; subclasses can be made to automaticaly parse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * them so there is fast access to these parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
58519
6e017b301287 8231262: Suppress warnings on non-serializable instance fields in security libs serializable classes
darcy
parents: 57950
diff changeset
    84
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected DerValue          params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Constructs an algorithm ID which will be initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * separately, for example by deserialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @deprecated use one of the other constructors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public AlgorithmId() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Constructs a parameterless algorithm ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param oid the identifier for the algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public AlgorithmId(ObjectIdentifier oid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        algid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Constructs an algorithm ID with algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param oid the identifier for the algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param algparams the associated algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public AlgorithmId(ObjectIdentifier oid, AlgorithmParameters algparams) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        algid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        algParams = algparams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        constructedFromDer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private AlgorithmId(ObjectIdentifier oid, DerValue params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.algid = oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.params = params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (this.params != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            decodeParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    protected void decodeParams() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        String algidString = algid.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            algParams = AlgorithmParameters.getInstance(algidString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        } catch (NoSuchAlgorithmException e) {
13661
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 13361
diff changeset
   131
            /*
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 13361
diff changeset
   132
             * This algorithm parameter type is not supported, so we cannot
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 13361
diff changeset
   133
             * parse the parameters.
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 13361
diff changeset
   134
             */
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 13361
diff changeset
   135
            algParams = null;
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 13361
diff changeset
   136
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
13661
7c894680910a 6995421: Eliminate the static dependency to sun.security.ec.ECKeyFactory
mullan
parents: 13361
diff changeset
   138
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        // Decode (parse) the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        algParams.init(params.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Marshal a DER-encoded "AlgorithmID" sequence on the DER stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public final void encode(DerOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        derEncode(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * DER encode this object onto an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Implements the <code>DerEncoder</code> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * the output stream on which to write the DER encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @exception IOException on encoding error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public void derEncode (OutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        DerOutputStream bytes = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        DerOutputStream tmp = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        bytes.putOID(algid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        // Setup params from algParams since no DER encoding is given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (constructedFromDer == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            if (algParams != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                params = new DerValue(algParams.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                params = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (params == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            // Changes backed out for compatibility with Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            // Several AlgorithmId should omit the whole parameter part when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            // it's NULL. They are ---
53082
4c539cb11633 8214532: Update RFC 2459 references in javadoc to RFC 5280
coffeys
parents: 52996
diff changeset
   177
            // RFC 3370 2.1: Implementations SHOULD generate SHA-1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            // AlgorithmIdentifiers with absent parameters.
53082
4c539cb11633 8214532: Update RFC 2459 references in javadoc to RFC 5280
coffeys
parents: 52996
diff changeset
   179
            // RFC 3447 C1: When id-sha1, id-sha224, id-sha256, id-sha384 and
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   180
            // id-sha512 are used in an AlgorithmIdentifier the parameters
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   181
            // (which are optional) SHOULD be omitted.
53082
4c539cb11633 8214532: Update RFC 2459 references in javadoc to RFC 5280
coffeys
parents: 52996
diff changeset
   182
            // RFC 3279 2.3.2: The id-dsa algorithm syntax includes optional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            // domain parameters... When omitted, the parameters component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            // MUST be omitted entirely
53082
4c539cb11633 8214532: Update RFC 2459 references in javadoc to RFC 5280
coffeys
parents: 52996
diff changeset
   185
            // RFC 3370 3.1: When the id-dsa-with-sha1 algorithm identifier
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // is used, the AlgorithmIdentifier parameters field MUST be absent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            /*if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                algid.equals((Object)SHA_oid) ||
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   189
                algid.equals((Object)SHA224_oid) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                algid.equals((Object)SHA256_oid) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                algid.equals((Object)SHA384_oid) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                algid.equals((Object)SHA512_oid) ||
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   193
                algid.equals((Object)SHA512_224_oid) ||
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   194
                algid.equals((Object)SHA512_256_oid) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                algid.equals((Object)DSA_oid) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                algid.equals((Object)sha1WithDSA_oid)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                ; // no parameter part encoded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                bytes.putNull();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }*/
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
   201
            if (algid.equals(RSASSA_PSS_oid)) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
   202
                // RFC 4055 3.3: when an RSASSA-PSS key does not require
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
   203
                // parameter validation, field is absent.
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
   204
            } else {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
   205
                bytes.putNull();
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
   206
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            bytes.putDerValue(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        tmp.write(DerValue.tag_Sequence, bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        out.write(tmp.toByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
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
     * Returns the DER-encoded X.509 AlgorithmId as a byte array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public final byte[] encode() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        DerOutputStream out = new DerOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        derEncode(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Returns the ISO OID for this algorithm.  This is usually converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * to a string and used as part of an algorithm name, for example
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * "OID.1.3.14.3.2.13" style notation.  Use the <code>getName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * call when you do not need to ensure cross-system portability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * of algorithm names, or need a user friendly name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public final ObjectIdentifier getOID () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return algid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Returns a name for the algorithm which may be more intelligible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * to humans than the algorithm's OID, but which won't necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * be comprehensible on other systems.  For example, this might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * return a name such as "MD5withRSA" for a signature algorithm on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * some systems.  It also returns names like "OID.1.2.3.4", when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * no particular name for the algorithm is known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        String algName = nameTable.get(algid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (algName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return algName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 6122
diff changeset
   248
        if ((params != null) && algid.equals((Object)specifiedWithECDSA_oid)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                AlgorithmId paramsId =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                        AlgorithmId.parse(new DerValue(getEncodedParams()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                String paramsName = paramsId.getName();
13361
bda5c2354fc6 7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents: 12685
diff changeset
   253
                algName = makeSigAlg(paramsName, "EC");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return (algName == null) ? algid.toString() : algName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public AlgorithmParameters getParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return algParams;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Returns the DER encoded parameter, which can then be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * used to initialize java.security.AlgorithmParamters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @return DER encoded parameters, or null not present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public byte[] getEncodedParams() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return (params == null) ? null : params.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Returns true iff the argument indicates the same algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * with the same parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public boolean equals(AlgorithmId other) {
57895
82a71d82e326 8226831: Use Objects.equals() when appropriate
igerasim
parents: 53351
diff changeset
   280
        boolean paramsEqual = Objects.equals(other.params, params);
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 6122
diff changeset
   281
        return (algid.equals((Object)other.algid) && paramsEqual);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Compares this AlgorithmID to another.  If algorithm parameters are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * available, they are compared.  Otherwise, just the object IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * for the algorithm are compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param other preferably an AlgorithmId, else an ObjectIdentifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (other instanceof AlgorithmId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            return equals((AlgorithmId) other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        } else if (other instanceof ObjectIdentifier) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            return equals((ObjectIdentifier) other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Compares two algorithm IDs for equality.  Returns true iff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * they are the same algorithm, ignoring algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public final boolean equals(ObjectIdentifier id) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 6122
diff changeset
   309
        return algid.equals((Object)id);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Returns a hashcode for this AlgorithmId.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @return a hashcode for this AlgorithmId.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        StringBuilder sbuf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        sbuf.append(algid.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        sbuf.append(paramsToString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return sbuf.toString().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Provides a human-readable description of the algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * This may be redefined by subclasses which parse those parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    protected String paramsToString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (params == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        } else if (algParams != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            return algParams.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return ", params unparsed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * Returns a string describing the algorithm and its parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return getName() + paramsToString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Parse (unmarshal) an ID from a DER sequence input value.  This form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * parsing might be used when expanding a value which has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * partially unmarshaled as a set or sequence member.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @exception IOException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param val the input value, which contains the algid and, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *          there are any parameters, those parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @return an ID for the algorithm.  If the system is configured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *          appropriately, this may be an instance of a class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *          with some kind of special support for this algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *          In that case, you may "narrow" the type of the ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public static AlgorithmId parse(DerValue val) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (val.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            throw new IOException("algid parse error, not a sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * Get the algorithm ID and any parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        ObjectIdentifier        algid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        DerValue                params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        DerInputStream          in = val.toDerInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        algid = in.getOID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (in.available() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            params = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            params = in.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (params.tag == DerValue.tag_Null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                if (params.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    throw new IOException("invalid NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                params = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (in.available() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                throw new IOException("Invalid AlgorithmIdentifier: extra data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        return new AlgorithmId(algid, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * Returns one of the algorithm IDs most commonly associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * with this algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @param algname the name being used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @deprecated use the short get form of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @exception NoSuchAlgorithmException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public static AlgorithmId getAlgorithmId(String algname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return get(algname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Returns one of the algorithm IDs most commonly associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * with this algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @param algname the name being used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @exception NoSuchAlgorithmException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public static AlgorithmId get(String algname)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        ObjectIdentifier oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            oid = algOID(algname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                ("Invalid ObjectIdentifier " + algname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (oid == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                ("unrecognized algorithm name: " + algname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return new AlgorithmId(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Returns one of the algorithm IDs most commonly associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * with this algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @param algparams the associated algorithm parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @exception NoSuchAlgorithmException on error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public static AlgorithmId get(AlgorithmParameters algparams)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        ObjectIdentifier oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        String algname = algparams.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            oid = algOID(algname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                ("Invalid ObjectIdentifier " + algname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        if (oid == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                ("unrecognized algorithm name: " + algname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        return new AlgorithmId(oid, algparams);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * Translates from some common algorithm names to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * OID with which they're usually associated ... this mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * is the reverse of the one below, except in those cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * where synonyms are supported or where a given algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * is commonly associated with multiple OIDs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * XXX This method needs to be enhanced so that we can also pass the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * scope of the algorithm name to it, e.g., the algorithm name "DSA"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * may have a different OID when used as a "Signature" algorithm than when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * used as a "KeyPairGenerator" algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    private static ObjectIdentifier algOID(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        // See if algname is in printable OID ("dot-dot") notation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (name.indexOf('.') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            if (name.startsWith("OID.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                return new ObjectIdentifier(name.substring("OID.".length()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                return new ObjectIdentifier(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        // Digesting algorithms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (name.equalsIgnoreCase("MD5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return AlgorithmId.MD5_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (name.equalsIgnoreCase("MD2")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            return AlgorithmId.MD2_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (name.equalsIgnoreCase("SHA") || name.equalsIgnoreCase("SHA1")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            || name.equalsIgnoreCase("SHA-1")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            return AlgorithmId.SHA_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (name.equalsIgnoreCase("SHA-256") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            name.equalsIgnoreCase("SHA256")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            return AlgorithmId.SHA256_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (name.equalsIgnoreCase("SHA-384") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            name.equalsIgnoreCase("SHA384")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return AlgorithmId.SHA384_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (name.equalsIgnoreCase("SHA-512") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            name.equalsIgnoreCase("SHA512")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return AlgorithmId.SHA512_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        }
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   496
        if (name.equalsIgnoreCase("SHA-224") ||
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   497
            name.equalsIgnoreCase("SHA224")) {
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   498
            return AlgorithmId.SHA224_oid;
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   499
        }
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   500
        if (name.equalsIgnoreCase("SHA-512/224") ||
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   501
            name.equalsIgnoreCase("SHA512/224")) {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   502
            return AlgorithmId.SHA512_224_oid;
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   503
        }
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   504
        if (name.equalsIgnoreCase("SHA-512/256") ||
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   505
            name.equalsIgnoreCase("SHA512/256")) {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   506
            return AlgorithmId.SHA512_256_oid;
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   507
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        // Various public key algorithms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if (name.equalsIgnoreCase("RSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            return AlgorithmId.RSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   512
        if (name.equalsIgnoreCase("RSASSA-PSS")) {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   513
            return AlgorithmId.RSASSA_PSS_oid;
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   514
        }
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   515
        if (name.equalsIgnoreCase("RSAES-OAEP")) {
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   516
            return AlgorithmId.RSAES_OAEP_oid;
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   517
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (name.equalsIgnoreCase("Diffie-Hellman")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            || name.equalsIgnoreCase("DH")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            return AlgorithmId.DH_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        if (name.equalsIgnoreCase("DSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            return AlgorithmId.DSA_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (name.equalsIgnoreCase("EC")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return EC_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   528
        if (name.equalsIgnoreCase("ECDH")) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   529
            return AlgorithmId.ECDH_oid;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   530
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
15298
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   532
        // Secret key algorithms
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   533
        if (name.equalsIgnoreCase("AES")) {
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   534
            return AlgorithmId.AES_oid;
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   535
        }
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   536
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        // Common signature types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (name.equalsIgnoreCase("MD5withRSA")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            || name.equalsIgnoreCase("MD5/RSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            return AlgorithmId.md5WithRSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        if (name.equalsIgnoreCase("MD2withRSA")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            || name.equalsIgnoreCase("MD2/RSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return AlgorithmId.md2WithRSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (name.equalsIgnoreCase("SHAwithDSA")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            || name.equalsIgnoreCase("SHA1withDSA")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            || name.equalsIgnoreCase("SHA/DSA")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            || name.equalsIgnoreCase("SHA1/DSA")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            || name.equalsIgnoreCase("DSAWithSHA1")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            || name.equalsIgnoreCase("DSS")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            || name.equalsIgnoreCase("SHA-1/DSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            return AlgorithmId.sha1WithDSA_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   555
        if (name.equalsIgnoreCase("SHA224WithDSA")) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   556
            return AlgorithmId.sha224WithDSA_oid;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   557
        }
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   558
        if (name.equalsIgnoreCase("SHA256WithDSA")) {
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   559
            return AlgorithmId.sha256WithDSA_oid;
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   560
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        if (name.equalsIgnoreCase("SHA1WithRSA")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            || name.equalsIgnoreCase("SHA1/RSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            return AlgorithmId.sha1WithRSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (name.equalsIgnoreCase("SHA1withECDSA")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                || name.equalsIgnoreCase("ECDSA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            return AlgorithmId.sha1WithECDSA_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
3717
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   569
        if (name.equalsIgnoreCase("SHA224withECDSA")) {
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   570
            return AlgorithmId.sha224WithECDSA_oid;
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   571
        }
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   572
        if (name.equalsIgnoreCase("SHA256withECDSA")) {
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   573
            return AlgorithmId.sha256WithECDSA_oid;
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   574
        }
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   575
        if (name.equalsIgnoreCase("SHA384withECDSA")) {
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   576
            return AlgorithmId.sha384WithECDSA_oid;
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   577
        }
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   578
        if (name.equalsIgnoreCase("SHA512withECDSA")) {
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   579
            return AlgorithmId.sha512WithECDSA_oid;
c2ea049a4442 6871847: AlgorithmId.get("SHA256withECDSA") not available
weijun
parents: 2944
diff changeset
   580
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
37908
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   582
        return oidTable().get(name.toUpperCase(Locale.ENGLISH));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    private static ObjectIdentifier oid(int ... values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return ObjectIdentifier.newInternal(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
37908
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   589
    private static volatile Map<String,ObjectIdentifier> oidTable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    private static final Map<ObjectIdentifier,String> nameTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
37908
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   592
    /** Returns the oidTable, lazily initializing it on first access. */
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   593
    private static Map<String,ObjectIdentifier> oidTable()
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   594
        throws IOException {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   595
        // Double checked locking; safe because oidTable is volatile
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   596
        Map<String,ObjectIdentifier> tab;
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   597
        if ((tab = oidTable) == null) {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   598
            synchronized (AlgorithmId.class) {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   599
                if ((tab = oidTable) == null)
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   600
                    oidTable = tab = computeOidTable();
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   601
            }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   602
        }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   603
        return tab;
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   604
    }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   605
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   606
    /** Collects the algorithm names from the installed providers. */
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   607
    private static HashMap<String,ObjectIdentifier> computeOidTable()
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   608
        throws IOException {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   609
        HashMap<String,ObjectIdentifier> tab = new HashMap<>();
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   610
        for (Provider provider : Security.getProviders()) {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   611
            for (Object key : provider.keySet()) {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   612
                String alias = (String)key;
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   613
                String upperCaseAlias = alias.toUpperCase(Locale.ENGLISH);
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   614
                int index;
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   615
                if (upperCaseAlias.startsWith("ALG.ALIAS") &&
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   616
                    (index=upperCaseAlias.indexOf("OID.", 0)) != -1) {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   617
                    index += "OID.".length();
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   618
                    if (index == alias.length()) {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   619
                        // invalid alias entry
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   620
                        break;
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   621
                    }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   622
                    String oidString = alias.substring(index);
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   623
                    String stdAlgName = provider.getProperty(alias);
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   624
                    if (stdAlgName != null) {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   625
                        stdAlgName = stdAlgName.toUpperCase(Locale.ENGLISH);
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   626
                    }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   627
                    if (stdAlgName != null &&
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   628
                        tab.get(stdAlgName) == null) {
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   629
                        tab.put(stdAlgName, new ObjectIdentifier(oidString));
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   630
                    }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   631
                }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   632
            }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   633
        }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   634
        return tab;
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   635
    }
b9bb960b959c 8156584: Initialization race in sun.security.x509.AlgorithmId.get
martin
parents: 35283
diff changeset
   636
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    /*****************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * HASHING ALGORITHMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * Algorithm ID for the MD2 Message Digest Algorthm, from RFC 1319.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * OID = 1.2.840.113549.2.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    public static final ObjectIdentifier MD2_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 2, 2});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * Algorithm ID for the MD5 Message Digest Algorthm, from RFC 1321.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * OID = 1.2.840.113549.2.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    public static final ObjectIdentifier MD5_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 2, 5});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * Algorithm ID for the SHA1 Message Digest Algorithm, from FIPS 180-1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * This is sometimes called "SHA", though that is often confusing since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * many people refer to FIPS 180 (which has an error) as defining SHA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * OID = 1.3.14.3.2.26. Old SHA-0 OID: 1.3.14.3.2.18.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public static final ObjectIdentifier SHA_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    ObjectIdentifier.newInternal(new int[] {1, 3, 14, 3, 2, 26});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   666
    public static final ObjectIdentifier SHA224_oid =
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   667
    ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 4});
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   668
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    public static final ObjectIdentifier SHA256_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 1});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public static final ObjectIdentifier SHA384_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 2});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    public static final ObjectIdentifier SHA512_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 3});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   678
    public static final ObjectIdentifier SHA512_224_oid =
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   679
    ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 5});
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   680
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   681
    public static final ObjectIdentifier SHA512_256_oid =
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   682
    ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 6});
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   683
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * COMMON PUBLIC KEY TYPES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     */
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   687
    private static final int[] DH_data = { 1, 2, 840, 113549, 1, 3, 1 };
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   688
    private static final int[] DH_PKIX_data = { 1, 2, 840, 10046, 2, 1 };
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   689
    private static final int[] DSA_OIW_data = { 1, 3, 14, 3, 2, 12 };
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   690
    private static final int[] DSA_PKIX_data = { 1, 2, 840, 10040, 4, 1 };
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   691
    private static final int[] RSA_data = { 2, 5, 8, 1, 1 };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    public static final ObjectIdentifier DH_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    public static final ObjectIdentifier DH_PKIX_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    public static final ObjectIdentifier DSA_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    public static final ObjectIdentifier DSA_OIW_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public static final ObjectIdentifier EC_oid = oid(1, 2, 840, 10045, 2, 1);
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   698
    public static final ObjectIdentifier ECDH_oid = oid(1, 3, 132, 1, 12);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    public static final ObjectIdentifier RSA_oid;
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   700
    public static final ObjectIdentifier RSAEncryption_oid =
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   701
                                            oid(1, 2, 840, 113549, 1, 1, 1);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   702
    public static final ObjectIdentifier RSAES_OAEP_oid =
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   703
                                            oid(1, 2, 840, 113549, 1, 1, 7);
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
   704
    public static final ObjectIdentifier mgf1_oid =
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
   705
                                            oid(1, 2, 840, 113549, 1, 1, 8);
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   706
    public static final ObjectIdentifier RSASSA_PSS_oid =
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   707
                                            oid(1, 2, 840, 113549, 1, 1, 10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    /*
15298
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   710
     * COMMON SECRET KEY TYPES
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   711
     */
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   712
    public static final ObjectIdentifier AES_oid =
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   713
                                            oid(2, 16, 840, 1, 101, 3, 4, 1);
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   714
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   715
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * COMMON SIGNATURE ALGORITHMS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   718
    private static final int[] md2WithRSAEncryption_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                                       { 1, 2, 840, 113549, 1, 1, 2 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   720
    private static final int[] md5WithRSAEncryption_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                                       { 1, 2, 840, 113549, 1, 1, 4 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   722
    private static final int[] sha1WithRSAEncryption_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                                       { 1, 2, 840, 113549, 1, 1, 5 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   724
    private static final int[] sha1WithRSAEncryption_OIW_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                                       { 1, 3, 14, 3, 2, 29 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   726
    private static final int[] sha224WithRSAEncryption_data =
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   727
                                       { 1, 2, 840, 113549, 1, 1, 14 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   728
    private static final int[] sha256WithRSAEncryption_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                                       { 1, 2, 840, 113549, 1, 1, 11 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   730
    private static final int[] sha384WithRSAEncryption_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                                       { 1, 2, 840, 113549, 1, 1, 12 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   732
    private static final int[] sha512WithRSAEncryption_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                                       { 1, 2, 840, 113549, 1, 1, 13 };
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   734
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   735
    private static final int[] shaWithDSA_OIW_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                                       { 1, 3, 14, 3, 2, 13 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   737
    private static final int[] sha1WithDSA_OIW_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                                       { 1, 3, 14, 3, 2, 27 };
31538
0981099a3e54 8130022: Use Java-style array declarations consistently
igerasim
parents: 30033
diff changeset
   739
    private static final int[] dsaWithSHA1_PKIX_data =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                       { 1, 2, 840, 10040, 4, 3 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    public static final ObjectIdentifier md2WithRSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    public static final ObjectIdentifier md5WithRSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    public static final ObjectIdentifier sha1WithRSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    public static final ObjectIdentifier sha1WithRSAEncryption_OIW_oid;
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   746
    public static final ObjectIdentifier sha224WithRSAEncryption_oid;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
    public static final ObjectIdentifier sha256WithRSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    public static final ObjectIdentifier sha384WithRSAEncryption_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public static final ObjectIdentifier sha512WithRSAEncryption_oid;
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   750
    public static final ObjectIdentifier sha512_224WithRSAEncryption_oid =
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   751
                                            oid(1, 2, 840, 113549, 1, 1, 15);
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   752
    public static final ObjectIdentifier sha512_256WithRSAEncryption_oid =
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   753
                                            oid(1, 2, 840, 113549, 1, 1, 16);;
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   754
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public static final ObjectIdentifier shaWithDSA_OIW_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    public static final ObjectIdentifier sha1WithDSA_OIW_oid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    public static final ObjectIdentifier sha1WithDSA_oid;
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   758
    public static final ObjectIdentifier sha224WithDSA_oid =
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   759
                                            oid(2, 16, 840, 1, 101, 3, 4, 3, 1);
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   760
    public static final ObjectIdentifier sha256WithDSA_oid =
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   761
                                            oid(2, 16, 840, 1, 101, 3, 4, 3, 2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    public static final ObjectIdentifier sha1WithECDSA_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                                            oid(1, 2, 840, 10045, 4, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    public static final ObjectIdentifier sha224WithECDSA_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                                            oid(1, 2, 840, 10045, 4, 3, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    public static final ObjectIdentifier sha256WithECDSA_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                                            oid(1, 2, 840, 10045, 4, 3, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    public static final ObjectIdentifier sha384WithECDSA_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                                            oid(1, 2, 840, 10045, 4, 3, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    public static final ObjectIdentifier sha512WithECDSA_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                                            oid(1, 2, 840, 10045, 4, 3, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    public static final ObjectIdentifier specifiedWithECDSA_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                                            oid(1, 2, 840, 10045, 4, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * Algorithm ID for the PBE encryption algorithms from PKCS#5 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * PKCS#12.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    public static final ObjectIdentifier pbeWithMD5AndDES_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        ObjectIdentifier.newInternal(new int[]{1, 2, 840, 113549, 1, 5, 3});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    public static final ObjectIdentifier pbeWithMD5AndRC2_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 5, 6});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    public static final ObjectIdentifier pbeWithSHA1AndDES_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 5, 10});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    public static final ObjectIdentifier pbeWithSHA1AndRC2_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 5, 11});
52996
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   788
    public static ObjectIdentifier pbeWithSHA1AndRC4_128_oid =
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   789
        ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 12, 1, 1});
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   790
    public static ObjectIdentifier pbeWithSHA1AndRC4_40_oid =
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   791
        ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 12, 1, 2});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    public static ObjectIdentifier pbeWithSHA1AndDESede_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 12, 1, 3});
52996
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   794
    public static ObjectIdentifier pbeWithSHA1AndRC2_128_oid =
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   795
        ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 12, 1, 5});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    public static ObjectIdentifier pbeWithSHA1AndRC2_40_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        ObjectIdentifier.newInternal(new int[] {1, 2, 840, 113549, 1, 12, 1, 6});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Note the preferred OIDs are named simply with no "OIW" or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * "PKIX" in them, even though they may point to data from these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * specs; e.g. SHA_oid, DH_oid, DSA_oid, SHA1WithDSA_oid...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * Algorithm ID for Diffie Hellman Key agreement, from PKCS #3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * Parameters include public values P and G, and may optionally specify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * the length of the private key X.  Alternatively, algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * may be derived from another source such as a Certificate Authority's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * OID = 1.2.840.113549.1.3.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        DH_oid = ObjectIdentifier.newInternal(DH_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * Algorithm ID for the Diffie Hellman Key Agreement (DH), from RFC 3279.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * Parameters may include public values P and G.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * OID = 1.2.840.10046.2.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        DH_PKIX_oid = ObjectIdentifier.newInternal(DH_PKIX_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * Algorithm ID for the Digital Signing Algorithm (DSA), from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * NIST OIW Stable Agreements part 12.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * Parameters may include public values P, Q, and G; or these may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * derived from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * another source such as a Certificate Authority's certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * OID = 1.3.14.3.2.12
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        DSA_OIW_oid = ObjectIdentifier.newInternal(DSA_OIW_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * Algorithm ID for the Digital Signing Algorithm (DSA), from RFC 3279.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * Parameters may include public values P, Q, and G; or these may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * derived from another source such as a Certificate Authority's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * OID = 1.2.840.10040.4.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        DSA_oid = ObjectIdentifier.newInternal(DSA_PKIX_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * Algorithm ID for RSA keys used for any purpose, as defined in X.509.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * The algorithm parameter is a single value, the number of bits in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * public modulus.
2944
276b6d106714 6570344: Invalid RSA OID in sun.security.x509.AlgorithmId
xuelei
parents: 2
diff changeset
   845
     * OID = 2.5.8.1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        RSA_oid = ObjectIdentifier.newInternal(RSA_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * Identifies a signing algorithm where an MD2 digest is encrypted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * using an RSA private key; defined in PKCS #1.  Use of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * signing algorithm is discouraged due to MD2 vulnerabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * OID = 1.2.840.113549.1.1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        md2WithRSAEncryption_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            ObjectIdentifier.newInternal(md2WithRSAEncryption_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * Identifies a signing algorithm where an MD5 digest is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * encrypted using an RSA private key; defined in PKCS #1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * OID = 1.2.840.113549.1.1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        md5WithRSAEncryption_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            ObjectIdentifier.newInternal(md5WithRSAEncryption_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * Identifies a signing algorithm where a SHA1 digest is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * encrypted using an RSA private key; defined by RSA DSI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * OID = 1.2.840.113549.1.1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        sha1WithRSAEncryption_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            ObjectIdentifier.newInternal(sha1WithRSAEncryption_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * Identifies a signing algorithm where a SHA1 digest is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * encrypted using an RSA private key; defined in NIST OIW.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * OID = 1.3.14.3.2.29
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        sha1WithRSAEncryption_OIW_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            ObjectIdentifier.newInternal(sha1WithRSAEncryption_OIW_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    /**
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   883
     * Identifies a signing algorithm where a SHA224 digest is
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   884
     * encrypted using an RSA private key; defined by PKCS #1.
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   885
     * OID = 1.2.840.113549.1.1.14
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   886
     */
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   887
        sha224WithRSAEncryption_oid =
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   888
            ObjectIdentifier.newInternal(sha224WithRSAEncryption_data);
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   889
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   890
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * Identifies a signing algorithm where a SHA256 digest is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * encrypted using an RSA private key; defined by PKCS #1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * OID = 1.2.840.113549.1.1.11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        sha256WithRSAEncryption_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            ObjectIdentifier.newInternal(sha256WithRSAEncryption_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * Identifies a signing algorithm where a SHA384 digest is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * encrypted using an RSA private key; defined by PKCS #1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * OID = 1.2.840.113549.1.1.12
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        sha384WithRSAEncryption_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            ObjectIdentifier.newInternal(sha384WithRSAEncryption_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * Identifies a signing algorithm where a SHA512 digest is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * encrypted using an RSA private key; defined by PKCS #1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * OID = 1.2.840.113549.1.1.13
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        sha512WithRSAEncryption_oid =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            ObjectIdentifier.newInternal(sha512WithRSAEncryption_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * SHA digest is signed using the Digital Signing Algorithm (DSA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * This should not be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * OID = 1.3.14.3.2.13
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        shaWithDSA_OIW_oid = ObjectIdentifier.newInternal(shaWithDSA_OIW_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * SHA1 digest is signed using the Digital Signing Algorithm (DSA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * OID = 1.3.14.3.2.27
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        sha1WithDSA_OIW_oid = ObjectIdentifier.newInternal(sha1WithDSA_OIW_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * Identifies the FIPS 186 "Digital Signature Standard" (DSS), where a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * SHA1 digest is signed using the Digital Signing Algorithm (DSA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * OID = 1.2.840.10040.4.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        sha1WithDSA_oid = ObjectIdentifier.newInternal(dsaWithSHA1_PKIX_data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
   936
        nameTable = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        nameTable.put(MD5_oid, "MD5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        nameTable.put(MD2_oid, "MD2");
13361
bda5c2354fc6 7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents: 12685
diff changeset
   939
        nameTable.put(SHA_oid, "SHA-1");
bda5c2354fc6 7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents: 12685
diff changeset
   940
        nameTable.put(SHA224_oid, "SHA-224");
bda5c2354fc6 7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents: 12685
diff changeset
   941
        nameTable.put(SHA256_oid, "SHA-256");
bda5c2354fc6 7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents: 12685
diff changeset
   942
        nameTable.put(SHA384_oid, "SHA-384");
bda5c2354fc6 7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents: 12685
diff changeset
   943
        nameTable.put(SHA512_oid, "SHA-512");
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   944
        nameTable.put(SHA512_224_oid, "SHA-512/224");
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   945
        nameTable.put(SHA512_256_oid, "SHA-512/256");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        nameTable.put(RSAEncryption_oid, "RSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        nameTable.put(RSA_oid, "RSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        nameTable.put(DH_oid, "Diffie-Hellman");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        nameTable.put(DH_PKIX_oid, "Diffie-Hellman");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        nameTable.put(DSA_oid, "DSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        nameTable.put(DSA_OIW_oid, "DSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        nameTable.put(EC_oid, "EC");
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   953
        nameTable.put(ECDH_oid, "ECDH");
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   954
15298
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   955
        nameTable.put(AES_oid, "AES");
06867bfe82ac 8005408: KeyStore API enhancements
vinnie
parents: 13672
diff changeset
   956
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        nameTable.put(sha1WithECDSA_oid, "SHA1withECDSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        nameTable.put(sha224WithECDSA_oid, "SHA224withECDSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        nameTable.put(sha256WithECDSA_oid, "SHA256withECDSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        nameTable.put(sha384WithECDSA_oid, "SHA384withECDSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        nameTable.put(sha512WithECDSA_oid, "SHA512withECDSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        nameTable.put(md5WithRSAEncryption_oid, "MD5withRSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        nameTable.put(md2WithRSAEncryption_oid, "MD2withRSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        nameTable.put(sha1WithDSA_oid, "SHA1withDSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        nameTable.put(sha1WithDSA_OIW_oid, "SHA1withDSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        nameTable.put(shaWithDSA_OIW_oid, "SHA1withDSA");
13672
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   967
        nameTable.put(sha224WithDSA_oid, "SHA224withDSA");
604588823b5a 7044060: Need to support NSA Suite B Cryptography algorithms
valeriep
parents: 13661
diff changeset
   968
        nameTable.put(sha256WithDSA_oid, "SHA256withDSA");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        nameTable.put(sha1WithRSAEncryption_oid, "SHA1withRSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        nameTable.put(sha1WithRSAEncryption_OIW_oid, "SHA1withRSA");
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 10336
diff changeset
   971
        nameTable.put(sha224WithRSAEncryption_oid, "SHA224withRSA");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        nameTable.put(sha256WithRSAEncryption_oid, "SHA256withRSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        nameTable.put(sha384WithRSAEncryption_oid, "SHA384withRSA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        nameTable.put(sha512WithRSAEncryption_oid, "SHA512withRSA");
50204
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   975
        nameTable.put(sha512_224WithRSAEncryption_oid, "SHA512/224withRSA");
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   976
        nameTable.put(sha512_256WithRSAEncryption_oid, "SHA512/256withRSA");
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   977
        nameTable.put(RSASSA_PSS_oid, "RSASSA-PSS");
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   978
        nameTable.put(RSAES_OAEP_oid, "RSAES-OAEP");
3195a713e24d 8146293: Add support for RSASSA-PSS Signature algorithm
valeriep
parents: 47216
diff changeset
   979
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        nameTable.put(pbeWithMD5AndDES_oid, "PBEWithMD5AndDES");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        nameTable.put(pbeWithMD5AndRC2_oid, "PBEWithMD5AndRC2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        nameTable.put(pbeWithSHA1AndDES_oid, "PBEWithSHA1AndDES");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        nameTable.put(pbeWithSHA1AndRC2_oid, "PBEWithSHA1AndRC2");
52996
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   984
        nameTable.put(pbeWithSHA1AndRC4_128_oid, "PBEWithSHA1AndRC4_128");
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   985
        nameTable.put(pbeWithSHA1AndRC4_40_oid, "PBEWithSHA1AndRC4_40");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        nameTable.put(pbeWithSHA1AndDESede_oid, "PBEWithSHA1AndDESede");
52996
2457d862a646 8076190: Customizing the generation of a PKCS12 keystore
weijun
parents: 51216
diff changeset
   987
        nameTable.put(pbeWithSHA1AndRC2_128_oid, "PBEWithSHA1AndRC2_128");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        nameTable.put(pbeWithSHA1AndRC2_40_oid, "PBEWithSHA1AndRC2_40");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
4152
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
   990
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
   991
    /**
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
   992
     * Creates a signature algorithm name from a digest algorithm
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
   993
     * name and a encryption algorithm name.
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
   994
     */
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
   995
    public static String makeSigAlg(String digAlg, String encAlg) {
13361
bda5c2354fc6 7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents: 12685
diff changeset
   996
        digAlg = digAlg.replace("-", "");
bda5c2354fc6 7180907: Jarsigner -verify fails if rsa file used sha-256 with authenticated attributes
weijun
parents: 12685
diff changeset
   997
        if (encAlg.equalsIgnoreCase("EC")) encAlg = "ECDSA";
4152
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
   998
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
   999
        return digAlg + "with" + encAlg;
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1000
    }
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1001
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1002
    /**
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1003
     * Extracts the encryption algorithm name from a signature
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1004
     * algorithm name.
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1005
      */
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1006
    public static String getEncAlgFromSigAlg(String signatureAlgorithm) {
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1007
        signatureAlgorithm = signatureAlgorithm.toUpperCase(Locale.ENGLISH);
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1008
        int with = signatureAlgorithm.indexOf("WITH");
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1009
        String keyAlgorithm = null;
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1010
        if (with > 0) {
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1011
            int and = signatureAlgorithm.indexOf("AND", with + 4);
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1012
            if (and > 0) {
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1013
                keyAlgorithm = signatureAlgorithm.substring(with + 4, and);
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1014
            } else {
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1015
                keyAlgorithm = signatureAlgorithm.substring(with + 4);
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1016
            }
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1017
            if (keyAlgorithm.equalsIgnoreCase("ECDSA")) {
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1018
                keyAlgorithm = "EC";
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1019
            }
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1020
        }
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1021
        return keyAlgorithm;
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1022
    }
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1023
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1024
    /**
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1025
     * Extracts the digest algorithm name from a signature
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1026
     * algorithm name.
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1027
      */
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1028
    public static String getDigAlgFromSigAlg(String signatureAlgorithm) {
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1029
        signatureAlgorithm = signatureAlgorithm.toUpperCase(Locale.ENGLISH);
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1030
        int with = signatureAlgorithm.indexOf("WITH");
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1031
        if (with > 0) {
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1032
            return signatureAlgorithm.substring(0, with);
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1033
        }
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1034
        return null;
bc36a9f01ac6 6870812: enhance security tools to use ECC algorithms
weijun
parents: 3717
diff changeset
  1035
    }
33872
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1036
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1037
    /**
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1038
     * Checks if a signature algorithm matches a key algorithm, i.e. a
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1039
     * signature can be initialized with a key.
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1040
     *
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1041
     * @param kAlg must not be null
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1042
     * @param sAlg must not be null
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1043
     * @throws IllegalArgumentException if they do not match
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1044
     */
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1045
    public static void checkKeyAndSigAlgMatch(String kAlg, String sAlg) {
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1046
        String sAlgUp = sAlg.toUpperCase(Locale.US);
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1047
        if ((sAlgUp.endsWith("WITHRSA") && !kAlg.equalsIgnoreCase("RSA")) ||
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1048
                (sAlgUp.endsWith("WITHECDSA") && !kAlg.equalsIgnoreCase("EC")) ||
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1049
                (sAlgUp.endsWith("WITHDSA") && !kAlg.equalsIgnoreCase("DSA"))) {
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1050
            throw new IllegalArgumentException(
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1051
                    "key algorithm not compatible with signature algorithm");
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1052
        }
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1053
    }
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1054
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1055
    /**
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1056
     * Returns the default signature algorithm for a private key. The digest
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1057
     * part might evolve with time. Remember to update the spec of
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1058
     * {@link jdk.security.jarsigner.JarSigner.Builder#getDefaultSignatureAlgorithm(PrivateKey)}
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1059
     * if updated.
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1060
     *
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1061
     * @param k cannot be null
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1062
     * @return the default alg, might be null if unsupported
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1063
     */
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1064
    public static String getDefaultSigAlgForKey(PrivateKey k) {
51216
e429a304c97d 8204196: integer cleanup
ascarpino
parents: 50204
diff changeset
  1065
        switch (k.getAlgorithm().toUpperCase(Locale.ENGLISH)) {
33872
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1066
            case "EC":
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1067
                return ecStrength(KeyUtil.getKeySize(k))
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1068
                    + "withECDSA";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1069
            case "DSA":
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1070
                return ifcFfcStrength(KeyUtil.getKeySize(k))
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1071
                    + "withDSA";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1072
            case "RSA":
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1073
                return ifcFfcStrength(KeyUtil.getKeySize(k))
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1074
                    + "withRSA";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1075
            default:
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1076
                return null;
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1077
        }
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1078
    }
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1079
53351
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1080
    // Most commonly used PSSParameterSpec and AlgorithmId
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1081
    private static class PSSParamsHolder {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1082
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1083
        final static PSSParameterSpec PSS_256_SPEC = new PSSParameterSpec(
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1084
                "SHA-256", "MGF1",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1085
                new MGF1ParameterSpec("SHA-256"),
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1086
                32, PSSParameterSpec.TRAILER_FIELD_BC);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1087
        final static PSSParameterSpec PSS_384_SPEC = new PSSParameterSpec(
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1088
                "SHA-384", "MGF1",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1089
                new MGF1ParameterSpec("SHA-384"),
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1090
                48, PSSParameterSpec.TRAILER_FIELD_BC);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1091
        final static PSSParameterSpec PSS_512_SPEC = new PSSParameterSpec(
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1092
                "SHA-512", "MGF1",
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1093
                new MGF1ParameterSpec("SHA-512"),
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1094
                64, PSSParameterSpec.TRAILER_FIELD_BC);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1095
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1096
        final static AlgorithmId PSS_256_ID;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1097
        final static AlgorithmId PSS_384_ID;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1098
        final static AlgorithmId PSS_512_ID;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1099
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1100
        static {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1101
            try {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1102
                PSS_256_ID = new AlgorithmId(RSASSA_PSS_oid,
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1103
                        new DerValue(PSSParameters.getEncoded(PSS_256_SPEC)));
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1104
                PSS_384_ID = new AlgorithmId(RSASSA_PSS_oid,
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1105
                        new DerValue(PSSParameters.getEncoded(PSS_384_SPEC)));
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1106
                PSS_512_ID = new AlgorithmId(RSASSA_PSS_oid,
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1107
                        new DerValue(PSSParameters.getEncoded(PSS_512_SPEC)));
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1108
            } catch (IOException e) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1109
                throw new AssertionError("Should not happen", e);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1110
            }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1111
        }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1112
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1113
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1114
    public static AlgorithmId getWithParameterSpec(String algName,
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1115
            AlgorithmParameterSpec spec) throws NoSuchAlgorithmException {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1116
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1117
        if (spec == null) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1118
            return AlgorithmId.get(algName);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1119
        } else if (spec == PSSParamsHolder.PSS_256_SPEC) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1120
            return PSSParamsHolder.PSS_256_ID;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1121
        } else if (spec == PSSParamsHolder.PSS_384_SPEC) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1122
            return PSSParamsHolder.PSS_384_ID;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1123
        } else if (spec == PSSParamsHolder.PSS_512_SPEC) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1124
            return PSSParamsHolder.PSS_512_ID;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1125
        } else {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1126
            try {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1127
                AlgorithmParameters result =
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1128
                        AlgorithmParameters.getInstance(algName);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1129
                result.init(spec);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1130
                return get(result);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1131
            } catch (InvalidParameterSpecException | NoSuchAlgorithmException e) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1132
                throw new ProviderException(e);
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1133
            }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1134
        }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1135
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1136
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1137
    public static PSSParameterSpec getDefaultAlgorithmParameterSpec(
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1138
            String sigAlg, PrivateKey k) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1139
        if (sigAlg.equalsIgnoreCase("RSASSA-PSS")) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1140
            switch (ifcFfcStrength(KeyUtil.getKeySize(k))) {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1141
                case "SHA256":
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1142
                    return PSSParamsHolder.PSS_256_SPEC;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1143
                case "SHA384":
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1144
                    return PSSParamsHolder.PSS_384_SPEC;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1145
                case "SHA512":
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1146
                    return PSSParamsHolder.PSS_512_SPEC;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1147
                default:
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1148
                    throw new AssertionError("Should not happen");
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1149
            }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1150
        } else {
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1151
            return null;
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1152
        }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1153
    }
bdb29aa5fd31 8215694: keytool cannot generate RSASSA-PSS certificates
weijun
parents: 53082
diff changeset
  1154
42685
a538ed225637 8171190: Bump reference of NIST 800-57 Part 1 Rev 3 to Rev 4 in JarSigner API spec
weijun
parents: 37908
diff changeset
  1155
    // Values from SP800-57 part 1 rev 4 tables 2 and 3
33872
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1156
    private static String ecStrength (int bitLength) {
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1157
        if (bitLength >= 512) { // 256 bits of strength
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1158
            return "SHA512";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1159
        } else if (bitLength >= 384) {  // 192 bits of strength
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1160
            return "SHA384";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1161
        } else { // 128 bits of strength and less
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1162
            return "SHA256";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1163
        }
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1164
    }
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1165
42685
a538ed225637 8171190: Bump reference of NIST 800-57 Part 1 Rev 3 to Rev 4 in JarSigner API spec
weijun
parents: 37908
diff changeset
  1166
    // Same values for RSA and DSA
33872
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1167
    private static String ifcFfcStrength (int bitLength) {
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1168
        if (bitLength > 7680) { // 256 bits
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1169
            return "SHA512";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1170
        } else if (bitLength > 3072) {  // 192 bits
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1171
            return "SHA384";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1172
        } else  { // 128 bits and less
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1173
            return "SHA256";
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1174
        }
94e3836950ec 8056174: New APIs for jar signing
weijun
parents: 31538
diff changeset
  1175
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
}