From fa21a9d8f3d43826efa6e9855d078a8b79413710 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 26 Nov 2017 21:09:53 +0100 Subject: [PATCH] iOS: Add initial parts of support for key files --- LegacyPasswordGenerator.h | 2 +- LegacyPasswordGenerator.m | 12 ++-- NewPasswordGenerator.h | 2 +- NewPasswordGenerator.m | 12 ++-- PasswordGenerator.h | 2 +- ScryptPWGen.m | 16 ++--- iOS/AddSiteController.h | 3 +- iOS/AddSiteController.m | 28 +++++++- iOS/Base.lproj/Main.storyboard | 114 ++++++++++++++++++++++++------- iOS/ShowDetailsController.h | 2 + iOS/ShowDetailsController.m | 6 +- iOS/SiteStorage.h | 6 +- iOS/SiteStorage.m | 120 ++++++++++++++++++++------------- 13 files changed, 226 insertions(+), 99 deletions(-) diff --git a/LegacyPasswordGenerator.h b/LegacyPasswordGenerator.h index 5cfbc22..5d02283 100644 --- a/LegacyPasswordGenerator.h +++ b/LegacyPasswordGenerator.h @@ -26,7 +26,7 @@ { size_t _length; OFString *_site; - OFData *_keyfile; + OFData *_keyFile; const char *_passphrase; unsigned char *_output; } diff --git a/LegacyPasswordGenerator.m b/LegacyPasswordGenerator.m index 4a92798..1f9af24 100644 --- a/LegacyPasswordGenerator.m +++ b/LegacyPasswordGenerator.m @@ -23,7 +23,7 @@ #import "LegacyPasswordGenerator.h" @implementation LegacyPasswordGenerator -@synthesize site = _site, keyfile = _keyfile, passphrase = _passphrase; +@synthesize site = _site, keyFile = _keyFile, passphrase = _passphrase; @synthesize output = _output; + (instancetype)generator @@ -70,11 +70,11 @@ _output = [self allocMemoryWithSize: _length + 1]; passphraseLength = combinedPassphraseLength = strlen(_passphrase); - if (_keyfile != nil) { - if (SIZE_MAX - combinedPassphraseLength < _keyfile.count) + if (_keyFile != nil) { + if (SIZE_MAX - combinedPassphraseLength < _keyFile.count) @throw [OFOutOfRangeException exception]; - combinedPassphraseLength += _keyfile.count; + combinedPassphraseLength += _keyFile.count; } if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL) @@ -83,9 +83,9 @@ @try { memcpy(combinedPassphrase, _passphrase, passphraseLength); - if (_keyfile != nil) + if (_keyFile != nil) memcpy(combinedPassphrase + passphraseLength, - _keyfile.items, _keyfile.count); + _keyFile.items, _keyFile.count); of_scrypt(8, 524288, 2, siteHash.digest, [siteHash.class digestSize], combinedPassphrase, diff --git a/NewPasswordGenerator.h b/NewPasswordGenerator.h index 6b89997..aa8781e 100644 --- a/NewPasswordGenerator.h +++ b/NewPasswordGenerator.h @@ -26,7 +26,7 @@ { size_t _length; OFString *_site; - OFData *_keyfile; + OFData *_keyFile; const char *_passphrase; unsigned char *_output; } diff --git a/NewPasswordGenerator.m b/NewPasswordGenerator.m index 66d132e..9771df8 100644 --- a/NewPasswordGenerator.m +++ b/NewPasswordGenerator.m @@ -23,7 +23,7 @@ #import "NewPasswordGenerator.h" @implementation NewPasswordGenerator -@synthesize length = _length, site = _site, keyfile = _keyfile; +@synthesize length = _length, site = _site, keyFile = _keyFile; @synthesize passphrase = _passphrase, output = _output; + (instancetype)generator @@ -57,11 +57,11 @@ _output = [self allocMemoryWithSize: _length + 1]; passphraseLength = combinedPassphraseLength = strlen(_passphrase); - if (_keyfile != nil) { - if (SIZE_MAX - combinedPassphraseLength < _keyfile.count) + if (_keyFile != nil) { + if (SIZE_MAX - combinedPassphraseLength < _keyFile.count) @throw [OFOutOfRangeException exception]; - combinedPassphraseLength += _keyfile.count; + combinedPassphraseLength += _keyFile.count; } if ((combinedPassphrase = malloc(combinedPassphraseLength)) == NULL) @@ -70,9 +70,9 @@ @try { memcpy(combinedPassphrase, _passphrase, passphraseLength); - if (_keyfile != nil) + if (_keyFile != nil) memcpy(combinedPassphrase + passphraseLength, - _keyfile.items, _keyfile.count); + _keyFile.items, _keyFile.count); of_scrypt(8, 524288, 2, siteHash.digest, [siteHash.class digestSize], combinedPassphrase, diff --git a/PasswordGenerator.h b/PasswordGenerator.h index e03d57f..bb8865e 100644 --- a/PasswordGenerator.h +++ b/PasswordGenerator.h @@ -25,7 +25,7 @@ @protocol PasswordGenerator @property (nonatomic) size_t length; @property (copy, nonatomic) OFString *site; -@property (retain, nonatomic) OFData *keyfile; +@property (retain, nonatomic) OFData *keyFile; @property (nonatomic) const char *passphrase; @property (readonly, nonatomic) unsigned char *output; diff --git a/ScryptPWGen.m b/ScryptPWGen.m index e316b9f..5aa889f 100644 --- a/ScryptPWGen.m +++ b/ScryptPWGen.m @@ -49,10 +49,10 @@ showHelp(OFStream *output, bool verbose) @implementation ScryptPWGen - (void)applicationDidFinishLaunching { - OFString *keyfilePath, *lengthString; + OFString *keyFilePath, *lengthString; const of_options_parser_option_t options[] = { { 'h', @"help", 0, NULL, NULL }, - { 'k', @"keyfile", 1, NULL, &keyfilePath }, + { 'k', @"keyfile", 1, NULL, &keyFilePath }, { 'l', @"length", 1, NULL, &lengthString }, { 'L', @"legacy", 0, &_legacy, NULL }, { 'r', @"repeat", 0, &_repeat, NULL }, @@ -61,7 +61,7 @@ showHelp(OFStream *output, bool verbose) OFOptionsParser *optionsParser = [OFOptionsParser parserWithOptions: options]; of_unichar_t option; - OFMutableData *keyfile = nil; + OFMutableData *keyFile = nil; OFString *prompt; const char *promptCString; char *passphrase; @@ -140,8 +140,8 @@ showHelp(OFStream *output, bool verbose) generator.site]; promptCString = [prompt cStringWithEncoding: [OFLocalization encoding]]; - if (keyfilePath != nil) - keyfile = [OFMutableData dataWithContentsOfFile: keyfilePath]; + if (keyFilePath != nil) + keyFile = [OFMutableData dataWithContentsOfFile: keyFilePath]; passphrase = getpass(promptCString); @try { @@ -173,7 +173,7 @@ showHelp(OFStream *output, bool verbose) } } - generator.keyfile = keyfile; + generator.keyFile = keyFile; generator.passphrase = passphrase; [generator derivePassword]; @@ -189,8 +189,8 @@ showHelp(OFStream *output, bool verbose) } @finally { of_explicit_memset(passphrase, 0, strlen(passphrase)); - if (keyfile != nil) - of_explicit_memset(keyfile.items, 0, keyfile.count); + if (keyFile != nil) + of_explicit_memset(keyFile.items, 0, keyFile.count); } [OFApplication terminate]; diff --git a/iOS/AddSiteController.h b/iOS/AddSiteController.h index a8fb671..33d0782 100644 --- a/iOS/AddSiteController.h +++ b/iOS/AddSiteController.h @@ -24,10 +24,11 @@ #import "MainViewController.h" -@interface AddSiteController: UITableViewController +@interface AddSiteController: UITableViewController @property (nonatomic, retain) IBOutlet UITextField *nameField; @property (nonatomic, retain) IBOutlet UITextField *lengthField; @property (nonatomic, retain) IBOutlet UISwitch *legacySwitch; +@property (nonatomic, retain) IBOutlet UILabel *keyFileLabel; @property (retain) MainViewController *mainViewController; - (IBAction)done: (id)sender; diff --git a/iOS/AddSiteController.m b/iOS/AddSiteController.m index acbaf0f..689fd7e 100644 --- a/iOS/AddSiteController.m +++ b/iOS/AddSiteController.m @@ -47,11 +47,36 @@ showAlert(UIViewController *controller, NSString *title, NSString *message) [_nameField release]; [_lengthField release]; [_legacySwitch release]; + [_keyFileLabel release]; [_mainViewController release]; [super dealloc]; } +- (void)tableView: (UITableView *)tableView + didSelectRowAtIndexPath: (NSIndexPath *)indexPath +{ + [tableView deselectRowAtIndexPath: indexPath + animated: YES]; + + if (indexPath.section == 1 && indexPath.row == 1) + [self selectKeyFile]; +} + +- (NSIndexPath *)tableView: (UITableView *)tableView + willSelectRowAtIndexPath: (NSIndexPath *)indexPath +{ + if (indexPath.section == 1 && indexPath.row == 1) + return indexPath; + + return nil; +} + +- (void)selectKeyFile +{ + showAlert(self, @"Not Supported", @"Key files are not supported yet"); +} + - (IBAction)done: (id)sender { OFString *name = self.nameField.text.OFObject; @@ -87,7 +112,8 @@ showAlert(UIViewController *controller, NSString *title, NSString *message) [self.mainViewController.siteStorage setSite: name length: length - legacy: self.legacySwitch.on]; + legacy: self.legacySwitch.on + keyFile: nil]; [self.mainViewController reset]; [self.navigationController popViewControllerAnimated: YES]; diff --git a/iOS/Base.lproj/Main.storyboard b/iOS/Base.lproj/Main.storyboard index 4786838..f38802b 100644 --- a/iOS/Base.lproj/Main.storyboard +++ b/iOS/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -131,7 +131,7 @@ - + @@ -146,7 +146,7 @@ - + @@ -178,7 +178,7 @@ - + @@ -214,7 +214,7 @@ - + @@ -234,12 +234,44 @@ + + + + + + + + + + + + + + + + + + + - + @@ -257,6 +289,7 @@ + @@ -267,7 +300,7 @@ - + @@ -288,7 +321,7 @@ - + @@ -320,7 +353,7 @@ - + @@ -356,7 +389,7 @@ - + @@ -376,19 +409,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -420,14 +485,14 @@ - + - +