Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/jdk.crypto.mscapi/windows/classes/sun/security/mscapi/SunMSCAPI.java
41159 views
1
/*
2
* Copyright (c) 2005, 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.mscapi;
27
28
import java.security.AccessController;
29
import java.security.PrivilegedAction;
30
import java.security.Provider;
31
import java.security.NoSuchAlgorithmException;
32
import java.security.InvalidParameterException;
33
import java.security.ProviderException;
34
import java.util.HashMap;
35
import java.util.List;
36
37
import static sun.security.util.SecurityConstants.PROVIDER_VER;
38
import static sun.security.util.SecurityProviderConstants.getAliases;
39
40
/**
41
* A Cryptographic Service Provider for the Microsoft Crypto API.
42
*
43
* @since 1.6
44
*/
45
46
public final class SunMSCAPI extends Provider {
47
48
private static final long serialVersionUID = 8622598936488630849L; //TODO
49
50
private static final String INFO = "Sun's Microsoft Crypto API provider";
51
52
static {
53
@SuppressWarnings("removal")
54
var dummy = AccessController.doPrivileged(new PrivilegedAction<Void>() {
55
public Void run() {
56
System.loadLibrary("sunmscapi");
57
return null;
58
}
59
});
60
}
61
private static class ProviderServiceA extends ProviderService {
62
ProviderServiceA(Provider p, String type, String algo, String cn,
63
HashMap<String, String> attrs) {
64
super(p, type, algo, cn, getAliases(algo), attrs);
65
}
66
}
67
68
private static class ProviderService extends Provider.Service {
69
ProviderService(Provider p, String type, String algo, String cn) {
70
super(p, type, algo, cn, null, null);
71
}
72
73
ProviderService(Provider p, String type, String algo, String cn,
74
List<String> aliases, HashMap<String, String> attrs) {
75
super(p, type, algo, cn, aliases, attrs);
76
}
77
78
@Override
79
public Object newInstance(Object ctrParamObj)
80
throws NoSuchAlgorithmException {
81
String type = getType();
82
if (ctrParamObj != null) {
83
throw new InvalidParameterException
84
("constructorParameter not used with " + type +
85
" engines");
86
}
87
String algo = getAlgorithm();
88
try {
89
if (type.equals("SecureRandom")) {
90
if (algo.equals("Windows-PRNG")) {
91
return new PRNG();
92
}
93
} else if (type.equals("KeyStore")) {
94
if (algo.equals("Windows-MY")) {
95
return new CKeyStore.MY();
96
} else if (algo.equals("Windows-ROOT")) {
97
return new CKeyStore.ROOT();
98
}
99
} else if (type.equals("Signature")) {
100
if (algo.equals("NONEwithRSA")) {
101
return new CSignature.NONEwithRSA();
102
} else if (algo.equals("SHA1withRSA")) {
103
return new CSignature.SHA1withRSA();
104
} else if (algo.equals("SHA256withRSA")) {
105
return new CSignature.SHA256withRSA();
106
} else if (algo.equals("SHA384withRSA")) {
107
return new CSignature.SHA384withRSA();
108
} else if (algo.equals("SHA512withRSA")) {
109
return new CSignature.SHA512withRSA();
110
} else if (algo.equals("MD5withRSA")) {
111
return new CSignature.MD5withRSA();
112
} else if (algo.equals("MD2withRSA")) {
113
return new CSignature.MD2withRSA();
114
} else if (algo.equals("RSASSA-PSS")) {
115
return new CSignature.PSS();
116
} else if (algo.equals("SHA1withECDSA")) {
117
return new CSignature.SHA1withECDSA();
118
} else if (algo.equals("SHA224withECDSA")) {
119
return new CSignature.SHA224withECDSA();
120
} else if (algo.equals("SHA256withECDSA")) {
121
return new CSignature.SHA256withECDSA();
122
} else if (algo.equals("SHA384withECDSA")) {
123
return new CSignature.SHA384withECDSA();
124
} else if (algo.equals("SHA512withECDSA")) {
125
return new CSignature.SHA512withECDSA();
126
}
127
} else if (type.equals("KeyPairGenerator")) {
128
if (algo.equals("RSA")) {
129
return new CKeyPairGenerator.RSA();
130
}
131
} else if (type.equals("Cipher")) {
132
if (algo.equals("RSA") ||
133
algo.equals("RSA/ECB/PKCS1Padding")) {
134
return new CRSACipher();
135
}
136
}
137
} catch (Exception ex) {
138
throw new NoSuchAlgorithmException
139
("Error constructing " + type + " for " +
140
algo + " using SunMSCAPI", ex);
141
}
142
throw new ProviderException("No impl for " + algo +
143
" " + type);
144
}
145
}
146
147
@SuppressWarnings("removal")
148
public SunMSCAPI() {
149
super("SunMSCAPI", PROVIDER_VER, INFO);
150
151
final Provider p = this;
152
AccessController.doPrivileged(new PrivilegedAction<Void>() {
153
public Void run() {
154
/*
155
* Secure random
156
*/
157
HashMap<String, String> srattrs = new HashMap<>(1);
158
srattrs.put("ThreadSafe", "true");
159
putService(new ProviderService(p, "SecureRandom",
160
"Windows-PRNG", "sun.security.mscapi.PRNG",
161
null, srattrs));
162
163
/*
164
* Key store
165
*/
166
putService(new ProviderService(p, "KeyStore",
167
"Windows-MY", "sun.security.mscapi.CKeyStore$MY"));
168
putService(new ProviderService(p, "KeyStore",
169
"Windows-ROOT", "sun.security.mscapi.CKeyStore$ROOT"));
170
171
/*
172
* Signature engines
173
*/
174
HashMap<String, String> attrs = new HashMap<>(1);
175
attrs.put("SupportedKeyClasses", "sun.security.mscapi.CKey");
176
177
// NONEwithRSA must be supplied with a pre-computed message digest.
178
// Only the following digest algorithms are supported: MD5, SHA-1,
179
// SHA-256, SHA-384, SHA-512 and a special-purpose digest
180
// algorithm which is a concatenation of SHA-1 and MD5 digests.
181
putService(new ProviderService(p, "Signature",
182
"NONEwithRSA", "sun.security.mscapi.CSignature$NONEwithRSA",
183
null, attrs));
184
putService(new ProviderService(p, "Signature",
185
"SHA1withRSA", "sun.security.mscapi.CSignature$SHA1withRSA",
186
null, attrs));
187
putService(new ProviderServiceA(p, "Signature",
188
"SHA256withRSA",
189
"sun.security.mscapi.CSignature$SHA256withRSA",
190
attrs));
191
putService(new ProviderServiceA(p, "Signature",
192
"SHA384withRSA",
193
"sun.security.mscapi.CSignature$SHA384withRSA",
194
attrs));
195
putService(new ProviderServiceA(p, "Signature",
196
"SHA512withRSA",
197
"sun.security.mscapi.CSignature$SHA512withRSA",
198
attrs));
199
putService(new ProviderServiceA(p, "Signature",
200
"RSASSA-PSS", "sun.security.mscapi.CSignature$PSS",
201
attrs));
202
putService(new ProviderService(p, "Signature",
203
"MD5withRSA", "sun.security.mscapi.CSignature$MD5withRSA",
204
null, attrs));
205
putService(new ProviderService(p, "Signature",
206
"MD2withRSA", "sun.security.mscapi.CSignature$MD2withRSA",
207
null, attrs));
208
putService(new ProviderServiceA(p, "Signature",
209
"SHA1withECDSA",
210
"sun.security.mscapi.CSignature$SHA1withECDSA",
211
attrs));
212
putService(new ProviderServiceA(p, "Signature",
213
"SHA224withECDSA",
214
"sun.security.mscapi.CSignature$SHA224withECDSA",
215
attrs));
216
putService(new ProviderServiceA(p, "Signature",
217
"SHA256withECDSA",
218
"sun.security.mscapi.CSignature$SHA256withECDSA",
219
attrs));
220
putService(new ProviderServiceA(p, "Signature",
221
"SHA384withECDSA",
222
"sun.security.mscapi.CSignature$SHA384withECDSA",
223
attrs));
224
putService(new ProviderServiceA(p, "Signature",
225
"SHA512withECDSA",
226
"sun.security.mscapi.CSignature$SHA512withECDSA",
227
attrs));
228
/*
229
* Key Pair Generator engines
230
*/
231
attrs.clear();
232
attrs.put("KeySize", "16384");
233
putService(new ProviderService(p, "KeyPairGenerator",
234
"RSA", "sun.security.mscapi.CKeyPairGenerator$RSA",
235
null, attrs));
236
237
/*
238
* Cipher engines
239
*/
240
attrs.clear();
241
attrs.put("SupportedModes", "ECB");
242
attrs.put("SupportedPaddings", "PKCS1PADDING");
243
attrs.put("SupportedKeyClasses", "sun.security.mscapi.CKey");
244
putService(new ProviderService(p, "Cipher",
245
"RSA", "sun.security.mscapi.CRSACipher",
246
null, attrs));
247
putService(new ProviderService(p, "Cipher",
248
"RSA/ECB/PKCS1Padding", "sun.security.mscapi.CRSACipher",
249
null, attrs));
250
return null;
251
}
252
});
253
}
254
}
255
256