Skip to content
Advertisement

PHP OpenSSL openssl_pkcs7_verify() not working, even if openssl from shell works

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.

I’m trying to “translate” this using openssl_pkcs7_verify():

JavaScript

This is the PHP line that does so:

JavaScript

The problem is that $result is -1 and openssl_error_string() gives me this error:

JavaScript

And no, I can’t use exec() nor shell_exec() etc.
I saw that OpenSSL PHP library needs S/MIME and not DER so I found this function to get the file as S/MIME:

JavaScript

But it doesn’t work either using this before using openssl.
How can I fix that? Thanks in advance!

Advertisement

Answer

Okay I’ve solved it this way:
First I had to extract the certificate of the signer from the file with

JavaScript

It extracts the certificate and it saves it in $signer.

Then I’ve used

JavaScript

to extract the content from the signed file in $output using the signer’s certificate.
Of course I still needed to convert the input from DER to SMIME using that function (der2smime()).
Hope it helps!

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement