Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/javax/crypto/ProviderVerifier.java
41152 views
1
/*
2
* Copyright (c) 2007, 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 javax.crypto;
27
28
import java.io.*;
29
import java.net.*;
30
import java.security.*;
31
import java.util.jar.*;
32
33
/**
34
* This class verifies Provider/Policy resources found at a URL
35
* (currently only JAR files and any supporting JAR files), and
36
* determines whether they may be used in this implementation.
37
*
38
* The JCE in OpenJDK has an open cryptographic interface, meaning it
39
* does not restrict which providers can be used. Compliance with
40
* United States export controls and with local law governing the
41
* import/export of products incorporating the JCE in the OpenJDK is
42
* the responsibility of the licensee.
43
*
44
* @since 1.7
45
*/
46
final class ProviderVerifier {
47
48
// The URL for the JAR file we want to verify.
49
private URL jarURL;
50
private Provider provider;
51
private boolean savePerms;
52
private CryptoPermissions appPerms = null;
53
54
/**
55
* Creates a ProviderVerifier object to verify the given URL.
56
*
57
* @param jarURL the JAR file to be verified.
58
* @param savePerms if true, save the permissions allowed by the
59
* exemption mechanism
60
*/
61
ProviderVerifier(URL jarURL, boolean savePerms) {
62
this(jarURL, null, savePerms);
63
}
64
65
/**
66
* Creates a ProviderVerifier object to verify the given URL.
67
*
68
* @param jarURL the JAR file to be verified
69
* @param provider the corresponding provider.
70
* @param savePerms if true, save the permissions allowed by the
71
* exemption mechanism
72
*/
73
ProviderVerifier(URL jarURL, Provider provider, boolean savePerms) {
74
this.jarURL = jarURL;
75
this.provider = provider;
76
this.savePerms = savePerms;
77
}
78
79
/**
80
* Verify the JAR file is signed by an entity which has a certificate
81
* issued by a trusted CA.
82
*
83
* In OpenJDK, we just need to examine the "cryptoperms" file to see
84
* if any permissions were bundled together with this jar file.
85
*/
86
void verify() throws IOException {
87
88
// Short-circuit. If we weren't asked to save any, we're done.
89
if (!savePerms) {
90
return;
91
}
92
93
// If the protocol of jarURL isn't "jar", we should
94
// construct a JAR URL so we can open a JarURLConnection
95
// for verifying this provider.
96
final URL url = jarURL.getProtocol().equalsIgnoreCase("jar")?
97
jarURL : new URL("jar:" + jarURL.toString() + "!/");
98
99
JarFile jf = null;
100
try {
101
102
// Get a link to the Jarfile to search.
103
try {
104
@SuppressWarnings("removal")
105
var tmp = AccessController.doPrivileged(
106
new PrivilegedExceptionAction<JarFile>() {
107
public JarFile run() throws Exception {
108
JarURLConnection conn =
109
(JarURLConnection) url.openConnection();
110
// You could do some caching here as
111
// an optimization.
112
conn.setUseCaches(false);
113
return conn.getJarFile();
114
}
115
});
116
jf = tmp;
117
} catch (java.security.PrivilegedActionException pae) {
118
throw new SecurityException("Cannot load " + url.toString(),
119
pae.getCause());
120
}
121
122
if (jf != null) {
123
JarEntry je = jf.getJarEntry("cryptoPerms");
124
if (je == null) {
125
throw new JarException(
126
"Can not find cryptoPerms");
127
}
128
try {
129
appPerms = new CryptoPermissions();
130
appPerms.load(jf.getInputStream(je));
131
} catch (Exception ex) {
132
JarException jex =
133
new JarException("Cannot load/parse" +
134
jarURL.toString());
135
jex.initCause(ex);
136
throw jex;
137
}
138
}
139
} finally {
140
// Only call close() when caching is not enabled.
141
// Otherwise, exceptions will be thrown for all
142
// subsequent accesses of this cached jar.
143
if (jf != null) {
144
jf.close();
145
}
146
}
147
}
148
149
/**
150
* Verify that the provided certs include the
151
* framework signing certificate.
152
*
153
* @param certs the list of certs to be checked.
154
* @throws Exception if the list of certs did not contain
155
* the framework signing certificate
156
*/
157
static void verifyPolicySigned(java.security.cert.Certificate[] certs)
158
throws Exception {
159
}
160
161
/**
162
* Returns true if the given provider is JDK trusted crypto provider
163
* if the implementation supports fast-path verification.
164
*/
165
static boolean isTrustedCryptoProvider(Provider provider) {
166
return false;
167
}
168
169
/**
170
* Returns the permissions which are bundled with the JAR file,
171
* aka the "cryptoperms" file.
172
*
173
* NOTE: if this ProviderVerifier instance is constructed with "savePerms"
174
* equal to false, then this method would always return null.
175
*/
176
CryptoPermissions getPermissions() {
177
return appPerms;
178
}
179
}
180
181