From c7dba730abf38e31d38dec1028d9844e0724e707 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Sep 2016 12:30:39 -0400 Subject: Added --name and --othername options. --- CHANGELOG | 1 + CmdLine.hs | 19 +++++++++++++++++-- TODO | 1 - keysafe.hs | 48 ++++++++++++++++++++++++++++-------------------- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c9cbc1f..39adc60 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ keysafe (0.20160832) UNRELEASED; urgency=medium * Fix bug that prevented keysafe --server from running when there was no controlling terminal and zenity was not installed. + * Added --name and --othername options. -- Joey Hess Thu, 01 Sep 2016 11:42:27 -0400 diff --git a/CmdLine.hs b/CmdLine.hs index 05ba7da..c3b8256 100644 --- a/CmdLine.hs +++ b/CmdLine.hs @@ -23,6 +23,8 @@ data CmdLine = CmdLine , testMode :: Bool , customShareParams :: Maybe ShareParams , serverConfig :: ServerConfig + , name :: Maybe Name + , othername :: Maybe Name } data Mode = Backup | Restore | UploadQueued | Server | Benchmark | Test @@ -38,11 +40,13 @@ parse = CmdLine <$> optional (backup <|> restore <|> uploadqueued <|> server <|> benchmark <|> test) <*> optional (gpgswitch <|> fileswitch) <*> localstorageswitch - <*> localstoragedirectory + <*> localstoragedirectoryopt <*> guiswitch <*> testmodeswitch <*> optional (ShareParams <$> totalobjects <*> neededobjects) <*> serverconfig + <*> nameopt + <*> othernameopt where backup = flag' Backup ( long "backup" @@ -82,7 +86,7 @@ parse = CmdLine ( long "store-local" <> help "Store data locally. (The default is to store data in the cloud.)" ) - localstoragedirectory = optional $ LocalStorageDirectory <$> option str + localstoragedirectoryopt = optional $ LocalStorageDirectory <$> option str ( long "store-directory" <> metavar "DIR" <> help "Where to store data locally. (default: ~/.keysafe/objects/)" @@ -120,6 +124,17 @@ parse = CmdLine <> showDefault <> help "Address for server to bind to. (Use \"*\" to bind to all addresses.)" ) + nameopt = optional $ Name . BU8.fromString <$> strOption + ( long "name" + <> metavar "N" + <> help "Specify name used for key backup/restore, avoiding the usual prompt." + ) + othernameopt = optional $ Name . BU8.fromString <$> strOption + ( long "othername" + <> metavar "N" + <> help "Specify other name used for key backup/restore, avoiding the usual prompt." + ) + get :: IO CmdLine get = execParser opts where diff --git a/TODO b/TODO index b5a601f..de71f3b 100644 --- a/TODO +++ b/TODO @@ -4,7 +4,6 @@ Soon: * Add some random padding to http requests and responses, to make it harder for traffic analysis to tell that it's keysafe traffic. * Implement the different categories of servers in the server list. -* Include an example tor hidden service config * Get some keysafe servers set up. * Keep a local record of keys that have been backed up, and the tunables and password entropy. This will allow warning later if the crack estimate diff --git a/keysafe.hs b/keysafe.hs index f78168b..569e678 100644 --- a/keysafe.hs +++ b/keysafe.hs @@ -53,15 +53,15 @@ dispatch cmdline ui storagelocations tunables possibletunables = do go mode (CmdLine.secretkeysource cmdline) where go CmdLine.Backup (Just secretkeysource) = - backup storagelocations ui tunables secretkeysource + backup cmdline storagelocations ui tunables secretkeysource =<< getSecretKey secretkeysource go CmdLine.Restore (Just secretkeydest) = - restore storagelocations ui possibletunables secretkeydest + restore cmdline storagelocations ui possibletunables secretkeydest go CmdLine.Backup Nothing = - backup storagelocations ui tunables Gpg.anyKey + backup cmdline storagelocations ui tunables Gpg.anyKey =<< Gpg.getKeyToBackup ui go CmdLine.Restore Nothing = - restore storagelocations ui possibletunables Gpg.anyKey + restore cmdline storagelocations ui possibletunables Gpg.anyKey go CmdLine.UploadQueued _ = uploadQueued (CmdLine.localstoragedirectory cmdline) go (CmdLine.Server) _ = @@ -74,19 +74,23 @@ dispatch cmdline ui storagelocations tunables possibletunables = do go CmdLine.Test _ = runTests -backup :: StorageLocations -> UI -> Tunables -> SecretKeySource -> SecretKey -> IO () -backup storagelocations ui tunables secretkeysource secretkey = do +backup :: CmdLine.CmdLine -> StorageLocations -> UI -> Tunables -> SecretKeySource -> SecretKey -> IO () +backup cmdline storagelocations ui tunables secretkeysource secretkey = do username <- userName - Name theirname <- fromMaybe (error "Aborting on no username") - <$> promptName ui "Enter your name" - usernamedesc (Just username) validateName + Name theirname <- case CmdLine.name cmdline of + Just n -> pure n + Nothing -> fromMaybe (error "Aborting on no username") + <$> promptName ui "Enter your name" + usernamedesc (Just username) validateName go theirname where go theirname = do cores <- fromMaybe 1 <$> getNumCores - Name othername <- fromMaybe (error "aborting on no othername") - <$> promptName ui "Enter other name" - othernamedesc Nothing validateName + Name othername <- case CmdLine.name cmdline of + Just n -> pure n + Nothing -> fromMaybe (error "aborting on no othername") + <$> promptName ui "Enter other name" + othernamedesc Nothing validateName let name = Name (theirname <> " " <> othername) kek <- promptkek name let sis = shareIdents tunables name secretkeysource @@ -184,16 +188,20 @@ otherNameSuggestions = unlines $ map (" * " ++) , "A place you like to visit." ] -restore :: StorageLocations -> UI -> [Tunables] -> SecretKeySource -> IO () -restore storagelocations ui possibletunables secretkeydest = do +restore :: CmdLine.CmdLine -> StorageLocations -> UI -> [Tunables] -> SecretKeySource -> IO () +restore cmdline storagelocations ui possibletunables secretkeydest = do cores <- fromMaybe 1 <$> getNumCores username <- userName - Name theirname <- fromMaybe (error "Aborting on no username") - <$> promptName ui "Enter your name" - namedesc (Just username) validateName - Name othername <- fromMaybe (error "aborting on no othername") - <$> promptName ui "Enter other name" - othernamedesc Nothing validateName + Name theirname <- case CmdLine.name cmdline of + Just n -> pure n + Nothing -> fromMaybe (error "Aborting on no username") + <$> promptName ui "Enter your name" + namedesc (Just username) validateName + Name othername <- case CmdLine.name cmdline of + Just n -> pure n + Nothing -> fromMaybe (error "aborting on no othername") + <$> promptName ui "Enter other name" + othernamedesc Nothing validateName let name = Name (theirname <> " " <> othername) password <- fromMaybe (error "Aborting on no password") <$> promptPassword ui True "Enter password" passworddesc -- cgit v1.2.3