Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace PHPMailer\Test\PHPMailer; use Exception; use PHPMailer\PHPMailer\PHPMaile..
Decoded Output download
<?php
namespace PHPMailer\Test\PHPMailer; use Exception; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\Test\SendTestCase; final class DKIMTest extends SendTestCase { const USE_EXCEPTIONS = true; const PRIVATE_KEY_FILE = "dkim_private.pem"; protected function tear_down() { if (file_exists(self::PRIVATE_KEY_FILE)) { unlink(self::PRIVATE_KEY_FILE); } parent::tear_down(); } public function testDKIMBodyCanonicalization() { $prebody = " C \xd\xaD \x9 E
\xa
\xa"; $postbody = " C \xd
D E\xd\xa"; self::assertSame("\xd
", $this->Mail->DKIM_BodyC(''), "DKIM empty body canonicalization incorrect (Empty body)"); self::assertSame("frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN/XKdLCPjaYaY=", base64_encode(hash("sha256", $this->Mail->DKIM_BodyC(''), true)), "DKIM canonicalized empty body hash mismatch"); self::assertSame($postbody, $this->Mail->DKIM_BodyC($prebody), "DKIM body canonicalization incorrect"); $prebody = " C
D \x9 E
\xa\xd\xa\xd
"; $postbody = " C
\xaD E \xd\xa"; self::assertSame($postbody, $this->Mail->DKIM_BodyC($prebody), "DKIM body canonicalization incorrect (trailing WSP)"); } public function testDKIMHeaderCanonicalization() { $preheaders = "A: X\xd\xaB : Y \xd
\x9Z \xd
"; $postheaders = "a:X
b:Y Z
"; self::assertSame($postheaders, $this->Mail->DKIM_HeaderC($preheaders), "DKIM header canonicalization incorrect"); $preheaders = "Long-Header-1: <https://example.com/somescript.php?" . "id=1234567890&name=Abcdefghijklmnopquestuvwxyz&hash=\xd\xa abc1234
" . "Long-Header-2: This is a long header value that contains runs of spaces and trailing \xd
" . " and is folded onto 2 lines"; $postheaders = "long-header-1:<https://example.com/somescript.php?id=1234567890&" . "name=Abcdefghijklmnopquestuvwxyz&hash= abc1234
\xalong-header-2:This is a long" . " header value that contains runs of spaces and trailing and is folded onto 2 lines"; self::assertSame($postheaders, $this->Mail->DKIM_HeaderC($preheaders), "DKIM header canonicalization of long lines incorrect"); } public function testDKIMOptionalHeaderFieldsCopy() { $pk = openssl_pkey_new(array("private_key_bits" => 2048, "private_key_type" => OPENSSL_KEYTYPE_RSA)); openssl_pkey_export_to_file($pk, self::PRIVATE_KEY_FILE); $this->Mail->DKIM_private = self::PRIVATE_KEY_FILE; $from = "[email protected]"; $to = "[email protected]"; $date = "date"; $subject = "example"; $headerLines = "From:{$from}
To:{$to}
\xaDate:{$date}\xd\xa"; $copyHeaderFields = " z=From:{$from}\xd\xa |To:{$to}
\xa |Date:{$date}
|Subject:{$subject};\xd
"; $this->Mail->DKIM_copyHeaderFields = true; self::assertStringContainsString($copyHeaderFields, $this->Mail->DKIM_Add($headerLines, $subject, ''), "DKIM header with copied header fields incorrect"); $this->Mail->DKIM_copyHeaderFields = false; self::assertStringNotContainsString($copyHeaderFields, $this->Mail->DKIM_Add($headerLines, $subject, ''), "DKIM header without copied header fields incorrect"); } public function testDKIMExtraHeaders() { $pk = openssl_pkey_new(array("private_key_bits" => 2048, "private_key_type" => OPENSSL_KEYTYPE_RSA)); openssl_pkey_export_to_file($pk, self::PRIVATE_KEY_FILE); $this->Mail->DKIM_private = self::PRIVATE_KEY_FILE; $from = "[email protected]"; $to = "[email protected]"; $date = "date"; $subject = "example"; $anyHeader = "foo"; $unsubscribeUrl = "<https://www.example.com/unsubscribe/?newsletterId=anytoken&actionToken=anyToken" . "&otherParam=otherValue&anotherParam=anotherVeryVeryVeryLongValue>"; $this->Mail->addCustomHeader("X-AnyHeader", $anyHeader); $this->Mail->addCustomHeader("Baz", "bar"); $this->Mail->addCustomHeader("List-Unsubscribe", $unsubscribeUrl); $this->Mail->DKIM_extraHeaders = array("Baz", "List-Unsubscribe"); $headerLines = "From:{$from}
To:{$to}\xd\xaDate:{$date}\xd\xa"; $headerLines .= "X-AnyHeader:{$anyHeader}
Baz:bar
\xa"; $headerLines .= "List-Unsubscribe:" . $this->Mail->encodeHeader($unsubscribeUrl) . "\xd\xa"; $headerFields = "h=From:To:Date:Baz:List-Unsubscribe:Subject"; $result = $this->Mail->DKIM_Add($headerLines, $subject, ''); self::assertStringContainsString($headerFields, $result, "DKIM header with extra headers incorrect"); } public function testDKIMSigningMail() { $this->Mail->Subject .= ": DKIM signing"; $this->Mail->Body = "This message is DKIM signed."; $this->buildBody(); $pk = openssl_pkey_new(array("private_key_bits" => 2048, "private_key_type" => OPENSSL_KEYTYPE_RSA)); openssl_pkey_export_to_file($pk, self::PRIVATE_KEY_FILE); $this->Mail->DKIM_domain = "example.com"; $this->Mail->DKIM_private = self::PRIVATE_KEY_FILE; $this->Mail->DKIM_selector = "phpmailer"; $this->Mail->DKIM_passphrase = ''; self::assertTrue($this->Mail->send(), "DKIM signed mail failed"); $this->Mail->isMail(); self::assertTrue($this->Mail->send(), "DKIM signed mail via mail() failed"); } public function testDKIMSignOpenSSLNotAvailable() { if (extension_loaded("openssl")) { $this->markTestSkipped("Test requires OpenSSL *not* to be available"); } $signature = $this->Mail->DKIM_Sign("foo"); self::assertSame('', $signature); } public function testDKIMSignOpenSSLNotAvailableException() { if (extension_loaded("openssl")) { $this->markTestSkipped("Test requires OpenSSL *not* to be available"); } $this->expectException(Exception::class); $this->expectExceptionMessage("Extension missing: openssl"); $this->Mail->DKIM_Sign("foo"); } } ?>
Did this file decode correctly?
Original Code
<?php
namespace PHPMailer\Test\PHPMailer; use Exception; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\Test\SendTestCase; final class DKIMTest extends SendTestCase { const USE_EXCEPTIONS = true; const PRIVATE_KEY_FILE = "\144\153\x69\155\x5f\x70\x72\151\166\141\x74\x65\56\160\145\155"; protected function tear_down() { if (file_exists(self::PRIVATE_KEY_FILE)) { unlink(self::PRIVATE_KEY_FILE); } parent::tear_down(); } public function testDKIMBodyCanonicalization() { $prebody = "\x20\x43\x20\xd\xa\x44\x20\x9\x20\105\15\12\15\xa\15\xa"; $postbody = "\40\x43\40\xd\12\x44\40\11\x20\x45\xd\xa"; self::assertSame("\xd\12", $this->Mail->DKIM_BodyC(''), "\x44\113\x49\x4d\x20\x65\x6d\160\164\171\x20\x62\x6f\144\171\x20\143\141\x6e\157\x6e\x69\143\141\x6c\x69\x7a\141\x74\x69\157\156\40\x69\156\143\157\162\162\145\x63\x74\x20\x28\x45\x6d\160\164\x79\40\142\x6f\144\x79\x29"); self::assertSame("\146\x72\x63\103\126\61\153\71\x6f\x47\x39\157\113\152\63\144\x70\125\161\144\112\x67\61\x50\170\x52\x54\x32\122\x53\x4e\x2f\x58\x4b\x64\x4c\103\120\x6a\x61\x59\141\x59\x3d", base64_encode(hash("\163\150\141\x32\x35\66", $this->Mail->DKIM_BodyC(''), true)), "\x44\x4b\x49\x4d\x20\143\x61\156\157\156\x69\143\x61\154\x69\172\145\x64\x20\x65\x6d\x70\164\x79\40\142\x6f\144\x79\40\150\141\163\150\40\155\151\x73\x6d\141\x74\x63\150"); self::assertSame($postbody, $this->Mail->DKIM_BodyC($prebody), "\104\113\x49\x4d\x20\142\157\x64\171\x20\x63\141\156\157\156\x69\143\x61\154\151\x7a\x61\x74\x69\x6f\x6e\x20\x69\156\x63\157\162\x72\145\143\164"); $prebody = "\40\x43\40\15\12\104\x20\x9\40\x45\40\15\xa\xd\xa\xd\12"; $postbody = "\40\103\40\15\xa\x44\40\11\x20\105\40\xd\xa"; self::assertSame($postbody, $this->Mail->DKIM_BodyC($prebody), "\104\113\x49\x4d\40\x62\x6f\144\171\40\x63\x61\156\x6f\156\x69\x63\x61\x6c\151\x7a\x61\164\151\157\x6e\x20\x69\156\x63\157\162\162\145\x63\164\40\x28\164\x72\x61\151\154\x69\156\x67\x20\127\x53\x50\51"); } public function testDKIMHeaderCanonicalization() { $preheaders = "\x41\x3a\x20\130\xd\xa\x42\40\x3a\40\131\11\xd\12\x9\x5a\40\x20\xd\12"; $postheaders = "\141\72\x58\15\12\x62\x3a\131\x20\132\15\12"; self::assertSame($postheaders, $this->Mail->DKIM_HeaderC($preheaders), "\x44\x4b\x49\x4d\x20\150\145\x61\x64\145\x72\40\x63\x61\x6e\157\156\151\x63\141\x6c\151\172\x61\164\151\x6f\156\40\x69\x6e\x63\157\162\162\145\143\164"); $preheaders = "\114\157\156\x67\x2d\110\145\141\144\145\162\55\x31\72\x20\74\150\164\164\160\163\x3a\x2f\x2f\145\x78\141\155\x70\154\145\56\x63\157\x6d\57\x73\x6f\155\x65\x73\x63\x72\151\x70\164\x2e\x70\150\x70\x3f" . "\151\x64\x3d\x31\62\63\x34\65\66\67\70\x39\x30\x26\156\x61\x6d\145\75\101\x62\143\144\145\146\147\150\x69\152\153\x6c\155\156\157\x70\161\x75\145\x73\x74\x75\166\x77\170\171\x7a\x26\150\x61\163\x68\x3d\xd\xa\40\x61\x62\x63\x31\62\63\64\15\12" . "\114\x6f\x6e\147\55\x48\145\141\x64\145\162\55\x32\x3a\x20\124\150\151\x73\x20\40\151\x73\x20\40\x61\40\40\154\x6f\x6e\147\x20\x20\x68\x65\x61\144\x65\162\x20\40\x76\x61\x6c\x75\145\40\x20\x74\x68\141\164\x20\40\x63\157\156\164\x61\x69\156\163\40\x20\162\165\156\x73\x20\40\x6f\146\x20\40\163\160\141\143\x65\163\40\x61\x6e\144\40\x74\x72\x61\151\x6c\151\156\147\40\x20\40\x20\xd\12" . "\40\x61\x6e\144\x20\40\x20\151\x73\x20\40\x20\x66\157\x6c\144\x65\144\x20\x20\40\157\x6e\x74\157\40\40\x20\x32\40\40\x20\x6c\151\x6e\x65\x73"; $postheaders = "\x6c\157\156\x67\55\150\145\141\144\145\162\x2d\x31\72\x3c\150\164\x74\160\163\72\57\x2f\x65\x78\x61\155\160\154\x65\56\x63\x6f\155\57\x73\x6f\x6d\145\163\143\x72\151\x70\164\56\160\x68\x70\x3f\151\x64\75\x31\62\63\64\x35\66\67\x38\71\60\x26" . "\x6e\141\155\x65\75\x41\142\x63\x64\x65\146\x67\x68\151\152\x6b\x6c\155\156\157\x70\161\165\145\163\x74\x75\166\167\170\x79\172\46\150\x61\163\x68\x3d\x20\141\142\x63\x31\x32\63\64\15\xa\154\157\156\x67\x2d\150\145\x61\144\145\x72\55\62\x3a\x54\x68\x69\x73\x20\x69\163\40\141\40\154\157\x6e\147" . "\40\150\145\141\144\x65\x72\x20\166\x61\154\x75\x65\40\164\150\x61\x74\40\x63\x6f\x6e\164\x61\x69\x6e\163\x20\x72\x75\x6e\x73\x20\x6f\x66\x20\163\160\141\x63\145\x73\x20\141\156\x64\x20\164\x72\x61\151\x6c\x69\x6e\x67\40\141\x6e\x64\x20\x69\x73\40\146\x6f\x6c\x64\145\144\40\x6f\156\x74\157\40\x32\40\x6c\x69\156\145\163"; self::assertSame($postheaders, $this->Mail->DKIM_HeaderC($preheaders), "\104\113\x49\115\40\x68\145\141\144\145\162\40\143\141\156\157\156\151\x63\141\x6c\151\x7a\141\164\151\x6f\156\x20\x6f\146\x20\154\x6f\x6e\x67\x20\154\x69\156\145\163\40\151\156\143\x6f\x72\x72\145\143\164"); } public function testDKIMOptionalHeaderFieldsCopy() { $pk = openssl_pkey_new(array("\x70\x72\x69\166\141\x74\x65\137\x6b\x65\171\137\142\151\x74\x73" => 2048, "\160\162\x69\166\141\164\145\137\x6b\x65\x79\x5f\164\x79\x70\x65" => OPENSSL_KEYTYPE_RSA)); openssl_pkey_export_to_file($pk, self::PRIVATE_KEY_FILE); $this->Mail->DKIM_private = self::PRIVATE_KEY_FILE; $from = "\146\162\157\155\x40\145\170\x61\x6d\x70\x6c\145\56\x63\157\x6d"; $to = "\164\157\100\145\x78\141\x6d\160\154\x65\x2e\143\157\155"; $date = "\x64\x61\x74\145"; $subject = "\145\170\141\x6d\160\x6c\145"; $headerLines = "\106\x72\x6f\155\72{$from}\15\12\124\x6f\x3a{$to}\15\xa\x44\141\x74\145\x3a{$date}\xd\xa"; $copyHeaderFields = "\40\x7a\75\106\x72\157\x6d\x3a{$from}\xd\xa\x20\174\x54\157\x3a{$to}\15\xa\x20\174\x44\141\164\x65\x3a{$date}\15\12\40\174\123\x75\x62\x6a\145\x63\x74\x3a{$subject}\x3b\xd\12"; $this->Mail->DKIM_copyHeaderFields = true; self::assertStringContainsString($copyHeaderFields, $this->Mail->DKIM_Add($headerLines, $subject, ''), "\104\113\x49\x4d\40\150\x65\x61\144\x65\162\40\x77\x69\x74\x68\x20\x63\x6f\160\151\x65\x64\40\150\145\141\x64\x65\x72\x20\x66\151\x65\154\x64\163\x20\x69\x6e\143\157\162\162\145\143\164"); $this->Mail->DKIM_copyHeaderFields = false; self::assertStringNotContainsString($copyHeaderFields, $this->Mail->DKIM_Add($headerLines, $subject, ''), "\x44\x4b\x49\x4d\x20\150\x65\141\x64\145\x72\x20\x77\x69\164\x68\157\165\164\40\143\157\x70\151\145\144\x20\x68\x65\x61\x64\x65\162\40\146\x69\x65\x6c\144\163\40\151\156\143\x6f\x72\x72\145\x63\x74"); } public function testDKIMExtraHeaders() { $pk = openssl_pkey_new(array("\160\162\x69\x76\141\164\x65\x5f\153\145\x79\137\142\x69\164\x73" => 2048, "\160\x72\151\166\x61\x74\x65\x5f\x6b\x65\171\137\164\x79\160\x65" => OPENSSL_KEYTYPE_RSA)); openssl_pkey_export_to_file($pk, self::PRIVATE_KEY_FILE); $this->Mail->DKIM_private = self::PRIVATE_KEY_FILE; $from = "\146\162\x6f\155\100\x65\170\x61\155\160\154\145\x2e\143\x6f\155"; $to = "\x74\157\x40\x65\x78\141\155\x70\154\145\x2e\143\x6f\x6d"; $date = "\144\141\x74\x65"; $subject = "\145\x78\141\x6d\160\154\x65"; $anyHeader = "\146\x6f\x6f"; $unsubscribeUrl = "\x3c\x68\x74\164\x70\163\x3a\x2f\57\167\x77\x77\x2e\145\x78\141\155\x70\154\145\56\x63\157\155\57\x75\x6e\x73\165\142\x73\x63\162\x69\142\145\57\x3f\156\x65\167\163\x6c\145\164\x74\x65\162\x49\144\75\x61\156\x79\164\x6f\153\145\x6e\46\x61\155\160\x3b\141\143\164\x69\x6f\156\x54\x6f\153\x65\156\75\x61\x6e\171\x54\157\x6b\145\x6e" . "\x26\x6f\164\x68\145\162\x50\141\x72\x61\x6d\x3d\157\164\150\145\x72\x56\141\154\x75\x65\x26\x61\156\157\164\150\145\162\120\141\x72\141\x6d\x3d\x61\x6e\157\x74\150\x65\x72\x56\145\x72\x79\126\145\x72\171\x56\145\x72\x79\114\x6f\x6e\x67\126\141\x6c\x75\x65\x3e"; $this->Mail->addCustomHeader("\x58\x2d\x41\156\x79\x48\x65\x61\144\x65\x72", $anyHeader); $this->Mail->addCustomHeader("\102\141\x7a", "\142\x61\x72"); $this->Mail->addCustomHeader("\x4c\x69\x73\x74\x2d\x55\156\163\165\142\x73\143\162\x69\x62\145", $unsubscribeUrl); $this->Mail->DKIM_extraHeaders = array("\102\x61\172", "\114\x69\163\x74\x2d\125\x6e\x73\x75\142\163\143\162\151\x62\145"); $headerLines = "\106\x72\x6f\x6d\72{$from}\15\12\x54\157\x3a{$to}\xd\xa\x44\x61\164\x65\x3a{$date}\xd\xa"; $headerLines .= "\130\55\101\156\171\x48\145\x61\x64\145\162\x3a{$anyHeader}\15\12\x42\141\x7a\72\x62\x61\x72\15\xa"; $headerLines .= "\x4c\151\x73\164\55\x55\156\163\x75\142\x73\x63\162\151\142\145\72" . $this->Mail->encodeHeader($unsubscribeUrl) . "\xd\xa"; $headerFields = "\x68\75\x46\x72\x6f\x6d\72\x54\x6f\x3a\104\141\x74\x65\72\x42\x61\x7a\72\114\x69\x73\164\x2d\x55\156\x73\x75\x62\x73\143\162\151\x62\145\x3a\123\165\x62\x6a\x65\x63\164"; $result = $this->Mail->DKIM_Add($headerLines, $subject, ''); self::assertStringContainsString($headerFields, $result, "\104\x4b\111\x4d\40\150\145\141\144\145\x72\x20\167\151\x74\x68\40\145\170\x74\162\141\x20\150\145\x61\x64\x65\162\x73\x20\x69\x6e\x63\x6f\162\x72\145\143\x74"); } public function testDKIMSigningMail() { $this->Mail->Subject .= "\x3a\x20\104\113\111\x4d\40\163\x69\x67\156\x69\x6e\x67"; $this->Mail->Body = "\x54\x68\x69\163\40\155\x65\163\x73\x61\147\x65\x20\151\x73\x20\104\113\111\x4d\40\163\x69\147\x6e\145\x64\56"; $this->buildBody(); $pk = openssl_pkey_new(array("\x70\x72\151\x76\141\x74\x65\x5f\x6b\x65\x79\137\142\x69\x74\163" => 2048, "\160\x72\x69\x76\x61\x74\x65\x5f\153\145\x79\x5f\164\171\160\x65" => OPENSSL_KEYTYPE_RSA)); openssl_pkey_export_to_file($pk, self::PRIVATE_KEY_FILE); $this->Mail->DKIM_domain = "\145\170\x61\x6d\x70\x6c\145\56\143\157\155"; $this->Mail->DKIM_private = self::PRIVATE_KEY_FILE; $this->Mail->DKIM_selector = "\x70\150\160\155\x61\x69\x6c\145\x72"; $this->Mail->DKIM_passphrase = ''; self::assertTrue($this->Mail->send(), "\x44\x4b\111\115\40\x73\x69\147\156\145\144\40\x6d\x61\x69\154\x20\146\141\151\154\145\x64"); $this->Mail->isMail(); self::assertTrue($this->Mail->send(), "\x44\113\111\x4d\x20\163\x69\147\156\x65\x64\40\x6d\141\151\x6c\x20\166\x69\141\40\x6d\x61\151\154\50\51\40\146\x61\151\x6c\145\144"); } public function testDKIMSignOpenSSLNotAvailable() { if (extension_loaded("\157\x70\x65\x6e\163\x73\154")) { $this->markTestSkipped("\124\145\163\164\40\x72\x65\x71\165\x69\x72\145\x73\x20\x4f\160\x65\x6e\123\123\114\40\x2a\x6e\x6f\x74\52\x20\164\x6f\40\x62\145\40\141\x76\x61\x69\x6c\141\x62\x6c\x65"); } $signature = $this->Mail->DKIM_Sign("\146\x6f\157"); self::assertSame('', $signature); } public function testDKIMSignOpenSSLNotAvailableException() { if (extension_loaded("\x6f\x70\x65\156\163\163\154")) { $this->markTestSkipped("\124\145\163\164\40\x72\x65\x71\x75\x69\162\x65\163\x20\x4f\x70\145\156\123\x53\x4c\40\x2a\156\x6f\x74\x2a\x20\164\157\40\142\145\x20\141\166\x61\x69\154\141\x62\154\x65"); } $this->expectException(Exception::class); $this->expectExceptionMessage("\105\x78\x74\145\x6e\x73\x69\157\x6e\40\x6d\151\163\x73\x69\x6e\x67\72\40\x6f\x70\145\156\x73\163\154"); $this->Mail->DKIM_Sign("\x66\157\x6f"); } }
Function Calls
None |
Stats
MD5 | 491ed27556b67dd3d6de41f29c6bb6ec |
Eval Count | 0 |
Decode Time | 106 ms |