到目前为止,我已经尝试过,可以转储系统属性和"安全属性";但很明显,安全属性没有考虑我的覆盖系统属性,看起来它只是读";java.security";(请参阅下面的代码(。我想知道实际使用的安全属性是什么。
例如,在";安全属性";我看到这个:
jdk.tls.disabledAlgorithms : SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, include jdk.disabled.namedCurves
并且在";系统属性";,我看到这个:
jdk.tls.disabledAlgorithms:SSLv3
但我无法知道哪一个是活动属性(不过系统属性应该覆盖java.security文件中的属性(。
在我尝试使用TLSv1.1访问遗留服务器的测试中,我得到了:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
当我尝试使用-Djava.security.debug=properties
进行调试时,我得到:
properties: reading security properties file: /opt/java/svr_openjdk11-11.0.16/conf/security/java.security
properties: {(...) jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, include jdk.disabled.namedCurves (...)}
properties: java.security.disableSystemPropertiesFile=false
properties: security.useSystemPropertiesFile=false
properties: System security property support disabled by user.
properties: WARNING: FIPS mode support can not be enabled without system security properties being enabled.
因此,看起来java已知的属性是java.security中的属性,而不是在命令行中作为系统属性传递的属性。
System.out.println("=== System properties ===");
Properties properties = System.getProperties();
properties.forEach((k, v) -> System.out.println(k + ":" + v));
System.out.println("=== Security properties ===");
Field f = null;
try {
f = Security.class.getDeclaredField("props");
f.setAccessible(true);
Properties allProps = (Properties) f.get(null);
@SuppressWarnings("unchecked")
Enumeration<String> propertyNames = (Enumeration<String>) allProps.propertyNames();
while (propertyNames.hasMoreElements()) {
String propertyName = propertyNames.nextElement();
System.out.println(propertyName + " : " + allProps.getProperty(propertyName));
}
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
更新:我刚刚添加了:
Security.setProperty("jdk.tls.disabledAlgorithms", "SSLv3");
在显示安全属性之前,并且看起来它只是被忽略了;jdk.tls.disabledAlgorithms";属性仍然显示java.security文件中的值。
看起来SO这些天已经死了。
所以我找到了答案:上面代码显示的安全属性是正确的,不,它们没有考虑系统属性和security.setProperty(…(.
要覆盖一个安全属性,你需要把它放在一个文件中(我的新安全道具.security(,并添加这个系统属性:
-Djava.security.properties=/full/path/to/my-new-security-props.security