简体   繁体   English

如何使用IP地址而不是DNS(.net C#)获得SSL证书

[英]How to get ssl certificates using IP address instead of DNS (.net C#)

I'm trying to get the SSL certificates using an ip address or if could be possible both (DNS and IP address), to be honest I don't have any idea about SSL certificates, I've been reading a little bit on it, I have to do it because is a new requirement and we have to use ip address that are not associated with a DNS (in some cases) 我正在尝试使用IP地址获取SSL证书,或者说如果可能的话(DNS和IP地址)都可以获取,老实说,我对SSL证书一无所知,我已经在上面读了一点,我必须这样做,因为这是一项新要求,我们必须使用与DNS不相关的ip地址(在某些情况下)

After search I found this solution: 搜索后,我找到了这个解决方案:

//Do webrequest to get info on secure site
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(txbURL.Text);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
request.AllowAutoRedirect = false;
response.Close();

//retrieve the ssl cert and assign it to an X509Certificate object
X509Certificate cert = request.ServicePoint.Certificate;

//convert the X509Certificate to an X509Certificate2 object by passing it into the constructor
X509Certificate2 cert2 = new X509Certificate2(cert);

//display the cert dialog box
rtbResult.Text = string.Format("Not Before: {0}\nNot After: {1}", cert2.NotBefore, cert2.NotAfter);

they asked only for the NotBefore and NotAfter date and is working if you use something like http://www.google.com but not with an ip address, do you know how could I use an ip address on it? 他们只要求提供NotBefore和NotAfter日期,如果您使用的是http://www.google.com之类的东西,但未提供IP地址,则可以正常工作吗?

I have recently successfully pulled a certificate issued on a private IP from a local server (signed by an experimental CA, but this doesn't matter), so this is neither a bug, nor your app fault (probably - I used HttpClient class methods, but your code looks fine too). 我最近成功地从本地服务器上拉了一个由私有IP颁发的证书(由实验性CA签名,但这无关紧要),所以这既不是错误,也不是您的应用程序错误(可能是-我使用了HttpClient类方法,但您的代码也看起来不错)。

The real question is, if the server you are trying to pull a certificate from, supports SSL/TLS on IP connections and has a valid (in the OS context) certificate assigned to its IP. 真正的问题是,如果您要尝试从中提取证书的服务器在IP连接上支持SSL / TLS, 并且为其IP分配了有效的证书(在OS上下文中)。 On most modern webservers certificates are implemented on virtual hosts using Server Name Indication and querying it only by its IP can return either a self-signed, untrusted certificate, an invalid (expired) one or no certificate at all, leading to SSL negotiation errors. 在大多数现代的Web服务器上,证书是使用服务器名称指示在虚拟主机上实现的,仅通过其IP查询它可以返回自签名,不受信任的证书,无效(过期)的证书或根本没有证书,从而导致SSL协商错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM