author | xuelei |
Tue, 12 Feb 2019 13:36:15 -0800 | |
changeset 53734 | cb1642ccc732 |
parent 51773 | 720fd6544b03 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53734
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
51773
diff
changeset
|
2 |
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.ssl; |
|
27 |
||
28 |
import java.math.BigInteger; |
|
29 |
import java.security.*; |
|
30 |
import java.security.interfaces.RSAPublicKey; |
|
31 |
import java.security.spec.*; |
|
32 |
import javax.crypto.*; |
|
33 |
||
34 |
/** |
|
35 |
* This class contains a few static methods for interaction with the JCA/JCE |
|
36 |
* to obtain implementations, etc. |
|
37 |
* |
|
38 |
* @author Andreas Sterbenz |
|
39 |
*/ |
|
40 |
final class JsseJce { |
|
50768 | 41 |
static final boolean ALLOW_ECC = |
42 |
Utilities.getBooleanProperty("com.sun.net.ssl.enableECC", true); |
|
2 | 43 |
|
44 |
/** |
|
45 |
* JCE transformation string for RSA with PKCS#1 v1.5 padding. |
|
46 |
* Can be used for encryption, decryption, signing, verifying. |
|
47 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
48 |
static final String CIPHER_RSA_PKCS1 = "RSA/ECB/PKCS1Padding"; |
50768 | 49 |
|
2 | 50 |
/** |
51 |
* JCE transformation string for the stream cipher RC4. |
|
52 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
53 |
static final String CIPHER_RC4 = "RC4"; |
50768 | 54 |
|
2 | 55 |
/** |
56 |
* JCE transformation string for DES in CBC mode without padding. |
|
57 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
58 |
static final String CIPHER_DES = "DES/CBC/NoPadding"; |
50768 | 59 |
|
2 | 60 |
/** |
61 |
* JCE transformation string for (3-key) Triple DES in CBC mode |
|
62 |
* without padding. |
|
63 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
64 |
static final String CIPHER_3DES = "DESede/CBC/NoPadding"; |
50768 | 65 |
|
2 | 66 |
/** |
67 |
* JCE transformation string for AES in CBC mode |
|
68 |
* without padding. |
|
69 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
70 |
static final String CIPHER_AES = "AES/CBC/NoPadding"; |
50768 | 71 |
|
2 | 72 |
/** |
16913 | 73 |
* JCE transformation string for AES in GCM mode |
74 |
* without padding. |
|
75 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
76 |
static final String CIPHER_AES_GCM = "AES/GCM/NoPadding"; |
50768 | 77 |
|
16913 | 78 |
/** |
51773 | 79 |
* JCE transformation string for ChaCha20-Poly1305 |
80 |
*/ |
|
81 |
static final String CIPHER_CHACHA20_POLY1305 = "ChaCha20-Poly1305"; |
|
82 |
||
83 |
/** |
|
2 | 84 |
* JCA identifier string for DSA, i.e. a DSA with SHA-1. |
85 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
86 |
static final String SIGNATURE_DSA = "DSA"; |
50768 | 87 |
|
2 | 88 |
/** |
89 |
* JCA identifier string for ECDSA, i.e. a ECDSA with SHA-1. |
|
90 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
91 |
static final String SIGNATURE_ECDSA = "SHA1withECDSA"; |
50768 | 92 |
|
2 | 93 |
/** |
94 |
* JCA identifier string for Raw DSA, i.e. a DSA signature without |
|
95 |
* hashing where the application provides the SHA-1 hash of the data. |
|
96 |
* Note that the standard name is "NONEwithDSA" but we use "RawDSA" |
|
97 |
* for compatibility. |
|
98 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
99 |
static final String SIGNATURE_RAWDSA = "RawDSA"; |
50768 | 100 |
|
2 | 101 |
/** |
102 |
* JCA identifier string for Raw ECDSA, i.e. a DSA signature without |
|
103 |
* hashing where the application provides the SHA-1 hash of the data. |
|
104 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
105 |
static final String SIGNATURE_RAWECDSA = "NONEwithECDSA"; |
50768 | 106 |
|
2 | 107 |
/** |
108 |
* JCA identifier string for Raw RSA, i.e. a RSA PKCS#1 v1.5 signature |
|
109 |
* without hashing where the application provides the hash of the data. |
|
110 |
* Used for RSA client authentication with a 36 byte hash. |
|
111 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
112 |
static final String SIGNATURE_RAWRSA = "NONEwithRSA"; |
50768 | 113 |
|
2 | 114 |
/** |
115 |
* JCA identifier string for the SSL/TLS style RSA Signature. I.e. |
|
116 |
* an signature using RSA with PKCS#1 v1.5 padding signing a |
|
117 |
* concatenation of an MD5 and SHA-1 digest. |
|
118 |
*/ |
|
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
30905
diff
changeset
|
119 |
static final String SIGNATURE_SSLRSA = "MD5andSHA1withRSA"; |
2 | 120 |
|
121 |
private JsseJce() { |
|
122 |
// no instantiation of this class |
|
123 |
} |
|
124 |
||
34826 | 125 |
static boolean isEcAvailable() { |
126 |
return EcAvailability.isAvailable; |
|
2 | 127 |
} |
128 |
||
129 |
static int getRSAKeyLength(PublicKey key) { |
|
130 |
BigInteger modulus; |
|
131 |
if (key instanceof RSAPublicKey) { |
|
132 |
modulus = ((RSAPublicKey)key).getModulus(); |
|
133 |
} else { |
|
134 |
RSAPublicKeySpec spec = getRSAPublicKeySpec(key); |
|
135 |
modulus = spec.getModulus(); |
|
136 |
} |
|
137 |
return modulus.bitLength(); |
|
138 |
} |
|
139 |
||
140 |
static RSAPublicKeySpec getRSAPublicKeySpec(PublicKey key) { |
|
141 |
if (key instanceof RSAPublicKey) { |
|
142 |
RSAPublicKey rsaKey = (RSAPublicKey)key; |
|
143 |
return new RSAPublicKeySpec(rsaKey.getModulus(), |
|
144 |
rsaKey.getPublicExponent()); |
|
145 |
} |
|
146 |
try { |
|
53734
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
51773
diff
changeset
|
147 |
KeyFactory factory = KeyFactory.getInstance("RSA"); |
51 | 148 |
return factory.getKeySpec(key, RSAPublicKeySpec.class); |
2 | 149 |
} catch (Exception e) { |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9691
diff
changeset
|
150 |
throw new RuntimeException(e); |
2 | 151 |
} |
152 |
} |
|
153 |
||
34826 | 154 |
// lazy initialization holder class idiom for static default parameters |
155 |
// |
|
156 |
// See Effective Java Second Edition: Item 71. |
|
157 |
private static class EcAvailability { |
|
158 |
// Is EC crypto available? |
|
50768 | 159 |
private static final boolean isAvailable; |
34826 | 160 |
|
161 |
static { |
|
162 |
boolean mediator = true; |
|
163 |
try { |
|
53734
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
51773
diff
changeset
|
164 |
Signature.getInstance(SIGNATURE_ECDSA); |
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
51773
diff
changeset
|
165 |
Signature.getInstance(SIGNATURE_RAWECDSA); |
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
51773
diff
changeset
|
166 |
KeyAgreement.getInstance("ECDH"); |
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
51773
diff
changeset
|
167 |
KeyFactory.getInstance("EC"); |
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
51773
diff
changeset
|
168 |
KeyPairGenerator.getInstance("EC"); |
cb1642ccc732
8217835: Remove the experimental SunJSSE FIPS compliant mode
xuelei
parents:
51773
diff
changeset
|
169 |
AlgorithmParameters.getInstance("EC"); |
34826 | 170 |
} catch (Exception e) { |
171 |
mediator = false; |
|
172 |
} |
|
173 |
||
174 |
isAvailable = mediator; |
|
175 |
} |
|
176 |
} |
|
2 | 177 |
} |