代码之家  ›  专栏  ›  技术社区  ›  Bruno Costa

如何检查服务器是否启用了ssl

ssl
  •  12
  • Bruno Costa  · 技术社区  · 16 年前

    你们中有谁知道,如果有,我如何用我的应用程序代码检查服务器是否启用了ssl?

    6 回复  |  直到 9 年前
        1
  •  10
  •   jfs    7 年前

    "It's easier to ask forgiveness than permission"

    例如,阅读 stackoverflow.com 通过SSL,不要询问是否

    >>> import urllib2
    >>> urllib2.urlopen('https://stackoverflow.com')
    Traceback (most recent call last):
    ...
    urllib2.URLError: <urlopen error (10060, 'Operation timed out')>
    >>> html = urllib2.urlopen('http://stackoverflow.com').read()
    >>> len(html)
    146271
    >>> 
    

    它表明 不支持SSL(2008)。


    更新:

        2
  •  6
  •   johnsyweb    14 年前

    您不需要指定编程语言,但可以从命令行执行此操作。

    bash-3.2$ echo ^D | telnet www.google.com https
    Trying 66.102.11.104...
    Connected to www.l.google.com.
    Escape character is '^]'.
    Connection closed by foreign host.
    bash-3.2$ echo ^D | telnet www.stackoverflow.com https
    Trying 69.59.196.211...
    telnet: connect to address 69.59.196.211: Connection refused
    telnet: Unable to connect to remote host
    

    好了。。。谷歌有,StackOverflow没有。

        3
  •  2
  •   dove    16 年前

    不确定您的首选语言,但这里是c语言#

    public bool IsSecureConnection()
    {
        return HttpContext.Current.Request.IsSecureConnection || 
               HttpContext.Current.Request.Headers["HTTP_X_SSL_REQUEST"].Equals("1");
    }
    

    请注意这个标题是定制的,但我想你明白了。我见过人们简单地查询“https”请求,除了看起来脏之外,这可能是可以合理接受的,这取决于您的安全模型。

    或者你是在问,它是否完全可用?

        4
  •  2
  •   Guy Lowe    8 年前

        [TestMethod]
        public void DetectSslSupport()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.someinsecuresite.com");
            try
            {
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    //some sites like stackoverflow will perform a service side redirect to the http site before the browser/request can throw an errror.
                    Assert.IsTrue(response.ResponseUri.Scheme == "https");
                }
            }
            catch (WebException)//"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."}
            {
                Assert.IsTrue(false);
            }
        }
    
        5
  •  1
  •   Yan Foto    5 年前

    11年后。。。

    我在这里结束,因为我有同样的问题(在终端)。

    我想最简单的解决办法是使用 s_client 属于 openssl :

    openssl s_client -quiet -connect google.com:443
    

    如果返回的退出状态为 0 (使用 echo "$?" 443

        6
  •  0
  •   genehack    16 年前

    您需要指定正在使用的协议——有HTTP、IMAP、POP等的SSL版本。

    假设您感兴趣的是HTTPS,您可以检查服务器上的端口443上是否有内容正在侦听,然后从那里开始。。。

        7
  •  0
  •   Des Cent    12 年前

    如果您在服务器上运行PHP或ASP代码,简单的回答是您没有。您可以尝试与非ssl IP地址建立套接字连接,查看是否获得ssl证书,并枚举其公用名和SubjectAlternativeName,但一般来说,简单的答案是您没有。apache的一个常见(错误)配置是在没有SSL证书的情况下侦听端口443,因此能够建立连接并不能保证那里有SSL。无法建立连接可能意味着您的应用程序没有联网权限。因为设置SSL是一件痛苦的事情,所以您知道是否有SSL,这是一个配置决策。这就像想知道你有多少个孩子——你应该知道。

        8
  •  0
  •   Petr Javorik    3 年前

    批处理SSL/TLS测试给定的输入文件 http.parsed

    10.31.11.5:443
    10.31.11.25:443
    10.31.11.37:55000
    10.31.11.116:80
    

    parallel -j10 'curl -k https://{} 1> /dev/null 2> /dev/null && echo https://{}' :::: http.parsed
    

    我们得到输出

    https://10.31.11.5:443
    https://10.31.11.25:443
    https://10.31.11.37:55000