jdk8的程序,连接sqlserver 的时候,出现 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client preferences [TLS12]。
第一个解决方案,升级sql支持TLS1.2
经过今晚一晚的搜索,主要是让禁用3DES_EDE_CBC,还有比较新的说明,取消禁用 TLS1.0,TLS1.1。
The server selected protocol version TLS10 is not accepted by client preferences [TLS12]_ROJDAR的博客-****博客
The server selected protocol version TLS10 is not accepted by client preferences [TLS12] 连接数据库报错_ZH`浩的博客-****博客
由于对java不熟,没有找到相关设置项。决定反向解决问题,给sql server支持tls1.2就无需更改java程序了。
sql server对于TLS1.2的相关支持下边的文档说明的很详细
KB3135244 - TLS 1.2 对 Microsoft SQL Server
总结一下,sql2008 打上SP4补丁,sql2008R2打上SP3补丁,sql2012打上SP4补丁,sql2014打上SP2及更高版本补丁都可以支持TLS1.2了,而sql2016、2017等原生支持TLS1.2,无需更新。
2021-11-06补充
windows server 2008 R2操作系统还需要启用tls1.2,将打包后的jar包运行到服务器没有问题,在开发电脑直连服务器数据库运行报错。
主要内容,将下列代码保存到后缀名为“.reg”的文件中,并双击执行,将下列配置添加到注册表中。
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello\Client]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\Multi-Protocol Unified Hello\Server]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0\Client]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\PCT 1.0\Server]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client]
"DisabledByDefault"=dword:00000001
"Enabled"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Server]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Client]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 3.0\Server]
"Enabled"=dword:00000000
"DisabledByDefault"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Client]
"Enabled"=dword:00000001
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server]
"Enabled"=dword:00000001
"DisabledByDefault"=dword:00000000
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
"DisabledByDefault"=dword:00000000
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
"Enabled"=dword:00000001
"DisabledByDefault"=dword:00000000
详细说明见网友文章:
【服务器】 Windows Server 2008 R2 配置HTTPS TLS1.2_学习永不晚-****博客
微软官方解释:
启用 TLS 1.2 以实现通信的正确注册表SQL Server是什么? 正确的注册表设置如下所示:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server] "DisabledByDefault"=dword:00000000 "Enabled"=dword:00000001
KB3135244 - TLS 1.2 对 Microsoft SQL Server
第二个解决方案,修改jdk配置
此方案是2021-11-16补充
第一方案,在第一个服务器成功,今天遇到同样配置的云服务器,没有成功。还是回到了修改jdk配置的老路,幸好找到了解决清晰的两篇文章,解决了问题。后续应该不用关心服务器配置了,省事。
1、文件的位置,很多文章之说修改此文件,但是没明确告知路径,C:\Program Files\Java\jdk1.8.0_291\jre\lib\security\文件和C:\Program Files\Java\jre1.8.0_291\lib\security\文件。
2、修改内容,。
原配置:
# Example:
# =MD5, SSLv3, DSA, RSA keySize < 2048
=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
include
修改为:
# Example:
# =DH_anon, DES_CBC, SSL_RSA_WITH_RC4_128_MD5
#
=SSLv3,RC4, DES, MD5withRSA, \
DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
include
参考文章:
The server selected protocol version TLS10 is not accepted by client preferences [TLS12] - IT_小树 - 博客园
The server selected protocol version TLS10 is not accepted by client preferences [TLS12]_代飞的企鹅-****博客