diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index e5c219b1..12392c2f 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -739,7 +739,14 @@ abstract class ASN1 return isset(self::$oids[$decoded['content']]) ? self::$oids[$decoded['content']] : $decoded['content']; case self::TYPE_UTC_TIME: case self::TYPE_GENERALIZED_TIME: - if (isset($mapping['implicit'])) { + // for explicitly tagged optional stuff + if (is_array($decoded['content'])) { + $decoded['content'] = $decoded['content'][0]['content']; + } + // for implicitly tagged optional stuff + // in theory, doing isset($mapping['implicit']) would work but malformed certs do exist + // in the wild that OpenSSL decodes without issue so we'll support them as well + if (!is_object($decoded['content'])) { $decoded['content'] = self::decodeTime($decoded['content'], $decoded['type']); } return $decoded['content'] ? $decoded['content']->format(self::$format) : false; diff --git a/phpseclib/File/ASN1/Maps/SubjectInfoAccessSyntax.php b/phpseclib/File/ASN1/Maps/SubjectInfoAccessSyntax.php new file mode 100644 index 00000000..c395ca1a --- /dev/null +++ b/phpseclib/File/ASN1/Maps/SubjectInfoAccessSyntax.php @@ -0,0 +1,35 @@ + + * @copyright 2016 Jim Wigginton + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @link http://phpseclib.sourceforge.net + */ + +namespace phpseclib\File\ASN1\Maps; + +use phpseclib\File\ASN1; + +/** + * SubjectInfoAccessSyntax + * + * @package ASN1 + * @author Jim Wigginton + * @access public + */ +abstract class SubjectInfoAccessSyntax +{ + const MAP = [ + 'type' => ASN1::TYPE_SEQUENCE, + 'min' => 1, + 'max' => -1, + 'children' => AccessDescription::MAP + ]; +} diff --git a/tests/Unit/File/ASN1Test.php b/tests/Unit/File/ASN1Test.php index baa9242b..ce64c112 100644 --- a/tests/Unit/File/ASN1Test.php +++ b/tests/Unit/File/ASN1Test.php @@ -364,4 +364,32 @@ class Unit_File_ASN1Test extends PhpseclibTestCase $this->assertSame(pack('H*', '6983f09da7ebcfdee0c7a1a7b2c0948cc8f9d776'), $new); $this->assertSame($orig, ASN1::decodeOID($new)); } + + /** + * @group github1388 + */ + public function testExplicitImplicitDate() + { + $map = [ + 'type' => ASN1::TYPE_SEQUENCE, + 'children' => [ + 'notBefore' => [ + 'constant' => 0, + 'optional' => true, + 'implicit' => true, + 'type' => ASN1::TYPE_GENERALIZED_TIME], + 'notAfter' => [ + 'constant' => 1, + 'optional' => true, + 'implicit' => true, + 'type' => ASN1::TYPE_GENERALIZED_TIME] + ] + ]; + + $a = pack('H*', '3026a011180f32303137303432313039303535305aa111180f32303138303432313230353935395a'); + $a = ASN1::decodeBER($a); + $a = ASN1::asn1map($a[0], $map); + + $this->assertInternalType('array', $a); + } }