使用自签名 SSL 证书进行 SQL Server 加密。从 ASP.NET 3.5 查询
我创建了一个自签名证书来测试我的 Web 应用程序和 SQL Server 之间的加密。
尝试使用“Encrypt=Yes;”查询数据库时在连接字符串中,我收到以下消息:
已成功与服务器建立连接,但在登录前握手期间发生错误。 (提供程序:SSL 提供程序,错误:0 - 证书链由不受信任的机构颁发。)
背景
当我第一次尝试从 Management Studio 进行加密连接时,我收到了一条相同的消息。通过将自签名证书安装到我的受信任的证书颁发机构中解决了这个问题。
问题
有没有办法让 ASP.NET 像我的用户帐户一样信任该证书?
I've created a self-signed cert for testing encryption between my web application and the SQL Server.
When attempting to query the database using "Encrypt=Yes;" in the connection string, I receive the following message:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
Background
I received an identical message when first attempting an encrypted connection from management studio. This was resolved by installing the self-signed cert into my Trusted Certificate Authorities.
Question
Is there a way I can get ASP.NET to trust the certificate the same way my user account does?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,正确的答案是将自签名证书添加到证书存储中。
错误的方式
通过双击服务器上的 .cer 文件安装证书
- 这只会为当前登录的用户添加证书,这就是模拟在某些情况下起作用的原因。
正确的方法
使用 CertMgr.exe 安装证书。
- 您可以在 Windows SDK 中找到 CertMgr.exe,或者显然在 Visual Studio 2005 的 bin 文件夹中。 VS2008 中没有。
- 您必须在本地计算机管理员帐户下运行CertMgr.exe。具有本地管理员权限的域帐户将无法工作
- 通过运行以下两个命令,运行 CertMgr.exe 将证书添加到本地计算机的 trustpublishers 存储中:
-
certmgr /add Your.Certificate.Filename.cer /s /r 本地计算机根
-
certmgr /add Your.Certificate.Filename.cer /s /r localmachine trustpublisher
另请注意,在引用证书文件名时不能使用通配符。 (/add *.cer 将失败。)
OK the proper answer for this lay in adding the self-signed cert to the certificate store.
The wrong way
Installing the certificate by double-clicking the .cer file on the server
- This adds the cert for the currently logged in user only, which is why impersonation worked in some cases.
The right way
Using CertMgr.exe to install the certificate.
- You can find CertMgr.exe in a Windows SDK, or apparently in Visual Studio 2005's bin folder. It's not in VS2008.
- You must run CertMgr.exe under a Local Machine Administrator account. A Domain account with local administrator privileges will not work
- Run CertMgr.exe to add the certificate to the localmachine trustedpublishers stores, by running both of the following commands:
-
certmgr /add Your.Certificate.Filename.cer /s /r localmachine root
-
certmgr /add Your.Certificate.Filename.cer /s /r localmachine trustedpublisher
Also note you can't use wildcards when referring to the certificate filename. (/add *.cer will fail.)
在我的本地开发机器上使用模拟工作:
(在我的 web.config 的 system.web 中)从而确保当 ASP.NET 连接到数据库时,它使用我的用户凭据和我的用户信任自签名证书。
注意 - 如果尝试在开发服务器上查看站点,则会失败。
Using impersonation works on my local development machine:
<identity impersonate="true"/>
(in system.web of my web.config)Thus ensuring that when ASP.NET connected to the database, it used my user credentials, and my user trusts the self-signed cert.
Note - this fails if attempting to view the site on the development server.