From 204ac100c605bb1911913cf786dc85fc7daa447f Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Fri, 26 Feb 2021 09:53:13 -0300 Subject: [PATCH 1/6] Authenticator: New auth with token API --- Simperium/SPAuthenticator.h | 3 +++ Simperium/SPAuthenticator.m | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Simperium/SPAuthenticator.h b/Simperium/SPAuthenticator.h index 6bd85528..46f2ec75 100644 --- a/Simperium/SPAuthenticator.h +++ b/Simperium/SPAuthenticator.h @@ -43,6 +43,9 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)authenticateIfNecessary; +- (void)authenticateWithUsername:(NSString *)username + token:(NSString *)token; + - (void)authenticateWithUsername:(NSString *)username password:(NSString *)password success:(SuccessBlockType)successHandler diff --git a/Simperium/SPAuthenticator.m b/Simperium/SPAuthenticator.m index 01685753..9fb0dd4d 100644 --- a/Simperium/SPAuthenticator.m +++ b/Simperium/SPAuthenticator.m @@ -117,6 +117,19 @@ - (BOOL)authenticateIfNecessary { #pragma mark - Authentication +- (void)authenticateWithUsername:(NSString *)username + token:(NSString *)token { + NSParameterAssert(username); + NSParameterAssert(token); + + SPUser *user = [[SPUser alloc] initWithEmail:username token:token]; + self.simperium.user = user; + + [self saveCredentialsForUser:user]; + [self notifySignupDidSucceed]; + [self notifyAuthenticationDidSucceed]; +} + - (void)authenticateWithUsername:(NSString *)username password:(NSString *)password success:(SuccessBlockType)successHandler From 40f5e92f0f707c7f0dd463e602b6d7f969e838b2 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Fri, 26 Feb 2021 18:01:18 -0300 Subject: [PATCH 2/6] SPAuthenticationTextField: NSCoder support --- Simperium-OSX/SPAuthenticationTextField.m | 62 ++++++++++++++--------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/Simperium-OSX/SPAuthenticationTextField.m b/Simperium-OSX/SPAuthenticationTextField.m index f495c2ec..de0ffd35 100644 --- a/Simperium-OSX/SPAuthenticationTextField.m +++ b/Simperium-OSX/SPAuthenticationTextField.m @@ -72,34 +72,48 @@ - (void)dealloc { - (instancetype)initWithFrame:(NSRect)frame secure:(BOOL)secure { self = [super initWithFrame:frame]; if (self) { - // Center the textField vertically - int paddingX = 10; - int fontSize = 20; - CGFloat fieldHeight = [[SPAuthenticationConfiguration sharedInstance] regularFontHeightForSize:fontSize]; - CGFloat fieldY = (self.frame.size.height - fieldHeight) / 2; - CGRect textFrame = NSMakeRect(paddingX, fieldY, frame.size.width-paddingX*2, fieldHeight); - - Class textFieldClass = secure ? [SPSecureTextField class] : [SPTextField class]; - _textField = [[textFieldClass alloc] initWithFrame:textFrame]; - NSFont *font = [NSFont fontWithName:[SPAuthenticationConfiguration sharedInstance].regularFontName size:fontSize]; - [_textField setFont:font]; - [_textField setTextColor:[NSColor colorWithCalibratedWhite:0.1 alpha:1.0]]; - [_textField setDrawsBackground:NO]; - [_textField setBezeled:NO]; - [_textField setBordered:NO]; - [_textField setFocusRingType:NSFocusRingTypeNone]; - [[_textField cell] setWraps:NO]; - [[_textField cell] setScrollable:YES]; - [self addSubview:_textField]; - - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - [nc addObserver:self selector:@selector(handleTextFieldDidBeginEditing:) name:SPTextFieldDidBecomeFirstResponder object:_textField]; - [nc addObserver:self selector:@selector(handleTextFieldDidFinishEditing:) name:NSControlTextDidEndEditingNotification object:_textField]; + [self setupInterface]; } - + + return self +} + + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super initWithCoder:coder]; + if (self) { + [self setupInterface]; + } + return self; } +- (void)setupInterface { + // Center the textField vertically + int paddingX = 10; + int fontSize = 20; + CGFloat fieldHeight = [[SPAuthenticationConfiguration sharedInstance] regularFontHeightForSize:fontSize]; + CGFloat fieldY = (self.frame.size.height - fieldHeight) / 2; + CGRect textFrame = NSMakeRect(paddingX, fieldY, frame.size.width-paddingX*2, fieldHeight); + + Class textFieldClass = secure ? [SPSecureTextField class] : [SPTextField class]; + _textField = [[textFieldClass alloc] initWithFrame:textFrame]; + NSFont *font = [NSFont fontWithName:[SPAuthenticationConfiguration sharedInstance].regularFontName size:fontSize]; + [_textField setFont:font]; + [_textField setTextColor:[NSColor colorWithCalibratedWhite:0.1 alpha:1.0]]; + [_textField setDrawsBackground:NO]; + [_textField setBezeled:NO]; + [_textField setBordered:NO]; + [_textField setFocusRingType:NSFocusRingTypeNone]; + [[_textField cell] setWraps:NO]; + [[_textField cell] setScrollable:YES]; + [self addSubview:_textField]; + + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc addObserver:self selector:@selector(handleTextFieldDidBeginEditing:) name:SPTextFieldDidBecomeFirstResponder object:_textField]; + [nc addObserver:self selector:@selector(handleTextFieldDidFinishEditing:) name:NSControlTextDidEndEditingNotification object:_textField]; +} + - (void)setStringValue:(NSString *)string { _textField.stringValue = string; } From 2d024462360a87cdaabe1779914e913ff9da4013 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Fri, 26 Feb 2021 18:08:38 -0300 Subject: [PATCH 3/6] SPAuthenticationTextField: Secure support --- Simperium-OSX/SPAuthenticationTextField.m | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Simperium-OSX/SPAuthenticationTextField.m b/Simperium-OSX/SPAuthenticationTextField.m index de0ffd35..d115e28e 100644 --- a/Simperium-OSX/SPAuthenticationTextField.m +++ b/Simperium-OSX/SPAuthenticationTextField.m @@ -16,6 +16,7 @@ #pragma mark ==================================================================================== static NSString* SPTextFieldDidBecomeFirstResponder = @"SPTextFieldDidBecomeFirstResponder"; +static NSString *SPTextFieldSecureKey = @"secure"; #pragma mark ==================================================================================== @@ -72,26 +73,28 @@ - (void)dealloc { - (instancetype)initWithFrame:(NSRect)frame secure:(BOOL)secure { self = [super initWithFrame:frame]; if (self) { - [self setupInterface]; + [self setupInterface:secure]; } - return self + return self; } - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; if (self) { - [self setupInterface]; + BOOL secure = [[self valueForKey:SPTextFieldSecureKey] boolValue]; + [self setupInterface:secure]; } return self; } -- (void)setupInterface { +- (void)setupInterface:(BOOL)secure { // Center the textField vertically - int paddingX = 10; - int fontSize = 20; + NSRect frame = self.frame; + CGFloat paddingX = 10; + CGFloat fontSize = 20; CGFloat fieldHeight = [[SPAuthenticationConfiguration sharedInstance] regularFontHeightForSize:fontSize]; CGFloat fieldY = (self.frame.size.height - fieldHeight) / 2; CGRect textFrame = NSMakeRect(paddingX, fieldY, frame.size.width-paddingX*2, fieldHeight); From 2449d3ce98380e283b40ac801133f410409e77ba Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Fri, 26 Feb 2021 18:24:14 -0300 Subject: [PATCH 4/6] SPAuthenticationTextField: Secured subclass --- Simperium-OSX/SPAuthenticationTextField.h | 8 ++++++- Simperium-OSX/SPAuthenticationTextField.m | 27 +++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Simperium-OSX/SPAuthenticationTextField.h b/Simperium-OSX/SPAuthenticationTextField.h index c9c68fec..7dc6d2b6 100644 --- a/Simperium-OSX/SPAuthenticationTextField.h +++ b/Simperium-OSX/SPAuthenticationTextField.h @@ -13,10 +13,16 @@ @property (assign) id delegate; @property (strong) NSTextField *textField; -- (id)initWithFrame:(NSRect)frame secure:(BOOL)secure; +- (instancetype)initWithFrame:(NSRect)frame secure:(BOOL)secure; + - (void)setPlaceholderString:(NSString *)string; - (NSString *)stringValue; - (void)setStringValue:(NSString *)string; - (void)setEnabled:(BOOL)enabled; @end + + +@interface SPAuthenticationSecureTextField : SPAuthenticationTextField + +@end diff --git a/Simperium-OSX/SPAuthenticationTextField.m b/Simperium-OSX/SPAuthenticationTextField.m index d115e28e..f0cd5e17 100644 --- a/Simperium-OSX/SPAuthenticationTextField.m +++ b/Simperium-OSX/SPAuthenticationTextField.m @@ -16,7 +16,6 @@ #pragma mark ==================================================================================== static NSString* SPTextFieldDidBecomeFirstResponder = @"SPTextFieldDidBecomeFirstResponder"; -static NSString *SPTextFieldSecureKey = @"secure"; #pragma mark ==================================================================================== @@ -56,9 +55,7 @@ - (BOOL)becomeFirstResponder { -#pragma mark ==================================================================================== -#pragma mark SPAuthenticationTextField -#pragma mark ==================================================================================== +#pragma mark - SPAuthenticationTextField @interface SPAuthenticationTextField() @property (nonatomic, assign) BOOL isWindowFistResponder; @@ -79,12 +76,11 @@ - (instancetype)initWithFrame:(NSRect)frame secure:(BOOL)secure { return self; } - - (instancetype)initWithCoder:(NSCoder *)coder { self = [super initWithCoder:coder]; if (self) { - BOOL secure = [[self valueForKey:SPTextFieldSecureKey] boolValue]; - [self setupInterface:secure]; + // TODO: Should probably read the mode from NSCoder. Falling back to unsecured by default + [self setupInterface:NO]; } return self; @@ -173,3 +169,20 @@ - (void)handleTextFieldDidFinishEditing:(NSNotification *)note { } @end + + + +#pragma mark - SPAuthenticationSecureTextField + +@implementation SPAuthenticationSecureTextField + +- (instancetype)initWithCoder:(NSCoder *)coder { + self = [super initWithCoder:coder]; + if (self) { + [super setupInterface:YES]; + } + + return self; +} + +@end From c8acbb5a7fe0bc8731a1655f4a1d9b8b919ca8ad Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Fri, 26 Feb 2021 18:36:37 -0300 Subject: [PATCH 5/6] SPAuthenticationTextField: Secure mechanism --- Simperium-OSX/SPAuthenticationTextField.h | 5 ---- Simperium-OSX/SPAuthenticationTextField.m | 33 +++++------------------ 2 files changed, 6 insertions(+), 32 deletions(-) diff --git a/Simperium-OSX/SPAuthenticationTextField.h b/Simperium-OSX/SPAuthenticationTextField.h index 7dc6d2b6..15e3c8dd 100644 --- a/Simperium-OSX/SPAuthenticationTextField.h +++ b/Simperium-OSX/SPAuthenticationTextField.h @@ -21,8 +21,3 @@ - (void)setEnabled:(BOOL)enabled; @end - - -@interface SPAuthenticationSecureTextField : SPAuthenticationTextField - -@end diff --git a/Simperium-OSX/SPAuthenticationTextField.m b/Simperium-OSX/SPAuthenticationTextField.m index f0cd5e17..00b905ef 100644 --- a/Simperium-OSX/SPAuthenticationTextField.m +++ b/Simperium-OSX/SPAuthenticationTextField.m @@ -59,6 +59,7 @@ - (BOOL)becomeFirstResponder { @interface SPAuthenticationTextField() @property (nonatomic, assign) BOOL isWindowFistResponder; +@property (nonatomic, assign) BOOL secure; @end @implementation SPAuthenticationTextField @@ -76,14 +77,9 @@ - (instancetype)initWithFrame:(NSRect)frame secure:(BOOL)secure { return self; } -- (instancetype)initWithCoder:(NSCoder *)coder { - self = [super initWithCoder:coder]; - if (self) { - // TODO: Should probably read the mode from NSCoder. Falling back to unsecured by default - [self setupInterface:NO]; - } - - return self; +- (void)awakeFromNib { + [super awakeFromNib]; + [self setupInterface:self.secure]; } - (void)setupInterface:(BOOL)secure { @@ -141,11 +137,11 @@ - (void)setEnabled:(BOOL)enabled { - (void)drawRect:(NSRect)dirtyRect { NSBezierPath *betterBounds = [NSBezierPath bezierPathWithRect:self.bounds]; [betterBounds addClip]; - + if (self.isWindowFistResponder) { [[NSColor colorWithCalibratedWhite:0.9 alpha:1.0] setFill]; [betterBounds fill]; - + } else { [[NSColor colorWithCalibratedWhite:250.f/255.f alpha:1.0] setFill]; [betterBounds fill]; @@ -169,20 +165,3 @@ - (void)handleTextFieldDidFinishEditing:(NSNotification *)note { } @end - - - -#pragma mark - SPAuthenticationSecureTextField - -@implementation SPAuthenticationSecureTextField - -- (instancetype)initWithCoder:(NSCoder *)coder { - self = [super initWithCoder:coder]; - if (self) { - [super setupInterface:YES]; - } - - return self; -} - -@end From 696dca67a63e3437b2071eca1788181688d8ad69 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Mon, 1 Mar 2021 10:59:24 -0300 Subject: [PATCH 6/6] Simperium mk1.5 --- Simperium/SPEnvironment.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Simperium/SPEnvironment.m b/Simperium/SPEnvironment.m index acfac6fe..0d2c51d8 100644 --- a/Simperium/SPEnvironment.m +++ b/Simperium/SPEnvironment.m @@ -30,7 +30,7 @@ #endif // TODO: Update this automatically via a script that looks at current git tag -NSString* const SPLibraryVersion = @"1.4.0"; +NSString* const SPLibraryVersion = @"1.5.0"; /// SSL Pinning ///