2011-06-23 30 views
2

我需要控制连接到Web服务器的客户端的SSL证书(主题,presense在DB等)SSL证书的参数。 在PHP中可以做到吗? 谢谢。PHP收到连接

回答

4

PHP在这个没有人举手。 SSL仅由网络服务器处理。但是Apache可以配置为在CGI环境中传递一些信息。

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

print $_SERVER['SSL_CLIENT_S_DN']; 
+0

+ 1'ed,比我的答案:) – stefgosselin

+0

+1如果你想在Apache的httpd一级,这进一步推高,你也可以使用'FakeBasicAuth'容易。 – Bruno

2

那么,这是可能的,但有一点从Curl的帮助。

以详细模式运行cURL并将输出发送到PHP(非常简单的权利?),然后在发布者名称(OU = Secure Server Certification Authority == Verisign)中解析PHP中的输出。

即样品卷曲电话:

>> 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查询,并且它应该返回输出的每一个字节。

+0

它似乎与客户端证书没有任何关系(这就是问题所在)。另外,提出两个请求(一个使用curl,一个使用PHP)并不一定意味着两个证书是相同的。 – Bruno