From 1c76e50192502556d3fe785748e0b8c22c069629 Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Tue, 1 Dec 2020 13:38:34 +0100 Subject: [PATCH] Adopted KeePassKit attribute keys and stripped our custom ones --- Cartfile | 2 +- Cartfile.resolved | 2 +- MacPass/KPKEntry+OTP.h | 6 -- MacPass/KPKEntry+OTP.m | 12 +--- MacPass/MPAddCustomFieldContextMenuDelegate.m | 64 ++++--------------- 5 files changed, 19 insertions(+), 67 deletions(-) diff --git a/Cartfile b/Cartfile index 99e78eb8..c59bcb5e 100644 --- a/Cartfile +++ b/Cartfile @@ -1,4 +1,4 @@ github "sparkle-project/Sparkle" ~> 1.22 github "mattt/TransformerKit" ~> 1.1.1 -github "MacPass/KeePassKit" "958637c267d29d4db59773d215d08e52b18442c0" +github "MacPass/KeePassKit" "27cd293a067aa99de0874a33ef0d10dd27c6d08c" github "mstarke/HNHUi" ~> 4.0 diff --git a/Cartfile.resolved b/Cartfile.resolved index 6875c82d..230f8db6 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,4 +1,4 @@ -github "MacPass/KeePassKit" "958637c267d29d4db59773d215d08e52b18442c0" +github "MacPass/KeePassKit" "27cd293a067aa99de0874a33ef0d10dd27c6d08c" github "mattt/TransformerKit" "1.1.1" github "mstarke/HNHUi" "4.0.2" github "robbiehanson/KissXML" "5.3.2" diff --git a/MacPass/KPKEntry+OTP.h b/MacPass/KPKEntry+OTP.h index a5d5de92..c465ed8c 100644 --- a/MacPass/KPKEntry+OTP.h +++ b/MacPass/KPKEntry+OTP.h @@ -10,12 +10,6 @@ NS_ASSUME_NONNULL_BEGIN -FOUNDATION_EXTERN NSString *const MPHMACOTPSeedAttributeKey; -FOUNDATION_EXTERN NSString *const MPHMACOTPConfigAttributeKey; -FOUNDATION_EXTERN NSString *const MPTOTPAuthAttributeKey; -FOUNDATION_EXTERN NSString *const MPTOTPSeedAttributeKey; -FOUNDATION_EXTERN NSString *const MPTOTPConfigAttributeKey; - @interface KPKEntry (OTP) @property (readonly, assign, nonatomic) BOOL hasTOTP; diff --git a/MacPass/KPKEntry+OTP.m b/MacPass/KPKEntry+OTP.m index c23a5d4c..e19011bb 100644 --- a/MacPass/KPKEntry+OTP.m +++ b/MacPass/KPKEntry+OTP.m @@ -10,20 +10,14 @@ @implementation KPKEntry (OTP) -NSString *const MPHMACOTPSeedAttributeKey = @"HMACOTP-Seed"; -NSString *const MPHMACOTPConfigAttributeKey = @"HMACOTP-Config"; -NSString *const MPTOTPAuthAttributeKey = @"otp"; -NSString *const MPTOTPSeedAttributeKey = @"TOTP Seed"; -NSString *const MPTOTPConfigAttributeKey = @"OTP Settings"; - + (NSSet *)keyPathsForValuesAffectingHasTOTP { return [NSSet setWithObject:NSStringFromSelector(@selector(attributes))]; } - (BOOL)hasTOTP { - BOOL hasURLKey = [self hasAttributeWithKey:MPTOTPAuthAttributeKey]; - BOOL hasSeedKey = [self hasAttributeWithKey:MPTOTPSeedAttributeKey]; - BOOL hasSettingsKey = [self hasAttributeWithKey:MPTOTPConfigAttributeKey]; + BOOL hasURLKey = [self hasAttributeWithKey:kKPKAttributeKeyOTPOAuthURL]; + BOOL hasSeedKey = [self hasAttributeWithKey:kKPKAttributeKeyTimeOTPSeed]; + BOOL hasSettingsKey = [self hasAttributeWithKey:kKPKAttributeKeyTimeOTPSettings]; return(hasURLKey || (hasSeedKey && hasSettingsKey)); } diff --git a/MacPass/MPAddCustomFieldContextMenuDelegate.m b/MacPass/MPAddCustomFieldContextMenuDelegate.m index 5fe042f6..97983a2d 100644 --- a/MacPass/MPAddCustomFieldContextMenuDelegate.m +++ b/MacPass/MPAddCustomFieldContextMenuDelegate.m @@ -26,13 +26,13 @@ #import "KPKEntry+OTP.h" /* -HmacOtp-Secret (the UTF-8 representation of the value is the secret), -HmacOtp-Secret-Hex (secret as hex string), -HmacOtp-Secret-Base32 (secret as Base32 string) -HmacOtp-Secret-Base64 (secret as Base64 string) + HmacOtp-Secret (the UTF-8 representation of the value is the secret), + HmacOtp-Secret-Hex (secret as hex string), + HmacOtp-Secret-Base32 (secret as Base32 string) + HmacOtp-Secret-Base64 (secret as Base64 string) -HmacOtp-Counter field. -*/ + HmacOtp-Counter field. + */ @interface MPAddCustomFieldContextMenuDelegate () @property (readonly, nonatomic) KPKEntry *entry; @@ -56,59 +56,23 @@ HmacOtp-Counter field. /* HMAC OTP */ - (void)_setupHOTPMenuItemsToMenu:(NSMenu *)menu { - BOOL hasConfigAttribute = nil != [self.entry customAttributeWithKey:MPHMACOTPConfigAttributeKey]; - if(!hasConfigAttribute) { - NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"ADD_CUSTOM_ATTRIBUTE_HMACOTP_CONFIG", @"Menu item title for adding an hmacotp config attribute") action:@selector(_addHMACConfig:) keyEquivalent:@""]; - item.target = self; - [menu addItem:item]; - } - BOOL hasSeedAttribute = nil != [self.entry customAttributeWithKey:MPHMACOTPSeedAttributeKey]; - if(!hasSeedAttribute) { - NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"ADD_CUSTOM_ATTRIBUTE_HMACOTP_SEED", @"Menu item title for adding an hmacotp seed attribute") action:@selector(_addHMACSeed:) keyEquivalent:@""]; - item.target = self; - [menu addItem:item]; - } + } -- (IBAction)_setupHMACConfig:(id)sender {} -- (IBAction)_delteHMACConfig:(id)sender {} - -- (IBAction)_addHMACConfig:(id)sender { - [self.entry addCustomAttribute:[[KPKAttribute alloc] initWithKey:MPHMACOTPConfigAttributeKey value:@""]]; +- (IBAction)_setupHMACConfig:(id)sender { + } - -- (IBAction)_addHMACSeed:(id)sender { - [self.entry addCustomAttribute:[[KPKAttribute alloc] initWithKey:MPHMACOTPSeedAttributeKey value:@""]]; +- (IBAction)_delteHMACConfig:(id)sender { + } /* Time OPT*/ - (void)_setupTOTPMenuItemsToMenu:(NSMenu *)menu { - BOOL hasTOTPAuthAttribute = nil != [self.entry customAttributeWithKey:MPTOTPAuthAttributeKey]; - BOOL hasTOTPSeedAttribute = nil != [self.entry customAttributeWithKey:MPTOTPSeedAttributeKey]; - BOOL hasTOTPSettingsAttribute = nil != [self.entry customAttributeWithKey:MPTOTPSeedAttributeKey]; - - - BOOL hasValidSettings = hasTOTPAuthAttribute || (hasTOTPSeedAttribute && hasTOTPSettingsAttribute); - if(hasValidSettings) { - // Edit - NSMenuItem *editItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"EDIT_TOTP_SETTINGS", @"Menu item title editing TOTP settings") action:@selector(_editTOTPSettings:) keyEquivalent:@""]; - editItem.target = self; - [menu addItem:editItem]; - // Delete - NSMenuItem *deleteItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DELETE_TOTP_SETTINGS", @"Menu item title for deleting TOTP settings") action:@selector(_deleteTOTPSettings:) keyEquivalent:@""]; - deleteItem.target = self; - [menu addItem:deleteItem]; - } - else { - // Setup - NSMenuItem *setupItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SETUP_TOTP_SETTINGS", @"Menu item title editing TOTP settings") action:@selector(_setupTOTPSettings:) keyEquivalent:@""]; - setupItem.target = self; - [menu addItem:setupItem]; - - } + NSMenuItem *setupItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"SETUP_TOTP_SETTINGS", @"Menu item title editing TOTP settings") action:@selector(_setupTOTPSettings:) keyEquivalent:@""]; + setupItem.target = self; + [menu addItem:setupItem]; } - (IBAction)_setupTOTPSettings:(id)sender {} -- (IBAction)_editTOTPSettings:(id)sender {} - (IBAction)_deleteTOTPSettings:(id)sender {} @end