Skip to content

Commit 99f3361

Browse files
committed
Force PSS padding to be sent to openssl_verify when algorithm is PSXXX
WE2-1028 Signed-off-by: Sven Mitt <[email protected]>
1 parent c9ddc19 commit 99f3361

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/validator/AuthTokenSignatureValidator.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
namespace web_eid\web_eid_authtoken_validation_php\validator;
2828

2929
use GuzzleHttp\Psr7\Uri;
30+
use phpseclib3\Crypt\RSA;
3031
use web_eid\web_eid_authtoken_validation_php\exceptions\AuthTokenParseException;
3132
use web_eid\web_eid_authtoken_validation_php\exceptions\ChallengeNullOrEmptyException;
3233
use InvalidArgumentException;
@@ -36,6 +37,10 @@
3637
class AuthTokenSignatureValidator
3738
{
3839

40+
private const ECDSA_ALGORITHMS = ['ES256', 'ES384', 'ES512'];
41+
42+
private const RSASSA_PSS_ALGORITHMS = ['PS256', 'PS384', 'PS512'];
43+
3944
/** Supported subset of JSON Web Signature algorithms as defined in RFC 7518, sections 3.3, 3.4, 3.5.
4045
* See https://github.com/web-eid/libelectronic-id/blob/main/include/electronic-id/enums.hpp#L176.
4146
*/
@@ -72,10 +77,17 @@ public function validate(string $algorithm, string $signature, $publicKey, strin
7277
$decodedSignature = base64_decode($signature);
7378

7479
// Note that in case of ECDSA, some eID cards output raw R||S, so we need to trascode it to DER
75-
if (in_array($algorithm, ["ES256", "ES384", "ES512"]) && !AsnUtil::isSignatureInAsn1Format($decodedSignature)) {
80+
if (in_array($algorithm, self::ECDSA_ALGORITHMS) && !AsnUtil::isSignatureInAsn1Format($decodedSignature)) {
7681
$decodedSignature = AsnUtil::transcodeSignatureToDER($decodedSignature);
7782
}
7883

84+
if (in_array($algorithm, self::RSASSA_PSS_ALGORITHMS)) {
85+
$publicKey = openssl_get_publickey($publicKey->withPadding(RSA::SIGNATURE_PSS)->toString('PSS'));
86+
if (!$publicKey) {
87+
throw new AuthTokenParseException();
88+
}
89+
}
90+
7991
$hashAlgorithm = $this->hashAlgorithmForName($algorithm);
8092

8193
$originHash = openssl_digest($this->siteOrigin->jsonSerialize(), $hashAlgorithm, true);

0 commit comments

Comments
 (0)