Skip to content

Commit

Permalink
refactor(web): replace SOGoGoogleAuthenticatorEnabled with
Browse files Browse the repository at this point in the history
SOGoTOTPEnabled

Fixes #5294
  • Loading branch information
cgx committed Jun 16, 2021
1 parent 34184aa commit 20b2fd5
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 36 deletions.
4 changes: 2 additions & 2 deletions SoObjects/SOGo/SOGoUser.h
@@ -1,5 +1,5 @@
/*
Copyright (C) 2006-2020 Inverse inc.
Copyright (C) 2006-2021 Inverse inc.
This file is part of SOGo.
Expand Down Expand Up @@ -120,7 +120,7 @@

- (BOOL) isSuperUser;
- (BOOL) canAuthenticate;
- (NSString *) googleAuthenticatorKey;
- (NSString *) totpKey;

/* resource */
- (BOOL) isResource;
Expand Down
2 changes: 1 addition & 1 deletion SoObjects/SOGo/SOGoUser.m
Expand Up @@ -1129,7 +1129,7 @@ - (BOOL) canAuthenticate
return [authValue boolValue];
}

- (NSString *) googleAuthenticatorKey
- (NSString *) totpKey
{
#if defined(MFA_CONFIG)
NSString *key, *result;
Expand Down
4 changes: 2 additions & 2 deletions SoObjects/SOGo/SOGoUserDefaults.h
Expand Up @@ -133,8 +133,8 @@ extern NSString *SOGoWeekStartFirstFullWeek;
- (void) setAnimationMode: (NSString *) newValue;
- (NSString *) animationMode;

- (BOOL) googleAuthenticatorEnabled;
- (void) setGoogleAuthenticatorEnabled: (BOOL) newValue;
- (BOOL) totpEnabled;
- (void) setTotpEnabled: (BOOL) newValue;

- (void) setMailComposeWindow: (NSString *) newValue;
- (NSString *) mailComposeWindow;
Expand Down
9 changes: 5 additions & 4 deletions SoObjects/SOGo/SOGoUserDefaults.m
Expand Up @@ -228,6 +228,7 @@ - (BOOL) migrate
@"SOGoReminderEnabled", @"ReminderEnabled",
@"SOGoReminderTime", @"ReminderTime",
@"SOGoRemindWithASound", @"RemindWithASound",
@"SOGoTOTPEnabled", @"SOGoGoogleAuthenticatorEnabled",
nil];
[migratedKeys retain];
}
Expand Down Expand Up @@ -567,14 +568,14 @@ - (NSString *) animationMode
return [self stringForKey: @"SOGoAnimationMode"];
}

- (BOOL) googleAuthenticatorEnabled
- (BOOL) totpEnabled
{
return [self boolForKey: @"SOGoGoogleAuthenticatorEnabled"];
return [self boolForKey: @"SOGoTOTPEnabled"];
}

- (void) setGoogleAuthenticatorEnabled: (BOOL) newValue
- (void) setTotpEnabled: (BOOL) newValue
{
[self setBool: newValue forKey: @"SOGoGoogleAuthenticatorEnabled"];
[self setBool: newValue forKey: @"SOGoTOTPEnabled"];
}

- (void) setMailComposeWindow: (NSString *) newValue
Expand Down
19 changes: 11 additions & 8 deletions UI/MainUI/SOGoRootPage.m
@@ -1,6 +1,6 @@
/*
Copyright (C) 2006-2015 Inverse inc.
Copyright (C) 2006-2021 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo.
Expand Down Expand Up @@ -33,6 +33,7 @@
#import <NGExtensions/NSNull+misc.h>
#import <NGExtensions/NSString+misc.h>
#import <NGExtensions/NSObject+Logs.h>
#import <NGExtensions/NSObject+Values.h>

#import <Appointments/SOGoAppointmentFolders.h>

Expand Down Expand Up @@ -185,7 +186,7 @@ - (WOResponse *) connectAction
SOGoUserDefaults *ud;
SOGoUser *loggedInUser;
NSDictionary *params;
NSString *username, *password, *language, *domain, *remoteHost, *verificationCode;
NSString *username, *password, *language, *domain, *remoteHost;
NSArray *supportedLanguages, *creds;

SOGoPasswordPolicyError err;
Expand All @@ -201,7 +202,6 @@ - (WOResponse *) connectAction

username = [params objectForKey: @"userName"];
password = [params objectForKey: @"password"];
verificationCode = [params objectForKey: @"verificationCode"];
language = [params objectForKey: @"language"];
rememberLogin = [[params objectForKey: @"rememberLogin"] boolValue];
domain = [params objectForKey: @"domain"];
Expand Down Expand Up @@ -232,8 +232,11 @@ - (WOResponse *) connectAction
loggedInUser = [SOGoUser userWithLogin: username];

#if defined(MFA_CONFIG)
if ([[loggedInUser userDefaults] googleAuthenticatorEnabled])
if ([[loggedInUser userDefaults] totpEnabled])
{
NSString *verificationCode;

verificationCode = [params objectForKey: @"verificationCode"];
if ([verificationCode length] == 6 && [verificationCode unsignedIntValue] > 0)
{
unsigned int code;
Expand All @@ -245,7 +248,7 @@ - (WOResponse *) connectAction
const auto time_step = OATH_TOTP_DEFAULT_TIME_STEP_SIZE;
const auto digits = 6;

real_secret = [[loggedInUser googleAuthenticatorKey] UTF8String];
real_secret = [[loggedInUser totpKey] UTF8String];

auto result = oath_init();
auto t = time(NULL);
Expand Down Expand Up @@ -275,7 +278,7 @@ - (WOResponse *) connectAction
{
[self logWithFormat: @"Invalid TOTP key for '%@'", username];
json = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 1]
forKey: @"GoogleAuthenticatorInvalidKey"];
forKey: @"totpInvalidKey"];
return [self responseWithStatus: 403
andJSONRepresentation: json];
}
Expand All @@ -284,7 +287,7 @@ - (WOResponse *) connectAction
{
[self logWithFormat: @"Missing TOTP key for '%@', asking it..", username];
json = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 1]
forKey: @"GoogleAuthenticatorMissingKey"];
forKey: @"totpMissingKey"];
return [self responseWithStatus: 202
andJSONRepresentation: json];
}
Expand Down Expand Up @@ -736,7 +739,7 @@ - (WOResponse *) changePasswordAction
return response;
}

- (BOOL) isGoogleAuthenticatorEnabled
- (BOOL) isTotpEnabled
{
#if defined(MFA_CONFIG)
return YES;
Expand Down
4 changes: 2 additions & 2 deletions UI/PreferencesUI/UIxJSONPreferences.m
Expand Up @@ -172,8 +172,8 @@ - (NSString *) jsonDefaults
if (![[defaults source] objectForKey: @"SOGoAnimationMode"])
[[defaults source] setObject: [defaults animationMode] forKey: @"SOGoAnimationMode"];

if (![[defaults source] objectForKey: @"SOGoGoogleAuthenticatorEnabled"])
[[defaults source] setObject: [NSNumber numberWithBool: NO] forKey: @"SOGoGoogleAuthenticatorEnabled"];
if (![[defaults source] objectForKey: @"SOGoTOTPEnabled"])
[[defaults source] setObject: [NSNumber numberWithBool: NO] forKey: @"SOGoTOTPEnabled"];

//
// Default Calendar preferences
Expand Down
6 changes: 3 additions & 3 deletions UI/PreferencesUI/UIxPreferences.m
Expand Up @@ -1002,7 +1002,7 @@ - (NSString *) sogoVersion
return [NSString stringWithString: SOGoVersion];
}

- (BOOL) isGoogleAuthenticatorEnabled
- (BOOL) isTotpEnabled
{
#if defined(MFA_CONFIG)
return YES;
Expand All @@ -1011,9 +1011,9 @@ - (BOOL) isGoogleAuthenticatorEnabled
#endif
}

- (NSString *) googleAuthenticatorKey
- (NSString *) totpKey
{
return [[context activeUser] googleAuthenticatorKey];
return [[context activeUser] totpKey];
}

//
Expand Down
8 changes: 4 additions & 4 deletions UI/Templates/MainUI/SOGoRootPage.wox
Expand Up @@ -127,14 +127,14 @@
</div>

<!-- TOTP Code -->
<var:if condition="isGoogleAuthenticatorEnabled">
<var:if condition="isTotpEnabled">
<div layout="row" layout-align="center center" layout-fill="layout-fill"
ng-switch-when="googleauthenticatorcode">
ng-switch-when="totpcode">
<div flex="80" flex-sm="50" flex-gt-sm="40">
<md-input-container class="md-block">
<label><var:string label:value="Verification Code"/></label>
<md-icon>lock</md-icon>
<input type="text" ng-pattern="app.verificationCodePattern" ng-model="app.creds.verificationCode" ng-required="app.loginState == 'googleauthenticatorcode'"/>
<input type="text" ng-pattern="app.verificationCodePattern" ng-model="app.creds.verificationCode" ng-required="app.loginState == 'totpcode'"/>
<div class="sg-hint"><var:string label:value="Enter the 6-digit verification code from your TOTP application."/></div>
</md-input-container>
<div layout="row" layout-align="space-between center">
Expand All @@ -146,7 +146,7 @@
</md-button>
<md-button class="md-fab md-accent md-hue-2" type="submit"
label:aria-label="Connect"
ng-if="app.loginState == 'googleauthenticatorcode'"
ng-if="app.loginState == 'totpcode'"
ng-disabled="loginForm.$invalid"
ng-click="app.login()">
<md-icon>arrow_forward</md-icon>
Expand Down
8 changes: 4 additions & 4 deletions UI/Templates/PreferencesUI/UIxPreferences.wox
Expand Up @@ -243,18 +243,18 @@
</md-radio-group>
</md-input-container>

<var:if condition="isGoogleAuthenticatorEnabled">
<md-checkbox ng-model="app.preferences.defaults.SOGoGoogleAuthenticatorEnabled"
<var:if condition="isTotpEnabled">
<md-checkbox ng-model="app.preferences.defaults.SOGoTOTPEnabled"
ng-true-value="1"
ng-false-value="0"
label:aria-label="Enable two-factor authentication using a TOTP application">
<var:string label:value="Enable two-factor authentication using a TOTP application"/>
</md-checkbox>
<div layout="row" layout-align="start center" layout-xs="column"
layout-padding="layout-padding" layout-margin="layout-margin"
ng-show="app.preferences.defaults.SOGoGoogleAuthenticatorEnabled">
ng-show="app.preferences.defaults.SOGoTOTPEnabled">
<div>
<sg-qr-code var:text="googleAuthenticatorKey" />
<sg-qr-code var:text="totpKey" />
</div>
<div flex="100" flex-sm="60" flex-gt-sm="50">
<var:string label:value="You must enter this key into your TOTP application."/> <b><var:string label:value="If you do not and you log out you will not be able to login again."/></b>
Expand Down
6 changes: 3 additions & 3 deletions UI/WebServerResources/js/Common/Authentication.service.js
Expand Up @@ -94,8 +94,8 @@
}
else {
// Check for TOTP
if (typeof data.GoogleAuthenticatorMissingKey != 'undefined' && response.status == 202) {
d.resolve({gamissingkey: 1});
if (typeof data.totpMissingKey != 'undefined' && response.status == 202) {
d.resolve({totpmissingkey: 1});
}
// Check password policy
else if (typeof data.expire != 'undefined' && typeof data.grace != 'undefined') {
Expand Down Expand Up @@ -125,7 +125,7 @@
}
}, function(error) {
var response, perr, data = error.data;
if (data && data.GoogleAuthenticatorInvalidKey) {
if (data && data.totpInvalidKey) {
response = {error: l('You provided an invalid TOTP key.')};
}
else if (data && angular.isDefined(data.LDAPPasswordPolicyError)) {
Expand Down
6 changes: 3 additions & 3 deletions UI/WebServerResources/js/Main/Main.app.js
Expand Up @@ -25,7 +25,7 @@
this.creds.language = $window.language;
this.loginState = false;

// Code pattern for Google verification code
// Code pattern for TOTP verification code
this.verificationCodePattern = '\\d{6}';

// Password policy - change expired password
Expand All @@ -41,8 +41,8 @@
Authentication.login(vm.creds)
.then(function(data) {

if (data.gamissingkey) {
vm.loginState = 'googleauthenticatorcode';
if (data.totpmissingkey) {
vm.loginState = 'totpcode';
}
else {
vm.loginState = 'logged';
Expand Down

0 comments on commit 20b2fd5

Please sign in to comment.