title: PHP OpenSSL openssl_pkcs7_verify() not working, even if openssl from shell works
body: <p>I'm trying to use the OpenSSL built in PHP library to get the content of a p7m signed file (an XML file, particularly a fattura elettronica for the italians out there). I don't need to check the sign/certificate, I need only the content.  </p>
  
  <p>I'm trying to "translate" this using openssl_pkcs7_verify():  </p>
  
  <pre><code>openssl smime -verify -noverify -in file.xml.p7m -inform DER -out file.xml
  </code></pre>
  
  <p>This is the PHP line that does so:</p>
  
  <pre><code>$result = openssl_pkcs7_verify('file.xml.p7m', PKCS7_NOVERIFY, 'file.xml');
  </code></pre>
  
  <p>The problem is that $result is -1 and openssl_error_string() gives me this error:</p>
  
  <pre><code>error:0B065068:x509 certificate routines:BY_FILE_CTRL:loading defaults
  </code></pre>
  
  <p>And no, I can't use exec() nor shell_exec() etc.<br>
  I saw that OpenSSL PHP library needs S/MIME and not DER so I found this function to get the file as S/MIME:  </p>
  
  <pre><code>function der2smime($file) {
  $to=&lt;&lt;&lt;TXT
  MIME-Version: 1.0
  Content-Disposition: attachment; filename="smime.p7m"
  Content-Type: application/x-pkcs7-mime; smime-type=signed-data;name="smime.p7m"
  Content-Transfer-Encoding: base64
  \n
  TXT;
      $from=file_get_contents($file);
      $to.=chunk_split(base64_encode($from));
      return file_put_contents($file,$to);
  }
  </code></pre>
  
  <p>But it doesn't work either using this before using openssl.<br>
  How can I fix that? Thanks in advance!</p>