|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LM\AuthAbstractor\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use Firehed\U2F\Registration; |
|
8
|
|
|
use LM\AuthAbstractor\Implementation\U2fRegistration; |
|
9
|
|
|
use LM\AuthAbstractor\Model\IU2fRegistration; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* This class provides methods Firehed U2F registrations into implementations of |
|
13
|
|
|
* IU2fRegistration, and vice versa. |
|
14
|
|
|
* |
|
15
|
|
|
* @internal |
|
16
|
|
|
*/ |
|
17
|
|
|
class U2fRegistrationFactory |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Converts a Firehed U2F Registration instance into an instance of |
|
21
|
|
|
* IU2fRegistration. |
|
22
|
|
|
* |
|
23
|
|
|
* @param Registration $registration A Firehed U2F registration. |
|
24
|
|
|
* @return IU2fRegistration |
|
25
|
|
|
*/ |
|
26
|
|
|
public function fromFirehed(Registration $registration): IU2fRegistration |
|
27
|
|
|
{ |
|
28
|
|
|
return new U2fRegistration( |
|
29
|
|
|
base64_encode($registration->getAttestationCertificateBinary()), |
|
30
|
|
|
$registration->getCounter(), |
|
31
|
|
|
base64_encode($registration->getKeyHandleBinary()), |
|
32
|
|
|
base64_encode($registration->getPublicKey()) |
|
33
|
|
|
) |
|
34
|
|
|
; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Converts a IU2fRegistration instance into a Firehed Registration |
|
39
|
|
|
* instance. |
|
40
|
|
|
* |
|
41
|
|
|
* @param IU2fRegistration $registration |
|
42
|
|
|
* @return Registration |
|
43
|
|
|
*/ |
|
44
|
|
|
public function toFirehed(IU2fRegistration $registration): Registration |
|
45
|
|
|
{ |
|
46
|
|
|
return (new Registration()) |
|
47
|
|
|
->setAttestationCertificate(base64_decode($registration->getAttestationCertificate(), true)) |
|
48
|
|
|
->setCounter($registration->getCounter()) |
|
49
|
|
|
->setKeyHandle(base64_decode($registration->getKeyHandle(), true)) |
|
50
|
|
|
->setPublicKey(base64_decode($registration->getPublicKey(), true)) |
|
51
|
|
|
; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|