diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5d96652..2c0bc73 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -12,7 +12,7 @@ jobs: strategy: matrix: - php-versions: [ '8.0', '8.1', '8.2', '8.3', '8.4'] + php-versions: [ '8.1', '8.2', '8.3', '8.4', '8.5'] dependency-version: [prefer-lowest, prefer-stable] name: PHP ${{ matrix.php-versions }} - ${{ matrix.dependency-version }} diff --git a/composer.json b/composer.json index 5cdd59b..ad04cb6 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ "keywords": [ "cms", "pkcs7", "cades", "x690", "asn1", "asn.1", "ber", "der", "binary", "encoding", "decoding" ], "require": { - "php": ">=8.0", - "adapik/phpasn1": "^2.4" + "php": ">=8.1", + "adapik/phpasn1": "^2.6.0" }, "require-dev": { "phpunit/phpunit": "^9.6" diff --git a/src/CMS/CMSBase.php b/src/CMS/CMSBase.php index c4f7cd9..cbeaa37 100644 --- a/src/CMS/CMSBase.php +++ b/src/CMS/CMSBase.php @@ -14,6 +14,7 @@ use Adapik\CMS\Interfaces\CMSInterface; use FG\ASN1\ASN1Object; use FG\ASN1\ASN1ObjectInterface; +use FG\ASN1\Exception\ParserException; use FG\ASN1\Mapper\Mapper; /** @@ -45,7 +46,11 @@ public function __construct(ASN1ObjectInterface $object) */ final protected static function makeFromContent(string $content, string $mapperClass, string $objectClass): ASN1ObjectInterface { - $object = ASN1Object::fromFile($content); + try { + $object = ASN1Object::fromFile($content); + } catch (ParserException $e) { + throw new FormatException($e->getMessage(), 0, $e); + } if (!$object instanceof $objectClass) { throw new FormatException( diff --git a/tests/CMS/PrivateKeyTest.php b/tests/CMS/PrivateKeyTest.php index 9de2915..46f6b60 100644 --- a/tests/CMS/PrivateKeyTest.php +++ b/tests/CMS/PrivateKeyTest.php @@ -61,4 +61,13 @@ public function testKeyAlgorithm() // RSA encryption OID is 1.2.840.113549.1.1.1 self::assertStringContainsString('1.2.840.113549.1.1.1', $algorithm->getAlgorithmOid()); } + + public function testNonOctetStringPrivateKeyIsRejected() + { + $this->expectException(FormatException::class); + + PrivateKey::createFromContent(hex2bin( + '3034020100300b0609608648016503040320442280203434343434343434343434343434343434343434343434343434343434343434' + )); + } }