|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the 2amigos/2fa-library project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2amigOS! <http://2amigos.us/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Da\TwoFA\Service; |
|
13
|
|
|
|
|
14
|
|
|
use Da\TwoFA\Contracts\StringGeneratorServiceInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class SecretKeyUriService |
|
18
|
|
|
* |
|
19
|
|
|
* @author Antonio Ramirez <[email protected]> |
|
20
|
|
|
* @package Da\TwoFA\Service |
|
21
|
|
|
* |
|
22
|
|
|
* @see https://github.com/google/google-authenticator/wiki/Key-Uri-Format |
|
23
|
|
|
*/ |
|
24
|
|
|
final class TOTPSecretKeyUriGeneratorService implements StringGeneratorServiceInterface |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string part of the compound label. Company (or site) issuing the TOTP. Will be used as the issuer too. |
|
28
|
|
|
* @see https://github.com/google/google-authenticator/wiki/Key-Uri-Format#issuer |
|
29
|
|
|
*/ |
|
30
|
|
|
private $company; |
|
31
|
|
|
/** |
|
32
|
|
|
* @var string part of the compound label. Holder could be a user's secret owner. |
|
33
|
|
|
*/ |
|
34
|
|
|
private $holder; |
|
35
|
|
|
/** |
|
36
|
|
|
* @var string an arbitrary key value encoded in Base32 according to RFC 3548 |
|
37
|
|
|
* @see http://tools.ietf.org/html/rfc3548 |
|
38
|
|
|
*/ |
|
39
|
|
|
private $secret; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* GoogleQrCodeUrlService constructor. |
|
43
|
|
|
* |
|
44
|
|
|
* @param $company |
|
45
|
|
|
* @param $holder |
|
46
|
|
|
* @param $secret |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct($company, $holder, $secret) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->company = $company; |
|
51
|
|
|
$this->holder = $holder; |
|
52
|
|
|
$this->secret = $secret; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
|
public function run(): string |
|
59
|
|
|
{ |
|
60
|
|
|
return sprintf( |
|
61
|
|
|
'otpauth://totp/%s:%s?secret=%s&issuer=%s', |
|
62
|
|
|
rawurlencode($this->company), |
|
63
|
|
|
rawurlencode($this->holder), |
|
64
|
|
|
$this->secret, |
|
65
|
|
|
rawurlencode($this->company) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|