1 | <?php |
||
17 | class YubikeyOtpCredentialProvider extends CredentialProviderBase |
||
18 | { |
||
19 | /** @var HttpHelper */ |
||
20 | private $httpHelper; |
||
21 | /** |
||
22 | * @var SiteConfiguration |
||
23 | */ |
||
24 | private $configuration; |
||
|
|||
25 | |||
26 | public function __construct(PdoDatabase $database, SiteConfiguration $configuration, HttpHelper $httpHelper) |
||
32 | |||
33 | public function authenticate(User $user, $data) |
||
52 | |||
53 | public function setCredential(User $user, $factor, $data) |
||
75 | |||
76 | /** |
||
77 | * Get the Yubikey ID. |
||
78 | * |
||
79 | * This looks like it's just dumping the "password" that's stored in the database, but it's actually fine. |
||
80 | * |
||
81 | * We only store the "serial number" of the Yubikey - if we get a validated (by webservice) token prefixed with the |
||
82 | * serial number, that's a successful OTP authentication. Thus, retrieving the stored data is just retrieving the |
||
83 | * yubikey's serial number (in modhex format), since the actual security credentials are stored on the device. |
||
84 | * |
||
85 | * Note that the serial number is actually the credential serial number - it's possible to regenerate the keys on |
||
86 | * the device, and that will change the serial number too. |
||
87 | * |
||
88 | * More information about the structure of OTPs can be found here: |
||
89 | * https://developers.yubico.com/OTP/OTPs_Explained.html |
||
90 | * |
||
91 | * @param int $userId |
||
92 | * |
||
93 | * @return null|string |
||
94 | */ |
||
95 | public function getYubikeyData($userId) |
||
105 | |||
106 | /** |
||
107 | * @param $result |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | private function parseYubicoApiResult($result) |
||
125 | |||
126 | private function getYubikeyId($data) |
||
130 | |||
131 | private function verifyHmac($apiResponse, $apiKey) |
||
147 | |||
148 | /** |
||
149 | * @param $data |
||
150 | * |
||
151 | * @return bool |
||
152 | */ |
||
153 | private function verifyToken($data) |
||
169 | } |
||
170 |