Upgrade composer packages
authorCyperghost <olaf_schmitz_1@t-online.de>
Tue, 25 Jun 2024 11:43:48 +0000 (13:43 +0200)
committerCyperghost <olaf_schmitz_1@t-online.de>
Tue, 25 Jun 2024 11:43:48 +0000 (13:43 +0200)
  `web-token/jwt-library` to `3.3.50`
  `spomky-labs/pki-framework` to `1.2.1`

wcfsetup/install/files/lib/system/api/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifier.php
wcfsetup/install/files/lib/system/api/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAPSSSSAEncryptionAlgorithmIdentifier.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/api/spomky-labs/pki-framework/src/CryptoTypes/Asymmetric/OneAsymmetricKey.php
wcfsetup/install/files/lib/system/api/spomky-labs/pki-framework/src/CryptoTypes/Asymmetric/RSA/RSASSAPSSPrivateKey.php [new file with mode: 0644]

index 71226d439586f3c9e614b9c1905b5ee1aa369045..c78e174c64e3d21364b16b05f7abb6c5036efad1 100644 (file)
@@ -29,6 +29,8 @@ abstract class AlgorithmIdentifier implements AlgorithmIdentifierType
 
     final public const OID_SHA1_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.5';
 
+    final public const OID_RSASSA_PSS_ENCRYPTION = '1.2.840.113549.1.1.10';
+
     final public const OID_SHA256_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.11';
 
     final public const OID_SHA384_WITH_RSA_ENCRYPTION = '1.2.840.113549.1.1.12';
diff --git a/wcfsetup/install/files/lib/system/api/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAPSSSSAEncryptionAlgorithmIdentifier.php b/wcfsetup/install/files/lib/system/api/spomky-labs/pki-framework/src/CryptoTypes/AlgorithmIdentifier/Asymmetric/RSAPSSSSAEncryptionAlgorithmIdentifier.php
new file mode 100644 (file)
index 0000000..34aebd0
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+declare(strict_types=1);
+
+namespace SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Asymmetric;
+
+use SpomkyLabs\Pki\ASN1\Element;
+use SpomkyLabs\Pki\ASN1\Type\Primitive\NullType;
+use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
+use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Feature\AsymmetricCryptoAlgorithmIdentifier;
+use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\SpecificAlgorithmIdentifier;
+use UnexpectedValueException;
+
+/*
+From RFC 3447:
+
+    When rsaEncryption is used in an AlgorithmIdentifier the
+    parameters MUST be present and MUST be NULL.
+ */
+
+/**
+ * Algorithm identifier for RSA encryption.
+ *
+ * @see http://www.oid-info.com/get/1.2.840.113549.1.1.10
+ * @see https://datatracker.ietf.org/doc/html/rfc8017#section-8.1
+ */
+final class RSAPSSSSAEncryptionAlgorithmIdentifier extends SpecificAlgorithmIdentifier implements AsymmetricCryptoAlgorithmIdentifier
+{
+    private function __construct()
+    {
+        parent::__construct(self::OID_RSASSA_PSS_ENCRYPTION);
+    }
+
+    public static function create(): self
+    {
+        return new self();
+    }
+
+    public function name(): string
+    {
+        return 'rsassa-pss';
+    }
+
+    /**
+     * @return self
+     */
+    public static function fromASN1Params(?UnspecifiedType $params = null): SpecificAlgorithmIdentifier
+    {
+        if (! isset($params)) {
+            throw new UnexpectedValueException('No parameters.');
+        }
+        $params->asNull();
+        return self::create();
+    }
+
+    /**
+     * @return NullType
+     */
+    protected function paramsASN1(): ?Element
+    {
+        return NullType::create();
+    }
+}
index 0ead2180248d4348b56f7d2a65a379543662c2fd..f7f29bf0038362944d86dbd3e933bf75a3a1b76e 100644 (file)
@@ -24,6 +24,7 @@ use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RFC8410\Curve25519\X25519PrivateKey;
 use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RFC8410\Curve448\Ed448PrivateKey;
 use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RFC8410\Curve448\X448PrivateKey;
 use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSAPrivateKey;
+use SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA\RSASSAPSSPrivateKey;
 use UnexpectedValueException;
 use function in_array;
 
@@ -184,6 +185,9 @@ class OneAsymmetricKey
             // RSA
             case AlgorithmIdentifier::OID_RSA_ENCRYPTION:
                 return RSAPrivateKey::fromDER($this->privateKeyData);
+                // RSASSA-PSS
+            case AlgorithmIdentifier::OID_RSASSA_PSS_ENCRYPTION:
+                return RSASSAPSSPrivateKey::fromDER($this->privateKeyData);
                 // elliptic curve
             case AlgorithmIdentifier::OID_EC_PUBLIC_KEY:
                 $pk = ECPrivateKey::fromDER($this->privateKeyData);
@@ -225,8 +229,9 @@ class OneAsymmetricKey
                 return X448PrivateKey::fromOctetString(OctetString::fromDER($this->privateKeyData), $pubkey)
                     ->withVersion($this->version)
                     ->withAttributes($this->attributes);
+            default:
+                throw new RuntimeException('Private key ' . $algo->name() . ' not supported.');
         }
-        throw new RuntimeException('Private key ' . $algo->name() . ' not supported.');
     }
 
     /**
diff --git a/wcfsetup/install/files/lib/system/api/spomky-labs/pki-framework/src/CryptoTypes/Asymmetric/RSA/RSASSAPSSPrivateKey.php b/wcfsetup/install/files/lib/system/api/spomky-labs/pki-framework/src/CryptoTypes/Asymmetric/RSA/RSASSAPSSPrivateKey.php
new file mode 100644 (file)
index 0000000..89703e8
--- /dev/null
@@ -0,0 +1,226 @@
+<?php
+
+declare(strict_types=1);
+
+namespace SpomkyLabs\Pki\CryptoTypes\Asymmetric\RSA;
+
+use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
+use SpomkyLabs\Pki\ASN1\Type\Primitive\Integer;
+use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
+use SpomkyLabs\Pki\CryptoEncoding\PEM;
+use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Asymmetric\RSAPSSSSAEncryptionAlgorithmIdentifier;
+use SpomkyLabs\Pki\CryptoTypes\AlgorithmIdentifier\Feature\AlgorithmIdentifierType;
+use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PrivateKey;
+use SpomkyLabs\Pki\CryptoTypes\Asymmetric\PublicKey;
+use UnexpectedValueException;
+
+/**
+ * Implements PKCS #1 RSASSAPSSPrivateKey ASN.1 type.
+ *
+ * @see https://datatracker.ietf.org/doc/html/rfc8017#section-8.1
+ */
+final class RSASSAPSSPrivateKey extends PrivateKey
+{
+    /**
+     * @param string $modulus Modulus
+     * @param string $publicExponent Public exponent
+     * @param string $privateExponent Private exponent
+     * @param string $prime1 First prime factor
+     * @param string $prime2 Second prime factor
+     * @param string $exponent1 First factor exponent
+     * @param string $exponent2 Second factor exponent
+     * @param string $coefficient CRT coefficient of the second factor
+     */
+    private function __construct(
+        private readonly string $modulus,
+        private readonly string $publicExponent,
+        private readonly string $privateExponent,
+        private readonly string $prime1,
+        private readonly string $prime2,
+        private readonly string $exponent1,
+        private readonly string $exponent2,
+        private readonly string $coefficient
+    ) {
+    }
+
+    public static function create(
+        string $n,
+        string $e,
+        string $d,
+        string $p,
+        string $q,
+        string $dp,
+        string $dq,
+        string $qi
+    ): self {
+        return new self($n, $e, $d, $p, $q, $dp, $dq, $qi);
+    }
+
+    /**
+     * Initialize from ASN.1.
+     */
+    public static function fromASN1(Sequence $seq): self
+    {
+        $version = $seq->at(0)
+            ->asInteger()
+            ->intNumber();
+        if ($version !== 0) {
+            throw new UnexpectedValueException('Version must be 0.');
+        }
+        // helper function get integer from given index
+        $get_int = static fn ($idx) => $seq->at($idx)
+            ->asInteger()
+            ->number();
+        $n = $get_int(1);
+        $e = $get_int(2);
+        $d = $get_int(3);
+        $p = $get_int(4);
+        $q = $get_int(5);
+        $dp = $get_int(6);
+        $dq = $get_int(7);
+        $qi = $get_int(8);
+        return self::create($n, $e, $d, $p, $q, $dp, $dq, $qi);
+    }
+
+    /**
+     * Initialize from DER data.
+     */
+    public static function fromDER(string $data): self
+    {
+        return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence());
+    }
+
+    /**
+     * @see PrivateKey::fromPEM()
+     */
+    public static function fromPEM(PEM $pem): self
+    {
+        $pk = parent::fromPEM($pem);
+        if (! ($pk instanceof self)) {
+            throw new UnexpectedValueException('Not an RSA private key.');
+        }
+        return $pk;
+    }
+
+    /**
+     * Get modulus.
+     *
+     * @return string Base 10 integer
+     */
+    public function modulus(): string
+    {
+        return $this->modulus;
+    }
+
+    /**
+     * Get public exponent.
+     *
+     * @return string Base 10 integer
+     */
+    public function publicExponent(): string
+    {
+        return $this->publicExponent;
+    }
+
+    /**
+     * Get private exponent.
+     *
+     * @return string Base 10 integer
+     */
+    public function privateExponent(): string
+    {
+        return $this->privateExponent;
+    }
+
+    /**
+     * Get first prime factor.
+     *
+     * @return string Base 10 integer
+     */
+    public function prime1(): string
+    {
+        return $this->prime1;
+    }
+
+    /**
+     * Get second prime factor.
+     *
+     * @return string Base 10 integer
+     */
+    public function prime2(): string
+    {
+        return $this->prime2;
+    }
+
+    /**
+     * Get first factor exponent.
+     *
+     * @return string Base 10 integer
+     */
+    public function exponent1(): string
+    {
+        return $this->exponent1;
+    }
+
+    /**
+     * Get second factor exponent.
+     *
+     * @return string Base 10 integer
+     */
+    public function exponent2(): string
+    {
+        return $this->exponent2;
+    }
+
+    /**
+     * Get CRT coefficient of the second factor.
+     *
+     * @return string Base 10 integer
+     */
+    public function coefficient(): string
+    {
+        return $this->coefficient;
+    }
+
+    public function algorithmIdentifier(): AlgorithmIdentifierType
+    {
+        return RSAPSSSSAEncryptionAlgorithmIdentifier::create();
+    }
+
+    /**
+     * @return RSAPublicKey
+     */
+    public function publicKey(): PublicKey
+    {
+        return RSAPublicKey::create($this->modulus, $this->publicExponent);
+    }
+
+    /**
+     * Generate ASN.1 structure.
+     */
+    public function toASN1(): Sequence
+    {
+        return Sequence::create(
+            Integer::create(0),
+            Integer::create($this->modulus),
+            Integer::create($this->publicExponent),
+            Integer::create($this->privateExponent),
+            Integer::create($this->prime1),
+            Integer::create($this->prime2),
+            Integer::create($this->exponent1),
+            Integer::create($this->exponent2),
+            Integer::create($this->coefficient)
+        );
+    }
+
+    public function toDER(): string
+    {
+        return $this->toASN1()
+            ->toDER();
+    }
+
+    public function toPEM(): PEM
+    {
+        return PEM::create(PEM::TYPE_PRIVATE_KEY, $this->toDER());
+    }
+}