1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWizard\WebAuthn\Extension\AppId; |
4
|
|
|
|
5
|
|
|
use MadWizard\WebAuthn\Exception\ExtensionException; |
6
|
|
|
use MadWizard\WebAuthn\Exception\ParseException; |
7
|
|
|
use MadWizard\WebAuthn\Extension\AbstractExtension; |
8
|
|
|
use MadWizard\WebAuthn\Extension\ExtensionInputInterface; |
9
|
|
|
use MadWizard\WebAuthn\Extension\ExtensionOutputInterface; |
10
|
|
|
use MadWizard\WebAuthn\Extension\ExtensionProcessingContext; |
11
|
|
|
use MadWizard\WebAuthn\Extension\ExtensionResponseInterface; |
12
|
|
|
|
13
|
|
|
class AppIdExtension extends AbstractExtension |
14
|
|
|
{ |
15
|
|
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
parent::__construct('appid', [self::OPERATION_AUTHENTICATION]); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function parseResponse(ExtensionResponseInterface $extensionResponse): ExtensionOutputInterface |
21
|
|
|
{ |
22
|
|
|
$extensionOutput = $extensionResponse->getClientExtensionOutput(); |
23
|
|
|
if (!is_bool($extensionOutput)) { |
24
|
|
|
throw new ParseException('Expecting boolean value in appid extension output.'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return new AppIdExtensionOutput($extensionOutput); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function processExtension(ExtensionInputInterface $input, ExtensionOutputInterface $output, ExtensionProcessingContext $context): void |
31
|
|
|
{ |
32
|
|
|
if (!$input instanceof AppIdExtensionInput) { |
33
|
|
|
throw new ExtensionException('Expecting appid extension input to be AppIdExtensionInput.'); |
34
|
|
|
} |
35
|
|
|
if (!$output instanceof AppIdExtensionOutput) { |
36
|
|
|
throw new ExtensionException('Expecting appid extension input to be AppIdExtensionInput.'); |
37
|
|
|
} |
38
|
|
|
// SPEC: Client extension output: If true, the AppID was used and thus, when verifying an assertion, |
39
|
|
|
// the Relying Party MUST expect the rpIdHash to be the hash of the AppID, not the RP ID. |
40
|
|
|
if ($output->getAppIdUsed()) { |
41
|
|
|
$context->setOverruledRpId($input->getAppId()); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|