| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_DEFENDER_VENDOR\Webauthn; |
| 4 |
|
| 5 |
use WP_DEFENDER_VENDOR\CBOR\ByteStringObject; |
| 6 |
use WP_DEFENDER_VENDOR\CBOR\MapItem; |
| 7 |
use WP_DEFENDER_VENDOR\CBOR\MapObject; |
| 8 |
use WP_DEFENDER_VENDOR\CBOR\NegativeIntegerObject; |
| 9 |
use WP_DEFENDER_VENDOR\CBOR\UnsignedIntegerObject; |
| 10 |
|
| 11 |
class U2FPublicKey |
| 12 |
{ |
| 13 |
public static function isU2FKey($publicKey): bool |
| 14 |
{ |
| 15 |
return $publicKey[0] === "\x04"; |
| 16 |
} |
| 17 |
|
| 18 |
public static function createCOSEKey($publicKey): string |
| 19 |
{ |
| 20 |
|
| 21 |
$mapObject = new MapObject([ |
| 22 |
1 => MapItem::create( |
| 23 |
new UnsignedIntegerObject(1, null), |
| 24 |
new UnsignedIntegerObject(2, null) |
| 25 |
), |
| 26 |
3 => MapItem::create( |
| 27 |
new UnsignedIntegerObject(3, null), |
| 28 |
new NegativeIntegerObject(6, null) |
| 29 |
), |
| 30 |
-1 => MapItem::create( |
| 31 |
new NegativeIntegerObject(0, null), |
| 32 |
new UnsignedIntegerObject(1, null) |
| 33 |
), |
| 34 |
-2 => MapItem::create( |
| 35 |
new NegativeIntegerObject(1, null), |
| 36 |
new ByteStringObject(substr($publicKey, 1, 32)) |
| 37 |
), |
| 38 |
-3 => MapItem::create( |
| 39 |
new NegativeIntegerObject(2, null), |
| 40 |
new ByteStringObject(substr($publicKey, 33)) |
| 41 |
), |
| 42 |
]); |
| 43 |
|
| 44 |
return $mapObject->__toString(); |
| 45 |
} |
| 46 |
} |
| 47 |
|