2017-10-05 4 views
0

C'est la première fois que je signe un certificat avec openssl. Continuez à frapper l'erreur ci-dessus et essayé realpath() et l'ajout de fichier: // mais ne peut toujours pas obtenir openssl pour signer le profil. Je ne comprends pas comment cela fonctionne. N'importe quelles idées seraient appréciées.Openssl_pkcs7_sign(): erreur lors de l'ouverture du fichier

Édition1: Je ne suis pas sûr quel fichier est problématique. Les messages d'erreur n'étaient pas assez spécifiques. Y a-t-il un moyen de le dire?

Code et captures d'écran ci-dessous:

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

Ne hésitez pas à me PM si vous croisez même question. :) – f0rfun

Répondre

0
  1. Supprimer Les champs indésirables si non utilisé dans

    openssl_pkcs7_sign ($ mobileconfig, $ tmpMobileConfig, certFile $, array (PKEY $ ""), array());

  2. Assurez-vous que les chemins de fichier sont correctement fournis.

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