PHP Conference Japan 2024

執行階段設定

這些函式的行為會受到 php.ini 中設定的影響。

openssl 設定選項
名稱 預設值 可變更性 變更記錄
openssl.cafile "" INI_PERDIR  
openssl.capath "" INI_PERDIR  
有關 INI_* 模式的更多詳細資訊和定義,請參閱 設定設定的位置

以下是設定指令的簡短說明。

openssl.cafile 字串

本地檔案系統上憑證授權檔案的位置,應與 verify_peer 上下文選項一起使用,以驗證遠端對等點的身分。

openssl.capath 字串

如果未指定 cafile 或在其中找不到證書,則會搜尋 capath 指向的目錄以尋找合適的證書。 capath 必須是一個經過正確雜湊處理的證書目錄。

另請參閱 SSL 資料流脈絡 選項。

新增註記

使用者貢獻的註記 2 則註記

mmi at uhb-consulting dot de
6 年前
在 capath 中,證書必須以證書雜湊值作為名稱,並以 .0 作為結尾。

以下是取得位於此資料夾中的證書雜湊值,並以正確方式自動重新命名它們的方法
<?php
$paths
=openssl_get_cert_locations();
$allowed=array("cer","crt","pem");
if (!empty(
$paths['ini_capath'])){
$capathDirectory = dir($paths['ini_capath']);
while (
false !== ($entry = $capathDirectory->read())) {
$Sourcefile=$paths['ini_capath']."/".$entry;
if (
file_exists( $Sourcefile)){
$path_parts = pathinfo($Sourcefile);
if (
in_array(strtolower($path_parts['extension']),$allowed)){
$ParsedCertificatePbject = openssl_x509_parse(file_get_contents($Sourcefile));
$Sourcefile= $ParsedCertificatePbject["hash"].".0";
$TargetFilename = dirname($Sourcefile)."/".$Sourcefile;
if (!
file_exists($TargetFilename)) {
rename ($Sourcefile ,$TargetFilename);
}
}
}
}
$capathDirectory->close();
}
?>
ofrick at bluewin dot ch
6 年前
以上程式碼應修正為

$Destfile= $ParsedCertificatePbject["hash"].".0";
$TargetFilename = dirname($Sourcefile)."/".$Destfile;
To Top