The Security Properties File
A security properties file is a text file that contains names of security properties and their values. You can customize certain aspects of Java security by setting these properties.
When you launch a Java application from a JDK located in
$JAVA_HOME
, by default, the JVM will set the set
the security properties to the values specified in
$JAVA_HOME/conf/security/java.security
, which is
known as the master security properties file. It's possible to
specify another security properties file; see Specifying an Alternative Security Properties File.
A security property set in a security properties file is statically set. You can dynamically set security properties by setting their values in your application's code. See Statically Setting a Security Property in a Security Properties File and Dynamically Setting a Security Property in Application Code.
See Troubleshooting Security Properties for information about enabling logging for security properties and viewing them.
You can include text files containing security property settings in the master security properties file or any other security properties file. When you include a file, all of its security property settings are added as if defined at that point. See Including a Security Properties File.
By default, the master security properties file sets security properties that customize certain aspects of Java, which include the following:
-
Registering a security provider: A security provider is a package or set of packages that supply a concrete implementation of a subset of the cryptography aspects of the Java Security API. The master security properties file sets several security properties in the form
security.provider.n
, wheren
is the provider's preference order. The preference order is the order in which providers are searched for requested algorithms (when no specific provider is requested).See Step 8.1: Configure the Provider for more information.
- Algorithm restrictions: This covers restricted and legacy
algorithms for certificate path validation, TLS, signed JAR files,
and XML signature validations. For example,
jdk.certpath.disabledAlgorithms
andjdk.tls.disabledAlgorithm
list which algorithms to disable during certification path validation and TLS/DTLS protocol negotiation. -
Java Secure Socket Extension (JSSE): JSSE enables secure Internet communications. It provides a framework and an implementation for a Java version of the TLS and DTLS protocols and includes functionality for data encryption, server authentication, message integrity, and optional client authentication. Related security properties include:
jdk.tls.keyLimits
, which limits the amount of data algorithms may encrypt with a set of keysssl.KeyManagerFactory
andssl.TrustManagerFactory
, which specify the default key and trust manager factory algorithms for the javax.net.ssl package
See Customizing JSSE for more information.
-
Other aspects of Java security: This includes default keystore type, configuration of SecureRandom implementations, and Kerberos.
Specifying an Alternative Security Properties File
You can specify an alternate java.security
properties
file from the command line with the system property
java.security.properties=<URL>
. This properties file is appended to the master security
properties file. If you specify a properties file with
java.security.properties==<URL>
(using two equals signs), then that properties file will
completely override the master security properties file.
Statically Setting a Security Property in a Security Properties File
To statically set a security property value in a security properties file, add or modify an existing line in the following form:
propertyName=propertyValue
For example, suppose that you want to specify a different key manager
factory algorithm name than the default SunX509. You do this by specifying the algorithm
name as the value of a security property named
ssl.KeyManagerFactory.algorithm
. For example, to set the value to
MyX509, add the following line:
ssl.KeyManagerFactory.algorithm=MyX509
To comment out a line in a security properties file, which means the JVM ignores it when
it sets security properties from a security properties file, insert the number sign
(#
) at the beginning of the line.
By default, the master security properties file contains many comments that describe in detail the security properties specified in it. Sometimes, these security properties themselves are commented out. These security properties that are commented out might have a value specified or no value at all.
Note:
A security property that has been set to no value is set to the empty string. A security property that has been commented out is set to a null value. In this case, the security property might be assigned a default value. The comments in the master security properties file should specify whether a security property has a default value.Dynamically Setting a Security Property in Application Code
To set a security property dynamically in application code, call the
java.security.Security.setProperty
method:
Security.setProperty("propertyName," "propertyValue");
For example, a call to the setProperty()
method corresponding to the
previous example for specifying the key manager factory algorithm name would be:
Security.setProperty("ssl.KeyManagerFactory.algorithm", "MyX509");
Note:
Some security properties cannot be set dynamically if they have already been read from a security properties file and cached, which happens when the java.security.Security class is initialized. No exception will be thrown if your code attempts to do this.Troubleshooting Security Properties
Enable logging for security properties by specifying the
command-line option -Djava.security.debug=properties
.
Messages prefixed by properties
contain the final values
for all security properties and information on how include
directives have been processed. See The java.security.debug System Property.
The command-line option -XshowSettings:security
prints an overview of the security settings that are effective in the JDK.
See The java -XshowSettings:security Option.
You can use the Java Flight Recorder (JFR) event
jdk.InitialSecurityProperty
to obtain the initial
values for security properties on a running JDK.
Including a Security Properties File
To include a security properties file in another security properties file,
use an include
directive. This feature enables security properties to be
defined in multiple files and can facilitate the centralized management of security profiles
across multiple JDKs.
For example, on Linux and macOS, to include the security properties file
/usr/lib/jvm/jdk-24/conf/security/extra.security
in another security properties file,
add the following include
directive:
include /usr/lib/jvm/jdk-24/conf/security/extra.security
On Windows, to include the security properties file C:\Java\jdk-24\conf\security\extra.security
in another
security properties file, add the following include
directive:
include C:\\Java\\jdk-24\\conf\\security\\extra.security
A file system path in an include
directive can be absolute,
like the previous examples, or relative. When it's a relative path, the location of the
file that contains the include
directive is used as the base. You can't
use a relative path if the include
directive is in a URL stream. For
example, if you specify the following option on the command line when launching a Java
application, then the security properties file extra.java.security
can't contain any include
directives that specify a relative path:
-Djava.security.properties=https://example.com/extra.java.security
On Linux and macOS, forward slashes (/
) are supported.
On Windows, double backward slashes (\\
), single forward
slashes (/
) and UNC paths are supported. For example:
include C:\\Program Files\\Java\\jdk-24\\java.config
include C:/Program Files/Java/jdk-24/additional.java.config
include \\\\WindowsHost\\Share\\unc.path.java.config
URL file paths (for example, those that start with file://
) are not
supported.
include
directives support property expansion. This is
similar to expanding variables in a shell. When a string like
${some.property}
appears in an include
directive,
it will be expanded to the value of the system property. For example:
include ${java.home}/extra.security
This will expand ${java.home}
to use the value of the
java.home
system property. If that property's value is
/usr/lib/jvm/jdk-24
, then the
previous example is equivalent to:
include /usr/lib/jvm/jdk-24/conf/security/extra.security
To assist in platform-independent policy files, you can also use the special
notation of ${/}
, which is a shortcut for
${file.separator}
. This allows directives like the following:
include ${java.home}${/}
extra.security
Note:
If a system property in aninclude
directive is undefined, it's replaced with an empty string
instead of the JVM generating an error.
When the JVM encounters an include
directive, it processes
it immediately irrespective of preceding or subsequent occurrences. Its position in the
file may affect security properties values as described in Order of include Directives in Security Properties Files. However, include
directives don't interfere with
each other; the JVM always processes them. By contrast, security properties defined
later in a security properties or brought in by a following inclusion would override a
previous definition if their names are the same.
The JVM generates an error if a file can't be included. This may happen if the file can't be resolved, doesn't exist, is a directory, has insufficient permissions for the JVM to read it, is recursively included more than once, or for any other reason.
Included security properties files can include others recursively as long as it doesn't
lead to a cycle. For example, suppose that java.security
includes
the security properties file A.security
, and
A.security
includes the security properties file
B.security
. The security properties file
B.security
can't include A.security
as
this would create a cycle.
Order of include Directives in Security Properties Files
When you include a security properties file with an include
directive, properties defined in the included file may either be added to the map of
security properties or replace existing ones if their names are the same. Thus, the effect
of an include
directive may depend on its position in the properties file.
Consequently, you can specify overridable security properties by defining them before an
include
directive, and specify non-overridable security properties by
defining them after an include
directive.
Security Considerations and include Directives in Security Properties Files
It's important that the layout of your security properties files enable system administrators to clearly and easily understand the reasoning why security properties have been defined and overridden. It's a good practice to check the final map of security properties in the JDK with the methods described in Troubleshooting Security Properties.
Note:
When including a security properties file, it's strongly recommended to verify that it comes from a trusted source and to check write permissions not only for the included file but also for the entire chain of parent directories starting at the file system's root. Any user who has capabilities to modify an included file may downgrade the security of the JDK by either replacing a security properties file or adding new ones that cause security property values to be overridden. Any user that can rename a directory in the chain of parent directories may be able to impersonate the included file with a rogue version, leading to a downgrade in the JDK security. As a rule of thumb, an included file and its chain of parent directories should have equal or more restrictive permissions than the file containing itsinclude
directive.
When placeholders are used in file system paths and system properties are passed as described in Security Profiles, it's worth noting the impact of a typo: If the typo is in the property name, then the placeholder will be ignored. If the typo is in the property value, an error will be thrown because included files must exist. Always check system properties in placeholders and arguments for typos.
Examples of Using include Directives
Security Profiles
System administrators frequently need to enforce security profiles across Java applications in multiple JDK deployments for security hardening, regulatory compliance, or preserving backward compatibility. The security properties specified in these security profiles should be in addition to those specified by individual JDK deployments. Often, system administrators need to enforce different security profiles depending on the environment, such as development or production. They also should be able to manage security profiles in a centralized location.
To implement this scenario, define multiple global security profiles
through separate security property files. A global security profile specifies security
properties that are required in each JDK deployment. Define a bridge file, which
contains an include
directive that specifies the global security
profile enforced by default. Include this bridge file in the master security properties
file of each JDK deployment. To change the default profile, modify the
include
directive in the bridge file.
To illustrate this concept of managing multiple global security profiles
through a bridge file, consider the following layout of security property files and
their include
directives:
- Directory
/global/profiles
- File
profile-.security
(bridge file):include profile-prod.security
- File
profile-custom.security
(global security profile) - File
profile-dev.security
(global security profile) - File
profile-prod.security
(global security profile, which is enforced by default)
- File
- JDK deployment A: directory
$JAVA_HOME_DEPLOYMENT_A/conf/security
- File
java.security
:include /global/profiles/profile-${securityProfile}.security
- File
- JDK deployment B: directory
$JAVA_HOME_DEPLOYMENT_B/conf/security
- File
java.security
:include /global/profiles/profile-${securityProfile}.security
- File
In this example layout, profile-.security
is the bridge
file that contains an include
directive that specifies the global
security profile enforced by default, profile-prod.security
. A
system administrator can change the default global security profile by modifying the
include
directive in the bridge file and referring to any of the
policies in the directory /global/profiles
(profile-custom.security
,
profile-dev.security
, or
profile-prod.security
).
On some occasions, applications require a security profile different from the
one enforced by default. In this example, include
directives in the JDK
deployments A and B use the placeholder suffix securityProfile
. When
the system property securityProfile
is undefined, this placeholder is
replaced with an empty string, which results in the JDK deployments A and B using the
bridge file profile-.security
. When the system property
securityProfile
is set to one of the available values
(custom
, dev
, or prod
), the
respective global security profile is selected. For example, if you launch a Java
application with the -DsecurityProfile=dev
command-line option, the
profile-dev.security
global security profile would be applied
in both JDK deployments A and B, irrespective of the profile enforced by default.
A layout in which the profile-.security
file doesn't
exist prevents a default choice and forces securityProfile
to be
defined.
Note:
Security properties are processed when the java.security.Security class is initialized. If a placeholder's system property is programmatically set after this point (by calling the java.lang.System.setProperty(String key, String value) method) to specify a global security profile, it will have no effect.You can extend this example to include security profiles that are specific
to a JDK release by creating security properties files named profile-.24.security
and profile-prod.24.security
. In this case, the
java.security
security properties file for JDK 24 must include both the global and the release-specific
bridge files in addition to the current global profile. Having a release-specific
profile may be useful when the map of security properties is not the same across all JDK
releases.
The JDK neither provides curated security profiles nor favors any particular structure for their organization. It's important to keep profiles updated and opt for secure defaults whenever possible. It's also recommended to analyze how profiles apply to each JDK release in terms of the availability of security properties.