From 4ce5fd25bcb2a4a67ae443d0b99066e8a568c401 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Mon, 29 Dec 2014 16:35:23 -0500 Subject: [PATCH] Allow importing without a KeyID, fix a possible deadlock and fix showing error messages + replace light font with regular on non-retina. --- External/Pearl | 2 +- MasterPassword/ObjC/MPAlgorithmV0.m | 2 ++ MasterPassword/ObjC/MPAppDelegate_Store.m | 9 +++---- MasterPassword/ObjC/Mac/MPMacAppDelegate.m | 13 +++++----- .../ObjC/Mac/MPPasswordWindowController.m | 25 +++++++++++++++++-- .../ObjC/Mac/MPPasswordWindowController.xib | 8 +++--- .../project.pbxproj | 24 ++++++++++++++++++ MasterPassword/ObjC/Pearl/Pearl-Prefix.pch | 6 +++++ 8 files changed, 71 insertions(+), 18 deletions(-) diff --git a/External/Pearl b/External/Pearl index 8c646abd..6abdab71 160000 --- a/External/Pearl +++ b/External/Pearl @@ -1 +1 @@ -Subproject commit 8c646abdaecb81c7131c8fe5d334c88171896ead +Subproject commit 6abdab7168dc72cbc78df36577ca40f507eecfe0 diff --git a/MasterPassword/ObjC/MPAlgorithmV0.m b/MasterPassword/ObjC/MPAlgorithmV0.m index f5bd4be5..6207f81e 100644 --- a/MasterPassword/ObjC/MPAlgorithmV0.m +++ b/MasterPassword/ObjC/MPAlgorithmV0.m @@ -793,6 +793,8 @@ - (NSString *)decryptContent:(NSData *)encryptedContent usingKey:(MPKey *)key { + if (!key) + return nil; NSData *decryptedContent = nil; if ([encryptedContent length]) decryptedContent = [encryptedContent decryptWithSymmetricKey:[key subKeyOfLength:PearlCryptKeySize].keyData padding:YES]; diff --git a/MasterPassword/ObjC/MPAppDelegate_Store.m b/MasterPassword/ObjC/MPAppDelegate_Store.m index cb7a7074..ca44a589 100644 --- a/MasterPassword/ObjC/MPAppDelegate_Store.m +++ b/MasterPassword/ObjC/MPAppDelegate_Store.m @@ -611,7 +611,7 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted ); } if (!headerEnded) continue; - if (!importKeyID || ![importUserName length]) + if (![importUserName length]) return MPImportResultMalformedInput; if (![importedSiteLine length]) continue; @@ -689,12 +689,11 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted ); if (user && ![userKey.keyID isEqualToData:user.keyID]) return MPImportResultInvalidPassword; __block MPKey *importKey = userKey; - if (![importKey.keyID isEqualToData:importKeyID]) + if (importKeyID && ![importKey.keyID isEqualToData:importKeyID]) importKey = [importAlgorithm keyForPassword:askImportPassword( importUserName ) ofUserNamed:importUserName]; - if (![importKey.keyID isEqualToData:importKeyID]) + if (importKeyID && ![importKey.keyID isEqualToData:importKeyID]) return MPImportResultInvalidPassword; - // Delete existing sites. if (sitesToDelete.count) [sitesToDelete enumerateObjectsUsingBlock:^(id obj, BOOL *stop) { @@ -711,7 +710,7 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted ); else { user = [MPUserEntity insertNewObjectInContext:context]; user.name = importUserName; - user.keyID = importKeyID; + user.keyID = [userKey keyID]; if (importAvatar != NSNotFound) user.avatar = importAvatar; dbg( @"Created User: %@", [user debugDescription] ); diff --git a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m index 27a6079d..78db532e 100644 --- a/MasterPassword/ObjC/Mac/MPMacAppDelegate.m +++ b/MasterPassword/ObjC/Mac/MPMacAppDelegate.m @@ -224,6 +224,7 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven return; NSURL *url = openPanel.URL; + [openPanel close]; PearlNotMainQueue( ^{ NSError *error; @@ -285,19 +286,19 @@ static OSStatus MPHotKeyHander(EventHandlerCallRef nextHandler, EventRef theEven case MPImportResultCancelled: break; case MPImportResultInternalError: - [NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ + [[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ NSLocalizedDescriptionKey : @"Import failed because of an internal error." - }]]; + }]] runModal]; break; case MPImportResultMalformedInput: - [NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ + [[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ NSLocalizedDescriptionKey : @"The import doesn't look like a Master Password export." - }]]; + }]] runModal]; break; case MPImportResultInvalidPassword: - [NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ + [[NSAlert alertWithError:[NSError errorWithDomain:MPErrorDomain code:0 userInfo:@{ NSLocalizedDescriptionKey : @"Incorrect master password for the import sites." - }]]; + }]] runModal]; break; } } ); diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m index 90447278..8371c4f8 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.m +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.m @@ -44,6 +44,8 @@ [super windowDidLoad]; + [self replaceFonts:self.window.contentView]; + // [[NSNotificationCenter defaultCenter] addObserverForName:NSApplicationWillBecomeActiveNotification object:nil // queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { // [self fadeIn]; @@ -95,6 +97,20 @@ self.siteTable.controller = self; } +- (void)replaceFonts:(NSView *)view { + + if (view.window.backingScaleFactor == 1) + [view enumerateViews:^(NSView *subview, BOOL *stop, BOOL *recurse) { + if ([subview respondsToSelector:@selector( setFont: )]) { + NSFont *font = [(id)subview font]; + if ([font.fontName isEqualToString:@"HelveticaNeue-Thin"]) + [(id)subview setFont:[NSFont fontWithName:@"HelveticaNeue" matrix:font.matrix]]; + if ([font.fontName isEqualToString:@"HelveticaNeue-Light"]) + [(id)subview setFont:[NSFont fontWithName:@"HelveticaNeue" matrix:font.matrix]]; + } + } recurse:YES]; +} + - (void)flagsChanged:(NSEvent *)theEvent { BOOL alternatePressed = (theEvent.modifierFlags & NSAlternateKeyMask) != 0; @@ -186,6 +202,11 @@ #pragma mark - NSTableViewDelegate +- (void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row { + + [self replaceFonts:rowView]; +} + #pragma mark - NSAlert - (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo { @@ -513,13 +534,13 @@ NSMutableArray *fuzzyGroups = [NSMutableArray new]; [fuzzyRE enumerateMatchesInString:queryString options:0 range:NSMakeRange( 0, queryString.length ) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) { - [fuzzyGroups addObject:[queryString substringWithRange:result.range] ]; + [fuzzyGroups addObject:[queryString substringWithRange:result.range]]; }]; [MPMacAppDelegate managedObjectContextPerformBlockAndWait:^(NSManagedObjectContext *context) { NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPSiteEntity class] )]; fetchRequest.sortDescriptors = @[ [[NSSortDescriptor alloc] initWithKey:@"lastUsed" ascending:NO] ]; fetchRequest.predicate = [NSPredicate predicateWithFormat:@"(%@ == '' OR name LIKE[cd] %@) AND user == %@", - queryPattern, queryPattern, [MPMacAppDelegate get].activeUserOID]; + queryPattern, queryPattern, [MPMacAppDelegate get].activeUserOID]; NSError *error = nil; NSArray *siteResults = [context executeFetchRequest:fetchRequest error:&error]; diff --git a/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib b/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib index f3eea456..1d2ce411 100644 --- a/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib +++ b/MasterPassword/ObjC/Mac/MPPasswordWindowController.xib @@ -1,8 +1,8 @@ - + - + @@ -26,7 +26,7 @@ - + @@ -144,7 +144,7 @@ - + diff --git a/MasterPassword/ObjC/Mac/MasterPassword-Mac.xcodeproj/project.pbxproj b/MasterPassword/ObjC/Mac/MasterPassword-Mac.xcodeproj/project.pbxproj index 6ece4ab7..612469cc 100644 --- a/MasterPassword/ObjC/Mac/MasterPassword-Mac.xcodeproj/project.pbxproj +++ b/MasterPassword/ObjC/Mac/MasterPassword-Mac.xcodeproj/project.pbxproj @@ -8,12 +8,14 @@ /* Begin PBXBuildFile section */ 93D390C676DF52DA7E459F19 /* MPPasswordWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39D9D0061FF1159998F06 /* MPPasswordWindow.m */; }; + 93D391E61DC23E128DA4446C /* NSView+Traversing.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D393EE88DE554BCCBC1C2D /* NSView+Traversing.h */; }; 93D392EC39DA43C46C692C12 /* NSDictionary+Indexing.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D393B97158D7BE9332EA53 /* NSDictionary+Indexing.h */; }; 93D394C4254EEB45FB335AFB /* MPSitesTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39423D7BF4FD31FE6D27C /* MPSitesTableView.m */; }; 93D395E4830290EBB6E71F34 /* MPNoStateButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39538C4CEFF46DF379254 /* MPNoStateButton.m */; }; 93D395F08A087F8A24689347 /* NSArray+Indexing.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39067C0AFDC581794E2B8 /* NSArray+Indexing.m */; }; 93D3970BCF85F7902E611168 /* PearlProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39DB3A8ADED08C39A6228 /* PearlProfiler.m */; }; 93D39784E725A34D1EE3FB3B /* MPInitialWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39D3CB30874147D9A9E1B /* MPInitialWindowController.m */; }; + 93D3987F6D9046DBEE4D8364 /* NSView+Traversing.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D392870DF659AFC1870521 /* NSView+Traversing.m */; }; 93D39C34FE35830EF5BE1D2A /* NSArray+Indexing.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D396D04E57792A54D437AC /* NSArray+Indexing.h */; }; 93D39C5789EFA607CF788082 /* MPSiteModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D39E73BF5CBF8E5B005CD3 /* MPSiteModel.m */; }; 93D39D304F73B3BBA031522A /* PearlProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D394EEFF5BF555A55AF361 /* PearlProfiler.h */; }; @@ -89,6 +91,8 @@ DA6774451A474A3B004F356A /* mpw-types.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6773C21A4746AF004F356A /* mpw-types.c */; }; DA6774461A474A3B004F356A /* mpw-util.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6773C51A4746AF004F356A /* mpw-util.c */; }; DA67744A1A47C8F7004F356A /* mpw-tests-util.c in Sources */ = {isa = PBXBuildFile; fileRef = DA6774481A47C8F7004F356A /* mpw-tests-util.c */; }; + DA89D4EC1A51EABD00AC64D7 /* Pearl-Cocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = DA89D4EA1A51EABD00AC64D7 /* Pearl-Cocoa.h */; }; + DA89D4ED1A51EABD00AC64D7 /* Pearl-Cocoa.m in Sources */ = {isa = PBXBuildFile; fileRef = DA89D4EB1A51EABD00AC64D7 /* Pearl-Cocoa.m */; }; DA8ED895192906920099B726 /* PearlTween.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8ED891192906920099B726 /* PearlTween.m */; }; DA8ED896192906920099B726 /* PearlTween.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8ED892192906920099B726 /* PearlTween.h */; }; DA8ED897192906920099B726 /* map-macro.h in Headers */ = {isa = PBXBuildFile; fileRef = DA8ED894192906920099B726 /* map-macro.h */; }; @@ -259,10 +263,12 @@ /* Begin PBXFileReference section */ 93D39067C0AFDC581794E2B8 /* NSArray+Indexing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Indexing.m"; sourceTree = ""; }; 93D39240B5143E01F0B75E96 /* MPSiteModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPSiteModel.h; sourceTree = ""; }; + 93D392870DF659AFC1870521 /* NSView+Traversing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSView+Traversing.m"; sourceTree = ""; }; 93D392A4F3DE0BD758B9B056 /* MPNoStateButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPNoStateButton.h; sourceTree = ""; }; 93D392C3918763B3B72CF366 /* MPPasswordWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPPasswordWindowController.h; sourceTree = ""; }; 93D39368EF3CBFEF2AFCA15A /* MPInitialWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPInitialWindowController.h; sourceTree = ""; }; 93D393B97158D7BE9332EA53 /* NSDictionary+Indexing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+Indexing.h"; sourceTree = ""; }; + 93D393EE88DE554BCCBC1C2D /* NSView+Traversing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSView+Traversing.h"; sourceTree = ""; }; 93D39423D7BF4FD31FE6D27C /* MPSitesTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPSitesTableView.m; sourceTree = ""; }; 93D394EEFF5BF555A55AF361 /* PearlProfiler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PearlProfiler.h; path = ../../../External/Pearl/Pearl/PearlProfiler.h; sourceTree = ""; }; 93D39538C4CEFF46DF379254 /* MPNoStateButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPNoStateButton.m; sourceTree = ""; }; @@ -783,6 +789,8 @@ DA67743B1A474A03004F356A /* mpw-test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "mpw-test"; sourceTree = BUILT_PRODUCTS_DIR; }; DA6774481A47C8F7004F356A /* mpw-tests-util.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "mpw-tests-util.c"; sourceTree = ""; }; DA6774491A47C8F7004F356A /* mpw-tests-util.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "mpw-tests-util.h"; sourceTree = ""; }; + DA89D4EA1A51EABD00AC64D7 /* Pearl-Cocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Pearl-Cocoa.h"; sourceTree = ""; }; + DA89D4EB1A51EABD00AC64D7 /* Pearl-Cocoa.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Pearl-Cocoa.m"; sourceTree = ""; }; DA8ED891192906920099B726 /* PearlTween.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PearlTween.m; sourceTree = ""; }; DA8ED892192906920099B726 /* PearlTween.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PearlTween.h; sourceTree = ""; }; DA8ED894192906920099B726 /* map-macro.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "map-macro.h"; sourceTree = ""; }; @@ -1551,6 +1559,17 @@ path = ../../C; sourceTree = ""; }; + DA89D4E51A51E53100AC64D7 /* Pearl-Cocoa */ = { + isa = PBXGroup; + children = ( + DA89D4EA1A51EABD00AC64D7 /* Pearl-Cocoa.h */, + DA89D4EB1A51EABD00AC64D7 /* Pearl-Cocoa.m */, + 93D392870DF659AFC1870521 /* NSView+Traversing.m */, + 93D393EE88DE554BCCBC1C2D /* NSView+Traversing.h */, + ); + path = "Pearl-Cocoa"; + sourceTree = ""; + }; DA8ED893192906920099B726 /* include */ = { isa = PBXGroup; children = ( @@ -1572,6 +1591,7 @@ isa = PBXGroup; children = ( DAFE45D715039823003ABA7C /* Pearl */, + DA89D4E51A51E53100AC64D7 /* Pearl-Cocoa */, DAFE45FC15039823003ABA7C /* Pearl-Crypto */, DAC77CB1148291A600BCF976 /* Pearl-Prefix.pch */, ); @@ -1857,6 +1877,7 @@ buildActionMask = 2147483647; files = ( DA10007F1998A4C6002B873F /* scrypt in Headers */, + DA89D4EC1A51EABD00AC64D7 /* Pearl-Cocoa.h in Headers */, DA1000801998A4C6002B873F /* openssl in Headers */, DA2CA4F218D323D3007798F8 /* NSTimer+PearlBlock.h in Headers */, DAFE4A1315039824003ABA7C /* NSObject+PearlExport.h in Headers */, @@ -1894,6 +1915,7 @@ DA2CA4EE18D323D3007798F8 /* NSError+PearlFullDescription.h in Headers */, DAADCC4819FAFFAD00987B1D /* NSPersistentStore+PearlMigration.h in Headers */, 93D39D304F73B3BBA031522A /* PearlProfiler.h in Headers */, + 93D391E61DC23E128DA4446C /* NSView+Traversing.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2281,6 +2303,7 @@ DAFE4A2E15039824003ABA7C /* PearlStrings.m in Sources */, DAFE4A3015039824003ABA7C /* PearlStringUtils.m in Sources */, DAFE4A3515039824003ABA7C /* PearlCryptUtils.m in Sources */, + DA89D4ED1A51EABD00AC64D7 /* Pearl-Cocoa.m in Sources */, DAFE4A3715039824003ABA7C /* PearlKeyChain.m in Sources */, DAFE4A3915039824003ABA7C /* PearlRSAKey.m in Sources */, DAFE4A3B15039824003ABA7C /* PearlSCrypt.m in Sources */, @@ -2298,6 +2321,7 @@ 93D39E281E3658B30550CB55 /* NSDictionary+Indexing.m in Sources */, DA3509FF15F101A500C14A8E /* PearlQueue.m in Sources */, 93D3970BCF85F7902E611168 /* PearlProfiler.m in Sources */, + 93D3987F6D9046DBEE4D8364 /* NSView+Traversing.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/MasterPassword/ObjC/Pearl/Pearl-Prefix.pch b/MasterPassword/ObjC/Pearl/Pearl-Prefix.pch index 2ed598bb..272d59ea 100644 --- a/MasterPassword/ObjC/Pearl/Pearl-Prefix.pch +++ b/MasterPassword/ObjC/Pearl/Pearl-Prefix.pch @@ -13,10 +13,16 @@ #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED #define PEARL_UIKIT #endif +#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED +#define PEARL_COCOA +#endif #import "Pearl.h" #import "Pearl-Crypto.h" #ifdef __IPHONE_OS_VERSION_MIN_REQUIRED #import "Pearl-UIKit.h" #endif +#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED +#import "Pearl-Cocoa.h" +#endif #endif