| 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 |
||
| 158 | public function main(Request $request): Template |
||
| 159 | { |
||
| 160 | $this->logger::info('FIDO2 - Accessing WebAuthn interface'); |
||
| 161 | |||
| 162 | $stateId = $request->query->get('StateId'); |
||
| 163 | if ($stateId === null) { |
||
| 164 | throw new Error\BadRequest('Missing required StateId query parameter.'); |
||
| 165 | } |
||
| 166 | |||
| 167 | $state = $this->authState::loadState($stateId, 'webauthn:request'); |
||
| 168 | |||
| 169 | if ( $this->workflowStateMachine($state) != self::STATE_AUTH_NOMGMT ) { |
||
| 170 | $templateFile = 'webauthn:webauthn.twig'; |
||
| 171 | } else { |
||
| 172 | $templateFile = 'webauthn:authentication.twig'; |
||
| 173 | } |
||
| 174 | |||
| 175 | // Make, populate and layout consent form |
||
| 176 | $t = new Template($this->config, $templateFile); |
||
| 177 | $t->data['UserID'] = $state['FIDO2Username']; |
||
| 178 | $t->data['FIDO2Tokens'] = $state['FIDO2Tokens']; |
||
| 179 | |||
| 180 | $challenge = str_split($state['FIDO2SignupChallenge'], 2); |
||
| 181 | $configUtils = new Utils\Config(); |
||
| 182 | $username = str_split( |
||
| 183 | hash('sha512', $state['FIDO2Username'] . '|' . $configUtils->getSecretSalt()), |
||
| 184 | 2 |
||
| 185 | ); |
||
| 186 | |||
| 187 | $challengeEncoded = []; |
||
| 188 | foreach ($challenge as $oneChar) { |
||
| 189 | $challengeEncoded[] = hexdec($oneChar); |
||
| 190 | } |
||
| 191 | |||
| 192 | $credentialIdEncoded = []; |
||
| 193 | foreach ($state['FIDO2Tokens'] as $number => $token) { |
||
| 194 | $idSplit = str_split($token[0], 2); |
||
| 195 | $credentialIdEncoded[$number] = []; |
||
| 196 | foreach ($idSplit as $credIdBlock) { |
||
| 197 | $credentialIdEncoded[$number][] = hexdec($credIdBlock); |
||
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | $usernameEncoded = []; |
||
| 202 | foreach ($username as $oneChar) { |
||
| 203 | $usernameEncoded[] = hexdec($oneChar); |
||
| 204 | } |
||
| 205 | |||
| 206 | $frontendData = []; |
||
| 207 | $frontendData['challengeEncoded'] = $challengeEncoded; |
||
| 208 | $frontendData['state'] = []; |
||
| 209 | foreach (['Source', 'FIDO2Scope','FIDO2Username','FIDO2Displayname','requestTokenModel'] as $stateItem) { |
||
| 210 | $frontendData['state'][$stateItem] = $state[$stateItem]; |
||
| 211 | } |
||
| 212 | |||
| 213 | $t->data['showExitButton'] = !array_key_exists('Registration', $state); |
||
| 214 | $frontendData['usernameEncoded'] = $usernameEncoded; |
||
| 215 | $frontendData['attestation'] = $state['requestTokenModel'] ? "indirect" : "none"; |
||
| 216 | $frontendData['credentialIdEncoded'] = $credentialIdEncoded; |
||
| 217 | $t->data['frontendData'] = json_encode($frontendData); |
||
| 218 | |||
| 219 | $t->data['FIDO2AuthSuccessful'] = $state['FIDO2AuthSuccessful']; |
||
| 220 | $frontendData['FIDO2PasswordlessAuthMode'] = $state['FIDO2PasswordlessAuthMode']; |
||
| 221 | if ( $this->workflowStateMachine($state) == self::STATE_MGMT ) { |
||
| 222 | $t->data['regURL'] = Module::getModuleURL('webauthn/regprocess?StateId=' . urlencode($stateId)); |
||
| 223 | $t->data['delURL'] = Module::getModuleURL('webauthn/managetoken?StateId=' . urlencode($stateId)); |
||
| 224 | |||
| 225 | } |
||
| 226 | |||
| 227 | $t->data['authForm'] = ""; |
||
| 228 | if ( |
||
| 229 | $this->workflowStateMachine($state) == self::STATE_AUTH_ALLOWMGMT || $this->workflowStateMachine($state) == self::STATE_AUTH_NOMGMT |
||
| 230 | ) { |
||
| 231 | $t->data['authURL'] = Module::getModuleURL('webauthn/authprocess?StateId=' . urlencode($stateId)); |
||
| 232 | } |
||
| 233 | |||
| 234 | // dynamically generate the JS code needed for token registration |
||
| 235 | return $t; |
||
| 236 | } |
||
| 238 |