1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\authYubiKey\Auth\Process; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\Assert\Assert; |
8
|
|
|
use SimpleSAML\Auth; |
9
|
|
|
use SimpleSAML\Logger; |
10
|
|
|
|
11
|
|
|
use function array_keys; |
12
|
|
|
use function implode; |
13
|
|
|
use function sprintf; |
14
|
|
|
use function strlen; |
15
|
|
|
use function substr; |
16
|
|
|
|
17
|
|
|
/* |
18
|
|
|
* Copyright (C) 2009 Simon Josefsson <[email protected]>. |
19
|
|
|
* |
20
|
|
|
* This file is part of SimpleSAMLphp |
21
|
|
|
* |
22
|
|
|
* SimpleSAMLphp is free software; you can redistribute it and/or |
23
|
|
|
* modify it under the terms of the GNU Lesser General Public License |
24
|
|
|
* as published by the Free Software Foundation; either version 3 of |
25
|
|
|
* the License, or (at your option) any later version. |
26
|
|
|
* |
27
|
|
|
* SimpleSAMLphp is distributed in the hope that it will be useful, |
28
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
29
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
30
|
|
|
* Lesser General Public License for more details. |
31
|
|
|
* |
32
|
|
|
* You should have received a copy of the GNU Lesser General Public |
33
|
|
|
* License License along with GNU SASL Library; if not, write to the |
34
|
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
35
|
|
|
* Boston, MA 02110-1301, USA. |
36
|
|
|
* |
37
|
|
|
*/ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* A processing filter to replace the 'otp' attribute with an attribute |
41
|
|
|
* 'yubiPrefix' that contains the static YubiKey prefix. |
42
|
|
|
* |
43
|
|
|
* Before: |
44
|
|
|
* otp=ekhgjhbctrgnubeeklijcibbgjnbtjlffdnjbhjluvur |
45
|
|
|
* |
46
|
|
|
* After: |
47
|
|
|
* otp undefined |
48
|
|
|
* yubiPrefix=ekhgjhbctrgn |
49
|
|
|
* |
50
|
|
|
* You use it by adding it as an authentication filter in config.php: |
51
|
|
|
* |
52
|
|
|
* 'authproc.idp' => array( |
53
|
|
|
* ... |
54
|
|
|
* 90 => 'authYubiKey:OTP2YubiPrefix', |
55
|
|
|
* ... |
56
|
|
|
* ); |
57
|
|
|
* |
58
|
|
|
*/ |
59
|
|
|
|
60
|
|
|
class OTP2YubiPrefix extends Auth\ProcessingFilter |
61
|
|
|
{ |
62
|
|
|
/** |
63
|
|
|
* Filter out YubiKey 'otp' attribute and replace it with |
64
|
|
|
* a 'yubiPrefix' attribute that leaves out the dynamic part. |
65
|
|
|
* |
66
|
|
|
* @param array &$state The state we should update. |
67
|
|
|
*/ |
68
|
|
|
public function process(array &$state): void |
69
|
|
|
{ |
70
|
|
|
Assert::keyExists($state, 'Attributes'); |
71
|
|
|
$attributes = $state['Attributes']; |
72
|
|
|
|
73
|
|
|
Logger::debug('OTP2YubiPrefix: enter with attributes: ' . implode(',', array_keys($attributes))); |
74
|
|
|
|
75
|
|
|
$otps = $attributes['otp']; |
76
|
|
|
$otp = $otps['0']; |
77
|
|
|
|
78
|
|
|
$token_size = 32; |
79
|
|
|
$identity = substr($otp, 0, strlen($otp) - $token_size); |
80
|
|
|
|
81
|
|
|
$attributes['yubiPrefix'] = [$identity]; |
82
|
|
|
|
83
|
|
|
Logger::info(sprintf( |
84
|
|
|
'OTP2YubiPrefix: otp: %s identity: %s (otp keys: %s)', |
85
|
|
|
$otp, |
86
|
|
|
$identity, |
87
|
|
|
implode(',', array_keys($otps)), |
88
|
|
|
)); |
89
|
|
|
|
90
|
|
|
unset($attributes['otp']); |
91
|
|
|
|
92
|
|
|
Logger::debug(sprintf( |
93
|
|
|
'OTP2YubiPrefix: leaving with attributes: %s', |
94
|
|
|
implode(',', array_keys($attributes)), |
95
|
|
|
)); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|