8344397: Remove Security Manager dependencies from java.security and sun.security packages

Reviewed-by: rriggs, hchao, weijun, alanb
This commit is contained in:
Sean Mullan 2024-12-02 21:30:53 +00:00
parent 3d0d0e6290
commit 940aa7c4cf
45 changed files with 406 additions and 1436 deletions

View file

@ -53,6 +53,7 @@ import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.constant.Constable;
import java.net.URL;
import java.security.AllPermission;
import java.security.Permissions;
import java.security.ProtectionDomain;
import java.util.ArrayList;
@ -89,7 +90,6 @@ import sun.reflect.generics.repository.ClassRepository;
import sun.reflect.generics.repository.MethodRepository;
import sun.reflect.generics.repository.ConstructorRepository;
import sun.reflect.generics.scope.ClassScope;
import sun.security.util.SecurityConstants;
import sun.reflect.annotation.*;
import sun.reflect.misc.ReflectUtil;
@ -2720,7 +2720,7 @@ public final class Class<T> implements java.io.Serializable,
private static final ProtectionDomain allPermDomain;
static {
Permissions perms = new Permissions();
perms.add(SecurityConstants.ALL_PERMISSION);
perms.add(new AllPermission());
allPermDomain = new ProtectionDomain(null, perms);
}
}

View file

@ -44,14 +44,6 @@ import java.util.List;
public final class AccessControlContext {
private ProtectionDomain[] context;
// isPrivileged and isAuthorized are referenced by the VM - do not remove
// or change their names
private boolean isPrivileged;
private boolean isAuthorized = false;
// Note: This field is directly used by the virtual machine
// native codes. Don't touch it.
private AccessControlContext privilegedContext;
@SuppressWarnings("removal")
private DomainCombiner combiner = null;

View file

@ -345,12 +345,6 @@ public abstract class Provider extends Properties {
return name + " version " + versionStr;
}
/*
* override the following methods to ensure that provider
* information can only be changed if the caller has the appropriate
* permissions.
*/
/**
* Clears this {@code Provider} so that it no longer contains the properties
* used to look up facilities implemented by the {@code Provider}.
@ -359,7 +353,7 @@ public abstract class Provider extends Properties {
*/
@Override
public synchronized void clear() {
check("clearProviderProperties."+name);
checkInitialized();
if (debug != null) {
debug.println("Remove " + name + " provider properties");
}
@ -376,7 +370,7 @@ public abstract class Provider extends Properties {
*/
@Override
public synchronized void load(InputStream inStream) throws IOException {
check("putProviderProperty."+name);
checkInitialized();
if (debug != null) {
debug.println("Load " + name + " provider properties");
}
@ -394,7 +388,7 @@ public abstract class Provider extends Properties {
*/
@Override
public synchronized void putAll(Map<?,?> t) {
check("putProviderProperty."+name);
checkInitialized();
if (debug != null) {
debug.println("Put all " + name + " provider properties");
}
@ -461,7 +455,7 @@ public abstract class Provider extends Properties {
*/
@Override
public synchronized Object put(Object key, Object value) {
check("putProviderProperty."+name);
checkInitialized();
if (debug != null) {
debug.println("Set " + name + " provider property [" +
key + "/" + value +"]");
@ -478,7 +472,7 @@ public abstract class Provider extends Properties {
*/
@Override
public synchronized Object putIfAbsent(Object key, Object value) {
check("putProviderProperty."+name);
checkInitialized();
if (debug != null) {
debug.println("Set " + name + " provider property [" +
key + "/" + value +"]");
@ -494,7 +488,7 @@ public abstract class Provider extends Properties {
*/
@Override
public synchronized Object remove(Object key) {
check("removeProviderProperty."+name);
checkInitialized();
if (debug != null) {
debug.println("Remove " + name + " provider property " + key);
}
@ -509,7 +503,7 @@ public abstract class Provider extends Properties {
*/
@Override
public synchronized boolean remove(Object key, Object value) {
check("removeProviderProperty."+name);
checkInitialized();
if (debug != null) {
debug.println("Remove " + name + " provider property " + key);
}
@ -525,7 +519,7 @@ public abstract class Provider extends Properties {
@Override
public synchronized boolean replace(Object key, Object oldValue,
Object newValue) {
check("putProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println("Replace " + name + " provider property " + key);
}
@ -540,7 +534,7 @@ public abstract class Provider extends Properties {
*/
@Override
public synchronized Object replace(Object key, Object value) {
check("putProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println("Replace " + name + " provider property " + key);
}
@ -558,7 +552,7 @@ public abstract class Provider extends Properties {
@Override
public synchronized void replaceAll(BiFunction<? super Object,
? super Object, ? extends Object> function) {
check("putProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println("ReplaceAll " + name + " provider property ");
}
@ -575,8 +569,7 @@ public abstract class Provider extends Properties {
@Override
public synchronized Object compute(Object key, BiFunction<? super Object,
? super Object, ? extends Object> remappingFunction) {
check("putProviderProperty." + name);
check("removeProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println("Compute " + name + " provider property " + key);
}
@ -594,8 +587,7 @@ public abstract class Provider extends Properties {
@Override
public synchronized Object computeIfAbsent(Object key,
Function<? super Object, ? extends Object> mappingFunction) {
check("putProviderProperty." + name);
check("removeProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println("ComputeIfAbsent " + name + " provider property " +
key);
@ -613,8 +605,7 @@ public abstract class Provider extends Properties {
public synchronized Object computeIfPresent(Object key,
BiFunction<? super Object, ? super Object, ? extends Object>
remappingFunction) {
check("putProviderProperty." + name);
check("removeProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println("ComputeIfPresent " + name + " provider property " +
key);
@ -635,8 +626,7 @@ public abstract class Provider extends Properties {
public synchronized Object merge(Object key, Object value,
BiFunction<? super Object, ? super Object, ? extends Object>
remappingFunction) {
check("putProviderProperty." + name);
check("removeProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println("Merge " + name + " provider property " + key);
}
@ -694,15 +684,6 @@ public abstract class Provider extends Properties {
}
}
private void check(String directive) {
checkInitialized();
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkSecurityAccess(directive);
}
}
// legacyMap changed since last call to getServices()
private transient volatile boolean legacyChanged;
// serviceMap changed since last call to getServices()
@ -789,8 +770,6 @@ public abstract class Provider extends Properties {
/**
* Copies all the mappings from the specified Map to this provider.
* Internal method to be called AFTER the security check has been
* performed.
*/
private void implPutAll(Map<?,?> t) {
for (Map.Entry<?,?> e : t.entrySet()) {
@ -1239,7 +1218,7 @@ public abstract class Provider extends Properties {
* @since 1.5
*/
protected void putService(Service s) {
check("putProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println(name + ".putService(): " + s);
}
@ -1303,7 +1282,7 @@ public abstract class Provider extends Properties {
private void putPropertyStrings(Service s) {
String type = s.getType();
String algorithm = s.getAlgorithm();
// use super() to avoid permission check and other processing
// use super() to avoid other processing
super.put(type + "." + algorithm, s.getClassName());
for (String alias : s.getAliases()) {
super.put(ALIAS_PREFIX + type + "." + alias, algorithm);
@ -1321,7 +1300,7 @@ public abstract class Provider extends Properties {
private void removePropertyStrings(Service s) {
String type = s.getType();
String algorithm = s.getAlgorithm();
// use super() to avoid permission check and other processing
// use super() to avoid other processing
super.remove(type + "." + algorithm);
for (String alias : s.getAliases()) {
super.remove(ALIAS_PREFIX + type + "." + alias);
@ -1346,7 +1325,7 @@ public abstract class Provider extends Properties {
* @since 1.5
*/
protected void removeService(Service s) {
check("removeProviderProperty." + name);
checkInitialized();
if (debug != null) {
debug.println(name + ".removeService(): " + s);
}

View file

@ -942,11 +942,7 @@ public class SecureRandom extends java.util.Random {
public static SecureRandom getInstanceStrong()
throws NoSuchAlgorithmException {
@SuppressWarnings("removal")
String property = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> Security.getProperty(
"securerandom.strongAlgorithms"));
String property = Security.getProperty("securerandom.strongAlgorithms");
if (property == null || property.isEmpty()) {
throw new NoSuchAlgorithmException(
"Null/empty securerandom.strongAlgorithms Security Property");

View file

@ -312,14 +312,7 @@ public final class Security {
}
static {
// doPrivileged here because there are multiple
// things in initialize that might require privs.
// (the FileInputStream call and the File.exists call, etc)
@SuppressWarnings("removal")
var dummy = AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
initialize();
return null;
});
initialize();
// Set up JavaSecurityPropertiesAccess in SharedSecrets
SharedSecrets.setJavaSecurityPropertiesAccess(new JavaSecurityPropertiesAccess() {
@Override
@ -475,15 +468,13 @@ public final class Security {
*/
public static synchronized int insertProviderAt(Provider provider,
int position) {
String providerName = provider.getName();
checkInsertProvider(providerName);
ProviderList list = Providers.getFullProviderList();
ProviderList newList = ProviderList.insertAt(list, provider, position - 1);
if (list == newList) {
return -1;
}
Providers.setProviderList(newList);
return newList.getIndex(providerName) + 1;
return newList.getIndex(provider.getName()) + 1;
}
/**
@ -527,7 +518,6 @@ public final class Security {
* @see #addProvider
*/
public static synchronized void removeProvider(String name) {
check("removeProvider." + name);
ProviderList list = Providers.getFullProviderList();
ProviderList newList = ProviderList.remove(list, name);
Providers.setProviderList(newList);
@ -822,7 +812,6 @@ public final class Security {
*/
public static String getProperty(String key) {
SecPropLoader.checkReservedKey(key);
check("getProperty." + key);
String name = props.getProperty(key);
if (name != null)
name = name.trim(); // could be a class name with trailing ws
@ -845,7 +834,6 @@ public final class Security {
*/
public static void setProperty(String key, String datum) {
SecPropLoader.checkReservedKey(key);
check("setProperty." + key);
props.put(key, datum);
SecurityPropertyModificationEvent spe = new SecurityPropertyModificationEvent();
@ -859,32 +847,6 @@ public final class Security {
}
}
private static void check(String directive) {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkSecurityAccess(directive);
}
}
private static void checkInsertProvider(String name) {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null) {
try {
security.checkSecurityAccess("insertProvider");
} catch (SecurityException se1) {
try {
security.checkSecurityAccess("insertProvider." + name);
} catch (SecurityException se2) {
// throw first exception, but add second to suppressed
se1.addSuppressed(se2);
throw se1;
}
}
}
}
private static class Criteria {
private final String serviceName;
private final String algName;

View file

@ -1,96 +0,0 @@
/*
* Copyright (c) 1998, 2022, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package sun.security.action;
import java.security.AccessController;
/**
* A convenience class for retrieving the boolean value of a system property
* as a privileged action.
*
* <p>An instance of this class can be used as the argument of
* <code>AccessController.doPrivileged</code>.
*
* <p>The following code retrieves the boolean value of the system
* property named <code>"prop"</code> as a privileged action:
*
* <pre>
* boolean b = java.security.AccessController.doPrivileged
* (new GetBooleanAction("prop")).booleanValue();
* </pre>
*
* @author Roland Schemers
* @see java.security.PrivilegedAction
* @see java.security.AccessController
* @since 1.2
*/
public class GetBooleanAction
implements java.security.PrivilegedAction<Boolean> {
private final String theProp;
/**
* Constructor that takes the name of the system property whose boolean
* value needs to be determined.
*
* @param theProp the name of the system property.
*/
public GetBooleanAction(String theProp) {
this.theProp = theProp;
}
/**
* Determines the boolean value of the system property whose name was
* specified in the constructor.
*
* @return the <code>Boolean</code> value of the system property.
*/
public Boolean run() {
return Boolean.getBoolean(theProp);
}
/**
* Convenience method to get a property without going through doPrivileged
* if no security manager is present. This is unsafe for inclusion in a
* public API but allowable here since this class is now encapsulated.
*
* Note that this method performs a privileged action using caller-provided
* inputs. The caller of this method should take care to ensure that the
* inputs are not tainted and the returned property is not made accessible
* to untrusted code if it contains sensitive information.
*
* @param theProp the name of the system property.
*/
@SuppressWarnings("removal")
public static boolean privilegedGetProperty(String theProp) {
if (System.getSecurityManager() == null) {
return Boolean.getBoolean(theProp);
} else {
return AccessController.doPrivileged(
new GetBooleanAction(theProp));
}
}
}

View file

@ -1,165 +0,0 @@
/*
* Copyright (c) 1998, 2022, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package sun.security.action;
import java.security.AccessController;
/**
* A convenience class for retrieving the integer value of a system property
* as a privileged action.
*
* <p>An instance of this class can be used as the argument of
* <code>AccessController.doPrivileged</code>.
*
* <p>The following code retrieves the integer value of the system
* property named <code>"prop"</code> as a privileged action. Since it does
* not pass a default value to be used in case the property
* <code>"prop"</code> is not defined, it has to check the result for
* <code>null</code>:
*
* <pre>
* Integer tmp = java.security.AccessController.doPrivileged
* (new sun.security.action.GetIntegerAction("prop"));
* int i;
* if (tmp != null) {
* i = tmp.intValue();
* }
* </pre>
*
* <p>The following code retrieves the integer value of the system
* property named <code>"prop"</code> as a privileged action, and also passes
* a default value to be used in case the property <code>"prop"</code> is not
* defined:
*
* <pre>
* int i = ((Integer)java.security.AccessController.doPrivileged(
* new GetIntegerAction("prop", 3))).intValue();
* </pre>
*
* @author Roland Schemers
* @see java.security.PrivilegedAction
* @see java.security.AccessController
* @since 1.2
*/
public class GetIntegerAction
implements java.security.PrivilegedAction<Integer> {
private final String theProp;
private final int defaultVal;
private final boolean defaultSet;
/**
* Constructor that takes the name of the system property whose integer
* value needs to be determined.
*
* @param theProp the name of the system property.
*/
public GetIntegerAction(String theProp) {
this.theProp = theProp;
this.defaultVal = 0;
this.defaultSet = false;
}
/**
* Constructor that takes the name of the system property and the default
* value of that property.
*
* @param theProp the name of the system property.
* @param defaultVal the default value.
*/
public GetIntegerAction(String theProp, int defaultVal) {
this.theProp = theProp;
this.defaultVal = defaultVal;
this.defaultSet = true;
}
/**
* Determines the integer value of the system property whose name was
* specified in the constructor.
*
* <p>If there is no property of the specified name, or if the property
* does not have the correct numeric format, then an <code>Integer</code>
* object representing the default value that was specified in the
* constructor is returned, or <code>null</code> if no default value was
* specified.
*
* @return the <code>Integer</code> value of the property.
*/
public Integer run() {
Integer value = Integer.getInteger(theProp);
if ((value == null) && defaultSet)
return defaultVal;
return value;
}
/**
* Convenience method to get a property without going through doPrivileged
* if no security manager is present. This is unsafe for inclusion in a
* public API but allowable here since this class is now encapsulated.
*
* Note that this method performs a privileged action using caller-provided
* inputs. The caller of this method should take care to ensure that the
* inputs are not tainted and the returned property is not made accessible
* to untrusted code if it contains sensitive information.
*
* @param theProp the name of the system property.
*/
@SuppressWarnings("removal")
public static Integer privilegedGetProperty(String theProp) {
if (System.getSecurityManager() == null) {
return Integer.getInteger(theProp);
} else {
return AccessController.doPrivileged(
new GetIntegerAction(theProp));
}
}
/**
* Convenience method to get a property without going through doPrivileged
* if no security manager is present. This is unsafe for inclusion in a
* public API but allowable here since this class is now encapsulated.
*
* Note that this method performs a privileged action using caller-provided
* inputs. The caller of this method should take care to ensure that the
* inputs are not tainted and the returned property is not made accessible
* to untrusted code if it contains sensitive information.
*
* @param theProp the name of the system property.
* @param defaultVal the default value.
*/
@SuppressWarnings("removal")
public static Integer privilegedGetProperty(String theProp,
int defaultVal) {
Integer value;
if (System.getSecurityManager() == null) {
value = Integer.getInteger(theProp);
} else {
value = AccessController.doPrivileged(
new GetIntegerAction(theProp));
}
return (value != null) ? value : defaultVal;
}
}

View file

@ -1,114 +0,0 @@
/*
* Copyright (c) 1998, 2022, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package sun.security.action;
/**
* A convenience class for retrieving the <code>Long</code> value of a system
* property as a privileged action.
*
* <p>An instance of this class can be used as the argument of
* <code>AccessController.doPrivileged</code>.
*
* <p>The following code retrieves the <code>Long</code> value of the system
* property named <code>"prop"</code> as a privileged action. Since it does
* not pass a default value to be used in case the property
* <code>"prop"</code> is not defined, it has to check the result for
* <code>null</code>:
*
* <pre>
* Long tmp = java.security.AccessController.doPrivileged
* (new sun.security.action.GetLongAction("prop"));
* long l;
* if (tmp != null) {
* l = tmp.longValue();
* }
* </pre>
*
* <p>The following code retrieves the <code>Long</code> value of the system
* property named <code>"prop"</code> as a privileged action, and also passes
* a default value to be used in case the property <code>"prop"</code> is not
* defined:
*
* <pre>
* long l = java.security.AccessController.doPrivileged
* (new GetLongAction("prop")).longValue();
* </pre>
*
* @author Roland Schemers
* @see java.security.PrivilegedAction
* @see java.security.AccessController
* @since 1.2
*/
public class GetLongAction implements java.security.PrivilegedAction<Long> {
private final String theProp;
private final long defaultVal;
private final boolean defaultSet;
/**
* Constructor that takes the name of the system property whose
* <code>Long</code> value needs to be determined.
*
* @param theProp the name of the system property.
*/
public GetLongAction(String theProp) {
this.theProp = theProp;
this.defaultVal = 0;
this.defaultSet = false;
}
/**
* Constructor that takes the name of the system property and the default
* value of that property.
*
* @param theProp the name of the system property.
* @param defaultVal the default value.
*/
public GetLongAction(String theProp, long defaultVal) {
this.theProp = theProp;
this.defaultVal = defaultVal;
this.defaultSet = true;
}
/**
* Determines the <code>Long</code> value of the system property whose
* name was specified in the constructor.
*
* <p>If there is no property of the specified name, or if the property
* does not have the correct numeric format, then a <code>Long</code>
* object representing the default value that was specified in the
* constructor is returned, or <code>null</code> if no default value was
* specified.
*
* @return the <code>Long</code> value of the property.
*/
public Long run() {
Long value = Long.getLong(theProp);
if ((value == null) && defaultSet)
return defaultVal;
return value;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024, 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
@ -27,9 +27,7 @@ package sun.security.action;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Locale;
import java.util.Properties;
import sun.security.util.Debug;
/**
* A convenience class for retrieving the string value of a system
@ -162,99 +160,4 @@ public class GetPropertyAction implements PrivilegedAction<String> {
);
}
}
/**
* Convenience method for fetching System property values that are timeouts.
* Accepted timeout values may be purely numeric, a numeric value
* followed by "s" (both interpreted as seconds), or a numeric value
* followed by "ms" (interpreted as milliseconds).
*
* @param prop the name of the System property
* @param def a default value (in milliseconds)
* @param dbg a Debug object, if null no debug messages will be sent
*
* @return an integer value corresponding to the timeout value in the System
* property in milliseconds. If the property value is empty, negative,
* or contains non-numeric characters (besides a trailing "s" or "ms")
* then the default value will be returned. If a negative value for
* the "def" parameter is supplied, zero will be returned if the
* property's value does not conform to the allowed syntax.
*/
public static int privilegedGetTimeoutProp(String prop, int def, Debug dbg) {
if (def < 0) {
def = 0;
}
String rawPropVal = privilegedGetProperty(prop, "").trim();
if (rawPropVal.length() == 0) {
return def;
}
// Determine if "ms" or just "s" is on the end of the string.
// We may do a little surgery on the value so we'll retain
// the original value in rawPropVal for debug messages.
boolean isMillis = false;
String propVal = rawPropVal;
if (rawPropVal.toLowerCase(Locale.ROOT).endsWith("ms")) {
propVal = rawPropVal.substring(0, rawPropVal.length() - 2);
isMillis = true;
} else if (rawPropVal.toLowerCase(Locale.ROOT).endsWith("s")) {
propVal = rawPropVal.substring(0, rawPropVal.length() - 1);
}
// Next check to make sure the string is built only from digits
if (propVal.matches("^\\d+$")) {
try {
int timeout = Integer.parseInt(propVal);
return isMillis ? timeout : timeout * 1000;
} catch (NumberFormatException nfe) {
if (dbg != null) {
dbg.println("Warning: Unexpected " + nfe +
" for timeout value " + rawPropVal +
". Using default value of " + def + " msec.");
}
return def;
}
} else {
if (dbg != null) {
dbg.println("Warning: Incorrect syntax for timeout value " +
rawPropVal + ". Using default value of " + def +
" msec.");
}
return def;
}
}
/**
* Convenience method for fetching System property values that are booleans.
*
* @param prop the name of the System property
* @param def a default value
* @param dbg a Debug object, if null no debug messages will be sent
*
* @return a boolean value corresponding to the value in the System property.
* If the property value is neither "true" or "false", the default value
* will be returned.
*/
public static boolean privilegedGetBooleanProp(String prop, boolean def, Debug dbg) {
String rawPropVal = privilegedGetProperty(prop, "");
if ("".equals(rawPropVal)) {
return def;
}
String lower = rawPropVal.toLowerCase(Locale.ROOT);
if ("true".equals(lower)) {
return true;
} else if ("false".equals(lower)) {
return false;
} else {
if (dbg != null) {
dbg.println("Warning: Unexpected value for " + prop +
": " + rawPropVal +
". Using default value: " + def);
}
return def;
}
}
}

View file

@ -1,56 +0,0 @@
/*
* Copyright (c) 2003, 2011, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package sun.security.action;
import java.util.Map;
import java.security.Provider;
import java.security.PrivilegedAction;
/**
* A convenience PrivilegedAction class for setting the properties of
* a provider. See the SunRsaSign provider for a usage example.
*
* @see sun.security.rsa.SunRsaSign
* @author Andreas Sterbenz
* @since 1.5
*/
public class PutAllAction implements PrivilegedAction<Void> {
private final Provider provider;
private final Map<?, ?> map;
public PutAllAction(Provider provider, Map<?, ?> map) {
this.provider = provider;
this.map = map;
}
public Void run() {
provider.putAll(map);
return null;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2024, 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
@ -25,10 +25,8 @@
package sun.security.ec;
import java.security.AccessController;
import java.security.InvalidParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedAction;
import java.security.Provider;
import java.security.ProviderException;
import java.util.HashMap;
@ -180,15 +178,9 @@ public final class SunEC extends Provider {
}
}
@SuppressWarnings("removal")
public SunEC() {
super("SunEC", PROVIDER_VER, "Sun Elliptic Curve provider");
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
putEntries();
return null;
}
});
putEntries();
}
void putEntries() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, 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
@ -25,8 +25,6 @@
package sun.security.internal.spec;
import sun.security.action.GetBooleanAction;
import java.security.spec.AlgorithmParameterSpec;
/**
@ -54,8 +52,8 @@ public class TlsRsaPremasterSecretParameterSpec
* Default is "false" (old behavior) for compatibility reasons in
* SSLv3/TLSv1. Later protocols (TLSv1.1+) do not use this property.
*/
private static final boolean rsaPreMasterSecretFix = GetBooleanAction
.privilegedGetProperty("com.sun.net.ssl.rsaPreMasterSecretFix");
private static final boolean rsaPreMasterSecretFix =
Boolean.getBoolean("com.sun.net.ssl.rsaPreMasterSecretFix");
private final int clientVersion;
private final int serverVersion;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, 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
@ -94,23 +94,11 @@ final class ProviderConfig {
// avoid if not available (pre Solaris 10) to reduce startup time
// or if disabled via system property
private void checkSunPKCS11Solaris() {
@SuppressWarnings("removal")
Boolean o = AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
public Boolean run() {
File file = new File("/usr/lib/libpkcs11.so");
if (file.exists() == false) {
return Boolean.FALSE;
}
if ("false".equalsIgnoreCase(System.getProperty
("sun.security.pkcs11.enable-solaris"))) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
});
if (o == Boolean.FALSE) {
tries = MAX_LOAD_TRIES;
File file = new File("/usr/lib/libpkcs11.so");
if (file.exists() == false ||
("false".equalsIgnoreCase(System.getProperty
("sun.security.pkcs11.enable-solaris")))) {
tries = MAX_LOAD_TRIES;
}
}
@ -190,28 +178,22 @@ final class ProviderConfig {
case "Apple", "apple.security.AppleProvider" -> {
// Reflection is needed for compile time as the class
// is not available for non-macosx systems
@SuppressWarnings("removal")
var tmp = AccessController.doPrivileged(
new PrivilegedAction<Provider>() {
public Provider run() {
try {
Class<?> c = Class.forName(
"apple.security.AppleProvider");
if (Provider.class.isAssignableFrom(c)) {
@SuppressWarnings("deprecation")
Object tmp = c.newInstance();
return (Provider) tmp;
}
} catch (Exception ex) {
if (debug != null) {
debug.println("Error loading provider Apple");
ex.printStackTrace();
}
}
return null;
}
});
yield tmp;
Provider ap = null;
try {
Class<?> c = Class.forName(
"apple.security.AppleProvider");
if (Provider.class.isAssignableFrom(c)) {
@SuppressWarnings("deprecation")
Object tmp = c.newInstance();
ap = (Provider) tmp;
}
} catch (Exception ex) {
if (debug != null) {
debug.println("Error loading provider Apple");
ex.printStackTrace();
}
}
yield ap;
}
default -> {
if (isLoading) {
@ -240,83 +222,69 @@ final class ProviderConfig {
/**
* Load and instantiate the Provider described by this class.
*
* NOTE use of doPrivileged().
*
* @return null if the Provider could not be loaded
*
* @throws ProviderException if executing the Provider's constructor
* throws a ProviderException. All other Exceptions are ignored.
*/
@SuppressWarnings("removal")
private Provider doLoadProvider() {
return AccessController.doPrivileged(new PrivilegedAction<Provider>() {
public Provider run() {
if (debug != null) {
debug.println("Loading provider " + ProviderConfig.this);
}
try {
Provider p = ProviderLoader.INSTANCE.load(provName);
if (p != null) {
if (hasArgument()) {
p = p.configure(argument);
}
if (debug != null) {
debug.println("Loading provider " + ProviderConfig.this);
debug.println("Loaded provider " + p.getName());
}
try {
Provider p = ProviderLoader.INSTANCE.load(provName);
if (p != null) {
if (hasArgument()) {
p = p.configure(argument);
}
if (debug != null) {
debug.println("Loaded provider " + p.getName());
}
} else {
if (debug != null) {
debug.println("Error loading provider " +
ProviderConfig.this);
}
disableLoad();
}
return p;
} catch (Exception e) {
if (e instanceof ProviderException) {
// pass up
throw e;
} else {
if (debug != null) {
debug.println("Error loading provider " +
ProviderConfig.this);
e.printStackTrace();
}
disableLoad();
return null;
}
} catch (ExceptionInInitializerError err) {
// no sufficient permission to initialize provider class
if (debug != null) {
debug.println("Error loading provider " + ProviderConfig.this);
err.printStackTrace();
}
disableLoad();
return null;
} else {
if (debug != null) {
debug.println("Error loading provider " +
ProviderConfig.this);
}
disableLoad();
}
});
return p;
} catch (Exception e) {
if (e instanceof ProviderException) {
// pass up
throw e;
} else {
if (debug != null) {
debug.println("Error loading provider " +
ProviderConfig.this);
e.printStackTrace();
}
disableLoad();
return null;
}
} catch (ExceptionInInitializerError err) {
// unable to initialize provider class
if (debug != null) {
debug.println("Error loading provider " + ProviderConfig.this);
err.printStackTrace();
}
disableLoad();
return null;
}
}
/**
* Perform property expansion of the provider value.
*
* NOTE use of doPrivileged().
*/
@SuppressWarnings("removal")
private static String expand(final String value) {
// shortcut if value does not contain any properties
if (value.contains("${") == false) {
return value;
}
return AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
try {
return PropertyExpander.expand(value);
} catch (GeneralSecurityException e) {
throw new ProviderException(e);
}
}
});
try {
return PropertyExpander.expand(value);
} catch (GeneralSecurityException e) {
throw new ProviderException(e);
}
}
// Inner class for loading security providers listed in java.security file
@ -356,9 +324,9 @@ final class ProviderConfig {
if (pName.equals(pn)) {
return p;
}
} catch (SecurityException | ServiceConfigurationError |
} catch (ServiceConfigurationError |
InvalidParameterException ex) {
// if provider loading fail due to security permission,
// if provider loading failed
// log it and move on to next provider
if (debug != null) {
debug.println("Encountered " + ex +
@ -385,6 +353,7 @@ final class ProviderConfig {
}
}
@SuppressWarnings("deprecation") // Class.newInstance
private Provider legacyLoad(String classname) {
if (debug != null) {
@ -403,15 +372,7 @@ final class ProviderConfig {
return null;
}
@SuppressWarnings("removal")
Provider p = AccessController.doPrivileged
(new PrivilegedExceptionAction<Provider>() {
@SuppressWarnings("deprecation") // Class.newInstance
public Provider run() throws Exception {
return (Provider) provClass.newInstance();
}
});
return p;
return (Provider) provClass.newInstance();
} catch (Exception e) {
Throwable t;
if (e instanceof InvocationTargetException) {
@ -429,7 +390,7 @@ final class ProviderConfig {
}
return null;
} catch (ExceptionInInitializerError | NoClassDefFoundError err) {
// no sufficient permission to access/initialize provider class
// unable to access/initialize provider class
if (debug != null) {
debug.println("Error loading legacy provider " + classname);
err.printStackTrace();

View file

@ -27,8 +27,6 @@ package sun.security.jca;
import java.util.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.Provider;
import java.security.Provider.Service;
import java.security.Security;
@ -87,15 +85,8 @@ public final class ProviderList {
// construct a ProviderList from the security properties
// (static provider configuration in the java.security file)
@SuppressWarnings("removal")
static ProviderList fromSecurityProperties() {
// doPrivileged() because of Security.getProperty()
return AccessController.doPrivileged(
new PrivilegedAction<ProviderList>() {
public ProviderList run() {
return new ProviderList();
}
});
return new ProviderList();
}
public static ProviderList add(ProviderList providerList, Provider p) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2024, 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
@ -29,15 +29,10 @@ import java.io.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.security.Security;
import java.security.URIParameter;
import java.text.MessageFormat;
import java.util.*;
import javax.security.auth.AuthPermission;
import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag;
import javax.security.auth.login.Configuration;
@ -159,34 +154,18 @@ public final class ConfigFile extends Configuration {
}
}
@SuppressWarnings("removal")
public Spi(final Configuration.Parameters params) throws IOException {
// call in a doPrivileged
//
// We have already passed the Configuration.getInstance
// security check. Also, this class is not freely accessible
// (it is in the "sun" package).
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
public Void run() throws IOException {
if (params == null) {
init();
} else {
if (!(params instanceof URIParameter)) {
throw new IllegalArgumentException
("Unrecognized parameter: " + params);
}
URIParameter uriParam = (URIParameter)params;
url = uriParam.getURI().toURL();
init();
}
return null;
}
});
} catch (PrivilegedActionException pae) {
throw (IOException)pae.getException();
if (params == null) {
init();
} else {
if (!(params instanceof URIParameter)) {
throw new IllegalArgumentException
("Unrecognized parameter: " + params);
}
URIParameter uriParam = (URIParameter)params;
url = uriParam.getURI().toURL();
init();
}
// if init() throws some other RuntimeException,
@ -198,8 +177,6 @@ public final class ConfigFile extends Configuration {
* configured URL.
*
* @throws IOException if the Configuration can not be initialized
* @throws SecurityException if the caller does not have permission
* to initialize the Configuration
*/
private void init() throws IOException {
@ -377,31 +354,15 @@ public final class ConfigFile extends Configuration {
/**
* Refresh and reload the Configuration by re-reading all the
* login configurations.
*
* @throws SecurityException if the caller does not have permission
* to refresh the Configuration.
*/
@SuppressWarnings("removal")
@Override
public synchronized void engineRefresh() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(
new AuthPermission("refreshLoginConfiguration"));
try {
init();
} catch (IOException ioe) {
throw new SecurityException(ioe.getLocalizedMessage(), ioe);
}
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
try {
init();
} catch (IOException ioe) {
throw new SecurityException(ioe.getLocalizedMessage(),
ioe);
}
return null;
}
});
}
private void readConfig(Reader reader,

View file

@ -27,9 +27,7 @@ package sun.security.provider;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.security.AccessController;
import java.security.DrbgParameters;
import java.security.PrivilegedAction;
import java.security.SecureRandomParameters;
import java.security.SecureRandomSpi;
import java.security.Security;
@ -93,10 +91,7 @@ public final class DRBG extends SecureRandomSpi {
byte[] nonce = null;
// Can be configured with a security property
@SuppressWarnings("removal")
String config = AccessController.doPrivileged((PrivilegedAction<String>)
() -> Security.getProperty(PROP_NAME));
String config = Security.getProperty(PROP_NAME);
if (config != null && !config.isEmpty()) {
for (String part : config.split(",")) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2024, 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
@ -65,9 +65,6 @@ class FileInputStreamPool {
* @throws FileNotFoundException if the file does not exist, is a directory
* rather than a regular file, or for some
* other reason cannot be opened for reading.
* @throws SecurityException if a security manager exists and its
* <code>checkRead</code> method denies read
* access to the file.
*/
static InputStream getInputStream(File file) throws IOException {
@ -78,9 +75,6 @@ class FileInputStreamPool {
}
// canonicalize the path
// (this also checks the read permission on the file if SecurityManager
// is present, so no checking is needed later when we just return the
// already opened stream)
File cfile = file.getCanonicalFile();
// check if it exists in pool

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, 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
@ -69,13 +69,7 @@ public final class MD4 extends DigestBase {
@java.io.Serial
private static final long serialVersionUID = -8850464997518327965L;
};
@SuppressWarnings("removal")
var dummy = AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
md4Provider.put("MessageDigest.MD4", "sun.security.provider.MD4");
return null;
}
});
md4Provider.put("MessageDigest.MD4", "sun.security.provider.MD4");
}
public static MessageDigest getInstance() {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, 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
@ -149,7 +149,6 @@ abstract class SeedGenerator {
/**
* Retrieve some system information, hashed.
*/
@SuppressWarnings("removal")
static byte[] getSystemEntropy() {
final MessageDigest md;
@ -164,57 +163,48 @@ abstract class SeedGenerator {
byte b =(byte)System.currentTimeMillis();
md.update(b);
java.security.AccessController.doPrivileged
(new java.security.PrivilegedAction<>() {
@Override
public Void run() {
try {
// System properties can change from machine to machine
Properties p = System.getProperties();
for (String s: p.stringPropertyNames()) {
md.update(s.getBytes());
md.update(p.getProperty(s).getBytes());
}
try {
// System properties can change from machine to machine
Properties p = System.getProperties();
for (String s: p.stringPropertyNames()) {
md.update(s.getBytes());
md.update(p.getProperty(s).getBytes());
}
// Include network adapter names (and a Mac address)
addNetworkAdapterInfo(md);
// Include network adapter names (and a Mac address)
addNetworkAdapterInfo(md);
// The temporary dir
File f = new File(p.getProperty("java.io.tmpdir"));
int count = 0;
try (
DirectoryStream<Path> stream =
Files.newDirectoryStream(f.toPath())) {
// We use a Random object to choose what file names
// should be used. Otherwise, on a machine with too
// many files, the same first 1024 files always get
// used. Any, We make sure the first 512 files are
// always used.
Random r = new Random();
for (Path entry: stream) {
if (count < 512 || r.nextBoolean()) {
md.update(entry.getFileName()
.toString().getBytes());
}
if (count++ > 1024) {
break;
}
}
}
} catch (Exception ex) {
md.update((byte)ex.hashCode());
// The temporary dir
File f = new File(p.getProperty("java.io.tmpdir"));
int count = 0;
try (DirectoryStream<Path> stream =
Files.newDirectoryStream(f.toPath())) {
// We use a Random object to choose what file names
// should be used. Otherwise, on a machine with too
// many files, the same first 1024 files always get
// used. Any, We make sure the first 512 files are
// always used.
Random r = new Random();
for (Path entry: stream) {
if (count < 512 || r.nextBoolean()) {
md.update(entry.getFileName().toString().getBytes());
}
if (count++ > 1024) {
break;
}
// get Runtime memory stats
Runtime rt = Runtime.getRuntime();
byte[] memBytes = longToByteArray(rt.totalMemory());
md.update(memBytes, 0, memBytes.length);
memBytes = longToByteArray(rt.freeMemory());
md.update(memBytes, 0, memBytes.length);
return null;
}
});
}
} catch (Exception ex) {
md.update((byte)ex.hashCode());
}
// get Runtime memory stats
Runtime rt = Runtime.getRuntime();
byte[] memBytes = longToByteArray(rt.totalMemory());
md.update(memBytes, 0, memBytes.length);
memBytes = longToByteArray(rt.freeMemory());
md.update(memBytes, 0, memBytes.length);
return md.digest();
}
@ -293,29 +283,19 @@ abstract class SeedGenerator {
, e);
}
final ThreadGroup[] finalsg = new ThreadGroup[1];
@SuppressWarnings("removal")
Thread t = java.security.AccessController.doPrivileged
(new java.security.PrivilegedAction<>() {
@Override
public Thread run() {
ThreadGroup parent, group =
Thread.currentThread().getThreadGroup();
while ((parent = group.getParent()) != null) {
group = parent;
}
finalsg[0] = new ThreadGroup
(group, "SeedGenerator ThreadGroup");
Thread newT = new Thread(finalsg[0],
ThreadedSeedGenerator.this,
"SeedGenerator Thread",
0,
false);
newT.setPriority(Thread.MIN_PRIORITY);
newT.setDaemon(true);
return newT;
}
});
ThreadGroup[] finalsg = new ThreadGroup[1];
ThreadGroup parent, group = Thread.currentThread().getThreadGroup();
while ((parent = group.getParent()) != null) {
group = parent;
}
finalsg[0] = new ThreadGroup(group, "SeedGenerator ThreadGroup");
Thread t = new Thread(finalsg[0],
ThreadedSeedGenerator.this,
"SeedGenerator Thread",
0,
false);
t.setPriority(Thread.MIN_PRIORITY);
t.setDaemon(true);
seedGroup = finalsg[0];
t.start();
}
@ -502,34 +482,25 @@ abstract class SeedGenerator {
init();
}
@SuppressWarnings("removal")
private void init() throws IOException {
@SuppressWarnings("deprecation")
final URL device = new URL(deviceName);
URL device = new URL(deviceName);
try {
seedStream = java.security.AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction<>() {
@Override
public InputStream run() throws IOException {
/*
* return a shared InputStream for file URLs and
* avoid buffering.
* The URL.openStream() call wraps InputStream in a
* BufferedInputStream which
* can buffer up to 8K bytes. This read is a
* performance issue for entropy sources which
* can be slow to replenish.
*/
if (device.getProtocol().equalsIgnoreCase("file")) {
File deviceFile =
SunEntries.getDeviceFile(device);
return FileInputStreamPool
.getInputStream(deviceFile);
} else {
return device.openStream();
}
}
});
/*
* return a shared InputStream for file URLs and
* avoid buffering.
* The URL.openStream() call wraps InputStream in a
* BufferedInputStream which
* can buffer up to 8K bytes. This read is a
* performance issue for entropy sources which
* can be slow to replenish.
*/
if (device.getProtocol().equalsIgnoreCase("file")) {
File deviceFile = SunEntries.getDeviceFile(device);
seedStream = FileInputStreamPool.getInputStream(deviceFile);
} else {
seedStream = device.openStream();
}
} catch (Exception e) {
throw new IOException(
"Failed to open " + deviceName, e.getCause());

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, 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
@ -47,7 +47,6 @@ public final class Sun extends Provider {
"PKIX CertPathBuilder; LDAP, Collection CertStores, JavaPolicy Policy; " +
"JavaLoginConfig Configuration)";
@SuppressWarnings("removal")
public Sun() {
/* We are the SUN provider */
super("SUN", PROVIDER_VER, INFO);
@ -55,24 +54,8 @@ public final class Sun extends Provider {
Provider p = this;
Iterator<Provider.Service> serviceIter = new SunEntries(p).iterator();
// if there is no security manager installed, put directly into
// the provider
if (System.getSecurityManager() == null) {
putEntries(serviceIter);
} else {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
putEntries(serviceIter);
return null;
}
});
}
}
void putEntries(Iterator<Provider.Service> i) {
while (i.hasNext()) {
putService(i.next());
while (serviceIter.hasNext()) {
putService(serviceIter.next());
}
}
}

View file

@ -30,8 +30,6 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.Provider;
import java.security.Security;
import java.util.HashMap;
@ -39,7 +37,6 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import jdk.internal.util.StaticProperty;
import sun.security.action.GetBooleanAction;
import static sun.security.util.SecurityProviderConstants.getAliases;
@ -345,29 +342,24 @@ public final class SunEntries {
private static final String PROP_RNDSOURCE = "securerandom.source";
private static final boolean useLegacyDSA =
GetBooleanAction.privilegedGetProperty
("jdk.security.legacyDSAKeyPairGenerator");
Boolean.getBoolean("jdk.security.legacyDSAKeyPairGenerator");
static final String URL_DEV_RANDOM = "file:/dev/random";
static final String URL_DEV_URANDOM = "file:/dev/urandom";
@SuppressWarnings("removal")
private static final String seedSource = AccessController.doPrivileged(
new PrivilegedAction<String>() {
private static final String seedSource = getOverridableSeedSource();
@Override
public String run() {
String egdSource = System.getProperty(PROP_EGD, "");
if (egdSource.length() != 0) {
return egdSource;
}
egdSource = Security.getProperty(PROP_RNDSOURCE);
if (egdSource == null) {
return "";
}
return egdSource;
}
});
private static String getOverridableSeedSource() {
String egdSource = System.getProperty(PROP_EGD, "");
if (egdSource.length() != 0) {
return egdSource;
}
egdSource = Security.getProperty(PROP_RNDSOURCE);
if (egdSource == null) {
return "";
}
return egdSource;
}
static {
DEF_SECURE_RANDOM_ALGO = (NativePRNG.isAvailable() &&
@ -386,8 +378,6 @@ public final class SunEntries {
* URISyntaxException we make a best effort for backwards
* compatibility. e.g. space character in deviceName string.
*
* Method called within PrivilegedExceptionAction block.
*
* Moved from SeedGenerator to avoid initialization problems with
* signed providers.
*/

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2024, 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
@ -61,7 +61,6 @@ public final class VerificationProvider extends Provider {
ACTIVE = b;
}
@SuppressWarnings("removal")
public VerificationProvider() {
super("SunJarVerification", PROVIDER_VER, "Jar Verification Provider");
// register all algorithms normally registered by the Sun and SunRsaSign
@ -75,20 +74,8 @@ public final class VerificationProvider extends Provider {
Iterator<Provider.Service> rsaIter =
new SunRsaSignEntries(p).iterator();
// if there is no security manager installed, put directly into
// the provider
if (System.getSecurityManager() == null) {
putEntries(sunIter);
putEntries(rsaIter);
} else {
AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Void run() {
putEntries(sunIter);
putEntries(rsaIter);
return null;
}
});
}
putEntries(sunIter);
putEntries(rsaIter);
}
void putEntries(Iterator<Provider.Service> i) {

View file

@ -38,10 +38,10 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import sun.security.action.GetPropertyAction;
import sun.security.util.Debug;
import sun.security.util.Event;
import sun.security.util.IOUtils;
import sun.security.util.SecurityProperties;
import sun.security.x509.AccessDescription;
import sun.security.x509.AuthorityInfoAccessExtension;
import sun.security.x509.GeneralName;
@ -114,7 +114,7 @@ public final class OCSP {
*/
private static int initializeTimeout(String prop, int def) {
int timeoutVal =
GetPropertyAction.privilegedGetTimeoutProp(prop, def, debug);
SecurityProperties.getTimeoutSystemProp(prop, def, debug);
if (debug != null) {
debug.println(prop + " set to " + timeoutVal + " milliseconds");
}
@ -123,7 +123,7 @@ public final class OCSP {
private static boolean initializeBoolean(String prop, boolean def) {
boolean value =
GetPropertyAction.privilegedGetBooleanProp(prop, def, debug);
SecurityProperties.getBooleanSystemProp(prop, def, debug);
if (debug != null) {
debug.println(prop + " set to " + value);
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2024, 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
@ -51,12 +51,12 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import sun.security.action.GetPropertyAction;
import sun.security.x509.AccessDescription;
import sun.security.x509.GeneralNameInterface;
import sun.security.x509.URIName;
import sun.security.util.Cache;
import sun.security.util.Debug;
import sun.security.util.SecurityProperties;
/**
* A <code>CertStore</code> that retrieves <code>Certificates</code> or
@ -175,7 +175,7 @@ class URICertStore extends CertStoreSpi {
*/
private static int initializeTimeout(String prop, int def) {
int timeoutVal =
GetPropertyAction.privilegedGetTimeoutProp(prop, def, debug);
SecurityProperties.getTimeoutSystemProp(prop, def, debug);
if (debug != null) {
debug.println(prop + " set to " + timeoutVal + " milliseconds");
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, 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,7 +32,6 @@ import java.security.interfaces.*;
import java.security.spec.*;
import java.util.Arrays;
import sun.security.action.GetPropertyAction;
import sun.security.rsa.RSAUtil.KeyType;
/**
@ -91,7 +90,7 @@ public class RSAKeyFactory extends KeyFactorySpi {
public static final int MAX_RESTRICTED_EXPLEN = 64;
private static final boolean restrictExpLen =
"true".equalsIgnoreCase(GetPropertyAction.privilegedGetProperty(
"true".equalsIgnoreCase(System.getProperty(
"sun.security.rsa.restrictRSAExponent", "true"));
static RSAKeyFactory getInstance(KeyType type) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2024, 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
@ -43,26 +43,11 @@ public final class SunRsaSign extends Provider {
@java.io.Serial
private static final long serialVersionUID = 866040293550393045L;
@SuppressWarnings("removal")
public SunRsaSign() {
super("SunRsaSign", PROVIDER_VER, "Sun RSA signature provider");
Provider p = this;
Iterator<Provider.Service> serviceIter = new SunRsaSignEntries(p).iterator();
if (System.getSecurityManager() == null) {
putEntries(serviceIter);
} else {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
@Override
public Void run() {
putEntries(serviceIter);
return null;
}
});
}
}
void putEntries(Iterator<Provider.Service> i) {
Iterator<Provider.Service> i = new SunRsaSignEntries(p).iterator();
while (i.hasNext()) {
putService(i.next());
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2024, 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
@ -25,9 +25,7 @@
package sun.security.util;
import java.security.AccessController;
import java.security.AlgorithmConstraints;
import java.security.PrivilegedAction;
import java.security.Security;
import java.util.Arrays;
import java.util.Collections;
@ -48,14 +46,7 @@ public abstract class AbstractAlgorithmConstraints
// Get algorithm constraints from the specified security property.
static Set<String> getAlgorithms(String propertyName) {
@SuppressWarnings("removal")
String property = AccessController.doPrivileged(
new PrivilegedAction<String>() {
@Override
public String run() {
return Security.getProperty(propertyName);
}
});
String property = Security.getProperty(propertyName);
String[] algorithmsInProperty = null;
if (property != null && !property.isEmpty()) {

View file

@ -34,7 +34,6 @@ import java.util.HexFormat;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.Locale;
import sun.security.action.GetPropertyAction;
/**
* A utility class for debugging.
@ -54,10 +53,9 @@ public class Debug {
private static final String THREAD_OPTION = "+thread";
static {
args = GetPropertyAction.privilegedGetProperty("java.security.debug");
args = System.getProperty("java.security.debug");
String args2 = GetPropertyAction
.privilegedGetProperty("java.security.auth.debug");
String args2 = System.getProperty("java.security.auth.debug");
if (args == null) {
args = args2;

View file

@ -32,8 +32,6 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
@ -205,21 +203,12 @@ class DomainName {
}
private static InputStream getPubSuffixStream() {
@SuppressWarnings("removal")
InputStream is = AccessController.doPrivileged(
new PrivilegedAction<>() {
@Override
public InputStream run() {
File f = new File(StaticProperty.javaHome(),
"lib/security/public_suffix_list.dat");
try {
return new FileInputStream(f);
} catch (FileNotFoundException e) {
return null;
}
}
}
);
InputStream is = null;
File f = new File(System.getProperty("java.home"),
"lib/security/public_suffix_list.dat");
try {
is = new FileInputStream(f);
} catch (FileNotFoundException e) { }
if (is == null) {
if (SSLLogger.isOn && SSLLogger.isOn("ssl") &&
SSLLogger.isOn("trustmanager")) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2024, 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
@ -40,7 +40,7 @@ public class FilePermCompat {
public static final boolean compat;
static {
String flag = SecurityProperties.privilegedGetOverridable(
String flag = SecurityProperties.getOverridableProperty(
"jdk.io.permissionsUseCanonicalPath");
if (flag == null) {
flag = "false";

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2024, 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
@ -153,7 +153,7 @@ public class HostnameChecker {
InetAddress.getByName(ipAddress))) {
return;
}
} catch (UnknownHostException | SecurityException e) {}
} catch (UnknownHostException e) {}
}
}
}

View file

@ -1,128 +0,0 @@
/*
* Copyright (c) 2019, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package sun.security.util;
import java.io.File;
import java.io.FilePermission;
import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.security.Permission;
import java.security.PermissionCollection;
import java.util.Enumeration;
/**
* This {@code PermissionCollection} implementation delegates to another
* {@code PermissionCollection}, taking care to lazily add the permission needed
* to read from the given {@code CodeSource} at first use, i.e., when either of
* {@link #elements}, {@link #implies} or {@link #toString} is called, or when
* the collection is serialized.
*/
public final class LazyCodeSourcePermissionCollection
extends PermissionCollection
{
@java.io.Serial
private static final long serialVersionUID = -6727011328946861783L;
private final PermissionCollection perms;
private final CodeSource cs;
private volatile boolean permissionAdded;
public LazyCodeSourcePermissionCollection(PermissionCollection perms,
CodeSource cs) {
this.perms = perms;
this.cs = cs;
}
private void ensureAdded() {
if (!permissionAdded) {
synchronized(perms) {
if (permissionAdded)
return;
// open connection to determine the permission needed
URL location = cs.getLocation();
if (location != null) {
try {
Permission p = location.openConnection().getPermission();
if (p != null) {
// for directories then need recursive access
if (p instanceof FilePermission) {
String path = p.getName();
if (path.endsWith(File.separator)) {
path += "-";
p = new FilePermission(path,
SecurityConstants.FILE_READ_ACTION);
}
}
perms.add(p);
}
} catch (IOException ioe) {
}
}
if (isReadOnly()) {
perms.setReadOnly();
}
permissionAdded = true;
}
}
}
@Override
public void add(Permission permission) {
if (isReadOnly())
throw new SecurityException(
"attempt to add a Permission to a readonly PermissionCollection");
perms.add(permission);
}
@Override
public boolean implies(Permission permission) {
ensureAdded();
return perms.implies(permission);
}
@Override
public Enumeration<Permission> elements() {
ensureAdded();
return perms.elements();
}
@Override
public String toString() {
ensureAdded();
return perms.toString();
}
/**
* On serialization, initialize and replace with the underlying
* permissions. This removes the laziness on deserialization.
*/
@java.io.Serial
private Object writeReplace() {
ensureAdded();
return perms;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024, 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,8 +49,8 @@ public class LocalizedMessage {
/**
* A LocalizedMessage can be instantiated with a key and formatted with
* arguments later in the style of MessageFormat. This organization
* allows the actual formatting (and associated permission checks) to be
* avoided unless the resulting string is needed.
* allows the actual formatting to be avoided unless the resulting string
* is needed.
* @param key
*/
public LocalizedMessage(String key) {

View file

@ -25,12 +25,7 @@
package sun.security.util;
import java.lang.reflect.ReflectPermission;
import java.net.NetPermission;
import java.net.SocketPermission;
import java.security.AllPermission;
import java.security.SecurityPermission;
import sun.security.action.GetPropertyAction;
/**
* Permission constants and string constants used to create permissions
@ -63,72 +58,9 @@ public final class SecurityConstants {
// Permission constants used in the various checkPermission() calls in JDK.
// java.lang.Class, java.lang.SecurityManager, java.lang.System,
// java.net.URLConnection, java.security.AllPermission, java.security.Policy,
// sun.security.provider.PolicyFile
// java.net.URLConnection, java.security.AllPermission
public static final AllPermission ALL_PERMISSION = new AllPermission();
// java.net.URL
public static final NetPermission SPECIFY_HANDLER_PERMISSION =
new NetPermission("specifyStreamHandler");
// java.net.ServerSocket, java.net.Socket
public static final NetPermission SET_SOCKETIMPL_PERMISSION =
new NetPermission("setSocketImpl");
// java.lang.SecurityManager, sun.applet.AppletPanel
public static final RuntimePermission CREATE_CLASSLOADER_PERMISSION =
new RuntimePermission("createClassLoader");
// java.lang.SecurityManager
public static final RuntimePermission CHECK_MEMBER_ACCESS_PERMISSION =
new RuntimePermission("accessDeclaredMembers");
// java.lang.SecurityManager, sun.applet.AppletSecurity
public static final RuntimePermission MODIFY_THREAD_PERMISSION =
new RuntimePermission("modifyThread");
// java.lang.SecurityManager, sun.applet.AppletSecurity
public static final RuntimePermission MODIFY_THREADGROUP_PERMISSION =
new RuntimePermission("modifyThreadGroup");
// java.lang.Class
public static final RuntimePermission GET_PD_PERMISSION =
new RuntimePermission("getProtectionDomain");
// java.lang.Thread
public static final RuntimePermission GET_STACK_TRACE_PERMISSION =
new RuntimePermission("getStackTrace");
// java.lang.Thread
public static final RuntimePermission SUBCLASS_IMPLEMENTATION_PERMISSION =
new RuntimePermission("enableContextClassLoaderOverride");
// java.security.AccessControlContext
public static final SecurityPermission CREATE_ACC_PERMISSION =
new SecurityPermission("createAccessControlContext");
// java.security.AccessControlContext
public static final SecurityPermission GET_COMBINER_PERMISSION =
new SecurityPermission("getDomainCombiner");
// java.security.Policy, java.security.ProtectionDomain
public static final SecurityPermission GET_POLICY_PERMISSION =
new SecurityPermission ("getPolicy");
// java.lang.SecurityManager
public static final SocketPermission LOCAL_LISTEN_PERMISSION =
new SocketPermission("localhost:0", SOCKET_LISTEN_ACTION);
public static final String PROVIDER_VER =
GetPropertyAction.privilegedGetProperty("java.specification.version");
// java.lang.reflect.AccessibleObject
public static final ReflectPermission ACCESS_PERMISSION =
new ReflectPermission("suppressAccessChecks");
// sun.reflect.ReflectionFactory
public static final RuntimePermission REFLECTION_FACTORY_ACCESS_PERMISSION =
new RuntimePermission("reflectionFactoryAccess");
System.getProperty("java.specification.version");
}

View file

@ -26,10 +26,12 @@
package sun.security.util;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.Security;
import java.util.Locale;
/**
* Utility methods for retrieving security and system properties.
*/
public class SecurityProperties {
public static final boolean INCLUDE_JAR_NAME_IN_EXCEPTIONS
@ -42,15 +44,6 @@ public class SecurityProperties {
* @param propName the name of the system or security property
* @return the value of the system or security property
*/
@SuppressWarnings("removal")
public static String privilegedGetOverridable(String propName) {
if (System.getSecurityManager() == null) {
return getOverridableProperty(propName);
} else {
return AccessController.doPrivileged((PrivilegedAction<String>) () -> getOverridableProperty(propName));
}
}
public static String getOverridableProperty(String propName) {
String val = System.getProperty(propName);
if (val == null) {
@ -69,7 +62,7 @@ public class SecurityProperties {
* contains refName, false otherwise
*/
public static boolean includedInExceptions(String refName) {
String val = privilegedGetOverridable("jdk.includeInExceptions");
String val = getOverridableProperty("jdk.includeInExceptions");
if (val == null) {
return false;
}
@ -83,4 +76,98 @@ public class SecurityProperties {
}
return false;
}
/**
* Convenience method for fetching System property values that are timeouts.
* Accepted timeout values may be purely numeric, a numeric value
* followed by "s" (both interpreted as seconds), or a numeric value
* followed by "ms" (interpreted as milliseconds).
*
* @param prop the name of the System property
* @param def a default value (in milliseconds)
* @param dbg a Debug object, if null no debug messages will be sent
*
* @return an integer value corresponding to the timeout value in the System
* property in milliseconds. If the property value is empty, negative,
* or contains non-numeric characters (besides a trailing "s" or "ms")
* then the default value will be returned. If a negative value for
* the "def" parameter is supplied, zero will be returned if the
* property's value does not conform to the allowed syntax.
*/
public static int getTimeoutSystemProp(String prop, int def, Debug dbg) {
if (def < 0) {
def = 0;
}
String rawPropVal = System.getProperty(prop, "").trim();
if (rawPropVal.length() == 0) {
return def;
}
// Determine if "ms" or just "s" is on the end of the string.
// We may do a little surgery on the value so we'll retain
// the original value in rawPropVal for debug messages.
boolean isMillis = false;
String propVal = rawPropVal;
if (rawPropVal.toLowerCase(Locale.ROOT).endsWith("ms")) {
propVal = rawPropVal.substring(0, rawPropVal.length() - 2);
isMillis = true;
} else if (rawPropVal.toLowerCase(Locale.ROOT).endsWith("s")) {
propVal = rawPropVal.substring(0, rawPropVal.length() - 1);
}
// Next check to make sure the string is built only from digits
if (propVal.matches("^\\d+$")) {
try {
int timeout = Integer.parseInt(propVal);
return isMillis ? timeout : timeout * 1000;
} catch (NumberFormatException nfe) {
if (dbg != null) {
dbg.println("Warning: Unexpected " + nfe +
" for timeout value " + rawPropVal +
". Using default value of " + def + " msec.");
}
return def;
}
} else {
if (dbg != null) {
dbg.println("Warning: Incorrect syntax for timeout value " +
rawPropVal + ". Using default value of " + def +
" msec.");
}
return def;
}
}
/**
* Convenience method for fetching System property values that are booleans.
*
* @param prop the name of the System property
* @param def a default value
* @param dbg a Debug object, if null no debug messages will be sent
*
* @return a boolean value corresponding to the value in the System property.
* If the property value is neither "true" or "false", the default value
* will be returned.
*/
public static boolean getBooleanSystemProp(String prop, boolean def, Debug dbg) {
String rawPropVal = System.getProperty(prop, "");
if ("".equals(rawPropVal)) {
return def;
}
String lower = rawPropVal.toLowerCase(Locale.ROOT);
if ("true".equals(lower)) {
return true;
} else if ("false".equals(lower)) {
return false;
} else {
if (dbg != null) {
dbg.println("Warning: Unexpected value for " + prop +
": " + rawPropVal +
". Using default value: " + def);
}
return def;
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024, 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,7 +34,6 @@ import java.security.ProviderException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.spec.DHParameterSpec;
import sun.security.action.GetPropertyAction;
/**
* Various constants such as version number, default key length, used by
@ -175,8 +174,7 @@ public final class SecurityProviderConstants {
"jdk.security.defaultKeySize";
static {
String keyLengthStr = GetPropertyAction.privilegedGetProperty
(KEY_LENGTH_PROP);
String keyLengthStr = System.getProperty(KEY_LENGTH_PROP);
int dsaKeySize = 2048;
int rsaKeySize = 3072;
int rsaSsaPssKeySize = rsaKeySize; // default to same value as RSA

View file

@ -37,7 +37,6 @@ import java.util.jar.Attributes;
import java.util.jar.Manifest;
import jdk.internal.util.ArraysSupport;
import sun.security.action.GetIntegerAction;
import sun.security.jca.Providers;
import sun.security.pkcs.PKCS7;
import sun.security.pkcs.SignerInfo;
@ -847,8 +846,7 @@ public class SignatureFileVerifier {
* the maximum allowed number of bytes for the signature-related files
* in a JAR file.
*/
int tmp = GetIntegerAction.privilegedGetProperty(
"jdk.jar.maxSignatureFileSize", 16000000);
int tmp = Integer.getInteger("jdk.jar.maxSignatureFileSize", 16000000);
if (tmp < 0 || tmp > MAX_ARRAY_SIZE) {
if (debug != null) {
debug.println("The default signature file size of 16000000 bytes " +