2011-06-23 28 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