This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8259319: Illegal package access when SunPKCS11 requires SunJCE's classes
Backport-of: 4be2173478bd1e84946bd903b350ce466bddb36b
- Loading branch information
Yuri Nesterenko
committed
Apr 12, 2021
1 parent
44c196a
commit ace2b56
Showing
4 changed files
with
122 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
test/jdk/sun/security/pkcs11/KeyAgreement/IllegalPackageAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Copyright (c) 2021, Red Hat, Inc. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
import java.security.AllPermission; | ||
import java.security.KeyFactory; | ||
import java.security.KeyPair; | ||
import java.security.KeyPairGenerator; | ||
import java.security.Permission; | ||
import java.security.PermissionCollection; | ||
import java.security.Permissions; | ||
import java.security.Policy; | ||
import java.security.ProtectionDomain; | ||
import java.security.Provider; | ||
import java.security.Security; | ||
import java.security.spec.X509EncodedKeySpec; | ||
|
||
/* | ||
* @test | ||
* @bug 8259319 | ||
* @library /test/lib .. | ||
* @run main/othervm IllegalPackageAccess | ||
*/ | ||
|
||
public class IllegalPackageAccess extends PKCS11Test { | ||
|
||
private static Policy policy = Policy.getPolicy(); | ||
private static RuntimePermission accessPerm = | ||
new RuntimePermission("accessClassInPackage.com.sun.crypto.provider"); | ||
|
||
private static class MyPolicy extends Policy { | ||
@Override | ||
public PermissionCollection getPermissions(ProtectionDomain domain) { | ||
PermissionCollection perms = new Permissions(); | ||
perms.add(new AllPermission()); | ||
return perms; | ||
} | ||
|
||
@Override | ||
public boolean implies(ProtectionDomain domain, Permission permission) { | ||
if (permission.equals(accessPerm)) { | ||
return policy.implies(domain, permission); | ||
} | ||
return super.implies(domain, permission); | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
main(new IllegalPackageAccess(), args); | ||
System.out.println("TEST PASS - OK"); | ||
} | ||
|
||
@Override | ||
public void main(Provider p) throws Exception { | ||
Policy.setPolicy(new MyPolicy()); | ||
System.setSecurityManager(new SecurityManager()); | ||
|
||
// Remove all security providers so a fallback scheme | ||
// that creates class instances is forced. | ||
for (Provider provider : Security.getProviders()) { | ||
Security.removeProvider(provider.getName()); | ||
} | ||
|
||
KeyPair kp = KeyPairGenerator.getInstance("DH", p) | ||
.generateKeyPair(); | ||
byte[] encPubKey = kp.getPublic().getEncoded(); | ||
KeyFactory kf = KeyFactory.getInstance("DH", p); | ||
|
||
// Requires access to a SunJCE class that parses | ||
// the encoded key. | ||
kf.generatePublic(new X509EncodedKeySpec(encPubKey)); | ||
|
||
System.setSecurityManager(null); | ||
Policy.setPolicy(policy); | ||
} | ||
|
||
} |
ace2b56
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues