Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/pkcs11/KeyAgreement/IllegalPackageAccess.java
41155 views
1
/*
2
* Copyright (c) 2021, Red Hat, Inc.
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.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.security.AllPermission;
25
import java.security.KeyFactory;
26
import java.security.KeyPair;
27
import java.security.KeyPairGenerator;
28
import java.security.Permission;
29
import java.security.PermissionCollection;
30
import java.security.Permissions;
31
import java.security.Policy;
32
import java.security.ProtectionDomain;
33
import java.security.Provider;
34
import java.security.Security;
35
import java.security.spec.X509EncodedKeySpec;
36
37
/*
38
* @test
39
* @bug 8259319
40
* @library /test/lib ..
41
* @run main/othervm -Djava.security.manager=allow IllegalPackageAccess
42
*/
43
44
public class IllegalPackageAccess extends PKCS11Test {
45
46
private static Policy policy = Policy.getPolicy();
47
private static RuntimePermission accessPerm =
48
new RuntimePermission("accessClassInPackage.com.sun.crypto.provider");
49
50
private static class MyPolicy extends Policy {
51
@Override
52
public PermissionCollection getPermissions(ProtectionDomain domain) {
53
PermissionCollection perms = new Permissions();
54
perms.add(new AllPermission());
55
return perms;
56
}
57
58
@Override
59
public boolean implies(ProtectionDomain domain, Permission permission) {
60
if (permission.equals(accessPerm)) {
61
return policy.implies(domain, permission);
62
}
63
return super.implies(domain, permission);
64
}
65
}
66
67
public static void main(String[] args) throws Exception {
68
main(new IllegalPackageAccess(), args);
69
System.out.println("TEST PASS - OK");
70
}
71
72
@Override
73
public void main(Provider p) throws Exception {
74
Policy.setPolicy(null);
75
Policy.setPolicy(new MyPolicy());
76
System.setSecurityManager(new SecurityManager());
77
78
// Remove all security providers so a fallback scheme
79
// that creates class instances is forced.
80
for (Provider provider : Security.getProviders()) {
81
Security.removeProvider(provider.getName());
82
}
83
84
KeyPair kp = KeyPairGenerator.getInstance("DH", p)
85
.generateKeyPair();
86
byte[] encPubKey = kp.getPublic().getEncoded();
87
KeyFactory kf = KeyFactory.getInstance("DH", p);
88
89
// Requires access to a SunJCE class that parses
90
// the encoded key.
91
kf.generatePublic(new X509EncodedKeySpec(encPubKey));
92
93
System.setSecurityManager(null);
94
Policy.setPolicy(policy);
95
}
96
97
}
98
99