From afd0bcbce1140a139fb4845083fda2d575a4c055 Mon Sep 17 00:00:00 2001 From: Sean Mullan Date: Mon, 13 Jan 2025 08:33:44 -0500 Subject: [PATCH] Initial changes. --- .../FailureDebugOption.java | 49 --------------- .../cert/CertPathBuilder/GetInstance.java | 6 +- test/jdk/sun/security/pkcs11/PKCS11Test.java | 3 +- .../tools/jarsigner/CertChainUnclosed.java | 7 +-- .../security/x509/AVA/AVAEqualsHashCode.java | 28 +++------ .../jdk/test/lib/net/SimpleSSLContext.java | 59 ++++--------------- 6 files changed, 23 insertions(+), 129 deletions(-) delete mode 100644 test/jdk/java/security/AccessControlContext/FailureDebugOption.java diff --git a/test/jdk/java/security/AccessControlContext/FailureDebugOption.java b/test/jdk/java/security/AccessControlContext/FailureDebugOption.java deleted file mode 100644 index 2c0dd489c70de..0000000000000 --- a/test/jdk/java/security/AccessControlContext/FailureDebugOption.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * 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. - */ - -/* - * @test - * @bug 6648816 - * @summary REGRESSION: setting -Djava.security.debug=failure result in NPE - * in ACC - * @run main/othervm -Djava.security.debug=failure FailureDebugOption - */ - -import java.security.ProtectionDomain; -import java.security.AccessController; -import java.security.AccessControlException; -import java.security.BasicPermission; - -public class FailureDebugOption { - - public static void main (String argv[]) throws Exception { - try { - AccessController.checkPermission( - new BasicPermission("no such permission"){}); - } catch (NullPointerException npe) { - throw new Exception("Unexpected NullPointerException for security" + - " debug option, -Djava.security.debug=failure"); - } catch (AccessControlException ace) { - } - } -} diff --git a/test/jdk/java/security/cert/CertPathBuilder/GetInstance.java b/test/jdk/java/security/cert/CertPathBuilder/GetInstance.java index 5ec4d6caa5a79..4289fcfaeced7 100644 --- a/test/jdk/java/security/cert/CertPathBuilder/GetInstance.java +++ b/test/jdk/java/security/cert/CertPathBuilder/GetInstance.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,11 +30,7 @@ * The test passes if it returns. * The test fails if an exception is thrown. */ -import java.security.cert.CertPathParameters; -import java.security.cert.CertPathBuilderResult; -import java.security.cert.CertPathBuilderSpi; import java.security.Provider; -import java.security.AccessController; import java.security.cert.CertPathBuilder; import java.security.NoSuchAlgorithmException; diff --git a/test/jdk/sun/security/pkcs11/PKCS11Test.java b/test/jdk/sun/security/pkcs11/PKCS11Test.java index 237436094ac6e..b624afd69fb3c 100644 --- a/test/jdk/sun/security/pkcs11/PKCS11Test.java +++ b/test/jdk/sun/security/pkcs11/PKCS11Test.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,7 +37,6 @@ import java.security.InvalidAlgorithmParameterException; import java.security.KeyPairGenerator; import java.security.NoSuchProviderException; -import java.security.Policy; import java.security.Provider; import java.security.ProviderException; import java.security.SecureRandom; diff --git a/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java b/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java index 7ec4d88d73a0f..d658dd9504c55 100644 --- a/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java +++ b/test/jdk/sun/security/tools/jarsigner/CertChainUnclosed.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,15 +32,12 @@ import java.nio.file.Files; import java.nio.file.Paths; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Locale; public class CertChainUnclosed { public static void main(String[] args) throws Exception { - String os = AccessController.doPrivileged( - (PrivilegedAction)() -> System.getProperty("os.name")); + String os = System.getProperty("os.name"); if (!os.toUpperCase(Locale.US).contains("WINDOWS")) { System.out.println("Not Windows. Skip test."); return; diff --git a/test/jdk/sun/security/x509/AVA/AVAEqualsHashCode.java b/test/jdk/sun/security/x509/AVA/AVAEqualsHashCode.java index 20beb8db63922..60fe9775c82dd 100644 --- a/test/jdk/sun/security/x509/AVA/AVAEqualsHashCode.java +++ b/test/jdk/sun/security/x509/AVA/AVAEqualsHashCode.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -49,9 +49,7 @@ public static void main(String[] args) throws Exception { byte[] ba = deros.toByteArray(); DerValue dv = new DerValue(ba); - GetAVAConstructor a = new GetAVAConstructor(); - java.security.AccessController.doPrivileged(a); - Constructor c = a.getCons(); + Constructor c = getAVAConstructor(); Object[] objs = new Object[2]; objs[0] = oid; @@ -72,16 +70,10 @@ public static void main(String[] args) throws Exception { else throw new Exception("FAILED equals()/hashCode() contract"); } -} - -class GetAVAConstructor implements java.security.PrivilegedExceptionAction { - private Class avaClass = null; - private Constructor avaCons = null; - - public Object run() throws Exception { + static Constructor getAVAConstructor() throws Exception { try { - avaClass = Class.forName("sun.security.x509.AVA"); + Class avaClass = Class.forName("sun.security.x509.AVA"); Constructor[] cons = avaClass.getDeclaredConstructors(); int i; @@ -90,22 +82,16 @@ public Object run() throws Exception { if (parms.length == 2) { if (parms[0].getName().equalsIgnoreCase("sun.security.util.ObjectIdentifier") && parms[1].getName().equalsIgnoreCase("sun.security.util.DerValue")) { - avaCons = cons[i]; + Constructor avaCons = cons[i]; avaCons.setAccessible(true); - break; + return avaCons; } } } - + return null; } catch (Exception e) { System.out.println("Caught unexpected exception " + e); throw e; } - return avaCons; } - - public Constructor getCons(){ - return avaCons; - } - } diff --git a/test/lib/jdk/test/lib/net/SimpleSSLContext.java b/test/lib/jdk/test/lib/net/SimpleSSLContext.java index e8611fb007f32..3c26809f1283e 100644 --- a/test/lib/jdk/test/lib/net/SimpleSSLContext.java +++ b/test/lib/jdk/test/lib/net/SimpleSSLContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,13 +34,6 @@ * Creates a simple usable SSLContext for SSLSocketFactory * or a HttpsServer using either a given keystore or a default * one in the test tree. - * - * Using this class with a security manager requires the following - * permissions to be granted: - * - * permission "java.util.PropertyPermission" "test.src.path", "read"; - * permission java.io.FilePermission "/path/to/test/lib/jdk/test/lib/testkeys", "read"; - * The exact path above depends on the location of the test. */ public class SimpleSSLContext { @@ -54,47 +47,19 @@ public SimpleSSLContext() throws IOException { this(() -> "TLS"); } - @SuppressWarnings("removal") private SimpleSSLContext(Supplier protocols) throws IOException { - try { - final String proto = protocols.get(); - AccessController.doPrivileged(new PrivilegedExceptionAction() { - @Override - public Void run() throws Exception { - String paths = System.getProperty("test.src.path"); - StringTokenizer st = new StringTokenizer(paths, File.pathSeparator); - boolean securityExceptions = false; - while (st.hasMoreTokens()) { - String path = st.nextToken(); - try { - File f = new File(path, "jdk/test/lib/net/testkeys"); - if (f.exists()) { - try (FileInputStream fis = new FileInputStream(f)) { - init(fis, proto); - return null; - } - } - } catch (SecurityException e) { - // catch and ignore because permission only required - // for one entry on path (at most) - securityExceptions = true; - } - } - if (securityExceptions) { - System.err.println("SecurityExceptions thrown on loading testkeys"); - } - return null; + String proto = protocols.get(); + String paths = System.getProperty("test.src.path"); + StringTokenizer st = new StringTokenizer(paths, File.pathSeparator); + while (st.hasMoreTokens()) { + String path = st.nextToken(); + File f = new File(path, "jdk/test/lib/net/testkeys"); + if (f.exists()) { + try (FileInputStream fis = new FileInputStream(f)) { + init(fis, proto); + break; } - }); - } catch (PrivilegedActionException pae) { - Throwable t = pae.getCause() != null ? pae.getCause() : pae; - if (t instanceof IOException) - throw (IOException)t; - if (t instanceof RuntimeException) - throw (RuntimeException)t; - if (t instanceof Error) - throw (Error)t; - throw new RuntimeException(t); + } } }