src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java
author wetmore
Fri, 11 May 2018 15:53:12 -0700
branchJDK-8145252-TLS13-branch
changeset 56542 56aaa6cb3693
parent 47216 71c04702a3d5
child 53257 5170dc2bcf64
permissions -rw-r--r--
Initial TLSv1.3 Implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, 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: 5291
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: 5291
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: 5291
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5291
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5291
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.pkcs11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
    29
import java.lang.ref.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.interfaces.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.crypto.interfaces.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.crypto.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    41
import sun.security.rsa.RSAUtil.KeyType;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.security.rsa.RSAPublicKeyImpl;
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
    43
import sun.security.rsa.RSAPrivateCrtKeyImpl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.security.internal.interfaces.TlsMasterSecret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.security.pkcs11.wrapper.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
36927
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
    50
import sun.security.util.Debug;
4809
c00eed67999d 6763530: Cannot decode PublicKey (Proider SunPKCS11, curve prime256v1)
vinnie
parents: 2180
diff changeset
    51
import sun.security.util.DerValue;
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 10781
diff changeset
    52
import sun.security.util.Length;
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 11521
diff changeset
    53
import sun.security.util.ECUtil;
4809
c00eed67999d 6763530: Cannot decode PublicKey (Proider SunPKCS11, curve prime256v1)
vinnie
parents: 2180
diff changeset
    54
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Key implementation classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * In PKCS#11, the components of private and secret keys may or may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * be accessible. If they are, we use the algorithm specific key classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * (e.g. DSAPrivateKey) for compatibility with existing applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * If the components are not accessible, we use a generic class that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * only implements PrivateKey (or SecretKey). Whether the components of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * key are extractable is automatically determined when the key object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 10781
diff changeset
    69
abstract class P11Key implements Key, Length {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
18813
02de3cfa6c49 8020310: JDK-6356530 broke the old build
valeriep
parents: 18809
diff changeset
    71
    private static final long serialVersionUID = -2575874101938349339L;
02de3cfa6c49 8020310: JDK-6356530 broke the old build
valeriep
parents: 18809
diff changeset
    72
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private final static String PUBLIC = "public";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private final static String PRIVATE = "private";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private final static String SECRET = "secret";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // type of key, one of (PUBLIC, PRIVATE, SECRET)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // token instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    final Token token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // algorithm name, returned by getAlgorithm(), etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    final String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // key id
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    final long keyID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // effective key length of the key, e.g. 56 for a DES key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    final int keyLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    // flags indicating whether the key is a token object, sensitive, extractable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    final boolean tokenObject, sensitive, extractable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
5291
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
    95
    // phantom reference notification clean up for session keys
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
    96
    private final SessionKeyRef sessionKeyRef;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
    97
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    P11Key(String type, Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.token = session.token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.keyID = keyID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.keyLength = keyLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        boolean tokenObject = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        boolean sensitive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        boolean extractable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        int n = (attributes == null) ? 0 : attributes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            CK_ATTRIBUTE attr = attributes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            if (attr.type == CKA_TOKEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                tokenObject = attr.getBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            } else if (attr.type == CKA_SENSITIVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                sensitive = attr.getBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            } else if (attr.type == CKA_EXTRACTABLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                extractable = attr.getBoolean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        this.tokenObject = tokenObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        this.sensitive = sensitive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        this.extractable = extractable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (tokenObject == false) {
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   123
            sessionKeyRef = new SessionKeyRef(this, keyID, session);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   124
        } else {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
   125
            sessionKeyRef = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    // see JCA spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    // see JCA spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public final byte[] getEncoded() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        byte[] b = getEncodedInternal();
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   138
        return (b == null) ? null : b.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    abstract byte[] getEncodedInternal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // equals() should never throw exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (token.isValid() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (obj instanceof Key == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        String thisFormat = getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (thisFormat == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            // no encoding, key only equal to itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            // XXX getEncoded() for unextractable keys will change that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        Key other = (Key)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (thisFormat.equals(other.getFormat()) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        byte[] thisEnc = this.getEncodedInternal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        byte[] otherEnc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (obj instanceof P11Key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            otherEnc = ((P11Key)other).getEncodedInternal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            otherEnc = other.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
31695
4d10942c9a7b 8074865: General crypto resilience changes
valeriep
parents: 27936
diff changeset
   171
        return MessageDigest.isEqual(thisEnc, otherEnc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        // hashCode() should never throw exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (token.isValid() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        byte[] b1 = getEncodedInternal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (b1 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        int r = b1.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        for (int i = 0; i < b1.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            r += (b1[i] & 0xff) * 37;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    protected Object writeReplace() throws ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        KeyRep.Type type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        String format = getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (isPrivate() && "PKCS#8".equals(format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            type = KeyRep.Type.PRIVATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        } else if (isPublic() && "X.509".equals(format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            type = KeyRep.Type.PUBLIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        } else if (isSecret() && "RAW".equals(format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            type = KeyRep.Type.SECRET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // XXX short term serialization for unextractable keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            throw new NotSerializableException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                ("Cannot serialize sensitive and unextractable keys");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return new KeyRep(type, getAlgorithm(), format, getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        String s1 = token.provider.getName() + " " + algorithm + " " + type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                + " key, " + keyLength + " bits";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        s1 += " (id " + keyID + ", "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                + (tokenObject ? "token" : "session") + " object";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (isPublic()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            s1 += ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            s1 += ", " + (sensitive ? "" : "not ") + "sensitive";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            s1 += ", " + (extractable ? "" : "un") + "extractable)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
11521
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 10781
diff changeset
   222
    /**
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 10781
diff changeset
   223
     * Return bit length of the key.
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 10781
diff changeset
   224
     */
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 10781
diff changeset
   225
    @Override
d7698e6c5f51 7106773: 512 bits RSA key cannot work with SHA384 and SHA512
xuelei
parents: 10781
diff changeset
   226
    public int length() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return keyLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    boolean isPublic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return type == PUBLIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    boolean isPrivate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return type == PRIVATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    boolean isSecret() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return type == SECRET;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    void fetchAttributes(CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        Session tempSession = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            tempSession = token.getOpSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            token.p11.C_GetAttributeValue(tempSession.id(), keyID, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        } catch (PKCS11Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            token.releaseSession(tempSession);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private final static CK_ATTRIBUTE[] A0 = new CK_ATTRIBUTE[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    private static CK_ATTRIBUTE[] getAttributes(Session session, long keyID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            CK_ATTRIBUTE[] knownAttributes, CK_ATTRIBUTE[] desiredAttributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (knownAttributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            knownAttributes = A0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        for (int i = 0; i < desiredAttributes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            // For each desired attribute, check to see if we have the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            // available already. If everything is here, we save a native call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            CK_ATTRIBUTE attr = desiredAttributes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            for (CK_ATTRIBUTE known : knownAttributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                if ((attr.type == known.type) && (known.pValue != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    attr.pValue = known.pValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    break; // break inner for loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (attr.pValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                // nothing found, need to call C_GetAttributeValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                for (int j = 0; j < i; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    // clear values copied from knownAttributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    desiredAttributes[j].pValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    session.token.p11.C_GetAttributeValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                            (session.id(), keyID, desiredAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                } catch (PKCS11Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                break; // break loop, goto return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return desiredAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    static SecretKey secretKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        attributes = getAttributes(session, keyID, attributes, new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            new CK_ATTRIBUTE(CKA_TOKEN),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            new CK_ATTRIBUTE(CKA_SENSITIVE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            new CK_ATTRIBUTE(CKA_EXTRACTABLE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return new P11SecretKey(session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    static SecretKey masterSecretKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            int keyLength, CK_ATTRIBUTE[] attributes, int major, int minor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        attributes = getAttributes(session, keyID, attributes, new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            new CK_ATTRIBUTE(CKA_TOKEN),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            new CK_ATTRIBUTE(CKA_SENSITIVE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            new CK_ATTRIBUTE(CKA_EXTRACTABLE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return new P11TlsMasterSecretKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                (session, keyID, algorithm, keyLength, attributes, major, minor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    // we assume that all components of public keys are always accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    static PublicKey publicKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            int keyLength, CK_ATTRIBUTE[] attributes) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   313
        switch (algorithm) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   314
            case "RSA":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   315
                return new P11RSAPublicKey
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   316
                    (session, keyID, algorithm, keyLength, attributes);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   317
            case "DSA":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   318
                return new P11DSAPublicKey
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   319
                    (session, keyID, algorithm, keyLength, attributes);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   320
            case "DH":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   321
                return new P11DHPublicKey
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   322
                    (session, keyID, algorithm, keyLength, attributes);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   323
            case "EC":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   324
                return new P11ECPublicKey
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   325
                    (session, keyID, algorithm, keyLength, attributes);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   326
            default:
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   327
                throw new ProviderException
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   328
                    ("Unknown public key algorithm " + algorithm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    static PrivateKey privateKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        attributes = getAttributes(session, keyID, attributes, new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            new CK_ATTRIBUTE(CKA_TOKEN),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            new CK_ATTRIBUTE(CKA_SENSITIVE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            new CK_ATTRIBUTE(CKA_EXTRACTABLE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        if (attributes[1].getBoolean() || (attributes[2].getBoolean() == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            return new P11PrivateKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                (session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        } else {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   343
            switch (algorithm) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   344
                case "RSA":
40453
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   345
                    // In order to decide if this is RSA CRT key, we first query
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   346
                    // and see if all extra CRT attributes are available.
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   347
                    CK_ATTRIBUTE[] attrs2 = new CK_ATTRIBUTE[] {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   348
                        new CK_ATTRIBUTE(CKA_PUBLIC_EXPONENT),
40453
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   349
                        new CK_ATTRIBUTE(CKA_PRIME_1),
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   350
                        new CK_ATTRIBUTE(CKA_PRIME_2),
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   351
                        new CK_ATTRIBUTE(CKA_EXPONENT_1),
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   352
                        new CK_ATTRIBUTE(CKA_EXPONENT_2),
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   353
                        new CK_ATTRIBUTE(CKA_COEFFICIENT),
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   354
                    };
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   355
                    boolean crtKey;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   356
                    try {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   357
                        session.token.p11.C_GetAttributeValue
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   358
                            (session.id(), keyID, attrs2);
40453
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   359
                        crtKey = ((attrs2[0].pValue instanceof byte[]) &&
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   360
                                  (attrs2[1].pValue instanceof byte[]) &&
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   361
                                  (attrs2[2].pValue instanceof byte[]) &&
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   362
                                  (attrs2[3].pValue instanceof byte[]) &&
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   363
                                  (attrs2[4].pValue instanceof byte[]) &&
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   364
                                  (attrs2[5].pValue instanceof byte[])) ;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   365
                    } catch (PKCS11Exception e) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   366
                        // ignore, assume not available
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   367
                        crtKey = false;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   368
                    }
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   369
                    if (crtKey) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   370
                        return new P11RSAPrivateKey
40453
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   371
                                (session, keyID, algorithm, keyLength, attributes, attrs2);
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   372
                    } else {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   373
                        return new P11RSAPrivateNonCRTKey
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   374
                                (session, keyID, algorithm, keyLength, attributes);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   375
                    }
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   376
                case "DSA":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   377
                    return new P11DSAPrivateKey
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                            (session, keyID, algorithm, keyLength, attributes);
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   379
                case "DH":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   380
                    return new P11DHPrivateKey
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                            (session, keyID, algorithm, keyLength, attributes);
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   382
                case "EC":
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   383
                    return new P11ECPrivateKey
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   384
                            (session, keyID, algorithm, keyLength, attributes);
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   385
                default:
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   386
                    throw new ProviderException
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   387
                            ("Unknown private key algorithm " + algorithm);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    // class for sensitive and unextractable private keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    private static final class P11PrivateKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                                implements PrivateKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   395
        private static final long serialVersionUID = -2138581185214187615L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   396
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        P11PrivateKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            super(PRIVATE, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        // XXX temporary encoding for serialization purposes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    private static class P11SecretKey extends P11Key implements SecretKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   413
        private static final long serialVersionUID = -7828241727014329084L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        private volatile byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        P11SecretKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            super(SECRET, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            if (sensitive || (extractable == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                return "RAW";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            if (getFormat() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            byte[] b = encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    b = encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        Session tempSession = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            tempSession = token.getOpSession();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                new CK_ATTRIBUTE(CKA_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                            token.p11.C_GetAttributeValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                                (tempSession.id(), keyID, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                            b = attributes[0].getByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        } catch (PKCS11Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                            throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                            token.releaseSession(tempSession);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        encoded = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
27936
ca9ee8e3d527 8066638: Suppress deprecation warnings in jdk.crypto module
darcy
parents: 25859
diff changeset
   459
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    private static class P11TlsMasterSecretKey extends P11SecretKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            implements TlsMasterSecret {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   462
        private static final long serialVersionUID = -1318560923770573441L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   463
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        private final int majorVersion, minorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        P11TlsMasterSecretKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                int keyLength, CK_ATTRIBUTE[] attributes, int major, int minor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            super(session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            this.majorVersion = major;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            this.minorVersion = minor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        public int getMajorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            return majorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        public int getMinorVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            return minorVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    // RSA CRT private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    private static final class P11RSAPrivateKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                implements RSAPrivateCrtKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   483
        private static final long serialVersionUID = 9215872438913515220L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   484
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        private BigInteger n, e, d, p, q, pe, qe, coeff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        P11RSAPrivateKey(Session session, long keyID, String algorithm,
40453
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   488
                int keyLength, CK_ATTRIBUTE[] attrs, CK_ATTRIBUTE[] crtAttrs) {
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   489
            super(PRIVATE, session, keyID, algorithm, keyLength, attrs);
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   490
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   491
            for (CK_ATTRIBUTE a : crtAttrs) {
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   492
                if (a.type == CKA_PUBLIC_EXPONENT) {
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   493
                    e = a.getBigInteger();
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   494
                } else if (a.type == CKA_PRIME_1) {
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   495
                    p = a.getBigInteger();
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   496
                } else if (a.type == CKA_PRIME_2) {
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   497
                    q = a.getBigInteger();
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   498
                } else if (a.type == CKA_EXPONENT_1) {
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   499
                    pe = a.getBigInteger();
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   500
                } else if (a.type == CKA_EXPONENT_2) {
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   501
                    qe = a.getBigInteger();
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   502
                } else if (a.type == CKA_COEFFICIENT) {
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   503
                    coeff = a.getBigInteger();
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   504
                }
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   505
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            if (n != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                new CK_ATTRIBUTE(CKA_MODULUS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                new CK_ATTRIBUTE(CKA_PRIVATE_EXPONENT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            fetchAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            n = attributes[0].getBigInteger();
40453
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   518
            d = attributes[1].getBigInteger();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
40453
0d68f70ab984 8078661: [SunPKCS11] Fails to cast into RSAPrivateCrtKey after RSA KeyPair Generation
valeriep
parents: 36927
diff changeset
   520
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            return "PKCS#8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                try {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   530
                    Key newKey = RSAPrivateCrtKeyImpl.newKey
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   531
                        (KeyType.RSA, null, n, e, d, p, q, pe, qe, coeff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    encoded = newKey.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        public BigInteger getModulus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        public BigInteger getPublicExponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        public BigInteger getPrivateExponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        public BigInteger getPrimeP() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        public BigInteger getPrimeQ() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            return q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        public BigInteger getPrimeExponentP() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            return pe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        public BigInteger getPrimeExponentQ() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            return qe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        public BigInteger getCrtCoefficient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            return coeff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    // RSA non-CRT private key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    private static final class P11RSAPrivateNonCRTKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                implements RSAPrivateKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   570
        private static final long serialVersionUID = 1137764983777411481L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   571
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        private BigInteger n, d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        P11RSAPrivateNonCRTKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            super(PRIVATE, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            if (n != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                new CK_ATTRIBUTE(CKA_MODULUS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                new CK_ATTRIBUTE(CKA_PRIVATE_EXPONENT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            fetchAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            n = attributes[0].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            d = attributes[1].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            return "PKCS#8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    // XXX make constructor in SunRsaSign provider public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    // and call it directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    KeyFactory factory = KeyFactory.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                        ("RSA", P11Util.getSunRsaSignProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    Key newKey = factory.translateKey(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                    encoded = newKey.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        public BigInteger getModulus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        public BigInteger getPrivateExponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    private static final class P11RSAPublicKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                                                implements RSAPublicKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   624
        private static final long serialVersionUID = -826726289023854455L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        private BigInteger n, e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        P11RSAPublicKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            super(PUBLIC, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            if (n != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                new CK_ATTRIBUTE(CKA_MODULUS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                new CK_ATTRIBUTE(CKA_PUBLIC_EXPONENT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            fetchAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            n = attributes[0].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            e = attributes[1].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            return "X.509";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                try {
56542
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   653
                    encoded = RSAPublicKeyImpl.newKey
56aaa6cb3693 Initial TLSv1.3 Implementation
wetmore
parents: 47216
diff changeset
   654
                        (KeyType.RSA, null, n, e).getEncoded();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                } catch (InvalidKeyException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        public BigInteger getModulus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            return n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        public BigInteger getPublicExponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            return super.toString() +  "\n  modulus: " + n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                + "\n  public exponent: " + e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    private static final class P11DSAPublicKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                                                implements DSAPublicKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   678
        private static final long serialVersionUID = 5989753793316396637L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   679
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        private BigInteger y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        private DSAParams params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        P11DSAPublicKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            super(PUBLIC, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            if (y != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                new CK_ATTRIBUTE(CKA_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                new CK_ATTRIBUTE(CKA_PRIME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                new CK_ATTRIBUTE(CKA_SUBPRIME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                new CK_ATTRIBUTE(CKA_BASE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            fetchAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            y = attributes[0].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            params = new DSAParameterSpec(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                attributes[1].getBigInteger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                attributes[2].getBigInteger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                attributes[3].getBigInteger()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            return "X.509";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    Key key = new sun.security.provider.DSAPublicKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                            (y, params.getP(), params.getQ(), params.getG());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    encoded = key.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                } catch (InvalidKeyException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        public BigInteger getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        public DSAParams getParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return super.toString() +  "\n  y: " + y + "\n  p: " + params.getP()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                + "\n  q: " + params.getQ() + "\n  g: " + params.getG();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    private static final class P11DSAPrivateKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                                                implements DSAPrivateKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   741
        private static final long serialVersionUID = 3119629997181999389L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   742
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        private BigInteger x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        private DSAParams params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        P11DSAPrivateKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            super(PRIVATE, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            if (x != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                new CK_ATTRIBUTE(CKA_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                new CK_ATTRIBUTE(CKA_PRIME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                new CK_ATTRIBUTE(CKA_SUBPRIME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                new CK_ATTRIBUTE(CKA_BASE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            fetchAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            x = attributes[0].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            params = new DSAParameterSpec(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                attributes[1].getBigInteger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                attributes[2].getBigInteger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                attributes[3].getBigInteger()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            return "PKCS#8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    Key key = new sun.security.provider.DSAPrivateKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                            (x, params.getP(), params.getQ(), params.getG());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                    encoded = key.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                } catch (InvalidKeyException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        public BigInteger getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        public DSAParams getParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    private static final class P11DHPrivateKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                                                implements DHPrivateKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   799
        private static final long serialVersionUID = -1698576167364928838L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   800
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        private BigInteger x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        private DHParameterSpec params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        P11DHPrivateKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            super(PRIVATE, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            if (x != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                new CK_ATTRIBUTE(CKA_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                new CK_ATTRIBUTE(CKA_PRIME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                new CK_ATTRIBUTE(CKA_BASE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            fetchAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            x = attributes[0].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
            params = new DHParameterSpec(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                attributes[1].getBigInteger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                attributes[2].getBigInteger()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            return "PKCS#8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    DHPrivateKeySpec spec = new DHPrivateKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                        (x, params.getP(), params.getG());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                    KeyFactory kf = KeyFactory.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                        ("DH", P11Util.getSunJceProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    Key key = kf.generatePrivate(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                    encoded = key.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        public BigInteger getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        public DHParameterSpec getParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
18809
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   854
        public int hashCode() {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   855
            if (token.isValid() == false) {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   856
                return 0;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   857
            }
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   858
            fetchValues();
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   859
            return Objects.hash(x, params.getP(), params.getG());
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   860
        }
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   861
        public boolean equals(Object obj) {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   862
            if (this == obj) return true;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   863
            // equals() should never throw exceptions
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   864
            if (token.isValid() == false) {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   865
                return false;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   866
            }
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   867
            if (!(obj instanceof DHPrivateKey)) {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   868
                return false;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   869
            }
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   870
            fetchValues();
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   871
            DHPrivateKey other = (DHPrivateKey) obj;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   872
            DHParameterSpec otherParams = other.getParams();
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   873
            return ((this.x.compareTo(other.getX()) == 0) &&
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   874
                    (this.params.getP().compareTo(otherParams.getP()) == 0) &&
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   875
                    (this.params.getG().compareTo(otherParams.getG()) == 0));
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   876
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
    private static final class P11DHPublicKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                                                implements DHPublicKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   881
        static final long serialVersionUID = -598383872153843657L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   882
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        private BigInteger y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        private DHParameterSpec params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        P11DHPublicKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            super(PUBLIC, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            if (y != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                new CK_ATTRIBUTE(CKA_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                new CK_ATTRIBUTE(CKA_PRIME),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                new CK_ATTRIBUTE(CKA_BASE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            fetchAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            y = attributes[0].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            params = new DHParameterSpec(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                attributes[1].getBigInteger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                attributes[2].getBigInteger()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            return "X.509";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                    DHPublicKeySpec spec = new DHPublicKeySpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                        (y, params.getP(), params.getG());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                    KeyFactory kf = KeyFactory.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                        ("DH", P11Util.getSunJceProvider());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    Key key = kf.generatePublic(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                    encoded = key.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                } catch (GeneralSecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        public BigInteger getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        public DHParameterSpec getParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            return super.toString() +  "\n  y: " + y + "\n  p: " + params.getP()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                + "\n  g: " + params.getG();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        }
18809
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   941
        public int hashCode() {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   942
            if (token.isValid() == false) {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   943
                return 0;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   944
            }
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   945
            fetchValues();
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   946
            return Objects.hash(y, params.getP(), params.getG());
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   947
        }
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   948
        public boolean equals(Object obj) {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   949
            if (this == obj) return true;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   950
            // equals() should never throw exceptions
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   951
            if (token.isValid() == false) {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   952
                return false;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   953
            }
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   954
            if (!(obj instanceof DHPublicKey)) {
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   955
                return false;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   956
            }
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   957
            fetchValues();
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   958
            DHPublicKey other = (DHPublicKey) obj;
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   959
            DHParameterSpec otherParams = other.getParams();
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   960
            return ((this.y.compareTo(other.getY()) == 0) &&
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   961
                    (this.params.getP().compareTo(otherParams.getP()) == 0) &&
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   962
                    (this.params.getG().compareTo(otherParams.getG()) == 0));
97f5713a0f1a 7196805: DH Key interoperability testing between SunJCE and JsafeJCE not successful
valeriep
parents: 17491
diff changeset
   963
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    private static final class P11ECPrivateKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                                                implements ECPrivateKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   968
        private static final long serialVersionUID = -7786054399510515515L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   969
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        private BigInteger s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        private ECParameterSpec params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        P11ECPrivateKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            super(PRIVATE, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                new CK_ATTRIBUTE(CKA_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                new CK_ATTRIBUTE(CKA_EC_PARAMS, params),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            fetchAttributes(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            s = attributes[0].getBigInteger();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                params = P11ECKeyFactory.decodeParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                            (attributes[1].getByteArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                throw new RuntimeException("Could not parse key values", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            return "PKCS#8";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                try {
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 11521
diff changeset
  1004
                    Key key = ECUtil.generateECPrivateKey(s, params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                    encoded = key.getEncoded();
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 11521
diff changeset
  1006
                } catch (InvalidKeySpecException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        public BigInteger getS() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        public ECParameterSpec getParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    private static final class P11ECPublicKey extends P11Key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                                                implements ECPublicKey {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1024
        private static final long serialVersionUID = -6371481375154806089L;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1025
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        private ECPoint w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        private ECParameterSpec params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        private byte[] encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        P11ECPublicKey(Session session, long keyID, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                int keyLength, CK_ATTRIBUTE[] attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            super(PUBLIC, session, keyID, algorithm, keyLength, attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        private synchronized void fetchValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            if (w != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                new CK_ATTRIBUTE(CKA_EC_POINT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                new CK_ATTRIBUTE(CKA_EC_PARAMS),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            fetchAttributes(attributes);
8773
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1043
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                params = P11ECKeyFactory.decodeParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                            (attributes[1].getByteArray());
8773
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1047
                byte[] ecKey = attributes[0].getByteArray();
4809
c00eed67999d 6763530: Cannot decode PublicKey (Proider SunPKCS11, curve prime256v1)
vinnie
parents: 2180
diff changeset
  1048
10781
f8a00c400655 7099228: Use a PKCS11 config attribute to control encoding of an EC point
vinnie
parents: 10336
diff changeset
  1049
                // Check whether the X9.63 encoding of an EC point is wrapped
f8a00c400655 7099228: Use a PKCS11 config attribute to control encoding of an EC point
vinnie
parents: 10336
diff changeset
  1050
                // in an ASN.1 OCTET STRING
f8a00c400655 7099228: Use a PKCS11 config attribute to control encoding of an EC point
vinnie
parents: 10336
diff changeset
  1051
                if (!token.config.getUseEcX963Encoding()) {
8773
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1052
                    DerValue wECPoint = new DerValue(ecKey);
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1053
10781
f8a00c400655 7099228: Use a PKCS11 config attribute to control encoding of an EC point
vinnie
parents: 10336
diff changeset
  1054
                    if (wECPoint.getTag() != DerValue.tag_OctetString) {
f8a00c400655 7099228: Use a PKCS11 config attribute to control encoding of an EC point
vinnie
parents: 10336
diff changeset
  1055
                        throw new IOException("Could not DER decode EC point." +
f8a00c400655 7099228: Use a PKCS11 config attribute to control encoding of an EC point
vinnie
parents: 10336
diff changeset
  1056
                            " Unexpected tag: " + wECPoint.getTag());
f8a00c400655 7099228: Use a PKCS11 config attribute to control encoding of an EC point
vinnie
parents: 10336
diff changeset
  1057
                    }
8773
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1058
                    w = P11ECKeyFactory.decodePoint
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1059
                        (wECPoint.getDataBytes(), params.getCurve());
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1060
10781
f8a00c400655 7099228: Use a PKCS11 config attribute to control encoding of an EC point
vinnie
parents: 10336
diff changeset
  1061
                } else {
8773
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1062
                    w = P11ECKeyFactory.decodePoint(ecKey, params.getCurve());
d8a2b71afa0c 7016078: javax.net.ssl.SSLException: Received fatal alert: internal_error starting JDK 7 b126
vinnie
parents: 5506
diff changeset
  1063
                }
4809
c00eed67999d 6763530: Cannot decode PublicKey (Proider SunPKCS11, curve prime256v1)
vinnie
parents: 2180
diff changeset
  1064
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                throw new RuntimeException("Could not parse key values", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        public String getFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            return "X.509";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        synchronized byte[] getEncodedInternal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            token.ensureValid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            if (encoded == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                try {
17491
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 11521
diff changeset
  1078
                    return ECUtil.x509EncodeECPublicKey(w, params);
7a33824ec8c5 7194075: Various classes of sunec.jar are duplicated in rt.jar
vinnie
parents: 11521
diff changeset
  1079
                } catch (InvalidKeySpecException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                    throw new ProviderException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            return encoded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        public ECPoint getW() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            return w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        public ECParameterSpec getParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            return params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            fetchValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            return super.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                + "\n  public x coord: " + w.getAffineX()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                + "\n  public y coord: " + w.getAffineY()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                + "\n  parameters: " + params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    }
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1101
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
5291
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1103
/*
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1104
 * NOTE: Must use PhantomReference here and not WeakReference
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1105
 * otherwise the key maybe cleared before other objects which
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1106
 * still use these keys during finalization such as SSLSocket.
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1107
 */
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1108
final class SessionKeyRef extends PhantomReference<P11Key>
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1109
    implements Comparable<SessionKeyRef> {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1110
    private static ReferenceQueue<P11Key> refQueue =
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1111
        new ReferenceQueue<P11Key>();
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1112
    private static Set<SessionKeyRef> refList =
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1113
        Collections.synchronizedSortedSet(new TreeSet<SessionKeyRef>());
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1114
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1115
    static ReferenceQueue<P11Key> referenceQueue() {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1116
        return refQueue;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1117
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1118
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1119
    private static void drainRefQueueBounded() {
36927
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1120
        Session sess = null;
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1121
        Token tkn = null;
5291
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1122
        while (true) {
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1123
            SessionKeyRef next = (SessionKeyRef) refQueue.poll();
36927
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1124
            if (next == null) {
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1125
                break;
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1126
            }
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1127
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1128
            // If the token is still valid, try to remove the object
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1129
            if (next.session.token.isValid()) {
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1130
                // If this key's token is the same as the previous key, the
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1131
                // same session can be used for C_DestroyObject.
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1132
                try {
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1133
                    if (next.session.token != tkn || sess == null) {
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1134
                        // Release session if not using previous token
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1135
                        if (tkn != null && sess != null) {
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1136
                            tkn.releaseSession(sess);
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1137
                            sess = null;
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1138
                        }
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1139
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1140
                        tkn = next.session.token;
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1141
                        sess = tkn.getOpSession();
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1142
                    }
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1143
                    next.disposeNative(sess);
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1144
                } catch (PKCS11Exception e) {
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1145
                    // ignore
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1146
                }
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1147
            }
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1148
            // Regardless of native results, dispose of java references
5291
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1149
            next.dispose();
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1150
        }
36927
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1151
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1152
        if (tkn != null && sess != null) {
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1153
            tkn.releaseSession(sess);
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1154
        }
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1155
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1156
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1157
    // handle to the native key
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1158
    private long keyID;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1159
    private Session session;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1160
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1161
    SessionKeyRef(P11Key key , long keyID, Session session) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1162
        super(key, refQueue);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1163
        this.keyID = keyID;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1164
        this.session = session;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1165
        this.session.addObject();
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1166
        refList.add(this);
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1167
        drainRefQueueBounded();
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1168
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1169
36927
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1170
    private void disposeNative(Session s) throws PKCS11Exception {
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1171
        session.token.p11.C_DestroyObject(s.id(), keyID);
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1172
    }
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1173
5291
d6df082f6524 6918573: sun.security.pkcs11.P11RSACipher.finalize() is a scalability blocker
valeriep
parents: 4809
diff changeset
  1174
    private void dispose() {
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1175
        refList.remove(this);
36927
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1176
        this.clear();
b59fed2c77e2 8098580: drainRefQueueBounds() puts pressure on pool.size()
ascarpino
parents: 31695
diff changeset
  1177
        session.removeObject();
2180
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1178
    }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1179
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1180
    public int compareTo(SessionKeyRef other) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1181
        if (this.keyID == other.keyID) {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1182
            return 0;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1183
        } else {
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1184
            return (this.keyID < other.keyID) ? -1 : 1;
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1185
        }
9994f4f08a59 6812738: SSL stress test with GF leads to 32 bit max process size in less than 5 minutes with PCKS11 provider
valeriep
parents: 2
diff changeset
  1186
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
}