Closed pslxx closed 4 years ago
if (!function_exists('getRootCertSN')) {
/**
* @param string $certPath
*
* @return string|null
*/
function getRootCertSN($certPath)
{
$array = explode('-----END CERTIFICATE-----', file_get_contents($certPath));
$rootSN = null;
foreach ($array as $i) {
$ssl = openssl_x509_parse($i . '-----END CERTIFICATE-----');
if (in_array($ssl['signatureTypeLN'], ['sha1WithRSAEncryption', 'sha256WithRSAEncryption'])) {
$sn = getCertSN($ssl, true);
if (is_null($rootSN)) {
$rootSN = $sn;
} else {
$rootSN .= "_{$sn}";
}
}
}
return $rootSN;
}
}
这个函数有问题啊,explode之后,最后一个元素肯定是空字符串 然后openssl_x509_parse 返回的肯定是false 后面直接使用in_array就会抛出提示Trying to access array offset on value of type bool
的确会存在这个问题,explode -----END CERTIFICATE-----
之后,尾部会出现个 \n
然后 openssl_x509_parse 处理失败返回 false,后边的 in_array 就会抛出异常了