Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Finish deprecation of all U2F-specific classes #36

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make registration PK configurable
  • Loading branch information
Firehed committed Oct 27, 2021
commit 0d7c57e292c0dee160b6456714ab9acd5b6331e3
17 changes: 9 additions & 8 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,14 @@ public function testValidateLoginThrowsIfRequestIsSignedWithWrongKey(): void
'9OxeRv2zYiz7SrVa8eb4LbGR9IDUE7gJySiiuQYWt1w='
);
assert($pk !== false);
$registration = (new Registration())
->setKeyHandle(fromBase64Web(self::ENCODED_KEY_HANDLE))
->setPublicKey(new ECPublicKey($pk))
->setCounter(2)
;
$request = $this->getDefaultSignRequest();
$registration = $this->getDefaultRegistration([
'publicKey' => new ECPublicKey($pk),
]);
$challenge = $this->getDefaultLoginChallenge();
$response = $this->getDefaultLoginResponse();
$this->expectException(SecurityException::class);
$this->expectExceptionCode(SecurityException::SIGNATURE_INVALID);
$this->server->validateLogin($request, $response, [$registration]);
$this->server->validateLogin($challenge, $response, [$registration]);
}

// -( Alternate formats (see #14) )----------------------------------------
Expand Down Expand Up @@ -762,26 +760,29 @@ private function getDefaultLoginChallenge(): ChallengeProviderInterface
* @param array{
* counter?: int,
* keyHandle?: string,
* publicKey?: PublicKeyInterface,
* } $overrides
*/
private function getDefaultRegistration(array $overrides = []): RegistrationInterface
{
$defaults = [
'counter' => 2,
'keyHandle' => fromBase64Web(self::ENCODED_KEY_HANDLE),
'publicKey' => $this->getDefaultPublicKey(),
];
/**
* @var array{
* counter: int,
* keyHandle: string,
* publicKey: PublicKeyInterface,
* } (phpstan/phpstan#5846)
*/
$data = array_merge($defaults, $overrides);
// From database attached to the authenticating user
return (new Registration())
->setKeyHandle($data['keyHandle'])
->setAttestationCertificate($this->getDefaultAttestationCertificate())
->setPublicKey($this->getDefaultPublicKey())
->setPublicKey($data['publicKey'])
->setCounter($data['counter'])
;
}
Expand Down