【问题标题】:PHP receive SSL certificate parameters on connectPHP 在连接时接收 SSL 证书参数
【发布时间】:2011-09-20 21:47:57
【问题描述】:

我需要控制连接到我们的 Web 服务器的客户端的 SSL 证书(主题、在 DB 中的存在等)。 可以用PHP做吗? 谢谢。

【问题讨论】:

    标签: php ssl controls client certificate


    【解决方案1】:

    PHP 在这方面无能为力。 SSL 仅由网络服务器处理。然而,Apache 可以配置为在 CGI 环境中传递一些信息。

    参见SSLOptions 的手册和SSL_* environment variables 的可用列表。你想读出的可能是:

    print $_SERVER['SSL_CLIENT_S_DN'];
    

    【讨论】:

    • +1 如果你想在 Apache Httpd 级别进一步推动这个,你也可以使用FakeBasicAuth
    【解决方案2】:

    嗯,有可能是的,但在 Curl 的帮助下。

    以详细模式运行 cURL 并将输出发送到 PHP(很简单吧?),然后在 PHP 中解析输出,因为存在颁发者名称(OU=Secure Server Certification Authority == Verisign)。

    IE,Curl 调用示例:

    >> curl -I -v https://login.yahoo.com
    

    会返回这个可解析的输出:

    * About to connect() to login.yahoo.com:443
    * Connected to login1.login.vip.dcn.yahoo.com (216.109.127.60) port 443
    * SSL connection using EDH-RSA-DES-CBC3-SHA
    * Server certificate:
    * subject: /C=US/ST=California/L=Santa Clara/O=Yahoo/OU=Yahoo/CN=login.yahoo.com
    * start date: 2003-02-08 00:00:00 GMT
    * expire date: 2004-02-08 23:59:59 GMT
    * common name: login.yahoo.com (matched)
    * issuer: /C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority
    > HEAD / HTTP/1.1
    User-Agent: curl/7.10.2 (i386-redhat-linux-gnu) libcurl/7.10.2 OpenSSL/0.9.6b ipv6 zlib/1.1.3
    Host: login.yahoo.com
    Pragma: no-cache
    Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
    
    HTTP/1.0 200 OK
    

    另一个选择是 use stunnel 代理您的 HTTPS 查询,这样让 PHP “认为”它正在使用标准 HTTP 查询并且它应该返回输出的每个字节。

    【讨论】:

    • 它似乎与客户证书没有任何关系(这就是问题所在)。此外,发出两个请求(一个使用 curl,一个使用 PHP)并不一定意味着两个证书相同。
    猜你喜欢
    • 2012-12-12
    • 1970-01-01
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    相关资源
    最近更新 更多