PHP 在连接时接收 SSL 证书参数

发布于 2024-11-16 18:41:16 字数 67 浏览 0 评论 0原文

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

I need to control SSL certificates (subject, presense in DB, etc.) of clients that connect to our web server.
Is it possible to do in PHP?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

囚你心 2024-11-23 18:41:16

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

请参阅 SSLOptions 手册以及可用的 SSL_* 环境变量。您想读出的内容可能是:

print $_SERVER['SSL_CLIENT_S_DN'];

PHP has no hands in this. SSL is handled by the webserver only. Apache can be configured to pass some information along in the CGI environment however.

See the manual on SSLOptions and the available list of SSL_* environment variables. What you wanted to read out is probably:

print $_SERVER['SSL_CLIENT_S_DN'];
一世旳自豪 2024-11-23 18:41:16

嗯,这是可能的,但需要 Curl 的一点帮助。

在详细模式下运行 cURL 并将输出发送到 PHP(非常简单,对吧?),然后在 PHP 中解析输出,因为存在颁发者名称(OU=安全服务器证书颁发机构 == 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

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

Well, it is possible yes but with a little help from Curl.

Run cURL in verbose mode and send the output to PHP (pretty simple right?), then parse the output in PHP as there is the issuer name (OU=Secure Server Certification Authority == Verisign).

IE, a sample Curl call:

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

Would return this parsable output:

* 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

Another option would be to use stunnel to proxy your HTTPS query and that way let PHP "think" that it's using a standard HTTP query and that it should return every single byte of the output.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文