Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/sun/security/provider/SunEntries.java
41159 views
1
/*
2
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
24
*/
25
26
package sun.security.provider;
27
28
import java.io.*;
29
import java.net.*;
30
import java.util.*;
31
import java.security.*;
32
33
import jdk.internal.util.StaticProperty;
34
import sun.security.action.GetPropertyAction;
35
import sun.security.util.SecurityProviderConstants;
36
import static sun.security.util.SecurityProviderConstants.getAliases;
37
38
/**
39
* Defines the entries of the SUN provider.
40
*
41
* Algorithms supported, and their names:
42
*
43
* - SHA is the message digest scheme described in FIPS 180-1.
44
* Aliases for SHA are SHA-1 and SHA1.
45
*
46
* - SHA1withDSA is the signature scheme described in FIPS 186.
47
* (SHA used in DSA is SHA-1: FIPS 186 with Change No 1.)
48
* Aliases for SHA1withDSA are DSA, DSS, SHA/DSA, SHA-1/DSA, SHA1/DSA,
49
* SHAwithDSA, DSAWithSHA1, and the object
50
* identifier strings "OID.1.3.14.3.2.13", "OID.1.3.14.3.2.27" and
51
* "OID.1.2.840.10040.4.3".
52
*
53
* - SHA-2 is a set of message digest schemes described in FIPS 180-2.
54
* SHA-2 family of hash functions includes SHA-224, SHA-256, SHA-384,
55
* and SHA-512.
56
*
57
* - [SHA-224|SHA-256|SHA-384|SHA-512]withDSA are the signature schemes
58
* described in FIPS 186-3. The associated object identifiers are
59
* "OID.2.16.840.1.101.3.4.3.[1|2|3|4]" respectively.
60
*
61
* - [SHA3-224|SHA3-256|SHA3-384|SHA3-512]withDSA are the signature schemes
62
* using SHA-3 family of digests with DSA. The associated object identifiers
63
* are "OID.2.16.840.1.101.3.4.3.[5|6|7|8]" respectively.
64
*
65
* - DSA is the key generation scheme as described in FIPS 186.
66
* Aliases for DSA include the OID strings "OID.1.3.14.3.2.12"
67
* and "OID.1.2.840.10040.4.1".
68
*
69
* - MD5 is the message digest scheme described in RFC 1321.
70
* There are no aliases for MD5.
71
*
72
* - X.509 is the certificate factory type for X.509 certificates
73
* and CRLs. Aliases for X.509 are X509.
74
*
75
* - PKIX is the certification path validation algorithm described
76
* in RFC 5280. The ValidationAlgorithm attribute notes the
77
* specification that this provider implements.
78
*
79
* - JavaPolicy is the default file-based Policy type.
80
*
81
* - JavaLoginConfig is the default file-based LoginModule Configuration type.
82
*/
83
84
public final class SunEntries {
85
86
// the default algo used by SecureRandom class for new SecureRandom() calls
87
public static final String DEF_SECURE_RANDOM_ALGO;
88
89
SunEntries(Provider p) {
90
services = new LinkedHashSet<>(50, 0.9f);
91
92
// start populating content using the specified provider
93
94
// common attribute map
95
HashMap<String, String> attrs = new HashMap<>(3);
96
97
/*
98
* SecureRandom engines
99
*/
100
attrs.put("ThreadSafe", "true");
101
if (NativePRNG.isAvailable()) {
102
add(p, "SecureRandom", "NativePRNG",
103
"sun.security.provider.NativePRNG", attrs);
104
}
105
if (NativePRNG.Blocking.isAvailable()) {
106
add(p, "SecureRandom", "NativePRNGBlocking",
107
"sun.security.provider.NativePRNG$Blocking", attrs);
108
}
109
if (NativePRNG.NonBlocking.isAvailable()) {
110
add(p, "SecureRandom", "NativePRNGNonBlocking",
111
"sun.security.provider.NativePRNG$NonBlocking", attrs);
112
}
113
attrs.put("ImplementedIn", "Software");
114
add(p, "SecureRandom", "DRBG", "sun.security.provider.DRBG", attrs);
115
add(p, "SecureRandom", "SHA1PRNG",
116
"sun.security.provider.SecureRandom", attrs);
117
118
/*
119
* Signature engines
120
*/
121
attrs.clear();
122
String dsaKeyClasses = "java.security.interfaces.DSAPublicKey" +
123
"|java.security.interfaces.DSAPrivateKey";
124
attrs.put("SupportedKeyClasses", dsaKeyClasses);
125
attrs.put("ImplementedIn", "Software");
126
127
attrs.put("KeySize", "1024"); // for NONE and SHA1 DSA signatures
128
129
addWithAlias(p, "Signature", "SHA1withDSA",
130
"sun.security.provider.DSA$SHA1withDSA", attrs);
131
addWithAlias(p, "Signature", "NONEwithDSA",
132
"sun.security.provider.DSA$RawDSA", attrs);
133
134
// for DSA signatures with 224/256-bit digests
135
attrs.put("KeySize", "2048");
136
137
addWithAlias(p, "Signature", "SHA224withDSA",
138
"sun.security.provider.DSA$SHA224withDSA", attrs);
139
addWithAlias(p, "Signature", "SHA256withDSA",
140
"sun.security.provider.DSA$SHA256withDSA", attrs);
141
142
addWithAlias(p, "Signature", "SHA3-224withDSA",
143
"sun.security.provider.DSA$SHA3_224withDSA", attrs);
144
addWithAlias(p, "Signature", "SHA3-256withDSA",
145
"sun.security.provider.DSA$SHA3_256withDSA", attrs);
146
147
attrs.put("KeySize", "3072"); // for DSA sig using 384/512-bit digests
148
149
addWithAlias(p, "Signature", "SHA384withDSA",
150
"sun.security.provider.DSA$SHA384withDSA", attrs);
151
addWithAlias(p, "Signature", "SHA512withDSA",
152
"sun.security.provider.DSA$SHA512withDSA", attrs);
153
addWithAlias(p, "Signature", "SHA3-384withDSA",
154
"sun.security.provider.DSA$SHA3_384withDSA", attrs);
155
addWithAlias(p, "Signature", "SHA3-512withDSA",
156
"sun.security.provider.DSA$SHA3_512withDSA", attrs);
157
158
attrs.remove("KeySize");
159
160
add(p, "Signature", "SHA1withDSAinP1363Format",
161
"sun.security.provider.DSA$SHA1withDSAinP1363Format");
162
add(p, "Signature", "NONEwithDSAinP1363Format",
163
"sun.security.provider.DSA$RawDSAinP1363Format");
164
add(p, "Signature", "SHA224withDSAinP1363Format",
165
"sun.security.provider.DSA$SHA224withDSAinP1363Format");
166
add(p, "Signature", "SHA256withDSAinP1363Format",
167
"sun.security.provider.DSA$SHA256withDSAinP1363Format");
168
add(p, "Signature", "SHA384withDSAinP1363Format",
169
"sun.security.provider.DSA$SHA384withDSAinP1363Format");
170
add(p, "Signature", "SHA512withDSAinP1363Format",
171
"sun.security.provider.DSA$SHA512withDSAinP1363Format");
172
add(p, "Signature", "SHA3-224withDSAinP1363Format",
173
"sun.security.provider.DSA$SHA3_224withDSAinP1363Format");
174
add(p, "Signature", "SHA3-256withDSAinP1363Format",
175
"sun.security.provider.DSA$SHA3_256withDSAinP1363Format");
176
add(p, "Signature", "SHA3-384withDSAinP1363Format",
177
"sun.security.provider.DSA$SHA3_384withDSAinP1363Format");
178
add(p, "Signature", "SHA3-512withDSAinP1363Format",
179
"sun.security.provider.DSA$SHA3_512withDSAinP1363Format");
180
/*
181
* Key Pair Generator engines
182
*/
183
attrs.clear();
184
attrs.put("ImplementedIn", "Software");
185
attrs.put("KeySize", "2048"); // for DSA KPG and APG only
186
187
String dsaKPGImplClass = "sun.security.provider.DSAKeyPairGenerator$";
188
dsaKPGImplClass += (useLegacyDSA? "Legacy" : "Current");
189
addWithAlias(p, "KeyPairGenerator", "DSA", dsaKPGImplClass, attrs);
190
191
/*
192
* Algorithm Parameter Generator engines
193
*/
194
addWithAlias(p, "AlgorithmParameterGenerator", "DSA",
195
"sun.security.provider.DSAParameterGenerator", attrs);
196
attrs.remove("KeySize");
197
198
/*
199
* Algorithm Parameter engines
200
*/
201
addWithAlias(p, "AlgorithmParameters", "DSA",
202
"sun.security.provider.DSAParameters", attrs);
203
204
/*
205
* Key factories
206
*/
207
addWithAlias(p, "KeyFactory", "DSA",
208
"sun.security.provider.DSAKeyFactory", attrs);
209
210
/*
211
* Digest engines
212
*/
213
add(p, "MessageDigest", "MD2", "sun.security.provider.MD2", attrs);
214
add(p, "MessageDigest", "MD5", "sun.security.provider.MD5", attrs);
215
addWithAlias(p, "MessageDigest", "SHA-1", "sun.security.provider.SHA",
216
attrs);
217
218
addWithAlias(p, "MessageDigest", "SHA-224",
219
"sun.security.provider.SHA2$SHA224", attrs);
220
addWithAlias(p, "MessageDigest", "SHA-256",
221
"sun.security.provider.SHA2$SHA256", attrs);
222
addWithAlias(p, "MessageDigest", "SHA-384",
223
"sun.security.provider.SHA5$SHA384", attrs);
224
addWithAlias(p, "MessageDigest", "SHA-512",
225
"sun.security.provider.SHA5$SHA512", attrs);
226
addWithAlias(p, "MessageDigest", "SHA-512/224",
227
"sun.security.provider.SHA5$SHA512_224", attrs);
228
addWithAlias(p, "MessageDigest", "SHA-512/256",
229
"sun.security.provider.SHA5$SHA512_256", attrs);
230
addWithAlias(p, "MessageDigest", "SHA3-224",
231
"sun.security.provider.SHA3$SHA224", attrs);
232
addWithAlias(p, "MessageDigest", "SHA3-256",
233
"sun.security.provider.SHA3$SHA256", attrs);
234
addWithAlias(p, "MessageDigest", "SHA3-384",
235
"sun.security.provider.SHA3$SHA384", attrs);
236
addWithAlias(p, "MessageDigest", "SHA3-512",
237
"sun.security.provider.SHA3$SHA512", attrs);
238
239
/*
240
* Certificates
241
*/
242
addWithAlias(p, "CertificateFactory", "X.509",
243
"sun.security.provider.X509Factory", attrs);
244
245
/*
246
* KeyStore
247
*/
248
add(p, "KeyStore", "PKCS12",
249
"sun.security.pkcs12.PKCS12KeyStore$DualFormatPKCS12");
250
add(p, "KeyStore", "JKS",
251
"sun.security.provider.JavaKeyStore$DualFormatJKS", attrs);
252
add(p, "KeyStore", "CaseExactJKS",
253
"sun.security.provider.JavaKeyStore$CaseExactJKS", attrs);
254
add(p, "KeyStore", "DKS", "sun.security.provider.DomainKeyStore$DKS",
255
attrs);
256
257
258
/*
259
* CertStores
260
*/
261
add(p, "CertStore", "Collection",
262
"sun.security.provider.certpath.CollectionCertStore",
263
attrs);
264
add(p, "CertStore", "com.sun.security.IndexedCollection",
265
"sun.security.provider.certpath.IndexedCollectionCertStore",
266
attrs);
267
268
/*
269
* Policy
270
*/
271
add(p, "Policy", "JavaPolicy", "sun.security.provider.PolicySpiFile");
272
273
/*
274
* Configuration
275
*/
276
add(p, "Configuration", "JavaLoginConfig",
277
"sun.security.provider.ConfigFile$Spi");
278
279
/*
280
* CertPathBuilder and CertPathValidator
281
*/
282
attrs.clear();
283
attrs.put("ValidationAlgorithm", "RFC5280");
284
attrs.put("ImplementedIn", "Software");
285
286
add(p, "CertPathBuilder", "PKIX",
287
"sun.security.provider.certpath.SunCertPathBuilder",
288
attrs);
289
add(p, "CertPathValidator", "PKIX",
290
"sun.security.provider.certpath.PKIXCertPathValidator",
291
attrs);
292
}
293
294
Iterator<Provider.Service> iterator() {
295
return services.iterator();
296
}
297
298
private void add(Provider p, String type, String algo, String cn) {
299
services.add(new Provider.Service(p, type, algo, cn, null, null));
300
}
301
302
private void add(Provider p, String type, String algo, String cn,
303
HashMap<String, String> attrs) {
304
services.add(new Provider.Service(p, type, algo, cn, null, attrs));
305
}
306
307
private void addWithAlias(Provider p, String type, String algo, String cn,
308
HashMap<String, String> attrs) {
309
services.add(new Provider.Service(p, type, algo, cn,
310
getAliases(algo), attrs));
311
}
312
313
private LinkedHashSet<Provider.Service> services;
314
315
// name of the *System* property, takes precedence over PROP_RNDSOURCE
316
private static final String PROP_EGD = "java.security.egd";
317
// name of the *Security* property
318
private static final String PROP_RNDSOURCE = "securerandom.source";
319
320
private static final boolean useLegacyDSA =
321
Boolean.parseBoolean(GetPropertyAction.privilegedGetProperty
322
("jdk.security.legacyDSAKeyPairGenerator"));
323
324
static final String URL_DEV_RANDOM = "file:/dev/random";
325
static final String URL_DEV_URANDOM = "file:/dev/urandom";
326
327
@SuppressWarnings("removal")
328
private static final String seedSource = AccessController.doPrivileged(
329
new PrivilegedAction<String>() {
330
331
@Override
332
public String run() {
333
String egdSource = System.getProperty(PROP_EGD, "");
334
if (egdSource.length() != 0) {
335
return egdSource;
336
}
337
egdSource = Security.getProperty(PROP_RNDSOURCE);
338
if (egdSource == null) {
339
return "";
340
}
341
return egdSource;
342
}
343
});
344
345
static {
346
DEF_SECURE_RANDOM_ALGO = (NativePRNG.isAvailable() &&
347
(seedSource.equals(URL_DEV_URANDOM) ||
348
seedSource.equals(URL_DEV_RANDOM)) ?
349
"NativePRNG" : "DRBG");
350
}
351
352
static String getSeedSource() {
353
return seedSource;
354
}
355
356
/*
357
* Use a URI to access this File. Previous code used a URL
358
* which is less strict on syntax. If we encounter a
359
* URISyntaxException we make best efforts for backwards
360
* compatibility. e.g. space character in deviceName string.
361
*
362
* Method called within PrivilegedExceptionAction block.
363
*
364
* Moved from SeedGenerator to avoid initialization problems with
365
* signed providers.
366
*/
367
static File getDeviceFile(URL device) throws IOException {
368
try {
369
URI deviceURI = device.toURI();
370
if(deviceURI.isOpaque()) {
371
// File constructor does not accept opaque URI
372
URI localDir = new File(
373
StaticProperty.userDir()).toURI();
374
String uriPath = localDir.toString() +
375
deviceURI.toString().substring(5);
376
return new File(URI.create(uriPath));
377
} else {
378
return new File(deviceURI);
379
}
380
} catch (URISyntaxException use) {
381
/*
382
* Make best effort to access this File.
383
* We can try using the URL path.
384
*/
385
return new File(device.getPath());
386
}
387
}
388
}
389
390