@@ -1,7 +1,7 @@ /* - * Copyright (c) 2016, Jonathan Schleifer + * Copyright (c) 2016, 2017, Jonathan Schleifer * * https://heap.zone/git/scrypt-pwgen.git * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -183,10 +183,28 @@ else generator = [NewPasswordGenerator generator]; generator.site = _name; generator.length = _length; + + if (_keyFile != nil) { + NSString *documentDirectory; + OFString *keyFilePath; + + if ((documentDirectory = NSSearchPathForDirectoriesInDomains( + NSDocumentDirectory, NSUserDomainMask, YES).firstObject) == + nil) { + NSLog(@"Could not get key files: No documents " + @"directory"); + return; + } + + keyFilePath = [documentDirectory.OFObject + stringByAppendingPathComponent: _keyFile]; + generator.keyFile = [OFMutableData + dataWithContentsOfFile: keyFilePath]; + } passphrase = of_strdup(self.passphraseField.text.UTF8String); generator.passphrase = passphrase; mainStoryboard = [UIStoryboard storyboardWithName: @"Main" @@ -198,10 +216,15 @@ dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { @try { [generator derivePassword]; } @finally { + if (generator.keyFile != nil) + of_explicit_memset( + (void *)generator.keyFile.items, 0, + generator.keyFile.count); + of_explicit_memset(passphrase, 0, strlen(passphrase)); free(passphrase); } NSMutableString *password = [[[NSMutableString alloc]