I want to verify a digitally signed PDF and get informations like in Adobe Acrobat in PHP 7.4.
What I already achieved:
- I get the signature of the PDF by reading the bytes defined in ByteRange in the PDF-File and store it in a variable.
- Then I convert it like this:
base64_encode(hex2bin($raw_signature_data));
- After that, I change the formatting to pkcs7:
$zertifikat_formattiert = "";
$zertifikat_formattiert .= "-----BEGIN PKCS7-----\n";
$zertifikat_formattiert .= chunk_split($raw_signature_data, 64);
$zertifikat_formattiert .= "-----END PKCS7-----";```
- Then I read the formatted pkcs7 string with
openssl_pkcs7_read($zertifikat_formattiert, $zertifikate);
- Now I loop the outputed array by openssl_pkcs7_read with foreach and for every element I obtain the fingerprint with:
foreach($zertifikate as $zertifikat_nummer => $zertifikat_x509_raw) {
openssl_x509_fingerprint($zertifikat_x509_raw, "sha1WithRSAEncryption");
}
Additionaly I get infomations like the valid from- and to-time like this (inside the foreach loop):
$x509_zertifikat = openssl_x509_parse(openssl_x509_read($zertifikat_x509_raw));
$valid_from_time = $x509_zertifikat['validFrom_time_t'];
$valid_to_time ['validTo_time_t'];
My questions
- Now how can I verify, that the document was not modified since it was signed, in PHP with this data / informations?
- How can I check if the PDF was signed with the clock from the signer's computer?
I have already tried it like the answer suggested from here (Verify signed PDF Document in PHP) with no success.
Greetings and thanks!