|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\webauthn\WebAuthn; |
|
4
|
|
|
|
|
5
|
|
|
use SimpleSAML\Auth; |
|
6
|
|
|
use SimpleSAML\Module; |
|
7
|
|
|
use SimpleSAML\Module\webauthn\WebAuthn\StateData; |
|
8
|
|
|
use SimpleSAML\Utils; |
|
9
|
|
|
|
|
10
|
|
|
class StaticProcessHelper |
|
11
|
|
|
{ |
|
12
|
|
|
public static function saveStateAndRedirect(array &$state): void |
|
13
|
|
|
{ |
|
14
|
|
|
$id = Auth\State::saveState($state, 'webauthn:request'); |
|
15
|
|
|
$url = Module::getModuleURL('webauthn/webauthn'); |
|
16
|
|
|
$httpUtils = new Utils\HTTP(); |
|
17
|
|
|
$httpUtils->redirectTrustedURL($url, ['StateId' => $id]); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public static function prepareState(StateData $stateData, array &$state): void |
|
21
|
|
|
{ |
|
22
|
|
|
$state['requestTokenModel'] = $stateData->requestTokenModel; |
|
23
|
|
|
$state['webauthn:store'] = $stateData->store; |
|
24
|
|
|
$state['FIDO2Tokens'] = $stateData->store->getTokenData($state['Attributes'][$stateData->usernameAttrib][0]); |
|
25
|
|
|
$state['FIDO2Scope'] = $stateData->scope; |
|
26
|
|
|
$state['FIDO2DerivedScope'] = $stateData->derivedScope; |
|
27
|
|
|
$state['FIDO2AttributeStoringUsername'] = $stateData->usernameAttrib; |
|
28
|
|
|
$state['FIDO2Username'] = $state['Attributes'][$stateData->usernameAttrib][0]; |
|
29
|
|
|
$state['FIDO2Displayname'] = $state['Attributes'][$stateData->displaynameAttrib][0]; |
|
30
|
|
|
$state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64)); |
|
31
|
|
|
$state['FIDO2WantsRegister'] = false; |
|
32
|
|
|
$state['FIDO2AuthSuccessful'] = false; |
|
33
|
|
|
$state['FIDO2PasswordlessAuthMode'] = false; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function prepareStatePasswordlessAuth(StateData $stateData, array &$state): void |
|
37
|
|
|
{ |
|
38
|
|
|
$state['webauthn:store'] = $stateData->store; |
|
39
|
|
|
$state['FIDO2Scope'] = $stateData->scope; |
|
40
|
|
|
$state['FIDO2DerivedScope'] = $stateData->derivedScope; |
|
41
|
|
|
$state['FIDO2AttributeStoringUsername'] = $stateData->usernameAttrib; |
|
42
|
|
|
$state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64)); |
|
43
|
|
|
$state['FIDO2PasswordlessAuthMode'] = true; |
|
44
|
|
|
$state['FIDO2AuthSuccessful'] = false; |
|
45
|
|
|
|
|
46
|
|
|
$state['FIDO2WantsRegister'] = false; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|