From 20b2fd5e4573392e374f465d63cb34346f17f2f6 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 16 Jun 2021 14:59:02 -0400 Subject: [PATCH] refactor(web): replace SOGoGoogleAuthenticatorEnabled with SOGoTOTPEnabled Fixes #5294 --- SoObjects/SOGo/SOGoUser.h | 4 ++-- SoObjects/SOGo/SOGoUser.m | 2 +- SoObjects/SOGo/SOGoUserDefaults.h | 4 ++-- SoObjects/SOGo/SOGoUserDefaults.m | 9 +++++---- UI/MainUI/SOGoRootPage.m | 19 +++++++++++-------- UI/PreferencesUI/UIxJSONPreferences.m | 4 ++-- UI/PreferencesUI/UIxPreferences.m | 6 +++--- UI/Templates/MainUI/SOGoRootPage.wox | 8 ++++---- UI/Templates/PreferencesUI/UIxPreferences.wox | 8 ++++---- .../js/Common/Authentication.service.js | 6 +++--- UI/WebServerResources/js/Main/Main.app.js | 6 +++--- 11 files changed, 40 insertions(+), 36 deletions(-) diff --git a/SoObjects/SOGo/SOGoUser.h b/SoObjects/SOGo/SOGoUser.h index a75929ccf..7ce25a30b 100644 --- a/SoObjects/SOGo/SOGoUser.h +++ b/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. @@ -120,7 +120,7 @@ - (BOOL) isSuperUser; - (BOOL) canAuthenticate; -- (NSString *) googleAuthenticatorKey; +- (NSString *) totpKey; /* resource */ - (BOOL) isResource; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 966aa1176..90d1c3ddf 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -1129,7 +1129,7 @@ return [authValue boolValue]; } -- (NSString *) googleAuthenticatorKey +- (NSString *) totpKey { #if defined(MFA_CONFIG) NSString *key, *result; diff --git a/SoObjects/SOGo/SOGoUserDefaults.h b/SoObjects/SOGo/SOGoUserDefaults.h index 1498416cd..62b9d9009 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.h +++ b/SoObjects/SOGo/SOGoUserDefaults.h @@ -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; diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index ff31249a3..edfdbd2cf 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -228,6 +228,7 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; @"SOGoReminderEnabled", @"ReminderEnabled", @"SOGoReminderTime", @"ReminderTime", @"SOGoRemindWithASound", @"RemindWithASound", + @"SOGoTOTPEnabled", @"SOGoGoogleAuthenticatorEnabled", nil]; [migratedKeys retain]; } @@ -567,14 +568,14 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; 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 diff --git a/UI/MainUI/SOGoRootPage.m b/UI/MainUI/SOGoRootPage.m index 5a8cee5bf..55cbb30e1 100644 --- a/UI/MainUI/SOGoRootPage.m +++ b/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. @@ -33,6 +33,7 @@ #import #import #import +#import #import @@ -185,7 +186,7 @@ SOGoUserDefaults *ud; SOGoUser *loggedInUser; NSDictionary *params; - NSString *username, *password, *language, *domain, *remoteHost, *verificationCode; + NSString *username, *password, *language, *domain, *remoteHost; NSArray *supportedLanguages, *creds; SOGoPasswordPolicyError err; @@ -201,7 +202,6 @@ 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"]; @@ -232,8 +232,11 @@ 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; @@ -245,7 +248,7 @@ 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); @@ -275,7 +278,7 @@ { [self logWithFormat: @"Invalid TOTP key for '%@'", username]; json = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 1] - forKey: @"GoogleAuthenticatorInvalidKey"]; + forKey: @"totpInvalidKey"]; return [self responseWithStatus: 403 andJSONRepresentation: json]; } @@ -284,7 +287,7 @@ { [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]; } @@ -736,7 +739,7 @@ return response; } -- (BOOL) isGoogleAuthenticatorEnabled +- (BOOL) isTotpEnabled { #if defined(MFA_CONFIG) return YES; diff --git a/UI/PreferencesUI/UIxJSONPreferences.m b/UI/PreferencesUI/UIxJSONPreferences.m index 8648c64ed..6905b46bc 100644 --- a/UI/PreferencesUI/UIxJSONPreferences.m +++ b/UI/PreferencesUI/UIxJSONPreferences.m @@ -172,8 +172,8 @@ static SoProduct *preferencesProduct = nil; 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 diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 2eb61adb7..15434b73c 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -1002,7 +1002,7 @@ static NSArray *reminderValues = nil; return [NSString stringWithString: SOGoVersion]; } -- (BOOL) isGoogleAuthenticatorEnabled +- (BOOL) isTotpEnabled { #if defined(MFA_CONFIG) return YES; @@ -1011,9 +1011,9 @@ static NSArray *reminderValues = nil; #endif } -- (NSString *) googleAuthenticatorKey +- (NSString *) totpKey { - return [[context activeUser] googleAuthenticatorKey]; + return [[context activeUser] totpKey]; } // diff --git a/UI/Templates/MainUI/SOGoRootPage.wox b/UI/Templates/MainUI/SOGoRootPage.wox index 8f9468905..7991f2868 100644 --- a/UI/Templates/MainUI/SOGoRootPage.wox +++ b/UI/Templates/MainUI/SOGoRootPage.wox @@ -127,14 +127,14 @@ - +
+ ng-switch-when="totpcode">
lock - +
@@ -146,7 +146,7 @@ arrow_forward diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index 572b4d4ec..2be2dd970 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -243,8 +243,8 @@ - - + @@ -252,9 +252,9 @@
+ ng-show="app.preferences.defaults.SOGoTOTPEnabled">
- +
diff --git a/UI/WebServerResources/js/Common/Authentication.service.js b/UI/WebServerResources/js/Common/Authentication.service.js index 074ba6679..7ced11aa8 100644 --- a/UI/WebServerResources/js/Common/Authentication.service.js +++ b/UI/WebServerResources/js/Common/Authentication.service.js @@ -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') { @@ -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)) { diff --git a/UI/WebServerResources/js/Main/Main.app.js b/UI/WebServerResources/js/Main/Main.app.js index 7996420b1..92d850a65 100644 --- a/UI/WebServerResources/js/Main/Main.app.js +++ b/UI/WebServerResources/js/Main/Main.app.js @@ -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 @@ -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';