mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8066709: Make some JDK system properties read only
Reviewed-by: lancea, sundar, bchristi, weijun, mchung, alanb, mullan
This commit is contained in:
parent
cad47f4a03
commit
4098f2560a
25 changed files with 215 additions and 46 deletions
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package sun.net;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
|
||||
import java.io.*;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
@ -57,7 +59,7 @@ public class NetProperties {
|
|||
* the file is in jre/lib/net.properties
|
||||
*/
|
||||
private static void loadDefaultProperties() {
|
||||
String fname = System.getProperty("java.home");
|
||||
String fname = StaticProperty.javaHome();
|
||||
if (fname == null) {
|
||||
throw new Error("Can't find java.home ??");
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
|
||||
package sun.net.www;
|
||||
import jdk.internal.util.StaticProperty;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.FileNameMap;
|
||||
import java.util.Hashtable;
|
||||
|
@ -53,7 +55,7 @@ public class MimeTable implements FileNameMap {
|
|||
|
||||
mailcapLocations = new String[] {
|
||||
System.getProperty("user.mailcap"),
|
||||
System.getProperty("user.home") + "/.mailcap",
|
||||
StaticProperty.userHome() + "/.mailcap",
|
||||
"/etc/mailcap",
|
||||
"/usr/etc/mailcap",
|
||||
"/usr/local/etc/mailcap",
|
||||
|
@ -384,7 +386,12 @@ public class MimeTable implements FileNameMap {
|
|||
Properties properties = getAsProperties();
|
||||
properties.put("temp.file.template", tempFileTemplate);
|
||||
String tag;
|
||||
String user = System.getProperty("user.name");
|
||||
// Perform the property security check for user.name
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPropertyAccess("user.name");
|
||||
}
|
||||
String user = StaticProperty.userName();
|
||||
if (user != null) {
|
||||
tag = "; customized for " + user;
|
||||
properties.store(os, filePreamble + tag);
|
||||
|
|
|
@ -30,6 +30,8 @@ import java.net.InetAddress;
|
|||
import java.net.SocketPermission;
|
||||
import java.io.*;
|
||||
import java.security.Permission;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.net.www.*;
|
||||
import sun.net.smtp.SmtpClient;
|
||||
import sun.net.www.ParseUtil;
|
||||
|
@ -65,7 +67,12 @@ public class MailToURLConnection extends URLConnection {
|
|||
String getFromAddress() {
|
||||
String str = System.getProperty("user.fromaddr");
|
||||
if (str == null) {
|
||||
str = System.getProperty("user.name");
|
||||
// Perform the property security check for user.name
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPropertyAccess("user.name");
|
||||
}
|
||||
str = StaticProperty.userName();
|
||||
if (str != null) {
|
||||
String host = System.getProperty("mail.host");
|
||||
if (host == null) {
|
||||
|
|
|
@ -44,6 +44,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import jdk.internal.misc.JavaSecurityAccess;
|
||||
import static jdk.internal.misc.JavaSecurityAccess.ProtectionDomainCache;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.util.*;
|
||||
import sun.net.www.ParseUtil;
|
||||
|
||||
|
@ -279,7 +280,7 @@ public class PolicyFile extends java.security.Policy {
|
|||
public URL run() {
|
||||
String sep = File.separator;
|
||||
try {
|
||||
return Path.of(System.getProperty("java.home"),
|
||||
return Path.of(StaticProperty.javaHome(),
|
||||
"lib", "security",
|
||||
"default.policy").toUri().toURL();
|
||||
} catch (MalformedURLException mue) {
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.io.*;
|
|||
import java.net.*;
|
||||
import java.util.Map;
|
||||
import java.security.*;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
|
@ -403,7 +405,7 @@ final class SunEntries {
|
|||
if(deviceURI.isOpaque()) {
|
||||
// File constructor does not accept opaque URI
|
||||
URI localDir = new File(
|
||||
System.getProperty("user.dir")).toURI();
|
||||
StaticProperty.userDir()).toURI();
|
||||
String uriPath = localDir.toString() +
|
||||
deviceURI.toString().substring(5);
|
||||
return new File(URI.create(uriPath));
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.Enumeration;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.x509.X509CertImpl;
|
||||
|
||||
/**
|
||||
|
@ -52,7 +53,7 @@ public class AnchorCertificates {
|
|||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
@Override
|
||||
public Void run() {
|
||||
File f = new File(System.getProperty("java.home"),
|
||||
File f = new File(StaticProperty.javaHome(),
|
||||
"lib/security/cacerts");
|
||||
KeyStore cacerts;
|
||||
try {
|
||||
|
|
|
@ -26,12 +26,12 @@ package sun.security.util;
|
|||
|
||||
import java.io.*;
|
||||
import java.security.AccessController;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.*;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.x509.X509CertImpl;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ public final class UntrustedCertificates {
|
|||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
@Override
|
||||
public Void run() {
|
||||
File f = new File(System.getProperty("java.home"),
|
||||
File f = new File(StaticProperty.javaHome(),
|
||||
"lib/security/blacklisted.certs");
|
||||
try (FileInputStream fin = new FileInputStream(f)) {
|
||||
props.load(fin);
|
||||
|
|
|
@ -45,12 +45,11 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.SimpleTimeZone;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import jdk.internal.util.StaticProperty;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
/**
|
||||
|
@ -252,7 +251,7 @@ public final class ZoneInfoFile {
|
|||
AccessController.doPrivileged(new PrivilegedAction<Void>() {
|
||||
public Void run() {
|
||||
try {
|
||||
String libDir = System.getProperty("java.home") + File.separator + "lib";
|
||||
String libDir = StaticProperty.javaHome() + File.separator + "lib";
|
||||
try (DataInputStream dis = new DataInputStream(
|
||||
new BufferedInputStream(new FileInputStream(
|
||||
new File(libDir, "tzdb.dat"))))) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue