Skip to content

Commit 2f2ad18

Browse files
author
Nicolas Heist
committed
TASK: Correctly use the secretKeyLength-parameter
1 parent 97f0914 commit 2f2ad18

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

Classes/Service/TwoFactorAuthenticationService.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class TwoFactorAuthenticationService
2525
*/
2626
protected $applicationName;
2727

28+
/**
29+
* @var string
30+
* @Flow\InjectConfiguration("secretKeyLength")
31+
*/
32+
protected $secretKeyLength;
33+
2834
public function getPasswordCredentialsSource(Account $account): string
2935
{
3036
if ($this->hasTwoFactorAuthenticationCredentials($account)) {
@@ -89,7 +95,7 @@ public function createActivationQrCode(Account $account): string
8995
$google2fa = new Google2Fa();
9096

9197
$existingCredentials = $this->getTwoFactorAuthenticationCredentials($account);
92-
$secret = $existingCredentials->pendingSecret ?: $google2fa->generateSecretKey();
98+
$secret = $existingCredentials->pendingSecret ?: $google2fa->generateSecretKey($this->getSecretKeyLength());
9399

94100
$updatedCredentials = new TwoFactorAuthenticationCredentialsSource(
95101
$existingCredentials->credentialsSource,
@@ -139,4 +145,9 @@ protected function hasTwoFactorAuthenticationCredentials(Account $account): bool
139145
&& is_array(json_decode($credentials, true))
140146
&& (json_last_error() == JSON_ERROR_NONE) ? true : false;
141147
}
148+
149+
protected function getSecretKeyLength(): int
150+
{
151+
return $this->secretKeyLength * 8;
152+
}
142153
}

Configuration/Settings.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Yeebase:
22
TwoFactorAuthentication:
33
# Length of the secret key that is created for the validation of secrets
4-
secretKeyLengthInByte: 1
4+
# The length given here is multiplied with 8 as the key must be at least 8 chars and be a power of 2
5+
secretKeyLength: 2
56

67
# The application name that should appear in the authenticator app
78
applicationName: 'default'
@@ -10,4 +11,4 @@ Yeebase:
1011
authenticationEntryPoint:
1112
package: ~
1213
controller: ~
13-
action: 'insertSecret'
14+
action: 'insertSecret'

0 commit comments

Comments
 (0)