Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
hotpalgorithm.php
1
<?php
2
3
namespace
Bitrix\Main\Security\Mfa
;
4
5
use
Bitrix\Main\Config\Option
;
6
use
Bitrix\Main\ArgumentOutOfRangeException
;
7
use
Bitrix\Main\Security\OtpException
;
8
use
Bitrix\Main\Localization\Loc
;
9
10
Loc::loadMessages
(__FILE__);
11
12
class
HotpAlgorithm
extends
OtpAlgorithm
13
{
14
const
SYNC_WINDOW
= 15000;
15
protected
static
$type
=
'hotp'
;
16
protected
$window
= 10;
17
18
public
function
__construct
()
19
{
20
$window
= (int)Option::get(
'security'
,
'hotp_user_window'
, 10);
21
if
(
$window
&&
$window
> 0)
22
{
23
$this->window =
$window
;
24
}
25
}
26
30
public
function
verify
($input, $params =
null
)
31
{
32
$input = (string)$input;
33
34
if
(!preg_match(
'#^\d+$#D'
, $input))
35
{
36
throw
new
ArgumentOutOfRangeException
(
'input'
,
'string with numbers'
);
37
}
38
39
$counter = (int)$params;
40
$result =
false
;
41
$window
=
$this->window
;
42
while
(
$window
--)
43
{
44
if
($this->
isStringsEqual
($input, $this->
generateOTP
($counter)))
45
{
46
$result =
true
;
47
break
;
48
}
49
$counter++;
50
}
51
52
if
($result ===
true
)
53
{
54
return
[
true
, $counter + 1];
55
}
56
57
return
[
false
,
null
];
58
}
59
63
public
function
generateUri
($label, array $opts = [])
64
{
65
$opts += [
'counter'
=> 1];
66
return
parent::generateUri($label, $opts);
67
}
68
72
public
function
getSyncParameters
($inputA, $inputB)
73
{
74
$counter = 0;
75
$this->window = 1;
76
for
($i = 0; $i <
self::SYNC_WINDOW
; $i++)
77
{
78
[$verifyA,] = $this->
verify
($inputA, $counter);
79
[$verifyB,] = $this->
verify
($inputB, $counter + 1);
80
$counter++;
81
if
($verifyA && $verifyB)
82
{
83
break
;
84
}
85
}
86
87
if
($i === self::SYNC_WINDOW)
88
{
89
throw
new
OtpException
(
'Cannot synchronize this secret key with the provided password values.'
);
90
}
91
92
return
$counter;
93
}
94
}
Bitrix\Main\ArgumentOutOfRangeException
Definition
exception.php:67
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Security\Mfa\HotpAlgorithm
Definition
hotpalgorithm.php:13
Bitrix\Main\Security\Mfa\HotpAlgorithm\__construct
__construct()
Definition
hotpalgorithm.php:18
Bitrix\Main\Security\Mfa\HotpAlgorithm\$window
$window
Definition
hotpalgorithm.php:16
Bitrix\Main\Security\Mfa\HotpAlgorithm\getSyncParameters
getSyncParameters($inputA, $inputB)
Definition
hotpalgorithm.php:72
Bitrix\Main\Security\Mfa\HotpAlgorithm\SYNC_WINDOW
const SYNC_WINDOW
Definition
hotpalgorithm.php:14
Bitrix\Main\Security\Mfa\HotpAlgorithm\$type
static $type
Definition
hotpalgorithm.php:15
Bitrix\Main\Security\Mfa\HotpAlgorithm\generateUri
generateUri($label, array $opts=[])
Definition
hotpalgorithm.php:63
Bitrix\Main\Security\Mfa\HotpAlgorithm\verify
verify($input, $params=null)
Definition
hotpalgorithm.php:30
Bitrix\Main\Security\Mfa\OtpAlgorithm
Definition
otpalgorithm.php:10
Bitrix\Main\Security\Mfa\OtpAlgorithm\isStringsEqual
isStringsEqual($expected, $actual)
Definition
otpalgorithm.php:170
Bitrix\Main\Security\Mfa\OtpAlgorithm\generateOTP
generateOTP($counter)
Definition
otpalgorithm.php:125
Bitrix\Main\Security\OtpException
Definition
securityexception.php:13
Bitrix\Main\Security\Mfa
Definition
hotpalgorithm.php:3
modules
main
lib
security
mfa
hotpalgorithm.php
Создано системой
1.10.0