Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional registration support #85

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function verify(
RelyingPartyInterface $rp,
Enums\UserVerificationRequirement $uv = Enums\UserVerificationRequirement::Preferred,
bool $rejectUncertainTrustPaths = true,
Enums\CredentialMediationRequirement $mediation = Enums\CredentialMediationRequirement::Optional,
): CredentialInterface {
// 7.1.1 - 7.1.3 are client code
// 7.1.4 is temporarily skpped
Expand Down Expand Up @@ -93,7 +94,7 @@ public function verify(
}

// 7.1.14
if (!$authData->isUserPresent()) {
if (!$authData->isUserPresent() && $mediation !== Enums\CredentialMediationRequirement::Conditional) {
$this->fail('7.1.14', 'authData.isUserPresent');
}

Expand Down
18 changes: 18 additions & 0 deletions src/Enums/CredentialMediationRequirement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Firehed\WebAuthn\Enums;

/**
* Credential Management (Level 1)
* §2.3.2
* @link https://w3c.github.io/webappsec-credential-management/#dom-credentialmediationrequirement-conditional
*/
enum CredentialMediationRequirement: string
{
case Silent = 'silent';
case Optional = 'optional';
case Conditional = 'conditional';
case Required = 'required';
}
58 changes: 56 additions & 2 deletions tests/CreateResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,62 @@
// 7.1.14
public function testUserNotPresentIsError(): void
{
// override authData
self::markTestIncomplete();
$ad = self::createMock(AuthenticatorData::class);
$ad->method('isUserPresent')->willReturn(false);
$ad->method('getRpIdHash')->willReturn(new BinaryString(hash('sha256', 'localhost', true)));

$ao = self::createMock(Attestations\AttestationObjectInterface::class);
$ao->method('getAuthenticatorData')->willReturn($ad);

$response = new CreateResponse(
type: Enums\PublicKeyCredentialType::PublicKey,
id: $this->id,
ao: $ao,
clientDataJson: $this->clientDataJson,
transports: [],
);

$this->expectRegistrationError('7.1.14');
$response->verify(
challengeLoader: $this->cm,
rp: $this->rp,
);
}

public function testUserNotPresentIsAllowedDuringConditionalRegistration(): void
{
$ad = self::createMock(AuthenticatorData::class);
$ad->method('isUserPresent')->willReturn(false);
$ad->method('getRpIdHash')->willReturn(new BinaryString(hash('sha256', 'localhost', true)));
$acd = new AttestedCredentialData(
aaguid: new BinaryString(''),
credentialId: $this->id,
coseKey: self::createMock(COSEKey::class),
);
$ad->method('getAttestedCredentialData')->willReturn($acd);

$ao = self::createMock(Attestations\AttestationObjectInterface::class);
$ao->method('getAuthenticatorData')->willReturn($ad);
$ao->method('verify')->willReturn(
new Attestations\VerificationResult(Attestations\AttestationType::None)
);

$response = new CreateResponse(
type: Enums\PublicKeyCredentialType::PublicKey,
id: $this->id,
ao: $ao,
clientDataJson: $this->clientDataJson,
transports: [],
);

$credential = $response->verify(
challengeLoader: $this->cm,
rp: $this->rp,
mediation: Enums\CredentialMediationRequirement::Conditional,
);

// This is mostly a smoke-test to inverse testUserNotPresentIsError
self::assertSame($this->id, $credential->getId());
}

// 7.1.15
Expand All @@ -279,7 +333,7 @@
// 7.1.16
public function testPubKeyAlgorithmNotMatchingOptionsIsError(): void
{
self::markTestSkipped('Only EC2/ED256 supported at this time');

Check warning on line 336 in tests/CreateResponseTest.php

View workflow job for this annotation

GitHub Actions / phpunit (high, 8.3)

Only EC2/ED256 supported at this time

Check warning on line 336 in tests/CreateResponseTest.php

View workflow job for this annotation

GitHub Actions / phpunit (high, 8.1)

Only EC2/ED256 supported at this time

Check warning on line 336 in tests/CreateResponseTest.php

View workflow job for this annotation

GitHub Actions / phpunit (high, 8.4-dev)

Only EC2/ED256 supported at this time

Check warning on line 336 in tests/CreateResponseTest.php

View workflow job for this annotation

GitHub Actions / phpunit (high, 8.2)

Only EC2/ED256 supported at this time

Check warning on line 336 in tests/CreateResponseTest.php

View workflow job for this annotation

GitHub Actions / phpunit (low, 8.2)

Only EC2/ED256 supported at this time

Check warning on line 336 in tests/CreateResponseTest.php

View workflow job for this annotation

GitHub Actions / phpunit (low, 8.4-dev)

Only EC2/ED256 supported at this time

Check warning on line 336 in tests/CreateResponseTest.php

View workflow job for this annotation

GitHub Actions / phpunit (low, 8.1)

Only EC2/ED256 supported at this time

Check warning on line 336 in tests/CreateResponseTest.php

View workflow job for this annotation

GitHub Actions / phpunit (low, 8.3)

Only EC2/ED256 supported at this time
}

// 7.1.19
Expand Down
Loading