2017-10-05 83 views
0

這是我第一次使用openssl簽署證書。繼續打上面的錯誤並嘗試realpath()並追加file://但仍然無法獲得openssl簽名配置文件。我不明白這是如何工作的。任何見解,將不勝感激。Openssl_pkcs7_sign():錯誤打開文件

編輯1:我不確定哪個文件是有問題的文件。錯誤消息不夠具體。有沒有辦法告訴?

代碼和下面截圖:

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; 
    } 
} 
+0

隨意PM我,如果你碰到同樣的問題。 :) – f0rfun

回答

0
  1. 如果不是在

    openssl_pkcs7_sign($ mobileConfig,$ tmpMobileConfig,$ certFile中,陣列($ p鍵, 「」)用於刪除不需要的領域,陣列());

  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());