Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在不更改源代码的情况下禁用TLSv1?_Java_Ssl - Fatal编程技术网

Java 如何在不更改源代码的情况下禁用TLSv1?

Java 如何在不更改源代码的情况下禁用TLSv1?,java,ssl,Java,Ssl,我编写了一个测试代码(不是HTTPS)来使用JDK8测试TLS。当测试代码运行时,我使用nmap工具进行扫描,得到如下结果: D:\softwares\nmap-7.12>nmap -p xxxx --script=ssl* x.x.x.x --unprivileged Starting Nmap 7.12 ( https://nmap.org ) at 2016-07-26 15:33 °?′óà????÷2?±ê×?ê±?? Nmap scan report for x.x.x.x

我编写了一个测试代码(不是HTTPS)来使用JDK8测试TLS。当测试代码运行时,我使用nmap工具进行扫描,得到如下结果:

D:\softwares\nmap-7.12>nmap -p xxxx --script=ssl* x.x.x.x --unprivileged


Starting Nmap 7.12 ( https://nmap.org ) at 2016-07-26 15:33 °?′óà????÷2?±ê×?ê±??
Nmap scan report for x.x.x.x
Host is up (1.0s latency).
PORT     STATE  SERVICE
xxxx/tcp open unknown
| ssl-enum-ciphers:
|  TLSv1.0:
|    ciphers:
|      TLS_RSA_WITH_AES_128_CBC_SHA (rsa 2048) -A
|    compressors:
|      NULL
|    cipher preference: indeterminate
|    cipher preference error: Too few ciphers supported
|  TLSv1.1:
|    ciphers:
|      TLS_RSA_WITH_AES_128_CBC_SHA (rsa 2048) -A
|    compressors:
|      NULL
|    cipher preference: indeterminate
|    cipher preference error: Too few ciphers supported
|  TLSv1.2:
|    ciphers:
|      TLS_RSA_WITH_AES_128_CBC_SHA (rsa 2048) -A
|    compressors:
|      NULL
|    cipher preference: indeterminate
|    cipher preference error: Too few ciphers supported
|_ least strength: A
MAC Address: xx:xx:xx:xx:xx:xx


Nmap done: 1 IP address (1 host up) scanned in 3.88 seconds


D:\softwares\nmap-7.12>
JDK8默认启用TLSv1.0,但我想禁用它

Protocols
The SunJSSE provider supports the following protocol parameters:
Protocol    Enabled by Default for Client   Enabled by Default for Server
SSLv3       No(Unavailable Footnote 2)      No(Unavailable Footnote 2)
TLSv1       Yes                             Yes
TLSv1.1     Yes                             Yes
TLSv1.2     Yes                             Yes

我在测试代码中调用javax.net.ssl.SSLEngine类的“setEnabledProtocols”方法,TLSv1.0可以完全禁用。 有没有办法在不更改代码的情况下禁用TLSv1.0?例如,通过配置文件。
我尝试了以下几种方法,但没有人能达到预期的效果:(
1.-Djdk.tls.client.protocols=TLSv1.1,TLSv1.2
2.-Ddeployment.security.TLSv1=false

以下是java版本:

java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

您似乎正在编写一个服务器,
jdk.tls.client.protocols
适用于客户端,因此得名;虽然稍微不太明显,但在基本JavaSE中,“部署”指的是浏览器或WebStart,它是客户端的一个子集


没有专门针对TLS(或HTTPS)服务器协议的属性,但是安全属性
jdk.TLS.disabledAlgorithms
适用于客户端和服务器(以及所有上下文类型),并且可以在
JRE/lib/security/java.security
中进行设置,如链接页面中所述。请确保保留现有的限制(特别是从8u31开始删除SSLv3)同时添加您的。

首先感谢您的回复。 如果修改
JRE/lib/security/java.security
,将产生全球性影响

以下是我的解决方案: 将
JRE/lib/security/java.security
复制到新文件中,并将TLSv1添加到
jdk.tls.disabledAlgorithms

然后,像这样启动JVM:
java
-Djava.security.properties=./java.security
-jar xxxxx

以下是来自
JRE/lib/security/java.security
的摘要:

#
# This is the "master security properties file".
#
# An alternate java.security properties file may be specified
# from the command line via the system property
#
#    -Djava.security.properties=<URL>
#
# This properties file appends to the master security properties file.
# If both properties files specify values for the same key, the value
# from the command-line properties file is selected, as it is the last
# one loaded.
#
# Also, if you specify
#
#    -Djava.security.properties==<URL> (2 equals),
#

#
# Determines whether this properties file can be appended to
# or overridden on the command line via -Djava.security.properties
#
security.overridePropertiesFile=true
#
#这是“主安全属性文件”。
#
#可以指定备用java.security属性文件
#通过系统属性从命令行执行
#
#-Djava.security.properties=
#
#此属性文件附加到主安全属性文件。
#如果两个属性文件都为同一个键指定了值,则该值
#从命令行属性中选择文件,因为它是最后一个属性
#一辆满载。
#
#另外,如果您指定
#
#-Djava.security.properties==(2等于),
#
#
#确定是否可以将此属性文件附加到
#或通过-Djava.security.properties在命令行上重写
#
security.overridePropertiesFile=true

Caveat emptor,
-D
将不适用于
jdk.tls.disabledAlgorithms
,正如您建议的,它应该进入
java.security
文件。