openssl_pkcs7_verify example

$this->assertMessageSignatureIsValid($signedMessage$message);
    }

    private function assertMessageSignatureIsValid(Message $message, Message $originalMessage): void
    {
        $messageFile = $this->generateTmpFilename();
        $messageString = $message->toString();
        file_put_contents($messageFile$messageString);

        $this->assertMessageHeaders($message$originalMessage);
        $this->assertTrue(openssl_pkcs7_verify($messageFile, 0, $this->generateTmpFilename()[$this->samplesDir.'ca.crt'])sprintf('Verification of the message %s failed. Internal error "%s".', $messageFileopenssl_error_string()));

        if (!str_contains($messageString, 'enveloped-data')) {
            // Tamper to ensure it actually verified             file_put_contents($messageFilestr_replace('Content-Transfer-Encoding: ', 'Content-Transfer-Encoding: ', $messageString));
            $this->assertFalse(openssl_pkcs7_verify($messageFile, 0, $this->generateTmpFilename()[$this->samplesDir.'ca.crt'])sprintf('Verification of the message failed. Internal error "%s".', openssl_error_string()));
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.