-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create COSE from u2f public key * add u2f key class * rpId hash assert
- Loading branch information
1 parent
8761be6
commit 5ef9b21
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Webauthn; | ||
|
||
use CBOR\ByteStringObject; | ||
use CBOR\MapItem; | ||
use CBOR\MapObject; | ||
use CBOR\NegativeIntegerObject; | ||
use CBOR\UnsignedIntegerObject; | ||
|
||
class U2FPublicKey | ||
{ | ||
public static function isU2FKey($publicKey): bool | ||
{ | ||
return $publicKey[0] === "\x04"; | ||
} | ||
|
||
public static function createCOSEKey($publicKey): string | ||
{ | ||
|
||
$mapObject = new MapObject([ | ||
1 => MapItem::create( | ||
new UnsignedIntegerObject(1, null), | ||
new UnsignedIntegerObject(2, null) | ||
), | ||
3 => MapItem::create( | ||
new UnsignedIntegerObject(3, null), | ||
new NegativeIntegerObject(6, null) | ||
), | ||
-1 => MapItem::create( | ||
new NegativeIntegerObject(0, null), | ||
new UnsignedIntegerObject(1, null) | ||
), | ||
-2 => MapItem::create( | ||
new NegativeIntegerObject(1, null), | ||
new ByteStringObject(substr($publicKey, 1, 32)) | ||
), | ||
-3 => MapItem::create( | ||
new NegativeIntegerObject(2, null), | ||
new ByteStringObject(substr($publicKey, 33)) | ||
), | ||
]); | ||
|
||
return $mapObject->__toString(); | ||
} | ||
} |