refactor(web): replace SOGoGoogleAuthenticatorEnabled with

SOGoTOTPEnabled

Fixes #5294
pull/299/head
Francis Lachapelle 2021-06-16 14:59:02 -04:00
parent 34184aa3fc
commit 20b2fd5e45
11 changed files with 40 additions and 36 deletions

View File

@ -1,5 +1,5 @@
/* /*
Copyright (C) 2006-2020 Inverse inc. Copyright (C) 2006-2021 Inverse inc.
This file is part of SOGo. This file is part of SOGo.
@ -120,7 +120,7 @@
- (BOOL) isSuperUser; - (BOOL) isSuperUser;
- (BOOL) canAuthenticate; - (BOOL) canAuthenticate;
- (NSString *) googleAuthenticatorKey; - (NSString *) totpKey;
/* resource */ /* resource */
- (BOOL) isResource; - (BOOL) isResource;

View File

@ -1129,7 +1129,7 @@
return [authValue boolValue]; return [authValue boolValue];
} }
- (NSString *) googleAuthenticatorKey - (NSString *) totpKey
{ {
#if defined(MFA_CONFIG) #if defined(MFA_CONFIG)
NSString *key, *result; NSString *key, *result;

View File

@ -133,8 +133,8 @@ extern NSString *SOGoWeekStartFirstFullWeek;
- (void) setAnimationMode: (NSString *) newValue; - (void) setAnimationMode: (NSString *) newValue;
- (NSString *) animationMode; - (NSString *) animationMode;
- (BOOL) googleAuthenticatorEnabled; - (BOOL) totpEnabled;
- (void) setGoogleAuthenticatorEnabled: (BOOL) newValue; - (void) setTotpEnabled: (BOOL) newValue;
- (void) setMailComposeWindow: (NSString *) newValue; - (void) setMailComposeWindow: (NSString *) newValue;
- (NSString *) mailComposeWindow; - (NSString *) mailComposeWindow;

View File

@ -228,6 +228,7 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek";
@"SOGoReminderEnabled", @"ReminderEnabled", @"SOGoReminderEnabled", @"ReminderEnabled",
@"SOGoReminderTime", @"ReminderTime", @"SOGoReminderTime", @"ReminderTime",
@"SOGoRemindWithASound", @"RemindWithASound", @"SOGoRemindWithASound", @"RemindWithASound",
@"SOGoTOTPEnabled", @"SOGoGoogleAuthenticatorEnabled",
nil]; nil];
[migratedKeys retain]; [migratedKeys retain];
} }
@ -567,14 +568,14 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek";
return [self stringForKey: @"SOGoAnimationMode"]; 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 - (void) setMailComposeWindow: (NSString *) newValue

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2006-2015 Inverse inc. Copyright (C) 2006-2021 Inverse inc.
Copyright (C) 2004-2005 SKYRIX Software AG Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of SOGo. This file is part of SOGo.
@ -33,6 +33,7 @@
#import <NGExtensions/NSNull+misc.h> #import <NGExtensions/NSNull+misc.h>
#import <NGExtensions/NSString+misc.h> #import <NGExtensions/NSString+misc.h>
#import <NGExtensions/NSObject+Logs.h> #import <NGExtensions/NSObject+Logs.h>
#import <NGExtensions/NSObject+Values.h>
#import <Appointments/SOGoAppointmentFolders.h> #import <Appointments/SOGoAppointmentFolders.h>
@ -185,7 +186,7 @@
SOGoUserDefaults *ud; SOGoUserDefaults *ud;
SOGoUser *loggedInUser; SOGoUser *loggedInUser;
NSDictionary *params; NSDictionary *params;
NSString *username, *password, *language, *domain, *remoteHost, *verificationCode; NSString *username, *password, *language, *domain, *remoteHost;
NSArray *supportedLanguages, *creds; NSArray *supportedLanguages, *creds;
SOGoPasswordPolicyError err; SOGoPasswordPolicyError err;
@ -201,7 +202,6 @@
username = [params objectForKey: @"userName"]; username = [params objectForKey: @"userName"];
password = [params objectForKey: @"password"]; password = [params objectForKey: @"password"];
verificationCode = [params objectForKey: @"verificationCode"];
language = [params objectForKey: @"language"]; language = [params objectForKey: @"language"];
rememberLogin = [[params objectForKey: @"rememberLogin"] boolValue]; rememberLogin = [[params objectForKey: @"rememberLogin"] boolValue];
domain = [params objectForKey: @"domain"]; domain = [params objectForKey: @"domain"];
@ -232,8 +232,11 @@
loggedInUser = [SOGoUser userWithLogin: username]; loggedInUser = [SOGoUser userWithLogin: username];
#if defined(MFA_CONFIG) #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) if ([verificationCode length] == 6 && [verificationCode unsignedIntValue] > 0)
{ {
unsigned int code; unsigned int code;
@ -245,7 +248,7 @@
const auto time_step = OATH_TOTP_DEFAULT_TIME_STEP_SIZE; const auto time_step = OATH_TOTP_DEFAULT_TIME_STEP_SIZE;
const auto digits = 6; const auto digits = 6;
real_secret = [[loggedInUser googleAuthenticatorKey] UTF8String]; real_secret = [[loggedInUser totpKey] UTF8String];
auto result = oath_init(); auto result = oath_init();
auto t = time(NULL); auto t = time(NULL);
@ -275,7 +278,7 @@
{ {
[self logWithFormat: @"Invalid TOTP key for '%@'", username]; [self logWithFormat: @"Invalid TOTP key for '%@'", username];
json = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 1] json = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 1]
forKey: @"GoogleAuthenticatorInvalidKey"]; forKey: @"totpInvalidKey"];
return [self responseWithStatus: 403 return [self responseWithStatus: 403
andJSONRepresentation: json]; andJSONRepresentation: json];
} }
@ -284,7 +287,7 @@
{ {
[self logWithFormat: @"Missing TOTP key for '%@', asking it..", username]; [self logWithFormat: @"Missing TOTP key for '%@', asking it..", username];
json = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 1] json = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: 1]
forKey: @"GoogleAuthenticatorMissingKey"]; forKey: @"totpMissingKey"];
return [self responseWithStatus: 202 return [self responseWithStatus: 202
andJSONRepresentation: json]; andJSONRepresentation: json];
} }
@ -736,7 +739,7 @@
return response; return response;
} }
- (BOOL) isGoogleAuthenticatorEnabled - (BOOL) isTotpEnabled
{ {
#if defined(MFA_CONFIG) #if defined(MFA_CONFIG)
return YES; return YES;

View File

@ -172,8 +172,8 @@ static SoProduct *preferencesProduct = nil;
if (![[defaults source] objectForKey: @"SOGoAnimationMode"]) if (![[defaults source] objectForKey: @"SOGoAnimationMode"])
[[defaults source] setObject: [defaults animationMode] forKey: @"SOGoAnimationMode"]; [[defaults source] setObject: [defaults animationMode] forKey: @"SOGoAnimationMode"];
if (![[defaults source] objectForKey: @"SOGoGoogleAuthenticatorEnabled"]) if (![[defaults source] objectForKey: @"SOGoTOTPEnabled"])
[[defaults source] setObject: [NSNumber numberWithBool: NO] forKey: @"SOGoGoogleAuthenticatorEnabled"]; [[defaults source] setObject: [NSNumber numberWithBool: NO] forKey: @"SOGoTOTPEnabled"];
// //
// Default Calendar preferences // Default Calendar preferences

View File

@ -1002,7 +1002,7 @@ static NSArray *reminderValues = nil;
return [NSString stringWithString: SOGoVersion]; return [NSString stringWithString: SOGoVersion];
} }
- (BOOL) isGoogleAuthenticatorEnabled - (BOOL) isTotpEnabled
{ {
#if defined(MFA_CONFIG) #if defined(MFA_CONFIG)
return YES; return YES;
@ -1011,9 +1011,9 @@ static NSArray *reminderValues = nil;
#endif #endif
} }
- (NSString *) googleAuthenticatorKey - (NSString *) totpKey
{ {
return [[context activeUser] googleAuthenticatorKey]; return [[context activeUser] totpKey];
} }
// //

View File

@ -127,14 +127,14 @@
</div> </div>
<!-- TOTP Code --> <!-- TOTP Code -->
<var:if condition="isGoogleAuthenticatorEnabled"> <var:if condition="isTotpEnabled">
<div layout="row" layout-align="center center" layout-fill="layout-fill" <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"> <div flex="80" flex-sm="50" flex-gt-sm="40">
<md-input-container class="md-block"> <md-input-container class="md-block">
<label><var:string label:value="Verification Code"/></label> <label><var:string label:value="Verification Code"/></label>
<md-icon>lock</md-icon> <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> <div class="sg-hint"><var:string label:value="Enter the 6-digit verification code from your TOTP application."/></div>
</md-input-container> </md-input-container>
<div layout="row" layout-align="space-between center"> <div layout="row" layout-align="space-between center">
@ -146,7 +146,7 @@
</md-button> </md-button>
<md-button class="md-fab md-accent md-hue-2" type="submit" <md-button class="md-fab md-accent md-hue-2" type="submit"
label:aria-label="Connect" label:aria-label="Connect"
ng-if="app.loginState == 'googleauthenticatorcode'" ng-if="app.loginState == 'totpcode'"
ng-disabled="loginForm.$invalid" ng-disabled="loginForm.$invalid"
ng-click="app.login()"> ng-click="app.login()">
<md-icon>arrow_forward</md-icon> <md-icon>arrow_forward</md-icon>

View File

@ -243,8 +243,8 @@
</md-radio-group> </md-radio-group>
</md-input-container> </md-input-container>
<var:if condition="isGoogleAuthenticatorEnabled"> <var:if condition="isTotpEnabled">
<md-checkbox ng-model="app.preferences.defaults.SOGoGoogleAuthenticatorEnabled" <md-checkbox ng-model="app.preferences.defaults.SOGoTOTPEnabled"
ng-true-value="1" ng-true-value="1"
ng-false-value="0" ng-false-value="0"
label:aria-label="Enable two-factor authentication using a TOTP application"> label:aria-label="Enable two-factor authentication using a TOTP application">
@ -252,9 +252,9 @@
</md-checkbox> </md-checkbox>
<div layout="row" layout-align="start center" layout-xs="column" <div layout="row" layout-align="start center" layout-xs="column"
layout-padding="layout-padding" layout-margin="layout-margin" layout-padding="layout-padding" layout-margin="layout-margin"
ng-show="app.preferences.defaults.SOGoGoogleAuthenticatorEnabled"> ng-show="app.preferences.defaults.SOGoTOTPEnabled">
<div> <div>
<sg-qr-code var:text="googleAuthenticatorKey" /> <sg-qr-code var:text="totpKey" />
</div> </div>
<div flex="100" flex-sm="60" flex-gt-sm="50"> <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> <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>

View File

@ -94,8 +94,8 @@
} }
else { else {
// Check for TOTP // Check for TOTP
if (typeof data.GoogleAuthenticatorMissingKey != 'undefined' && response.status == 202) { if (typeof data.totpMissingKey != 'undefined' && response.status == 202) {
d.resolve({gamissingkey: 1}); d.resolve({totpmissingkey: 1});
} }
// Check password policy // Check password policy
else if (typeof data.expire != 'undefined' && typeof data.grace != 'undefined') { else if (typeof data.expire != 'undefined' && typeof data.grace != 'undefined') {
@ -125,7 +125,7 @@
} }
}, function(error) { }, function(error) {
var response, perr, data = error.data; var response, perr, data = error.data;
if (data && data.GoogleAuthenticatorInvalidKey) { if (data && data.totpInvalidKey) {
response = {error: l('You provided an invalid TOTP key.')}; response = {error: l('You provided an invalid TOTP key.')};
} }
else if (data && angular.isDefined(data.LDAPPasswordPolicyError)) { else if (data && angular.isDefined(data.LDAPPasswordPolicyError)) {

View File

@ -25,7 +25,7 @@
this.creds.language = $window.language; this.creds.language = $window.language;
this.loginState = false; this.loginState = false;
// Code pattern for Google verification code // Code pattern for TOTP verification code
this.verificationCodePattern = '\\d{6}'; this.verificationCodePattern = '\\d{6}';
// Password policy - change expired password // Password policy - change expired password
@ -41,8 +41,8 @@
Authentication.login(vm.creds) Authentication.login(vm.creds)
.then(function(data) { .then(function(data) {
if (data.gamissingkey) { if (data.totpmissingkey) {
vm.loginState = 'googleauthenticatorcode'; vm.loginState = 'totpcode';
} }
else { else {
vm.loginState = 'logged'; vm.loginState = 'logged';