From 64829c99d86d8312a1c167b15f04d520b4112db8 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sat, 20 Feb 2016 21:56:04 -0500 Subject: [PATCH] Initial support for security questions in Mac app. --- .idea/inspectionProfiles/Project_Default.xml | 1 - MasterPassword/ObjC/MPEntities.h | 9 + MasterPassword/ObjC/MPEntities.m | 24 +++ MasterPassword/ObjC/Mac/MPInitialWindow.xib | 4 +- .../ObjC/Mac/MPPasswordWindowController.h | 1 + .../ObjC/Mac/MPPasswordWindowController.m | 6 +- .../ObjC/Mac/MPPasswordWindowController.xib | 166 ++++++++++-------- MasterPassword/ObjC/Mac/MPSiteModel.h | 2 + MasterPassword/ObjC/Mac/MPSiteModel.m | 25 ++- .../ObjC/iOS/MPAnswersViewController.m | 8 +- 10 files changed, 157 insertions(+), 89 deletions(-) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index d72e0862..3772b7cd 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -5,7 +5,6 @@ - diff --git a/MasterPassword/ObjC/MPEntities.h b/MasterPassword/ObjC/MPEntities.h index edd2c375..c2368667 100644 --- a/MasterPassword/ObjC/MPEntities.h +++ b/MasterPassword/ObjC/MPEntities.h @@ -22,6 +22,13 @@ @end +@interface MPSiteQuestionEntity(MP) + +- (NSString *)resolveQuestionAnswerUsingKey:(MPKey *)key; +- (void)resolveQuestionAnswerUsingKey:(MPKey *)key result:(void ( ^ )(NSString *))result; + +@end + @interface MPSiteEntity(MP) @property(assign) BOOL loginGenerated; @@ -38,8 +45,10 @@ - (BOOL)tryMigrateExplicitly:(BOOL)explicit; - (NSString *)resolveLoginUsingKey:(MPKey *)key; - (NSString *)resolvePasswordUsingKey:(MPKey *)key; +- (NSString *)resolveSiteAnswerUsingKey:(MPKey *)key; - (void)resolveLoginUsingKey:(MPKey *)key result:(void ( ^ )(NSString *))result; - (void)resolvePasswordUsingKey:(MPKey *)key result:(void ( ^ )(NSString *))result; +- (void)resolveSiteAnswerUsingKey:(MPKey *)key result:(void ( ^ )(NSString *))result; @end diff --git a/MasterPassword/ObjC/MPEntities.m b/MasterPassword/ObjC/MPEntities.m index f2b57da2..5ae3259d 100644 --- a/MasterPassword/ObjC/MPEntities.m +++ b/MasterPassword/ObjC/MPEntities.m @@ -35,6 +35,20 @@ @end +@implementation MPSiteQuestionEntity(MP) + +- (NSString *)resolveQuestionAnswerUsingKey:(MPKey *)key { + + return [self.site.algorithm resolveAnswerForQuestion:self usingKey:key]; +} + +- (void)resolveQuestionAnswerUsingKey:(MPKey *)key result:(void ( ^ )(NSString *))result { + + [self.site.algorithm resolveAnswerForQuestion:self usingKey:key result:result]; +} + +@end + @implementation MPSiteEntity(MP) - (MPFixableResult)findAndFixInconsistenciesInContext:(NSManagedObjectContext *)context { @@ -175,6 +189,11 @@ return [self.algorithm resolvePasswordForSite:self usingKey:key]; } +- (NSString *)resolveSiteAnswerUsingKey:(MPKey *)key { + + return [self.algorithm resolveAnswerForSite:self usingKey:key]; +} + - (void)resolveLoginUsingKey:(MPKey *)key result:(void ( ^ )(NSString *))result { [self.algorithm resolveLoginForSite:self usingKey:key result:result]; @@ -185,6 +204,11 @@ [self.algorithm resolvePasswordForSite:self usingKey:key result:result]; } +- (void)resolveSiteAnswerUsingKey:(MPKey *)key result:(void ( ^ )(NSString *))result { + + [self.algorithm resolveAnswerForSite:self usingKey:key result:result]; +} + @end @implementation MPGeneratedSiteEntity(MP) diff --git a/MasterPassword/ObjC/Mac/MPInitialWindow.xib b/MasterPassword/ObjC/Mac/MPInitialWindow.xib index 54d9f470..d3a0b46c 100644 --- a/MasterPassword/ObjC/Mac/MPInitialWindow.xib +++ b/MasterPassword/ObjC/Mac/MPInitialWindow.xib @@ -1,8 +1,8 @@ - + - + diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.h b/MasterPassword/ObjC/Mac/MPPasswordWindowController.h index 90e94019..29613088 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.h +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.h @@ -28,6 +28,7 @@ @property(nonatomic) NSString *masterPassword; @property(nonatomic) BOOL showVersionContainer; @property(nonatomic) BOOL alternatePressed; +@property(nonatomic) BOOL shiftPressed; @property(nonatomic) BOOL locked; @property(nonatomic) BOOL newUser; diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m index 37dd0c82..e6d9410d 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m @@ -124,6 +124,10 @@ - (void)flagsChanged:(NSEvent *)theEvent { + BOOL shiftPressed = (theEvent.modifierFlags & NSShiftKeyMask) != 0; + if (shiftPressed != self.shiftPressed) + self.shiftPressed = shiftPressed; + BOOL alternatePressed = (theEvent.modifierFlags & NSAlternateKeyMask) != 0; if (alternatePressed != self.alternatePressed) { self.alternatePressed = alternatePressed; @@ -486,7 +490,7 @@ } // Performing action while content is available. Copy it. - [self copyContent:selectedSite.content]; + [self copyContent:self.shiftPressed? selectedSite.answer: selectedSite.content]; [self fadeOut]; diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib b/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib index 857e5018..5881bcc3 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib @@ -1,8 +1,8 @@ - + - + @@ -28,10 +28,10 @@ - + - + @@ -55,19 +55,16 @@ - - + - @@ -101,7 +97,6 @@ - @@ -137,7 +132,6 @@ - @@ -173,7 +167,6 @@