| Conditions | 12 |
| Paths | 385 |
| Total Lines | 78 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 117 | public function main(Request $request): Template |
||
| 118 | { |
||
| 119 | $this->logger::info('FIDO2 - Accessing WebAuthn interface'); |
||
| 120 | |||
| 121 | $stateId = $request->query->get('StateId'); |
||
| 122 | if ($stateId === null) { |
||
| 123 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 124 | } |
||
| 125 | |||
| 126 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
| 127 | |||
| 128 | if ( $this->workflowStateMachine($state) != self::STATE_AUTH_NOMGMT ) { |
||
| 129 | $templateFile = 'webauthn:webauthn.twig'; |
||
| 130 | } else { |
||
| 131 | $templateFile = 'webauthn:authentication.twig'; |
||
| 132 | } |
||
| 133 | |||
| 134 | // Make, populate and layout consent form |
||
| 135 | $t = new Template($this->config, $templateFile); |
||
| 136 | $t->data['UserID'] = $state['FIDO2Username']; |
||
| 137 | $t->data['FIDO2Tokens'] = $state['FIDO2Tokens']; |
||
| 138 | |||
| 139 | $challenge = str_split($state['FIDO2SignupChallenge'], 2); |
||
| 140 | $entityid = $state['Source']['entityid']; |
||
| 141 | $configUtils = new Utils\Config(); |
||
| 142 | $username = str_split( |
||
| 143 | hash('sha512', $state['FIDO2Username'] . '|' . $configUtils->getSecretSalt() . '|' . $entityid), |
||
| 144 | 2 |
||
| 145 | ); |
||
| 146 | |||
| 147 | $challengeEncoded = []; |
||
| 148 | foreach ($challenge as $oneChar) { |
||
| 149 | $challengeEncoded[] = hexdec($oneChar); |
||
| 150 | } |
||
| 151 | |||
| 152 | $credentialIdEncoded = []; |
||
| 153 | foreach ($state['FIDO2Tokens'] as $number => $token) { |
||
| 154 | $idSplit = str_split($token[0], 2); |
||
| 155 | $credentialIdEncoded[$number] = []; |
||
| 156 | foreach ($idSplit as $credIdBlock) { |
||
| 157 | $credentialIdEncoded[$number][] = hexdec($credIdBlock); |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | $usernameEncoded = []; |
||
| 162 | foreach ($username as $oneChar) { |
||
| 163 | $usernameEncoded[] = hexdec($oneChar); |
||
| 164 | } |
||
| 165 | |||
| 166 | $frontendData = []; |
||
| 167 | $frontendData['challengeEncoded'] = $challengeEncoded; |
||
| 168 | $frontendData['state'] = []; |
||
| 169 | foreach (['Source', 'FIDO2Scope','FIDO2Username','FIDO2Displayname','requestTokenModel'] as $stateItem) { |
||
| 170 | $frontendData['state'][$stateItem] = $state[$stateItem]; |
||
| 171 | } |
||
| 172 | |||
| 173 | $t->data['showExitButton'] = !array_key_exists('Registration', $state); |
||
| 174 | $frontendData['usernameEncoded'] = $usernameEncoded; |
||
| 175 | $frontendData['attestation'] = $state['requestTokenModel'] ? "indirect" : "none"; |
||
| 176 | $frontendData['credentialIdEncoded'] = $credentialIdEncoded; |
||
| 177 | $t->data['frontendData'] = json_encode($frontendData); |
||
| 178 | |||
| 179 | $t->data['FIDO2AuthSuccessful'] = $state['FIDO2AuthSuccessful']; |
||
| 180 | if ( $this->workflowStateMachine($state) == self::STATE_MGMT ) { |
||
| 181 | $t->data['regURL'] = Module::getModuleURL('webauthn/regprocess?StateId=' . urlencode($stateId)); |
||
| 182 | $t->data['delURL'] = Module::getModuleURL('webauthn/managetoken?StateId=' . urlencode($stateId)); |
||
| 183 | |||
| 184 | } |
||
| 185 | |||
| 186 | $t->data['authForm'] = ""; |
||
| 187 | if ( |
||
| 188 | $this->workflowStateMachine($state) == self::STATE_AUTH_ALLOWMGMT || $this->workflowStateMachine($state) == self::STATE_AUTH_NOMGMT |
||
| 189 | ) { |
||
| 190 | $t->data['authURL'] = Module::getModuleURL('webauthn/authprocess?StateId=' . urlencode($stateId)); |
||
| 191 | } |
||
| 192 | |||
| 193 | // dynamically generate the JS code needed for token registration |
||
| 194 | return $t; |
||
| 195 | } |
||
| 197 |