Skip to content

Commit

Permalink
Move OID info to curve for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Firehed committed Mar 9, 2024
1 parent 85bdf1e commit e63da93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Attestations/FidoU2F.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Firehed\WebAuthn\AuthenticatorData;
use Firehed\WebAuthn\BinaryString;
use Firehed\WebAuthn\Certificate;
use Firehed\WebAuthn\COSE\Curve;
use Firehed\WebAuthn\PublicKey\EllipticCurve;

/**
Expand Down Expand Up @@ -46,10 +47,7 @@ public function verify(AuthenticatorData $data, BinaryString $clientDataHash): V
if ($info['type'] !== OPENSSL_KEYTYPE_EC) {
throw new \Exception('Certificate PubKey is not Elliptic Curve');
}
// OID for P-156 curve
// http://oid-info.com/get/1.2.840.10045.3.1.7
// See also EllipticCurve
if ($info['ec']['curve_oid'] !== '1.2.840.10045.3.1.7') {
if ($info['ec']['curve_oid'] !== Curve::P256->getOid()) {
throw new \Exception('Certificate PubKey is not Elliptic Curve');
}

Expand Down
8 changes: 8 additions & 0 deletions src/COSE/Curve.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ enum Curve: int
case ED25519 = 6; // OKP

case ED448 = 7; // OKP

public function getOid(): string
{
return match ($this) { // @phpstan-ignore-line default unhandled match is desired
self::P256 => '1.2.840.10045.3.1.7',
// TODO: add others as support increases
};
}
}

0 comments on commit e63da93

Please sign in to comment.