From 6dc7b3e6b975b06c7aee390cd9d0f1f38aabd767 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 14 Apr 2018 23:39:05 -0500 Subject: [PATCH 1/3] ASN1: class is never set as key in _decode_ber --- phpseclib/File/ASN1.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index 732bd9c6..aa0f43b9 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -666,7 +666,7 @@ class File_ASN1 $childClass = $tempClass = FILE_ASN1_CLASS_UNIVERSAL; $constant = null; if (isset($temp['constant'])) { - $tempClass = isset($temp['class']) ? $temp['class'] : FILE_ASN1_CLASS_CONTEXT_SPECIFIC; + $tempClass = $temp['type']; } if (isset($child['class'])) { $childClass = $child['class']; @@ -729,7 +729,7 @@ class File_ASN1 $temp = $decoded['content'][$i]; $tempClass = FILE_ASN1_CLASS_UNIVERSAL; if (isset($temp['constant'])) { - $tempClass = isset($temp['class']) ? $temp['class'] : FILE_ASN1_CLASS_CONTEXT_SPECIFIC; + $tempClass = $temp['type']; } foreach ($mapping['children'] as $key => $child) { From 6bfca3df72959be8d3fa10a7a08e1f2185e6e45c Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 14 Apr 2018 23:41:00 -0500 Subject: [PATCH 2/3] X509: CS adjustment --- phpseclib/File/X509.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/File/X509.php b/phpseclib/File/X509.php index 34a9c585..22266ec0 100644 --- a/phpseclib/File/X509.php +++ b/phpseclib/File/X509.php @@ -3698,7 +3698,7 @@ class File_X509 'tbsCertificate' => array( 'version' => 'v3', - 'serialNumber' => $serialNumber, // $this->setserialNumber() + 'serialNumber' => $serialNumber, // $this->setSerialNumber() 'signature' => array('algorithm' => $signatureAlgorithm), 'issuer' => false, // this is going to be overwritten later 'validity' => array( From 7fc3cf69f817c50688b26b2d2228360fd733585d Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 15 Apr 2018 08:30:02 -0500 Subject: [PATCH 3/3] Tests/ASN1: add test for commit 6dc7b3e --- tests/Unit/File/ASN1Test.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Unit/File/ASN1Test.php b/tests/Unit/File/ASN1Test.php index 2708b858..7e01e1aa 100644 --- a/tests/Unit/File/ASN1Test.php +++ b/tests/Unit/File/ASN1Test.php @@ -299,4 +299,36 @@ class Unit_File_ASN1Test extends PhpseclibTestCase $data = base64_decode('MD6gJQYKKwYBBAGCNxQCA6AXDBVvZmZpY2VAY2VydGRpZ2l0YWwucm+BFW9mZmljZUBjZXJ0ZGlnaXRhbC5ybw=='); $asn1->decodeBER($data); } + + public function testApplicationTag() + { + $map = array( + 'type' => FILE_ASN1_TYPE_SEQUENCE, + 'children' => array( + // technically, default implies optional, but we'll define it as being optional, none-the-less, just to + // reenforce that fact + 'version' => array( + // if class isn't present it's assumed to be FILE_ASN1_CLASS_UNIVERSAL or + // (if constant is present) FILE_ASN1_CLASS_CONTEXT_SPECIFIC + 'class' => FILE_ASN1_CLASS_APPLICATION, + 'cast' => 2, + 'optional' => true, + 'explicit' => true, + 'default' => 'v1', + 'type' => FILE_ASN1_TYPE_INTEGER, + 'mapping' => array('v1', 'v2', 'v3') + ) + ) + ); + + $data = array('version' => 'v3'); + + $asn1 = new File_ASN1(); + $str = $asn1->encodeDER($data, $map); + + $decoded = $asn1->decodeBER($str); + $arr = $asn1->asn1map($decoded[0], $map); + + $this->assertSame($data, $arr); + } }