- md5
- c9b7cbe0c6b0ce6ab479db8e9a6030b1
- sha1
- 41581729e4cc5f033289433649d1e8503d404d0a
- sha256
- 6bdd841983c52e2a636c6ee58b902636bfff584d44be54bd30df3efe2207b099
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
<?php
declare(strict_types=1);
namespace Jose\Component\KeyManagement\Analyzer;
use Brick\Math\BigInteger;
use Jose\Component\Core\JWK;
use Jose\Component\Core\Util\Base64UrlSafe;
use Jose\Component\Core\Util\Ecc\Curve;
use function is_string;
abstract class ESKeyAnalyzer implements KeyAnalyzer
{
public function analyze(JWK $jwk, MessageBag $bag): void
{
if ($jwk->get('kty') !== 'EC') {
return;
}
if (! $jwk->has('crv')) {
$bag->add(Message::high('Invalid key. The components "crv" is missing.'));
return;
}
if ($jwk->get('crv') !== $this->getCurveName()) {
return;
}
$x = $jwk->get('x');
if (! is_string($x)) {
$bag->add(Message::high('Invalid key. The components "x" shall be a string.'));
return;
}
$x = Base64UrlSafe::decodeNoPadding($x);
$xLength = 8 * mb_strlen($x, '8bit');
$y = $jwk->get('y');
if (! is_string($y)) {
$bag->add(Message::high('Invalid key. The components "y" shall be a string.'));
return;
}
$y = Base64UrlSafe::decodeNoPadding($y);
$yLength = 8 * mb_strlen($y, '8bit');
if ($yLength !== $xLength || $yLength !== $this->getKeySize()) {
$bag->add(
Message::high(sprintf(
'Invalid key. The components "x" and "y" size shall be %d bits.',
$this->getKeySize()
))
);
}
$xBI = BigInteger::fromBase(bin2hex($x), 16);
$yBI = BigInteger::fromBase(bin2hex($y), 16);
if (! $this->getCurve()->contains($xBI, $yBI)) {
$bag->add(Message::high('Invalid key. The point is not on the curve.'));
}
}
abstract protected function getAlgorithmName(): string;
abstract protected function getCurveName(): string;
abstract protected function getCurve(): Curve;
abstract protected function getKeySize(): int;
}
The same content is in 117 releases, Joomla 5.2.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.