|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\Module\webauthn\WebAuthn; |
|
6
|
|
|
|
|
7
|
|
|
use SimpleSAML\Auth; |
|
8
|
|
|
use SimpleSAML\Module; |
|
9
|
|
|
use SimpleSAML\Module\webauthn\WebAuthn\StateData; |
|
10
|
|
|
use SimpleSAML\Utils; |
|
11
|
|
|
|
|
12
|
|
|
class StaticProcessHelper |
|
13
|
|
|
{ |
|
14
|
|
|
public static function saveStateAndRedirect(array &$state): void |
|
15
|
|
|
{ |
|
16
|
|
|
$id = Auth\State::saveState($state, 'webauthn:request'); |
|
17
|
|
|
$url = Module::getModuleURL('webauthn/webauthn'); |
|
18
|
|
|
$httpUtils = new Utils\HTTP(); |
|
19
|
|
|
$httpUtils->redirectTrustedURL($url, ['StateId' => $id]); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public static function saveStateAndRedirectSupercharged(array &$state): void |
|
23
|
|
|
{ |
|
24
|
|
|
$id = Auth\State::saveState($state, 'webauthn:request'); |
|
25
|
|
|
$url = Module::getModuleURL('webauthn/supercharged'); |
|
26
|
|
|
$httpUtils = new Utils\HTTP(); |
|
27
|
|
|
$httpUtils->redirectTrustedURL($url, ['StateId' => $id]); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public static function prepareState(StateData $stateData, array &$state): void |
|
31
|
|
|
{ |
|
32
|
|
|
$state['requestTokenModel'] = $stateData->requestTokenModel; |
|
33
|
|
|
$state['authenticatorAcceptability2FA'] = [ |
|
34
|
|
|
'minCertLevel' => $stateData->minCertLevel2FA, |
|
35
|
|
|
'aaguidWhitelist' => $stateData->aaguidWhitelist2FA, |
|
36
|
|
|
'attFmtWhitelist' => $stateData->attFmtWhitelist2FA, |
|
37
|
|
|
]; |
|
38
|
|
|
$state['authenticatorAcceptabilityPasswordless'] = [ |
|
39
|
|
|
'minCertLevel' => $stateData->minCertLevelPasswordless, |
|
40
|
|
|
'aaguidWhitelist' => $stateData->aaguidWhitelistPasswordless, |
|
41
|
|
|
'attFmtWhitelist' => $stateData->attFmtWhitelistPasswordless, |
|
42
|
|
|
]; |
|
43
|
|
|
$state['webauthn:store'] = $stateData->store; |
|
44
|
|
|
$state['FIDO2Tokens'] = $stateData->store->getTokenData($state['Attributes'][$stateData->usernameAttrib][0]); |
|
45
|
|
|
$state['FIDO2Scope'] = $stateData->scope; |
|
46
|
|
|
$state['FIDO2DerivedScope'] = $stateData->derivedScope; |
|
47
|
|
|
$state['FIDO2AttributeStoringUsername'] = $stateData->usernameAttrib; |
|
48
|
|
|
$state['FIDO2Username'] = $state['Attributes'][$stateData->usernameAttrib][0]; |
|
49
|
|
|
$state['FIDO2Displayname'] = $state['Attributes'][$stateData->displaynameAttrib][0]; |
|
50
|
|
|
$state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64)); |
|
51
|
|
|
$state['FIDO2WantsRegister'] = false; |
|
52
|
|
|
$state['FIDO2AuthSuccessful'] = false; |
|
53
|
|
|
$state['FIDO2PasswordlessAuthMode'] = false; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public static function prepareStatePasswordlessAuth(StateData $stateData, array &$state): void |
|
57
|
|
|
{ |
|
58
|
|
|
$state['requestTokenModel'] = $stateData->requestTokenModel; |
|
59
|
|
|
$state['webauthn:store'] = $stateData->store; |
|
60
|
|
|
$state['FIDO2Scope'] = $stateData->scope; |
|
61
|
|
|
$state['FIDO2DerivedScope'] = $stateData->derivedScope; |
|
62
|
|
|
$state['FIDO2AttributeStoringUsername'] = $stateData->usernameAttrib; |
|
63
|
|
|
$state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64)); |
|
64
|
|
|
$state['FIDO2PasswordlessAuthMode'] = true; |
|
65
|
|
|
$state['FIDO2AuthSuccessful'] = false; |
|
66
|
|
|
$state['FIDO2Tokens'] = []; // we don't know which token comes in. |
|
67
|
|
|
$state['FIDO2Username'] = 'notauthenticated'; |
|
68
|
|
|
$state['FIDO2Displayname'] = 'User Not Authenticated Yet'; |
|
69
|
|
|
$state['FIDO2WantsRegister'] = false; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|