Files
apache
wp-content
mu-plugins
plugins
activitypub
audioigniter
authldap
companion-auto-update
easy-digital-downloads
gitium
gp-premium
jetpack-protect
menu-icons
simple-local-avatars
smtp-mailer
two-factor
wp-piwik
wp-webauthn
blocks
css
js
languages
vendor
beberlei
brick
composer
fgrosse
league
nyholm
php-http
psr
ramsey
spomky-labs
symfony
thecodingmachine
web-auth
web-token
jwt-core
jwt-key-mgmt
.github
Analyzer
AlgorithmAnalyzer.php
ES256KeyAnalyzer.php
ES384KeyAnalyzer.php
ES512KeyAnalyzer.php
HS256KeyAnalyzer.php
HS384KeyAnalyzer.php
HS512KeyAnalyzer.php
KeyAnalyzer.php
KeyAnalyzerManager.php
KeyIdentifierAnalyzer.php
KeysetAnalyzer.php
KeysetAnalyzerManager.php
Message.php
MessageBag.php
MixedKeyTypes.php
MixedPublicAndPrivateKeys.php
NoneAnalyzer.php
OctAnalyzer.php
RsaAnalyzer.php
UsageAnalyzer.php
ZxcvbnKeyAnalyzer.php
KeyConverter
JKUFactory.php
JWKFactory.php
LICENSE
README.md
UrlKeySetFactory.php
X5UFactory.php
composer.json
jwt-signature
jwt-signature-algorithm-ecdsa
jwt-signature-algorithm-eddsa
jwt-signature-algorithm-rsa
autoload.php
LICENSE
readme.txt
wp-webauthn.php
wwa-admin-content.php
wwa-ajax.php
wwa-compatibility.php
wwa-functions.php
wwa-menus.php
wwa-profile-content.php
wwa-shortcodes.php
wwa-version.php
index.php
themes
index.php
.dbsetup
.gitignore
htaccess
php.ini
laipower/wp-content/plugins/wp-webauthn/vendor/web-token/jwt-key-mgmt/Analyzer/ES256KeyAnalyzer.php

62 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
/*
* The MIT License (MIT)
*
* Copyright (c) 2014-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace Jose\Component\KeyManagement\Analyzer;
use Base64Url\Base64Url;
use Brick\Math\BigInteger;
use Jose\Component\Core\JWK;
use Jose\Component\Core\Util\Ecc\NistCurve;
use RuntimeException;
final class ES256KeyAnalyzer implements KeyAnalyzer
{
/**
* @throws RuntimeException if the component "web-token/jwt-util-ecc" is missing
*/
public function __construct()
{
if (!class_exists(NistCurve::class)) {
throw new RuntimeException('Please install web-token/jwt-util-ecc to use this key analyzer');
}
}
public function analyze(JWK $jwk, MessageBag $bag): void
{
if ('EC' !== $jwk->get('kty')) {
return;
}
if (!$jwk->has('crv')) {
$bag->add(Message::high('Invalid key. The components "crv" is missing.'));
return;
}
if ('P-256' !== $jwk->get('crv')) {
return;
}
$x = Base64Url::decode($jwk->get('x'));
$xLength = 8 * mb_strlen($x, '8bit');
$y = Base64Url::decode($jwk->get('y'));
$yLength = 8 * mb_strlen($y, '8bit');
if ($yLength !== $xLength || 256 !== $yLength) {
$bag->add(Message::high('Invalid key. The components "x" and "y" size shall be 256 bits.'));
}
$xBI = BigInteger::fromBase(bin2hex($x), 16);
$yBI = BigInteger::fromBase(bin2hex($y), 16);
$curve = NistCurve::curve256();
if (!$curve->contains($xBI, $yBI)) {
$bag->add(Message::high('Invalid key. The point is not on the curve.'));
}
}
}