- md5
- cf615baf73504f9779d5f14d15c9068a
- sha1
- 9cbd4dac0d995e4b066e58a110486d554da10067
- sha256
- 1bab7a68c8a2398697f57ff75d1750e164361fc144dab3448f44e723b9e16a40
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\Ecc\Curve;
use ParagonIE\ConstantTime\Base64UrlSafe;
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 19 releases, Joomla 5.1.0-beta1 to 5.2.0-alpha3. See them all, or every version of this file.