StaticProcessHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 41
c 4
b 0
f 0
dl 0
loc 61
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A saveStateAndRedirect() 0 6 1
A prepareState() 0 24 1
A prepareStatePasswordlessAuth() 0 14 1
A saveStateAndRedirectSupercharged() 0 6 1
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
23
    public static function saveStateAndRedirectSupercharged(array &$state): void
24
    {
25
        $id = Auth\State::saveState($state, 'webauthn:request');
26
        $url = Module::getModuleURL('webauthn/supercharged');
27
        $httpUtils = new Utils\HTTP();
28
        $httpUtils->redirectTrustedURL($url, ['StateId' => $id]);
29
    }
30
31
32
    public static function prepareState(StateData $stateData, array &$state): void
33
    {
34
        $state['requestTokenModel'] = $stateData->requestTokenModel;
35
        $state['authenticatorAcceptability2FA'] = [
36
            'minCertLevel' => $stateData->minCertLevel2FA,
37
            'aaguidWhitelist' => $stateData->aaguidWhitelist2FA,
38
            'attFmtWhitelist' => $stateData->attFmtWhitelist2FA,
39
        ];
40
        $state['authenticatorAcceptabilityPasswordless'] = [
41
            'minCertLevel' => $stateData->minCertLevelPasswordless,
42
            'aaguidWhitelist' => $stateData->aaguidWhitelistPasswordless,
43
            'attFmtWhitelist' => $stateData->attFmtWhitelistPasswordless,
44
        ];
45
        $state['webauthn:store'] = $stateData->store;
46
        $state['FIDO2Tokens'] = $stateData->store->getTokenData($state['Attributes'][$stateData->usernameAttrib][0]);
47
        $state['FIDO2Scope'] = $stateData->scope;
48
        $state['FIDO2DerivedScope'] = $stateData->derivedScope;
49
        $state['FIDO2AttributeStoringUsername'] = $stateData->usernameAttrib;
50
        $state['FIDO2Username'] = $state['Attributes'][$stateData->usernameAttrib][0];
51
        $state['FIDO2Displayname'] = $state['Attributes'][$stateData->displaynameAttrib][0];
52
        $state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64));
53
        $state['FIDO2WantsRegister'] = false;
54
        $state['FIDO2AuthSuccessful'] = false;
55
        $state['FIDO2PasswordlessAuthMode'] = false;
56
    }
57
58
59
    public static function prepareStatePasswordlessAuth(StateData $stateData, array &$state): void
60
    {
61
        $state['requestTokenModel'] = $stateData->requestTokenModel;
62
        $state['webauthn:store'] = $stateData->store;
63
        $state['FIDO2Scope'] = $stateData->scope;
64
        $state['FIDO2DerivedScope'] = $stateData->derivedScope;
65
        $state['FIDO2AttributeStoringUsername'] = $stateData->usernameAttrib;
66
        $state['FIDO2SignupChallenge'] = hash('sha512', random_bytes(64));
67
        $state['FIDO2PasswordlessAuthMode'] = true;
68
        $state['FIDO2AuthSuccessful'] = false;
69
        $state['FIDO2Tokens'] = []; // we don't know which token comes in.
70
        $state['FIDO2Username'] = 'notauthenticated';
71
        $state['FIDO2Displayname'] = 'User Not Authenticated Yet';
72
        $state['FIDO2WantsRegister'] = false;
73
    }
74
}
75