在 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();
}
?>