Java连接sqlserver,驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接的问题

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的博客-CSDN博客

The server selected protocol version TLS10 is not accepted by client preferences [TLS12] 连接数据库报错_ZH`浩的博客-CSDN博客

由于对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_学习永不晚-CSDN博客

微软官方解释:

启用 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、java.security文件的位置,很多文章之说修改此文件,但是没明确告知路径,C:\Program Files\Java\jdk1.8.0_291\jre\lib\security\java.security文件和C:\Program Files\Java\jre1.8.0_291\lib\security\java.security文件。

2、修改内容,jdk.tls.legacyAlgorithms。

原配置:

# Example:
#   jdk.tls.disabledAlgorithms=MD5, SSLv3, DSA, RSA keySize < 2048
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

修改为:

# Example:
#   jdk.tls.legacyAlgorithms=DH_anon, DES_CBC, SSL_RSA_WITH_RC4_128_MD5
#
jdk.tls.disabledAlgorithms=SSLv3,RC4, DES, MD5withRSA, \
    DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
    include jdk.disabled.namedCurves

参考文章:

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]_代飞的企鹅-CSDN博客

  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值