【问题标题】:Sql Server 2016: Enable TLS 1.2 for SQL Server ConnectionSql Server 2016:为 SQL Server 连接启用 TLS 1.2
【发布时间】:2018-07-27 19:41:41
【问题描述】:

我在windows 2012 R2 上运行了SQL server 2016,并应用了支持TLSv1.2 的补丁并重新启动了VM,https://support.microsoft.com/en-us/help/3135244/tls-1-2-support-for-microsoft-sql-server 我确实看到在SQL Server VM 上使用IISCrypto 工具启用了TLS 1.2

我们有 Java 8 Web 应用程序,我们使用 JVM 参数 -Djdk.tls.client.protocols="TLSv1.2" 强制 Web 应用程序仅使用 TLS1.2(如果我删除此 JVM 参数应用程序连接到 sql server 正常),但我们看到以下错误尽管为 SQL server 启用了TLSv1.2

org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "Server chose TLSv1, but that protocol version is not enabled or not supported by the client.". ClientConnectionId:7564b6a1-60c0-4a24-8baa-7bd21f9512cf)  

我们还有一个.Net 2.0 windows 服务(仅在注册表中启用了 TLSv1.2)也无法连接到SQL Server 2016

System.Data.OleDb.OleDbException: [DBNETLIB][ConnectionOpen (SECCreateCredentials()).]SSL Security error.
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()

但如果我在注册表中启用 SSL3 和 TLS1.0,.Net 2.0 windows 服务可以正常连接到 SQL Server 2016。

我怀疑,问题是 SQL Server 没有使用 TLSv1.2 尽管在 SQL Server VM 上启用了 TLSv1.2,如果需要为 SQL Server 应用更多配置或补丁以支持 @987654334,有人可以帮助我吗@?

【问题讨论】:

  • 你引用的那个链接说你必须在服务器的注册表中禁用 1.0 和 1.1 才能使 1.2 工作。与其使用 IISCrypto 工具,为什么不检查服务器的实际注册表设置并验证 1.0 和 1.1 已禁用,1.2 已启用?
  • @RanPaul 您能否尝试我在下面的答案中给出的方法,让我知道它是否有效?提前谢谢..
  • @RanPaul,有答案了吗?

标签: java .net sql-server sql-server-2016 tls1.2


【解决方案1】:

Microsoft Windows Server 存储有关 Windows Server 支持的不同安全增强通道协议的信息。此信息存储在以下注册表项中:

HKey_Local_Machine\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols

通常,此键包含以下子键:

PCT 1.0、SSL 2.0、SSL 3.0、TLS 1.0 ...

每个密钥都包含有关密钥协议的信息。这些协议中的任何一种都可以在服务器上启用。为此,您需要在协议的服务器子项中创建一个新的 DWORD 值。您将 DWORD 值设置为“1”。

重要提示:在修改注册表之前备份它。然后,如果出现问题,您可以恢复注册表。

要启用 TLS 1.x 协议,请按以下步骤操作:

单击开始,单击运行,键入 regedt32 或键入 regedit,然后单击确定。 在注册表编辑器中,找到以下注册表项:

HKey_Local_Machine\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.x\Server

在编辑菜单上,单击添加值。 在数据类型列表中,单击 DWORD。 在“值名称”框中,键入“已启用”,然后单击“确定”。

注意如果存在此值,请双击该值以编辑其当前值。

在二进制编辑器中键入 11111111 以将新键的值设置为“1”。 单击确定。重启电脑。

希望这会有所帮助...

【讨论】:

    【解决方案2】:

    检查涉及的证书。一个可能是无效的。

    如果机器验证其证书,请尝试:

    用于禁用愚蠢加密的注册表脚本: 将此另存为 .reg

    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client]
    "Enabled"=dword:00000000
    "DisabledByDefault"=dword:00000001
    [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\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\Client]
    "Enabled"=dword:00000000
    "DisabledByDefault"=dword:00000001
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.0\Server]
    "Enabled"=dword:00000000
    "DisabledByDefault"=dword:00000001
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client]
    "Enabled"=dword:00000000
    "DisabledByDefault"=dword:00000001
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Server]
    "Enabled"=dword:00000000
    "DisabledByDefault"=dword:00000001
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client]
    "Enabled"=dword:00000001
    "DisabledByDefault"=dword:00000000
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server]
    "Enabled"=dword:00000001
    "DisabledByDefault"=dword:00000000
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
    "SchUseStrongCrypto"=dword:00000001
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
    "SchUseStrongCrypto"=dword:00000001
    

    您必须调整您的 .NET Framework。如果您实际上使用的是 .Net 2.0(旧!)最后两个键应该是

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727]
    "SystemDefaultTlsVersions"=dword:00000001
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v2.0.50727]
    "SystemDefaultTlsVersions"=dword:00000001 
    

    这是 Chris Duck 的 .ps1,用于检查启用的加密

        <#
     .DESCRIPTION
       Outputs the SSL protocols that the client is able to successfully use to connect to a server.
    
     .NOTES
    
       Copyright 2014 Chris Duck
       http://blog.whatsupduck.net
    
       Licensed under the Apache License, Version 2.0 (the "License");
       you may not use this file except in compliance with the License.
       You may obtain a copy of the License at
    
         http://www.apache.org/licenses/LICENSE-2.0
    
       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
    
     .PARAMETER ComputerName
       The name of the remote computer to connect to.
    
     .PARAMETER Port
       The remote port to connect to. The default is 443.
    
     .EXAMPLE
       Test-SslProtocols -ComputerName "www.google.com"
    
       ComputerName       : www.google.com
       Port               : 443
       KeyLength          : 2048
       SignatureAlgorithm : rsa-sha1
       Ssl2               : False
       Ssl3               : True
       Tls                : True
       Tls11              : True
       Tls12              : True
     #>
     function Test-SslProtocols {
       param(
         [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$true)]
         $ComputerName,
    
         [Parameter(ValueFromPipelineByPropertyName=$true)]
         [int]$Port = 443
       )
       begin {
         $ProtocolNames = [System.Security.Authentication.SslProtocols] | gm -static -MemberType Property | ?{$_.Name -notin @("Default","None")} | %{$_.Name}
       }
       process {
         $ProtocolStatus = [Ordered]@{}
         $ProtocolStatus.Add("ComputerName", $ComputerName)
         $ProtocolStatus.Add("Port", $Port)
         $ProtocolStatus.Add("KeyLength", $null)
         $ProtocolStatus.Add("SignatureAlgorithm", $null)
    
         $ProtocolNames | %{
           $ProtocolName = $_
           $Socket = New-Object System.Net.Sockets.Socket([System.Net.Sockets.SocketType]::Stream, [System.Net.Sockets.ProtocolType]::Tcp)
           $Socket.Connect($ComputerName, $Port)
           try {
             $NetStream = New-Object System.Net.Sockets.NetworkStream($Socket, $true)
             $SslStream = New-Object System.Net.Security.SslStream($NetStream, $true)
             $SslStream.AuthenticateAsClient($ComputerName,  $null, $ProtocolName, $false )
             $RemoteCertificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]$SslStream.RemoteCertificate
             $ProtocolStatus["KeyLength"] = $RemoteCertificate.PublicKey.Key.KeySize
             $ProtocolStatus["SignatureAlgorithm"] = $RemoteCertificate.SignatureAlgorithm.FriendlyName
             $ProtocolStatus["Certificate"] = $RemoteCertificate
             $ProtocolStatus.Add($ProtocolName, $true)
           } catch  {
             $ProtocolStatus.Add($ProtocolName, $false)
           } finally {
             $SslStream.Close()
           }
         }
         [PSCustomObject]$ProtocolStatus
       }
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-31
      • 2018-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-26
      • 1970-01-01
      相关资源
      最近更新 更多