Update composer package `minishlink/web-push` to `^v9.0.1`
authorCyperghost <olaf_schmitz_1@t-online.de>
Mon, 4 Nov 2024 10:57:47 +0000 (11:57 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Mon, 4 Nov 2024 10:57:47 +0000 (11:57 +0100)
Set alias for `web-token/jwt-library`

26 files changed:
wcfsetup/install/files/lib/system/api/composer.json
wcfsetup/install/files/lib/system/api/composer.lock
wcfsetup/install/files/lib/system/api/composer/installed.json
wcfsetup/install/files/lib/system/api/composer/installed.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Checker/ClaimCheckerManager.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Checker/HeaderCheckerManager.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Console/NoneKeyGeneratorCommand.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Console/PublicKeyCommand.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Console/X5ULoaderCommand.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Core/AlgorithmManager.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Core/AlgorithmManagerFactory.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/Compression/CompressionMethod.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/Compression/CompressionMethodManager.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/Compression/CompressionMethodManagerFactory.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/Compression/Deflate.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/JWEBuilder.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/JWEBuilderFactory.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/JWEDecrypter.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/JWEDecrypterFactory.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/JWELoaderFactory.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Encryption/Serializer/JWESerializerManager.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/KeyManagement/KeyConverter/KeyConverter.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/NestedToken/NestedTokenBuilderFactory.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/NestedToken/NestedTokenLoaderFactory.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/Signature/Serializer/JWSSerializerManager.php
wcfsetup/install/files/lib/system/api/web-token/jwt-library/composer.json

index b5304b6a3c17d397d69920d2d9d208b1688edf02..cf8cc8a17fe875fe0eba2c91fcfbfefe0fdcc1ee 100644 (file)
@@ -19,7 +19,7 @@
     "laminas/laminas-diactoros": "^3.3.1",
     "laminas/laminas-httphandlerrunner": "^2.10.0",
     "laminas/laminas-progressbar": "^2.13",
-    "minishlink/web-push": "^v9.0.0-rc2",
+    "minishlink/web-push": "^v9.0.1",
     "nikic/fast-route": "2.0.0-beta1",
     "paragonie/constant_time_encoding": "^3.0",
     "pelago/emogrifier": "^7.2.0",
@@ -33,7 +33,7 @@
     "sebastian/diff": "^5.1.1",
     "symfony/polyfill-php82": "^1.30.0",
     "symfony/polyfill-php83": "^1.30",
-    "web-token/jwt-library": "^3.3.50",
+    "web-token/jwt-library": "3.3.50 as dev-3.3.x",
     "willdurand/negotiation": "^3.1"
   },
   "replace": {
index f30ffc59417dab18dc0e866990453020d1174786..272511bc9e2c2c7cb4ca6d3639ef652089586af1 100644 (file)
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "70268093034722fc94f786ec6395a6bf",
+    "content-hash": "7fb0b03afd912128e100c108aa1b7fd1",
     "packages": [
         {
             "name": "brick/math",
                 "url": "https://github.com/WoltLab/jwt-library.git",
                 "reference": "18b89d806835d351ebebab3eeb8103a45cfd10b5"
             },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/WoltLab/jwt-library/zipball/18b89d806835d351ebebab3eeb8103a45cfd10b5",
-                "reference": "18b89d806835d351ebebab3eeb8103a45cfd10b5",
-                "shasum": ""
-            },
             "require": {
                 "brick/math": "^0.9|^0.10|^0.11|^0.12",
                 "ext-json": "*",
     "aliases": [],
     "minimum-stability": "stable",
     "stability-flags": {
-        "minishlink/web-push": 5,
         "nikic/fast-route": 10
     },
     "prefer-stable": false,
index 351d1eb825bbc98a9ca03b0456fc17c32bb60fcf..acaffda29a0ef72095f5a81e9dea6663104fed8d 100644 (file)
                 "url": "https://github.com/WoltLab/jwt-library.git",
                 "reference": "18b89d806835d351ebebab3eeb8103a45cfd10b5"
             },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/WoltLab/jwt-library/zipball/18b89d806835d351ebebab3eeb8103a45cfd10b5",
-                "reference": "18b89d806835d351ebebab3eeb8103a45cfd10b5",
-                "shasum": ""
-            },
             "require": {
                 "brick/math": "^0.9|^0.10|^0.11|^0.12",
                 "ext-json": "*",
                 "RFC7520",
                 "Symfony"
             ],
-            "support": {
-                "source": "https://github.com/WoltLab/jwt-library/tree/3.3.50"
-            },
-            "funding": [
-                {
-                    "type": "github",
-                    "url": "https://github.com/Spomky"
-                },
-                {
-                    "type": "patreon",
-                    "url": "https://www.patreon.com/FlorentMorselli"
-                }
-            ],
             "install-path": "../web-token/jwt-library"
         },
         {
             "install-path": "../willdurand/negotiation"
         }
     ],
-    "dev": false,
+    "dev": true,
     "dev-package-names": []
 }
index 0e4c28ec32a185a835027449e93f9692bccac303..c8b938cf34d0aeb0032cca17fdc1aa324937fb88 100644 (file)
@@ -1,19 +1,19 @@
 <?php return array(
     'root' => array(
         'name' => '__root__',
-        'pretty_version' => 'dev-master',
-        'version' => 'dev-master',
-        'reference' => '37708311277ea8a294ac6ee74bfe8f055446016b',
+        'pretty_version' => '6.1.x-dev',
+        'version' => '6.1.9999999.9999999-dev',
+        'reference' => 'fe4913df9ac21beb9718c8dc312246df476fc7ff',
         'type' => 'project',
         'install_path' => __DIR__ . '/../',
         'aliases' => array(),
-        'dev' => false,
+        'dev' => true,
     ),
     'versions' => array(
         '__root__' => array(
-            'pretty_version' => 'dev-master',
-            'version' => 'dev-master',
-            'reference' => '37708311277ea8a294ac6ee74bfe8f055446016b',
+            'pretty_version' => '6.1.x-dev',
+            'version' => '6.1.9999999.9999999-dev',
+            'reference' => 'fe4913df9ac21beb9718c8dc312246df476fc7ff',
             'type' => 'project',
             'install_path' => __DIR__ . '/../',
             'aliases' => array(),
index 5b7230d3e7a26f52c02d50be58f23b188ef58de0..64f0c405b467bee140d71a6bbdcda1b23ef6a4f1 100644 (file)
@@ -22,7 +22,7 @@ class ClaimCheckerManager
     /**
      * @param ClaimChecker[] $checkers
      */
-    public function __construct(array $checkers)
+    public function __construct(iterable $checkers)
     {
         foreach ($checkers as $checker) {
             $this->add($checker);
index 124bfe920e0c8f9e566979212f72b7d8088b0a77..1b05be6e869ede2360a6f4da61d8f0c76c8467c4 100644 (file)
@@ -28,7 +28,7 @@ class HeaderCheckerManager
      * @param HeaderChecker[] $checkers
      * @param TokenTypeSupport[] $tokenTypes
      */
-    public function __construct(array $checkers, array $tokenTypes)
+    public function __construct(iterable $checkers, iterable $tokenTypes)
     {
         foreach ($checkers as $checker) {
             $this->add($checker);
index 86dd6cf91b07fd68ff41ef092093f48c96e8b8ee..ec1e1b59df5e6a5b32f09cb13c0e0b01d31af846 100644 (file)
@@ -5,6 +5,7 @@ declare(strict_types=1);
 namespace Jose\Component\Console;
 
 use Jose\Component\KeyManagement\JWKFactory;
+use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
index 81bd93fb96e038ada8312f8d4c54f12902999b2e..fd721b723104338e129f200e8ebb8dfc178516dc 100644 (file)
@@ -7,6 +7,7 @@ namespace Jose\Component\Console;
 use InvalidArgumentException;
 use Jose\Component\Core\JWK;
 use Jose\Component\Core\Util\JsonConverter;
+use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
index 2592c5ba20715f14993153486d0aefdf4d491012..5c7ae16709185563c4cb1c1495e9a5e53664c259 100644 (file)
@@ -6,6 +6,7 @@ namespace Jose\Component\Console;
 
 use InvalidArgumentException;
 use Jose\Component\KeyManagement\X5UFactory;
+use Symfony\Component\Console\Attribute\AsCommand;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
index 147921b5e77fcc5f0f6aaa58d59f84d9e88c27d7..c528c9b4630a15b36c6da3bcf00d60fc301824e5 100644 (file)
@@ -17,7 +17,7 @@ class AlgorithmManager
     /**
      * @param Algorithm[] $algorithms
      */
-    public function __construct(array $algorithms)
+    public function __construct(iterable $algorithms)
     {
         foreach ($algorithms as $algorithm) {
             $this->add($algorithm);
index 3854e668fcfcc11664689839a02bc6cd38c53b3b..4303e512c123cda34c1077e8f1c74feb981d95df 100644 (file)
@@ -17,7 +17,7 @@ class AlgorithmManagerFactory
     /**
      * @param Algorithm[] $algorithms
      */
-    public function __construct(array $algorithms = [])
+    public function __construct(iterable $algorithms = [])
     {
         foreach ($algorithms as $algorithm) {
             $this->add($algorithm->name(), $algorithm);
index 85d2bf38a2cc20e0fee61bb00920c2c19baa6b78..16b316b47a6bc7d6865ac89de7e21fafcd425a94 100644 (file)
@@ -4,6 +4,9 @@ declare(strict_types=1);
 
 namespace Jose\Component\Encryption\Compression;
 
+/**
+ * @deprecated This class is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
+ */
 interface CompressionMethod
 {
     /**
index 8a51e6a6bfb5f3af881b1587ed0fab9f1a72942d..3708e3a41c407982031ee8f5058c8138fa7c5fd9 100644 (file)
@@ -7,6 +7,9 @@ namespace Jose\Component\Encryption\Compression;
 use InvalidArgumentException;
 use function array_key_exists;
 
+/**
+ * @deprecated This class is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
+ */
 class CompressionMethodManager
 {
     /**
@@ -14,7 +17,10 @@ class CompressionMethodManager
      */
     private array $compressionMethods = [];
 
-    public function __construct(array $methods = [])
+    /**
+     * @param CompressionMethod[] $methods
+     */
+    public function __construct(iterable $methods = [])
     {
         foreach ($methods as $method) {
             $this->add($method);
index 806424ef9aabbe1109d290523c6733c6928fdf9f..592ae7bbbb793d92e9caf50f4c0df91e7927952b 100644 (file)
@@ -6,6 +6,9 @@ namespace Jose\Component\Encryption\Compression;
 
 use InvalidArgumentException;
 
+/**
+ * @deprecated This class is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
+ */
 class CompressionMethodManagerFactory
 {
     /**
index 3f87968510c2dd3fa38ca53423dca3eeea36ebe3..5c3deaa4e0a912a681d3dd6d81ace7ee10cba3de 100644 (file)
@@ -8,6 +8,9 @@ use InvalidArgumentException;
 use Throwable;
 use function is_string;
 
+/**
+ * @deprecated This class is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
+ */
 final class Deflate implements CompressionMethod
 {
     private int $compressionLevel = -1;
index 73827c9c5750c13e04ec4c26e97b220900d202d9..0d34218077bb456c89323bdfec84f50cb8fd3a0a 100644 (file)
@@ -51,9 +51,16 @@ class JWEBuilder
 
     public function __construct(
         AlgorithmManager $algorithmManager,
-        null|AlgorithmManager $contentEncryptionAlgorithmManager,
-        private readonly CompressionMethodManager $compressionManager
+        null|AlgorithmManager $contentEncryptionAlgorithmManager = null,
+        private readonly null|CompressionMethodManager $compressionManager = null
     ) {
+        if ($compressionManager !== null) {
+            trigger_deprecation(
+                'web-token/jwt-library',
+                '3.3.0',
+                'The parameter "$compressionManager" is deprecated and will be removed in 4.0.0. Compression is not recommended for JWE. Please set "null" instead.'
+            );
+        }
         if ($contentEncryptionAlgorithmManager !== null) {
             trigger_deprecation(
                 'web-token/jwt-library',
@@ -113,8 +120,9 @@ class JWEBuilder
 
     /**
      * Returns the compression method manager.
+     * @deprecated This method is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
      */
-    public function getCompressionMethodManager(): CompressionMethodManager
+    public function getCompressionMethodManager(): null|CompressionMethodManager
     {
         return $this->compressionManager;
     }
@@ -519,7 +527,7 @@ class JWEBuilder
 
     private function getCompressionMethod(array $completeHeader): ?CompressionMethod
     {
-        if (! array_key_exists('zip', $completeHeader)) {
+        if ($this->compressionManager === null || ! array_key_exists('zip', $completeHeader)) {
             return null;
         }
 
index 37f5d9b1066062dbed6d96b2a4fcfb901898837d..038050898ef286cbc20f16e8314de999184610e0 100644 (file)
@@ -11,31 +11,43 @@ class JWEBuilderFactory
 {
     public function __construct(
         private readonly AlgorithmManagerFactory $algorithmManagerFactory,
-        private readonly CompressionMethodManagerFactory $compressionMethodManagerFactory
+        private readonly null|CompressionMethodManagerFactory $compressionMethodManagerFactory = null
     ) {
+        if ($compressionMethodManagerFactory !== null) {
+            trigger_deprecation(
+                'web-token/jwt-library',
+                '3.3.0',
+                'The parameter "$compressionMethodManagerFactory" is deprecated and will be removed in 4.0.0. Compression is not recommended for JWE. Please set "null" instead.'
+            );
+        }
     }
 
     /**
      * Creates a JWE Builder object using the given key encryption algorithms, content encryption algorithms and
      * compression methods.
      *
-     * @param string[] $keyEncryptionAlgorithms
-     * @param string[] $contentEncryptionAlgorithm
-     * @param string[] $compressionMethods
+     * @param array<string> $encryptionAlgorithms
+     * @param null|array<string> $contentEncryptionAlgorithm
+     * @param null|string[] $compressionMethods
      */
     public function create(
-        array $keyEncryptionAlgorithms,
-        array $contentEncryptionAlgorithm,
-        array $compressionMethods
+        array $encryptionAlgorithms,
+        null|array $contentEncryptionAlgorithm = null,
+        null|array $compressionMethods = null
     ): JWEBuilder {
-        $keyEncryptionAlgorithmManager = $this->algorithmManagerFactory->create($keyEncryptionAlgorithms);
-        $contentEncryptionAlgorithmManager = $this->algorithmManagerFactory->create($contentEncryptionAlgorithm);
-        $compressionMethodManager = $this->compressionMethodManagerFactory->create($compressionMethods);
-
-        return new JWEBuilder(
-            $keyEncryptionAlgorithmManager,
-            $contentEncryptionAlgorithmManager,
-            $compressionMethodManager
+        if ($contentEncryptionAlgorithm !== null) {
+            trigger_deprecation(
+                'web-token/jwt-library',
+                '3.3.0',
+                'The parameter "$contentEncryptionAlgorithm" is deprecated and will be removed in 4.0.0. Please set "null" instead.'
+            );
+            $encryptionAlgorithms = array_merge($encryptionAlgorithms, $contentEncryptionAlgorithm);
+        }
+        $encryptionAlgorithmManager = $this->algorithmManagerFactory->create($encryptionAlgorithms);
+        $compressionMethodManager = $compressionMethods === null ? null : $this->compressionMethodManagerFactory?->create(
+            $compressionMethods
         );
+
+        return new JWEBuilder($encryptionAlgorithmManager, null, $compressionMethodManager);
     }
 }
index e688112efe6a5bb68855d7306ee550e6c377b255..fdbe8d91b190696a21cfd5c0f2f6b75831d1ebb2 100644 (file)
@@ -31,8 +31,15 @@ class JWEDecrypter
     public function __construct(
         AlgorithmManager $algorithmManager,
         null|AlgorithmManager $contentEncryptionAlgorithmManager,
-        private readonly CompressionMethodManager $compressionMethodManager
+        private readonly null|CompressionMethodManager $compressionMethodManager = null
     ) {
+        if ($compressionMethodManager !== null) {
+            trigger_deprecation(
+                'web-token/jwt-library',
+                '3.3.0',
+                'The parameter "$compressionMethodManager" is deprecated and will be removed in 4.0.0. Compression is not recommended for JWE. Please set "null" instead.'
+            );
+        }
         if ($contentEncryptionAlgorithmManager !== null) {
             trigger_deprecation(
                 'web-token/jwt-library',
@@ -75,8 +82,9 @@ class JWEDecrypter
 
     /**
      * Returns the compression method manager.
+     * @deprecated This method is deprecated and will be removed in v4.0. Compression is not recommended for JWE.
      */
-    public function getCompressionMethodManager(): CompressionMethodManager
+    public function getCompressionMethodManager(): null|CompressionMethodManager
     {
         return $this->compressionMethodManager;
     }
@@ -270,12 +278,13 @@ class JWEDecrypter
 
     private function decompressIfNeeded(string $payload, array $completeHeaders): string
     {
-        if (array_key_exists('zip', $completeHeaders)) {
-            $compression_method = $this->compressionMethodManager->get($completeHeaders['zip']);
-            $payload = $compression_method->uncompress($payload);
+        if ($this->compressionMethodManager === null || ! array_key_exists('zip', $completeHeaders)) {
+            return $payload;
         }
 
-        return $payload;
+        $compression_method = $this->compressionMethodManager->get($completeHeaders['zip']);
+
+        return $compression_method->uncompress($payload);
     }
 
     private function checkCompleteHeader(array $completeHeaders): void
index a61ef3bae836c217dff5af8cd1a70dedcc3751ad..0df9b7daed86a4d9f1f9679b5e2f49d02b667671 100644 (file)
@@ -11,27 +11,38 @@ class JWEDecrypterFactory
 {
     public function __construct(
         private readonly AlgorithmManagerFactory $algorithmManagerFactory,
-        private readonly CompressionMethodManagerFactory $compressionMethodManagerFactory
+        private readonly null|CompressionMethodManagerFactory $compressionMethodManagerFactory = null
     ) {
+        if ($compressionMethodManagerFactory !== null) {
+            trigger_deprecation(
+                'web-token/jwt-library',
+                '3.3.0',
+                'The parameter "$compressionMethodManagerFactory" is deprecated and will be removed in 4.0.0. Compression is not recommended for JWE. Please set "null" instead.'
+            );
+        }
     }
 
     /**
      * Creates a JWE Decrypter object using the given key encryption algorithms, content encryption algorithms and
      * compression methods.
      *
-     * @param string[] $keyEncryptionAlgorithms
-     * @param string[] $contentEncryptionAlgorithms
-     * @param string[] $compressionMethods
+     * @param string[] $encryptionAlgorithms
+     * @param null|string[] $contentEncryptionAlgorithms
+     * @param null|string[] $compressionMethods
      */
     public function create(
-        array $keyEncryptionAlgorithms,
-        array $contentEncryptionAlgorithms,
-        array $compressionMethods
+        array $encryptionAlgorithms,
+        null|array $contentEncryptionAlgorithms = null,
+        null|array $compressionMethods = null
     ): JWEDecrypter {
-        $algorithmManager = $this->algorithmManagerFactory->create(
-            array_merge($keyEncryptionAlgorithms, $contentEncryptionAlgorithms)
+        if ($contentEncryptionAlgorithms !== null) {
+            $encryptionAlgorithms = array_merge($encryptionAlgorithms, $contentEncryptionAlgorithms);
+        }
+
+        $algorithmManager = $this->algorithmManagerFactory->create($encryptionAlgorithms);
+        $compressionMethodManager = $compressionMethods === null ? null : $this->compressionMethodManagerFactory?->create(
+            $compressionMethods
         );
-        $compressionMethodManager = $this->compressionMethodManagerFactory->create($compressionMethods);
 
         return new JWEDecrypter($algorithmManager, null, $compressionMethodManager);
     }
index 818e2d486314df320a5144445b0524dab46f1577..98159109a3ab706e9d219fde1c38ad036d8a8693 100644 (file)
@@ -22,17 +22,16 @@ class JWELoaderFactory
      */
     public function create(
         array $serializers,
-        array $keyEncryptionAlgorithms,
-        array $contentEncryptionAlgorithms,
-        array $compressionMethods,
+        array $encryptionAlgorithms,
+        null|array $contentEncryptionAlgorithms = null,
+        null|array $compressionMethods = null,
         array $headerCheckers = []
     ): JWELoader {
+        if ($contentEncryptionAlgorithms !== null) {
+            $encryptionAlgorithms = array_merge($encryptionAlgorithms, $contentEncryptionAlgorithms);
+        }
         $serializerManager = $this->jweSerializerManagerFactory->create($serializers);
-        $jweDecrypter = $this->jweDecrypterFactory->create(
-            $keyEncryptionAlgorithms,
-            $contentEncryptionAlgorithms,
-            $compressionMethods
-        );
+        $jweDecrypter = $this->jweDecrypterFactory->create($encryptionAlgorithms, null, $compressionMethods);
         if ($this->headerCheckerManagerFactory !== null) {
             $headerCheckerManager = $this->headerCheckerManagerFactory->create($headerCheckers);
         } else {
index 14641bbaa672b73ddd48d1024473cbc000cf8d82..5082c798833e50e4fa388b8b7c775b4e7c0776d3 100644 (file)
@@ -17,7 +17,7 @@ class JWESerializerManager
     /**
      * @param JWESerializer[] $serializers
      */
-    public function __construct(array $serializers)
+    public function __construct(iterable $serializers)
     {
         foreach ($serializers as $serializer) {
             $this->add($serializer);
index 82442bb7d49c2bcfaf0772ccb3901ba43f56ab17..010c7ab88e9c07ccbe4ea75494beadf941e8851f 100644 (file)
@@ -4,14 +4,17 @@ declare(strict_types=1);
 
 namespace Jose\Component\KeyManagement\KeyConverter;
 
+use Brick\Math\BigInteger;
 use InvalidArgumentException;
 use OpenSSLCertificate;
 use ParagonIE\ConstantTime\Base64UrlSafe;
 use ParagonIE\Sodium\Core\Ed25519;
 use RuntimeException;
 use SpomkyLabs\Pki\CryptoEncoding\PEM;
+use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\AlgorithmIdentifier;
 use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PrivateKey;
 use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PublicKey;
+use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSASSAPSSPrivateKey;
 use Throwable;
 use function array_key_exists;
 use function assert;
@@ -229,29 +232,79 @@ final class KeyConverter
     private static function tryToLoadOtherKeyTypes(string $input): array
     {
         $pem = PEM::fromString($input);
+        return match ($pem->type()) {
+            PEM::TYPE_PUBLIC_KEY => self::loadPublicKey($pem),
+            PEM::TYPE_PRIVATE_KEY => self::loadPrivateKey($pem),
+            default => throw new InvalidArgumentException('Unsupported key type'),
+        };
+    }
+
+    /**
+     * @return array<string, mixed>
+     */
+    private static function loadPrivateKey(PEM $pem): array
+    {
         try {
             $key = PrivateKey::fromPEM($pem);
-            $curve = self::getCurve($key->algorithmIdentifier()->oid());
-            $values = [
-                'kty' => 'OKP',
-                'crv' => $curve,
-                'd' => Base64UrlSafe::encodeUnpadded($key->privateKeyData()),
-            ];
-            return self::populatePoints($key, $values);
-        } catch (Throwable) {
+            switch ($key->algorithmIdentifier()->oid()) {
+                case AlgorithmIdentifier::OID_RSASSA_PSS_ENCRYPTION:
+                    assert($key instanceof RSASSAPSSPrivateKey);
+                    return [
+                        'kty' => 'RSA',
+                        'n' => self::convertDecimalToBas64Url($key->modulus()),
+                        'e' => self::convertDecimalToBas64Url($key->publicExponent()),
+                        'd' => self::convertDecimalToBas64Url($key->privateExponent()),
+                        'dp' => self::convertDecimalToBas64Url($key->exponent1()),
+                        'dq' => self::convertDecimalToBas64Url($key->exponent2()),
+                        'p' => self::convertDecimalToBas64Url($key->prime1()),
+                        'q' => self::convertDecimalToBas64Url($key->prime2()),
+                        'qi' => self::convertDecimalToBas64Url($key->coefficient()),
+                    ];
+                case AlgorithmIdentifier::OID_ED25519:
+                case AlgorithmIdentifier::OID_ED448:
+                case AlgorithmIdentifier::OID_X25519:
+                case AlgorithmIdentifier::OID_X448:
+                    $curve = self::getCurve($key->algorithmIdentifier()->oid());
+                    $values = [
+                        'kty' => 'OKP',
+                        'crv' => $curve,
+                        'd' => Base64UrlSafe::encodeUnpadded($key->privateKeyData()),
+                    ];
+                    return self::populatePoints($key, $values);
+                default:
+                    throw new InvalidArgumentException('Unsupported key type');
+            }
+        } catch (Throwable $e) {
+            throw new InvalidArgumentException('Unable to load the key.', 0, $e);
         }
-        try {
-            $key = PublicKey::fromPEM($pem);
-            $curve = self::getCurve($key->algorithmIdentifier()->oid());
-            self::checkType($curve);
-            return [
-                'kty' => 'OKP',
-                'crv' => $curve,
-                'x' => Base64UrlSafe::encodeUnpadded((string) $key->subjectPublicKey()),
-            ];
-        } catch (Throwable) {
+    }
+
+    /**
+     * @return array<string, mixed>
+     */
+    private static function loadPublicKey(PEM $pem): array
+    {
+        $key = PublicKey::fromPEM($pem);
+        switch ($key->algorithmIdentifier()->oid()) {
+            case AlgorithmIdentifier::OID_ED25519:
+            case AlgorithmIdentifier::OID_ED448:
+            case AlgorithmIdentifier::OID_X25519:
+            case AlgorithmIdentifier::OID_X448:
+                $curve = self::getCurve($key->algorithmIdentifier()->oid());
+                self::checkType($curve);
+                return [
+                    'kty' => 'OKP',
+                    'crv' => $curve,
+                    'x' => Base64UrlSafe::encodeUnpadded((string) $key->subjectPublicKey()),
+                ];
+            default:
+                throw new InvalidArgumentException('Unsupported key type');
         }
-        throw new InvalidArgumentException('Unsupported key type');
+    }
+
+    private static function convertDecimalToBas64Url(string $decimal): string
+    {
+        return Base64UrlSafe::encodeUnpadded(BigInteger::fromBase($decimal, 10)->toBytes());
     }
 
     /**
index 81269e829aec99033b97dbc9d543cb270e2853b3..f3f9259ff2ee8fb3796d5205397bb1c4ebeba284 100644 (file)
@@ -24,25 +24,24 @@ class NestedTokenBuilderFactory
      * compression methods.
      *
      * @param array<string> $jwe_serializers
-     * @param array<string> $keyEncryptionAlgorithms
-     * @param array<string> $contentEncryptionAlgorithms
-     * @param array<string> $compressionMethods
+     * @param array<string> $encryptionAlgorithms
+     * @param null|array<string> $contentEncryptionAlgorithms
+     * @param null|array<string> $compressionMethods
      * @param array<string> $jws_serializers
      * @param array<string> $signatureAlgorithms
      */
     public function create(
         array $jwe_serializers,
-        array $keyEncryptionAlgorithms,
-        array $contentEncryptionAlgorithms,
-        array $compressionMethods,
+        array $encryptionAlgorithms,
+        null|array $contentEncryptionAlgorithms,
+        null|array $compressionMethods,
         array $jws_serializers,
         array $signatureAlgorithms
     ): NestedTokenBuilder {
-        $jweBuilder = $this->jweBuilderFactory->create(
-            $keyEncryptionAlgorithms,
-            $contentEncryptionAlgorithms,
-            $compressionMethods
-        );
+        if ($contentEncryptionAlgorithms !== null) {
+            $encryptionAlgorithms = array_merge($encryptionAlgorithms, $contentEncryptionAlgorithms);
+        }
+        $jweBuilder = $this->jweBuilderFactory->create($encryptionAlgorithms, null, $compressionMethods);
         $jweSerializerManager = $this->jweSerializerManagerFactory->create($jwe_serializers);
         $jwsBuilder = $this->jwsBuilderFactory->create($signatureAlgorithms);
         $jwsSerializerManager = $this->jwsSerializerManagerFactory->create($jws_serializers);
index eb2d7bd598ae68e1b857b41907d7b3adc5f543cb..632ff5e87e169f4afb192962b208051b60dda7be 100644 (file)
@@ -22,7 +22,7 @@ class NestedTokenLoaderFactory
      * @param array<string> $jweSerializers
      * @param array<string> $keyEncryptionAlgorithms
      * @param array<string> $contentEncryptionAlgorithms
-     * @param array<string> $compressionMethods
+     * @param null|array<string> $compressionMethods
      * @param array<string> $jweHeaderCheckers
      * @param array<string> $jwsSerializers
      * @param array<string> $signatureAlgorithms
@@ -31,8 +31,8 @@ class NestedTokenLoaderFactory
     public function create(
         array $jweSerializers,
         array $keyEncryptionAlgorithms,
-        array $contentEncryptionAlgorithms,
-        array $compressionMethods,
+        null|array $contentEncryptionAlgorithms,
+        null|array $compressionMethods,
         array $jweHeaderCheckers,
         array $jwsSerializers,
         array $signatureAlgorithms,
index fdf5b481c80fbe5e5af2190fe2a6adf823df6124..ebdfc70dfaf30ba412254eaa44b6328d40dc4071 100644 (file)
@@ -17,7 +17,7 @@ class JWSSerializerManager
     /**
      * @param JWSSerializer[] $serializers
      */
-    public function __construct(array $serializers)
+    public function __construct(iterable $serializers)
     {
         foreach ($serializers as $serializer) {
             $this->add($serializer);
index bf35f837be0cde862cdfc6b77c6f486bdfbee65f..72452717888b1fe00c62a3d1e9781c2ebb9d2986 100644 (file)
         "ext-json": "*",
         "ext-mbstring": "*",
         "brick/math": "^0.9|^0.10|^0.11|^0.12",
-        "paragonie/constant_time_encoding": "^2.6",
+        "paragonie/constant_time_encoding": "^3.0",
         "paragonie/sodium_compat": "^1.20",
         "psr/clock": "^1.0",
         "psr/http-factory": "^1.0",
         "psr/http-client": "^1.0",
-        "spomky-labs/pki-framework": "^1.0",
+        "spomky-labs/pki-framework": "^1.2.1",
         "symfony/console": "^5.4|^6.0|^7.0",
         "symfony/http-client": "^5.4|^6.0|^7.0",
         "symfony/polyfill-mbstring": "^1.12"