Unwrapping DER signed content in PHP

386 views Asked by At

I have a DER signed file and I want to extract his content stripping the signature... Php openssl_pkcs7_verify function only works with PEM signed files, that's the first thing I've discovered. So I've base64 encoded the content, saved it to a file and tried to unwrap it again.

Nothing, I still get these errors:

error:02001000:system library:fopen:system library

error:2006D002:BIO routines:BIO_new_file:system lib

This is an extract from my code:

$nomeFileEstratto = substr($nomeFileP7M,0,-4);
$nomeTemporaneoP7M = $_SERVER['DOCUMENT_ROOT'].'/temp/'.basename($nomeFileP7M);
$nomeTemporaneoEstratto = $_SERVER['DOCUMENT_ROOT'].'/temp/'.basename($nomeFileEstratto);

//Salvo il file p7m nella cartella temporanea
file_put_contents($nomeTemporaneoP7M,$this->der2pem($contenutoFileP7M));

//Estrazione dei dati
//exec('openssl smime -decript -in \''.$nomeTemporaneoP7M.'\' -inform DER -verify -noverify -out \''.$nomeTemporaneoEstratto.'\'');
openssl_pkcs7_verify($nomeTemporaneoP7M, PKCS7_NOVERIFY, null, array(), null, $nomeTemporaneoEstratto);

Note that I can't use a system call.

I also fell in ANS1PHP and PHPSECLIB, but I don't guess out how to use them for my purpose.

0

There are 0 answers