使用 PFX 文件的 SslStream AuthenticateAsClient
我正在尝试使用 SslStream 连接到服务器。服务器所有者向我提供了一个 PFX 文件,并将其安装在我的客户端上,但我不确定如何从我的代码访问证书。
具体来说,假设我有以下代码...
var serverName = "?";
var stream = new SslStream();
stream.AuthenticateAsClient(serverName);
serverName 的值是什么?我已经尝试过了
服务器的IP地址
“我的服务器”
“CN = MyServer”
这些值似乎都不起作用。我是否需要执行其他操作才能访问计算机上的证书存储,或者我不明白 serverName 需要是什么?
I'm trying to connect to a server using an SslStream. I've been given a PFX file from the owner of the server and I've installed it on my client but I'm not sure how to access the certificate from my code.
Specifically, imagine that I have the following code...
var serverName = "?";
var stream = new SslStream();
stream.AuthenticateAsClient(serverName);
What would the value of serverName be? I've tried
the IP address of the server
"MyServer"
"CN = MyServer"
None of these values seem to work. Is there something additional I need to do to access the cert store on my machine, or do I not understand what the serverName needs to be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它必须是<的通用名称(CN - 通常是完全限定域名) em>您要连接的主机的服务器证书主题。
例如,如果服务器证书主题看起来像:
您应该使用:
如果您要连接的主机允许在没有客户端证书验证的情况下进行连接,那么您应该能够连接到它(例如使用浏览器 - 如果是 HTTPS)并查看服务器证书,或者您可以尝试使用 OpenSSL 客户端。
It must be the Common Name (CN - which is usually a fully qualified domain name) of the servers certificates subject for the host you are connecting to.
For example if the servers certificates subject looks like:
you should use:
If the host you are connecting to allows connections without client certificate verification then you should be able to connect to it (with a browser for example - if HTTPS) and see the server certificate, or you can try using OpenSSL client.