SQL Server 2008 R2 Express +通配符SSL证书

通配符证书(例如* .example.com)在SQL Server 2008或更低版本中不起作用。 但是,在MSDN上encryption连接到SQL Server的连接就像那天一样

SQL Server 2008 R2支持通配符证书。

优秀。 因此,我在一台机器上安装了SQL Server 2008 R2 Express,并将HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Certificate条目configuration为通配符SSL证书的指纹(因为在五年处理SQL服务器,我从来没有得到#$ @#对话框在Sql Serverconfiguration显示任何证书)。

SQL Server日志然后告诉我,这很顺利:

2010-08-31 11:46:04.04服务器证书[Cert Hash(sha1)“5DDD9E51B30E0CA6CE3656AE54EC6D0B8B75904A”]已成功加载encryption。

不幸的是,如果我尝试使用.NET Framework 4.0中提供的Microsoft SQL Server Management Studio(2008 R2版本)或Sql *类,我总是会收到以下exception:

与服务器build立了连接,但在login前握手过程中发生错误。 (提供程序:SSL提供程序,错误:0 – 证书的CN名称与传递的值不匹配。)(Microsoft SQL Server,错误:-2146762481)

这里是我尝试过的东西:

  • 确保主机名configuration正确。 (例如,主机名是prod ,并且DNS后缀已正确设置: prod.example.com 。)
  • 确保prod.example.com的PTRlogging正确设置。
  • 在连接string中设置TrustServerCertificate=Yes

有趣的是,如果我尝试通过sqlcmd.exe连接,我没有收到有关证书的投诉。

我开始怀疑SQL服务器中的通配符证书将被服务器加载 ,但是没有任何.NET SQL客户端的实例可以正确地针对其中的一个工作。

任何人都可以点亮这个?


更新 :关于通配符证书的一些附加信息:

  • 是的,它安装在本地计算机>个人>证书。
  • 它有Server Authentication (1.3.6.1.5.5.7.3.1)增强的密钥用法。
  • 它具有Key Encipherment (a0) ,其中(a0)表示AT_KEYEXCHANGE 。 (对于FTP服务器和IIS网站来说,它工作的很好,所以如果这个问题被搞砸了,我想它不会在那里工作。)
  • 证书的主题是CN = *.example.com (用“example”代替我们的工作域)。 也就是说,它发布到*.example.com 。 这是2008 R2之前的版本中的破坏者,它阻止了SQL Server加载证书。
  • 它有私钥。
  • 友好名称可以设置为任何 – prod.example.com是现在。

更新2 :所以这真的会炸你的大脑:

如果我通过ODBCbuild立连接:

Microsoft SQL Server本机客户端版本10.50.1600

 Data Source Name: prod.example.com Data Source Description: prod Server: tcp:prod.example.com,8484\SQLEXPRESS Use Integrated Security: No Database: (Default) Language: (Default) Data Encryption: Yes Trust Server Certificate: No Multiple Active Result Sets(MARS): No Translate Character Data: Yes Log Long Running Queries: No Log Driver Statistics: No Use Regional Settings: No Use ANSI Quoted Identifiers: Yes Use ANSI Null, Paddings and Warnings: Yes 

然后我得到一个成功的结果:

 Microsoft SQL Server Native Client Version 10.50.1600 Running connectivity tests... Attempting connection Connection established Verifying option settings INFO: Connection was encrypted with server certificate validation. Disconnecting from server TESTS COMPLETED SUCCESSFULLY! 

更新3 :好的,在放弃通配符证书之前,最后一次拍摄。 这里是我用C#编写的一个小示例程序:

  static void Main(string[] args) { Console.WriteLine(new string('-', 40)); try { var connectionString = @"Data Source=tcp:prod.example.com,8484\SQLEXPRESS; " + "User ID=ExampleDev;Password=ExamplePass; " + "Encrypt=True"; Console.WriteLine("Trying SqlConnection..."); using (var connection = new SqlConnection(connectionString)) { connection.Open(); Console.WriteLine("SUCCESS!"); } } catch (Exception e) { Console.WriteLine("FAILED!"); Console.WriteLine(e); } Console.WriteLine(new string('-', 40)); try { var connectionString = @"Driver={SQL Server Native Client 10.0}; " + "Server=tcp:prod.example.com,8484\SQLEXPRESS; " + "Uid=ExampleDev; Pwd=ExamplePass; Encrypt=yes"; Console.WriteLine("Trying OdbcConnection..."); using (var connection = new OdbcConnection(connectionString)) { connection.Open(); Console.WriteLine("SUCCESS!"); } } catch (Exception e) { Console.WriteLine("FAILED!"); Console.WriteLine(e); } Console.WriteLine(new string('-', 40)); Console.ReadLine(); } } 

这个程序的输出,在我的机器上运行后用用户名和密码代替是合适的,如下所示:

  ----------------------------------------
尝试SqlConnection ...
失败!
 System.Data.SqlClient.SqlException(0x80131904):连接成功e
与服务器build立了联系,但是在login前手发生错误
摇。  (提供程序:SSL提供程序,错误:0  - 证书的CN名称不能
通过价值。)
   在System.Data.SqlClient.SqlInternalConnection.OnError(SqlExceptionexception
 ,布尔breakConnection)
   在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   在System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(布尔encryption,
 Boolean trustServerCert,Boolean&marsCapable)
   在System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternal
 ConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,Bool
 eanencryption,布尔值trustServerCert,布尔integratedSecurity)
    >
 ----------------------------------------
尝试OdbcConnection ...
成功!
 ---------------------------------------- 

这就是我喝酒的原因。

我知道“select通常不会中断”,但我不知道该怎么做。 看起来,.NET Framework 4.0中的SqlClient类在validation通配符证书时刚刚被破坏。 这两种方法还有什么不同呢?

证书没有显示在configuration工具中的事实提出了第一个问题。 如果证书安装正确,那么它应该显示在该列表上。 你在证书店的哪个地方放置证书? 它应该位于“个人”>“证书”下的本地计算机证书存储区中。

您还需要确保服务器身份validation证书具有证书的“增强型密钥用法”属性,以指定“服务器身份validation”(1.3.6.1.5.5.7.3.1)。 证书还必须使用AT_KEYEXCHANGE的KeySpec选项创build,您可以select将密钥使用属性设置为包含密钥encryption。

微软的答案是,.NET SqlClient不会对通配符证书起作用。

尽pipeSQL Server 2008 R2 Express现在支持通配符证书,并且本机提供程序已经更新,以便了解它们(这意味着ODBC和OLEDB),但是.NET Framework 4.0中的System.Data.SqlClient类仍然存在。

从本质上讲,这意味着如果您支持.NET应用程序对数据库服务器,通配符证书function仍然是不行的。