diff --git a/src/Attestations/FidoU2F.php b/src/Attestations/FidoU2F.php index 3d180fb..7a00093 100644 --- a/src/Attestations/FidoU2F.php +++ b/src/Attestations/FidoU2F.php @@ -55,9 +55,9 @@ public function verify(AuthenticatorData $data, BinaryString $clientDataHash): V // 8.6.v.3 $rpIdHash = $data->getRpIdHash(); - $attestedCredential = $data->getAttestedCredential(); - $credentialId = $attestedCredential->getId(); - $credentialPublicKey = $attestedCredential->getPublicKey(); + $attestedCredentialData = $data->getAttestedCredentialData(); + $credentialId = $attestedCredentialData->credentialId; + $credentialPublicKey = $attestedCredentialData->coseKey->getPublicKey(); assert($credentialPublicKey instanceof EllipticCurve); // 8.6.v.4 diff --git a/src/AttestedCredentialData.php b/src/AttestedCredentialData.php new file mode 100644 index 0000000..40b1836 --- /dev/null +++ b/src/AttestedCredentialData.php @@ -0,0 +1,18 @@ +getRemaining(); - $authData->ACD = [ - 'aaguid' => new BinaryString($aaguid), - 'credentialId' => new BinaryString($credentialId), - 'credentialPublicKey' => new BinaryString($rawCredentialPublicKey), - ]; + $authData->ACD = new AttestedCredentialData( + aaguid: new BinaryString($aaguid), + credentialId: new BinaryString($credentialId), + coseKey: new COSEKey(new BinaryString($rawCredentialPublicKey)), + ); } if ($ED) { // @codeCoverageIgnoreStart @@ -95,7 +86,7 @@ public static function parse(BinaryString $bytes): AuthenticatorData return $authData; } - public function getAttestedCredential(): CredentialInterface + public function getAttestedCredentialData(): AttestedCredentialData { if ($this->ACD === null) { throw new OutOfRangeException( @@ -110,11 +101,7 @@ public function getAttestedCredential(): CredentialInterface ); } - return new Credential( - $this->ACD['credentialId'], - new COSEKey($this->ACD['credentialPublicKey']), - $this->signCount, - ); + return $this->ACD; } public function getRpIdHash(): BinaryString diff --git a/src/CreateResponse.php b/src/CreateResponse.php index 800e544..a5ffa9b 100644 --- a/src/CreateResponse.php +++ b/src/CreateResponse.php @@ -153,12 +153,17 @@ public function verify( // 7.1.27 // associate credential with new user // done in client code - $credential = $authData->getAttestedCredential(); + $data = $authData->getAttestedCredentialData(); + $credential = new Credential( + id: $this->id, + signCount: $authData->getSignCount(), + coseKey: $data->coseKey, + ); + // This is not part of the official procedure, but serves as a general - // sanity-check around data handling. It also silences an unused - // variable warning in PHPStan :) - assert($credential->getId()->equals($this->id)); + // sanity-check around data handling. + assert($this->id->equals($data->credentialId)); return $credential; diff --git a/tests/Attestations/AttestationObjectTest.php b/tests/Attestations/AttestationObjectTest.php index 0aa37e1..98b43dc 100644 --- a/tests/Attestations/AttestationObjectTest.php +++ b/tests/Attestations/AttestationObjectTest.php @@ -140,7 +140,7 @@ public function testParsingCBOR(): void ); self::assertSame(0, $ad->getSignCount(), 'sign count'); - $credential = $ad->getAttestedCredential(); + $credential = $ad->getAttestedCredentialData(); // TODO: check keypair? } diff --git a/tests/AuthenticatorDataTest.php b/tests/AuthenticatorDataTest.php index 152a3f9..8adba9a 100644 --- a/tests/AuthenticatorDataTest.php +++ b/tests/AuthenticatorDataTest.php @@ -29,7 +29,7 @@ public function testParseAssertion(): void self::assertTrue($ad->isUserVerified(), 'Flags bit 2 is set, UV=true'); self::assertSame(0, $ad->getSignCount(), 'Sign count should be zero'); try { - $_ = $ad->getAttestedCredential(); + $_ = $ad->getAttestedCredentialData(); self::fail('AuthData does not include an attested credential'); } catch (\Throwable) { } @@ -70,7 +70,7 @@ public function testParseAttestation(): void ); self::assertTrue($ad->isUserPresent(), 'Flags bit 0 is set, UP=true'); self::assertTrue($ad->isUserVerified(), 'Flags bit 2 is set, UV=true'); - $_ = $ad->getAttestedCredential(); // Checking that this dones't throw. + $_ = $ad->getAttestedCredentialData(); // Checking that this doesn't throw. } public function testParseAssertionWithNoFlags(): void @@ -93,7 +93,7 @@ public function testParseAssertionWithNoFlags(): void self::assertFalse($ad->isUserVerified(), 'Flags bit 2 is not set, UV=false'); self::assertSame(258, $ad->getSignCount(), 'Sign count wrong'); try { - $_ = $ad->getAttestedCredential(); + $_ = $ad->getAttestedCredentialData(); self::fail('AuthData does not include an attested credential'); } catch (\Throwable) { }