Rano przejrzę wątek co zaproponowaleś
define ("TMP_FILE", "/tmp/1");
define ("EMAIL", "info@antykwariat-lublin.pl");
// following PATHS must be created
// recipients/certs
// users/keys
// users/certs
// mails/crypt
// mails/decrypt
/*
* sender and recipient
*/
function senRez($mBox, $mId){
$hInfo = imap_headerinfo ($mBox, $mId);
$to = $hInfo->to[0]->mailbox . "@" . $hInfo->to[0]->host;
$from = $hInfo->from[0]->mailbox . "@" . $hInfo->from[0]->host;
return array($from, $to); }
/*
* shit main test func
*/
function getMsgStrct($mBox, $mId){
$struc = imap_fetchstructure($mBox, $mId);
$header = imap_fetchheader($mBox, $mId);
$signtxt = "Content-Type: application/pkcs7-signature; name=\"smime.p7s\"\n";
$signtxt .= "Content-Transfer-Encoding: base64\n";
$signtxt .= "Content-Disposition: attachment; filename=\"smime.p7s\"\n";
$signtxt .= "Content-Description: S/MIME Cryptographic Signature\n\n";
$senRez = senRez($mBox, $mId);
if ($struc->subtype == "SIGNED") {
print " message is singed "; $hdrsign = "This is a cryptographically signed message in MIME format.\n\n";
$hdrsign .= "--" . $struc->parameters[0]->value. "\n";
$hdrsign .= "Content-Type: multipart/alternative;\n";
$hdrsign .= " " .$struc->parts[0]->parameters[0]->attribute . "=\"" . $struc->parts[0]->parameters[0]->value . "\"\n\n";
$signtxt = "\n--" . $struc->parameters[0]->value . "\n" . $signtxt;
$body = imap_fetchbody($mBox, $mId, 1);
$body .= $signtxt;
$body .= imap_fetchbody($mBox, $mId, 2);
$text = $header . $hdrsign . $body . "\n--" . $struc->parameters[0]->value . "--\n";
stoM("decrypt", $mId, $text); //zapisuje plik na dysku
verM($mId, $senRez[0]);
}
elseif ( $struc->subtype == "S/MIME Encrypted Message" || $struc->subtype == "PKCS7-MIME" || $struc->subtype == "X-PKCS7-MIME") {
print " message is encrypted "; $body = imap_fetchbody($mBox, $mId, 1);
$text = $header . "\n" . $body;
stoM("crypt", $mId, $text);
if (decM($mBox, $mId, $senRez[1]) == "signet") {
verM($mId, $senRez[0]);
}
}
}
/*
* store mail
*/
function stoM($type, $mId, $text){
$mailDir = "mails/";
$infile = $mailDir . $type . "/" . $mId;
$fh = fopen($infile, "w"); //$text = strtr($text, array("\r" => ""));
// fwrite ($fh, "\n");
// fwrite ($fh , $body);
}
/*
* verify email
*/
// this function knows etrycerts and outfile where the cert will be storted !!!
function verM($mId, $from){
$reciDir ="recipients/certs/";
$mailDir ="mails/";
$file = $mailDir . "decrypt/" . $mId;
$outfile = $reciDir ."cert" . $from;
$outfile = TMP_FILE;
}
//der2smime($file);
//$test=openssl_pkcs7_verify($file, PKCS7_NOVERIFY | PKCS7_NOSIGS, $from);
//$test=openssl_pkcs7_verify($file, PKCS7_NOVERIFY | PKCS7_NOSIGS, $from, [], $from, $outfile);
//$test = openssl_pkcs7_verify($file, PKCS7_BINARY | PKCS7_NOSIGS | PKCS7_NOVERIFY, $outfile, array(CA));
$test = openssl_pkcs7_verify
($file, PKCS7_BINARY
| PKCS7_NOSIGS
, $outfile, array(CA
)); print "signature is " . $test . "\n"; print openssl_error_string
(); }
/*
* decryt mail
*/
function decM($mBox, $mId, $to) {
$mailDir = "mails/";
$infile = $mailDir . "crypt/" . $mId;
$outfile = $mailDir . "decrypt/" . $mId;
$keyDir = "users/keys/";
$certDir = "users/certs/";
openssl_pkcs7_decrypt($infile, $outfile, $cert, $key);
// print openssl_error_string();
if (stripos
(file_get_contents($outfile), "Content-Type: multipart/signed; protocol=\"application/pkcs7-signature\";") === 0
) { return "signet";
}
if (stripos
(file_get_contents($outfile), "Content-Type: application/x-pkcs7-mime; name=smime.p7m; smime-type=signed-data") === 0
) { return "signet";
}
}
/*
* testrun
*/
require_once('poczta.php');
$P = new Poczta('info@antykwariat-lublin.pl');
$hdr = imap_mailboxmsginfo($P->polaczenie->connection);
print "messages: " . $hdr->Nmsgs . "\n";
$mId = "233";
while ($mId <= $hdr->Nmsgs){
print "<li>message: " . $mId . "\n"; getMsgStrct($P->polaczenie->connection, $mId);
$mId++;
}
W linku co wskazałeś jest inny problem. Ja jakby nie wiem jak się dobrać do załącznika kodowanego, podpisanego cyfrowo. Part 0 u mnie wygląda tak: Play - e-faktura do pobrania','X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on spamassassin.itsaas.pl X-Spam-Level: X-Spam-Status: No, score=-0.6 required=7.0 tests=BAYES_00,HTML_MESSAGE, INVALID_MSGID,MIME_HTML_ONLY,T_DKIM_INVALID autolearn=no version=3.3.2 Received: (qmail 9880 invoked from network); 27 May 2020 11:42:35 -0000 Received: from unknown (HELO mx.dmtec.eu) ([83.143.130.6]) by 192.168.133.41 with SMTP; 27 May 2020 11:42:35 -0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mx.dmtec.eu (Postfix) with ESMTP id 01ABF1605F1 for ; Wed, 27 May 2020 13:42:34 +0200 (CEST) X-Virus-Scanned: by amavisd-new-2.5.3 (20071212) at dmtec.eu Received: from mx.dmtec.eu ([127.0.0.1]) by localhost (mx.dmtec.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K4UZZjbozU94 for ; Wed, 27 May 2020 13:42:28 +0200 (CEST) X-policyd-weight: using cached result; rate: -7.6 Received: from mojefinanseplay.pl (mx-soe.mojefinanseplay.pl [213.222.202.2]) by mx.dmtec.eu (Postfix) with ESMTPS id E81861605B8 for ; Wed, 27 May 2020 13:42:24 +0200 (CEST) Received: from soe-server (unknown [10.170.5.43]) by mojefinanseplay.pl (Postfix) with ESMTP id 49X87x58Xfz7QW9Q for ; Wed, 27 May 2020 13:42:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mojefinanseplay.pl; s=default; t=1590579741; bh=kWy5Im4mVXa3vrkhUto8jB1CZJFt+HB+wb7kV+r2A+I=; h=From:To:Subject:Date; b=JkHbtX/JeAwVaWBw79Am2CpQ5O3voD9Hpy4Tra4i8h/MyCF5Etj+qgVIhUva/4n6r LywzFlrnSyoy9uy9yOyfo88YSGvSjzo6V1fGLWp2g+e3umAZ7yN9h0kBe70KLNYWbK OUUdKMiq+LI/K+yMk1d3Msg0fkEZeHJMGRSTlnRU= From: awizo@mojefinanseplay.pl To: INFO@ANTYKWARIAT-LUBLIN.PL Subject: Play - e-faktura do pobrania Message-Id: X-Mailer: ADSMailer-169999441@eDocument MIME-Version: 1.0 Content-Type: multipart/signed; charset="utf-8"; protocol="application/pkcs7-signature"; micalg=sha-256; boundary=assecods7unizeto1smime2boundary Date: Wed, 27 May 2020 13:42:21 +0200
W żadnym part nie widać treści email ani załącznika PDF który widoczny jest przez np pocztę webową. Nie jestem profesjonalistą, bardzo mi to potrzebne (obsługa emaili, mam fajny własny program pisany latami i ważne by emaile same podpinały się pod zamówienia), a tracę już głowę 2 dni zmarnowane. W Part 0jest: "micalg=sha-256" co to? skąd wziąć klucz? nie powinien być jakiś publiczny bądź przesyłany z wiadomością?