lokielse / omnipay-alipay

Alipay driver for the Omnipay PHP payment processing library
MIT License
565 stars 155 forks source link

getRootCertSN function throw notice` #179

Closed pslxx closed 4 years ago

pslxx commented 4 years ago
 getRootCertSN(base_path('certs/alipay/alipayRootCert.crt'))
PHP Notice:  Trying to access array offset on value of type bool in /var/www/zuqiuyoudao/api/vendor/lokielse/omnipay-alipay/src/Common/helpers.php on line 110
pslxx commented 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

lialosiu commented 4 years ago

Snipaste_2020-08-31_17-38-31

的确会存在这个问题,explode -----END CERTIFICATE----- 之后,尾部会出现个 \n 然后 openssl_x509_parse 处理失败返回 false,后边的 in_array 就会抛出异常了