updated plugin WP-WebAuthn
version 1.3.1
This commit is contained in:
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2021 Spomky-Labs
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Webauthn\TrustPath;
|
||||
|
||||
use Assert\Assertion;
|
||||
|
||||
final class CertificateTrustPath implements TrustPath
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $certificates;
|
||||
|
||||
/**
|
||||
* @param string[] $certificates
|
||||
*/
|
||||
public function __construct(array $certificates)
|
||||
{
|
||||
$this->certificates = $certificates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCertificates(): array
|
||||
{
|
||||
return $this->certificates;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function createFromArray(array $data): TrustPath
|
||||
{
|
||||
Assertion::keyExists($data, 'x5c', 'The trust path type is invalid');
|
||||
|
||||
return new CertificateTrustPath($data['x5c']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::class,
|
||||
'x5c' => $this->certificates,
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2021 Spomky-Labs
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Webauthn\TrustPath;
|
||||
|
||||
use Assert\Assertion;
|
||||
|
||||
final class EcdaaKeyIdTrustPath implements TrustPath
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $ecdaaKeyId;
|
||||
|
||||
public function __construct(string $ecdaaKeyId)
|
||||
{
|
||||
$this->ecdaaKeyId = $ecdaaKeyId;
|
||||
}
|
||||
|
||||
public function getEcdaaKeyId(): string
|
||||
{
|
||||
return $this->ecdaaKeyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::class,
|
||||
'ecdaaKeyId' => $this->ecdaaKeyId,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function createFromArray(array $data): TrustPath
|
||||
{
|
||||
Assertion::keyExists($data, 'ecdaaKeyId', 'The trust path type is invalid');
|
||||
|
||||
return new EcdaaKeyIdTrustPath($data['ecdaaKeyId']);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2021 Spomky-Labs
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Webauthn\TrustPath;
|
||||
|
||||
final class EmptyTrustPath implements TrustPath
|
||||
{
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function createFromArray(array $data): TrustPath
|
||||
{
|
||||
return new EmptyTrustPath();
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2021 Spomky-Labs
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Webauthn\TrustPath;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
interface TrustPath extends JsonSerializable
|
||||
{
|
||||
/**
|
||||
* @param mixed[] $data
|
||||
*/
|
||||
public static function createFromArray(array $data): self;
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2021 Spomky-Labs
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Webauthn\TrustPath;
|
||||
|
||||
use function array_key_exists;
|
||||
use Assert\Assertion;
|
||||
use function in_array;
|
||||
use InvalidArgumentException;
|
||||
use function Safe\class_implements;
|
||||
use function Safe\sprintf;
|
||||
|
||||
abstract class TrustPathLoader
|
||||
{
|
||||
/**
|
||||
* @param mixed[] $data
|
||||
*/
|
||||
public static function loadTrustPath(array $data): TrustPath
|
||||
{
|
||||
Assertion::keyExists($data, 'type', 'The trust path type is missing');
|
||||
$type = $data['type'];
|
||||
$oldTypes = self::oldTrustPathTypes();
|
||||
switch (true) {
|
||||
case array_key_exists($type, $oldTypes):
|
||||
return $oldTypes[$type]::createFromArray($data);
|
||||
case class_exists($type):
|
||||
$implements = class_implements($type);
|
||||
if (in_array(TrustPath::class, $implements, true)) {
|
||||
return $type::createFromArray($data);
|
||||
}
|
||||
// no break
|
||||
default:
|
||||
throw new InvalidArgumentException(sprintf('The trust path type "%s" is not supported', $data['type']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
private static function oldTrustPathTypes(): array
|
||||
{
|
||||
return [
|
||||
'empty' => EmptyTrustPath::class,
|
||||
'ecdaa_key_id' => EcdaaKeyIdTrustPath::class,
|
||||
'x5c' => CertificateTrustPath::class,
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user