feat(core): initial Google Authenticator support for 2FA

This commit is contained in:
Ludovic Marcotte
2020-05-07 07:22:24 -04:00
parent 33d3154d15
commit f78300a12e
17 changed files with 263 additions and 27 deletions
+4
View File
@@ -43,6 +43,10 @@ ADDITIONAL_CPPFLAGS += $(LASSO_CFLAGS)
SOGo_LIBRARIES_DEPEND_UPON += $(LASSO_LIBS)
endif
ifeq ($(HAS_LIBRARY_oath), yes)
SOGo_LIBRARIES_DEPEND_UPON += $(MFA_LIBS)
endif
ifeq ($(findstring openbsd, $(GNUSTEP_HOST_OS)), openbsd)
SOGo_LIBRARIES_DEPEND_UPON += -lcrypto
else
+1 -1
View File
@@ -1,6 +1,6 @@
/* SOGoCache.m - this file is part of SOGo
*
* Copyright (C) 2008-2014 Inverse inc.
* Copyright (C) 2008-2020 Inverse inc.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
+2 -1
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2006-2016 Inverse inc.
Copyright (C) 2006-2020 Inverse inc.
This file is part of SOGo.
@@ -120,6 +120,7 @@
- (BOOL) isSuperUser;
- (BOOL) canAuthenticate;
- (NSString *) googleAuthenticatorKey;
/* resource */
- (BOOL) isResource;
+33 -1
View File
@@ -1,5 +1,5 @@
/*
Copyright (C) 2006-2016 Inverse inc.
Copyright (C) 2006-2020 Inverse inc.
This file is part of SOGo.
@@ -39,6 +39,10 @@
#import "SOGoUserSettings.h"
#import "WOResourceManager+SOGo.h"
#if defined(MFA_CONFIG)
#include <liboath/oath.h>
#endif
#import "SOGoUser.h"
@implementation SoUser (SOGoExtension)
@@ -1079,6 +1083,34 @@
return [authValue boolValue];
}
- (NSString *) googleAuthenticatorKey
{
#if defined(MFA_CONFIG)
NSString *key, *result;
const char *s;
char *secret;
size_t s_len, secret_len;
key = [[[self userSettings] userSalt] substringToIndex: 12];
s = [key UTF8String];
s_len = strlen(s);
oath_init();
oath_base32_encode(s,s_len, &secret, &secret_len);
oath_done();
result = [[NSString alloc] initWithBytesNoCopy: secret
length: secret_len
encoding: NSASCIIStringEncoding
freeWhenDone: YES];
return [result autorelease];
#else
return nil;
#endif
}
/* resource */
- (BOOL) isResource
{
+3
View File
@@ -133,6 +133,9 @@ extern NSString *SOGoWeekStartFirstFullWeek;
- (void) setAnimationMode: (NSString *) newValue;
- (NSString *) animationMode;
- (BOOL) googleAuthenticatorEnabled;
- (void) setGoogleAuthenticatorEnabled: (BOOL) newValue;
- (void) setMailComposeWindow: (NSString *) newValue;
- (NSString *) mailComposeWindow;
+11 -1
View File
@@ -1,6 +1,6 @@
/* SOGoUserDefaults.m - this file is part of SOGo
*
* Copyright (C) 2009-2017 Inverse inc.
* Copyright (C) 2009-2020 Inverse inc.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -542,6 +542,16 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek";
return [self stringForKey: @"SOGoAnimationMode"];
}
- (BOOL) googleAuthenticatorEnabled
{
return [self boolForKey: @"SOGoGoogleAuthenticatorEnabled"];
}
- (void) setGoogleAuthenticatorEnabled: (BOOL) newValue
{
[self setBool: newValue forKey: @"SOGoGoogleAuthenticatorEnabled"];
}
- (void) setMailComposeWindow: (NSString *) newValue
{
[self setObject: newValue forKey: @"SOGoMailComposeWindow"];