openssl_pkcs7_verify

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

openssl_pkcs7_verifyS/MIME imzalı bir iletinin imzasını doğrular

Açıklama

openssl_pkcs7_verify(
    string $dosya,
    int $seçenekler,
    string $sertifikalar = ?,
    array $CA_bilgisi = ?,
    string $ek_sertifikalar = ?,
    string $çıktı_dosyası = ?
): mixed

S/MIME imzalı iletiyi içeren dosya okunur ve iletinin imzası doğrulanmaya çalışılır.

Değiştirgeler

dosya

İletinin bulunduğu dosyanın yolu..

seçenekler

İmzanın nasıl doğrulanacağı belirtilir. Ayrıntılı bilgi için PKCS7 sabitlerine bakınız.

sertifikalar

Belirtildiği takdirde, şahsın iletileri imzalamakta kullandığı sertifikaların PEM biçemli olarak saklandığı dosyanın yolu olmalıdır.

CA_bilgisi

Belirtildiği takdirde, doğrulama işleminde kullanılacak güvenilir CA sertifikaları hakkında bilgileri içeren bir dizi olmalıdır. Ayrıntılı bilgi için Sertifika Doğrulama bölümüne bakınız.

ek_sertifikalar

Belirtildiği takdirde, güvenilmez CA'lar olarak kullanılacak sertifikaların bulunduğu dosyanın yolu olmalıdır.

çıktı_dosyası

Belirtildiği takdirde, imzası doğrulanmış iletinin içeriği imzasız olarak bu dosyaya kaydedilir.

Dönen Değerler

İmza doğru ise true, değilse (ileti kurcalanmışsa veya sertifika geçersizse) false, işlem sırasında bir hata oluşmuşsa -1 döner.

Sürüm Bilgisi

Sürüm: Açıklama
5.1.0 çıktı_dosyası değiştirgesi eklendi.

add a note add a note

User Contributed Notes 2 notes

up
4
reg1barclay at REMOVETHIS dot live dot it
5 years ago
To verify a .p7m file with openssl_pkcs7_verify() you must convert it to S/MIME format. For example...
<?php
function der2smime($file)
{
   
$to=<<<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);
}
?>
up
-2
Krzychu
10 years ago
To read signed message in base64 (not encrypted with priv&pub key):

You can just decode content by "base64_decode" or "imap_base64" functions and then erase by hand(regexp) sign from bottom of mail. Unfortunately  in my case (mail from Outlook) that  message (decoded by "base64_decode") has some additional special chars in some places (ie. before every attachment encoded base_64) what make message e-mail unable to parse.

After couple of hours I solved this:
It's needed to save single e-mail and use 2x "openssl_pkcs7_verify" function in row on original email (with headers and content in base64 ):
  1st use - extract sign (certificate) from e-mail and save to file *.cert
  2nd use - extract (with use that *.cert file) decoded message to  file*.out

Code:
  $handle  =  imap_open('mailbox.eml', '', '');

  $msg = 'home/john/tmp/email1.eml';
  imap_savebody($handle, $msg,  1);

  openssl_pkcs7_verify($msg, 0, $msg . '.cert');
  openssl_pkcs7_verify($msg, 0, $msg . '.cert', array(), $msg . '.cert', $msg.'.out');

  $email_content = file_get_contents($msg . '.out');
To Top