From 871e1a3070bd79e1a8c26679358edc659031b7c8 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 3 Sep 2014 00:29:04 -0500 Subject: [PATCH] ASN1: add unit tests for indefinite length decoding --- .../File/{ASN1/DevTest.php => ASN1Test.php} | 37 +++++++++++++++++- tests/Unit/File/FE.pdf.p7m | Bin 0 -> 14223 bytes 2 files changed, 36 insertions(+), 1 deletion(-) rename tests/Unit/File/{ASN1/DevTest.php => ASN1Test.php} (81%) create mode 100644 tests/Unit/File/FE.pdf.p7m diff --git a/tests/Unit/File/ASN1/DevTest.php b/tests/Unit/File/ASN1Test.php similarity index 81% rename from tests/Unit/File/ASN1/DevTest.php rename to tests/Unit/File/ASN1Test.php index d0d51042..cededfbe 100644 --- a/tests/Unit/File/ASN1/DevTest.php +++ b/tests/Unit/File/ASN1Test.php @@ -233,4 +233,39 @@ class Unit_File_ASN1_DevTest extends PhpseclibTestCase $this->assertInternalType('array', $result); } -} + + /** + * older versions of File_ASN1 didn't handle indefinite length tags very well + */ + public function testIndefiniteLength() + { + $asn1 = new File_ASN1(); + $decoded = $asn1->decodeBER(file_get_contents('tests/Unit/File/FE.pdf.p7m')); + $this->assertEquals(count($decoded[0]['content'][1]['content'][0]['content']), 5); // older versions would have returned 3 + } + + public function testDefiniteLength() + { + // the following base64-encoded string is the X.509 cert from + $str = 'MIIDITCCAoqgAwIBAgIQT52W2WawmStUwpV8tBV9TTANBgkqhkiG9w0BAQUFADBM' . + 'MQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg' . + 'THRkLjEWMBQGA1UEAxMNVGhhd3RlIFNHQyBDQTAeFw0xMTEwMjYwMDAwMDBaFw0x' . + 'MzA5MzAyMzU5NTlaMGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlh' . + 'MRYwFAYDVQQHFA1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKFApHb29nbGUgSW5jMRcw' . + 'FQYDVQQDFA53d3cuZ29vZ2xlLmNvbTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC' . + 'gYEA3rcmQ6aZhc04pxUJuc8PycNVjIjujI0oJyRLKl6g2Bb6YRhLz21ggNM1QDJy' . + 'wI8S2OVOj7my9tkVXlqGMaO6hqpryNlxjMzNJxMenUJdOPanrO/6YvMYgdQkRn8B' . + 'd3zGKokUmbuYOR2oGfs5AER9G5RqeC1prcB6LPrQ2iASmNMCAwEAAaOB5zCB5DAM' . + 'BgNVHRMBAf8EAjAAMDYGA1UdHwQvMC0wK6ApoCeGJWh0dHA6Ly9jcmwudGhhd3Rl' . + 'LmNvbS9UaGF3dGVTR0NDQS5jcmwwKAYDVR0lBCEwHwYIKwYBBQUHAwEGCCsGAQUF' . + 'BwMCBglghkgBhvhCBAEwcgYIKwYBBQUHAQEEZjBkMCIGCCsGAQUFBzABhhZodHRw' . + 'Oi8vb2NzcC50aGF3dGUuY29tMD4GCCsGAQUFBzAChjJodHRwOi8vd3d3LnRoYXd0' . + 'ZS5jb20vcmVwb3NpdG9yeS9UaGF3dGVfU0dDX0NBLmNydDANBgkqhkiG9w0BAQUF' . + 'AAOBgQAhrNWuyjSJWsKrUtKyNGadeqvu5nzVfsJcKLt0AMkQH0IT/GmKHiSgAgDp' . + 'ulvKGQSy068Bsn5fFNum21K5mvMSf3yinDtvmX3qUA12IxL/92ZzKbeVCq3Yi7Le' . + 'IOkKcGQRCMha8X2e7GmlpdWC1ycenlbN0nbVeSv3JUMcafC4+Q=='; + $asn1 = new File_ASN1(); + $decoded = $asn1->decodeBER(base64_decode($str)); + $this->assertEquals(count($decoded[0]['content']), 3); + } +} \ No newline at end of file diff --git a/tests/Unit/File/FE.pdf.p7m b/tests/Unit/File/FE.pdf.p7m new file mode 100644 index 0000000000000000000000000000000000000000..6b9127156081130ac66dc8ed8cc8afe3af42fe28 GIT binary patch literal 14223 zcmeHuc|4R~`@b3cmNg-2kR{vPGX_J*zGbIuS;ov@EH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