Openssl_pkcs7_sign(): 打开文件时出错

Openssl_pkcs7_sign(): error opening file

这是我第一次使用 openssl 签署证书。继续出现上述错误并尝试使用 realpath() 并附加 file:// 但仍然无法让 openssl 对配置文件进行签名。我不明白这是怎么回事。任何见解将不胜感激。

Edit1:我不确定哪个文件有问题。错误信息不够具体。有办法告诉吗?

下面的代码和截图:

function signProfile()
{
    $filename = "./template.mobileconfig";
    $filename = realpath($filename);
    $outFilename = $filename . ".tmp";
    $pkey = dirname(__FILE__) . "/PteKey.key";
    $pkey = realpath($pkey);
    $certFile = dirname(__FILE__) . "/CertToSign.crt";
    $certFile = realpath($certFile);

    // try signing the plain XML profile
    if (openssl_pkcs7_sign($filename, $outFilename, 'file://'.$certFile, array('file://'.$pkey, ""), array(), 0, "")) 
    {
        // get the data back from the filesystem
        $signedString = file_get_contents($outFilename);
        // trim the fat
        $trimmedString = preg_replace('/(.+\n)+\n/', '', $signedString, 1);
        // convert to binary (DER)
        $decodedString = base64_decode($trimmedString);
        // write the file back to the filesystem (using the filename originally given)
        $fh = fopen($filename, 'w');
        fwrite($fh, $decodedString);
        fclose($fh);
        // delete the temporary file
        unlink($outFilename);
        return TRUE;
    } 
    else
    {
        return FALSE;
    }
}
  1. 如果

    中没有使用,请删除不需要的字段

    openssl_pkcs7_sign($mobileConfig, $tmpMobileConfig, $certFile, array($pkey, ""), array());

  2. 确保文件路径提供正确。

    require_once('variables.php'); //stores abs path to $tmpMobileConfig/$pteKeyPath/$CertToSignPath
    $prepend = "file://";
    $mobileConfig = realpath("./template.mobileconfig");
    $pkey = $prepend . $pteKeyPath;
    $pkey = str_replace('\', '/', $pkey);
    $certFile = $prepend . $CertToSignPath;
    $certFile = str_replace('\', '/', $certFile);
    $isSignedCert = openssl_pkcs7_sign($mobileConfig, $tmpMobileConfig, $certFile, array($pkey, ""), array());