From a774bc8d566c55564d008863b3c1be7d03a9fdde Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 18 Aug 2016 17:06:51 -0400 Subject: minor prompt flow --- keysafe.hs | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'keysafe.hs') diff --git a/keysafe.hs b/keysafe.hs index 919150b..93efa63 100644 --- a/keysafe.hs +++ b/keysafe.hs @@ -70,32 +70,34 @@ backup storagelocations ui tunables secretkeysource secretkey = do Name theirname <- fromMaybe (error "Aborting on no username") <$> promptName ui "Enter your name" usernamedesc (Just username) validateName - Name othername <- fromMaybe (error "aborting on no othername") - <$> promptName ui "Enter other name" - othernamedesc Nothing validateName - let name = Name (theirname <> " " <> othername) - kek <- promptkek name - let sis = shardIdents tunables name secretkeysource - let cost = getCreationCost kek <> getCreationCost sis - r <- withProgress ui "Encrypting and storing data" - (encryptdesc cost) $ \setpercent -> do - let esk = encrypt tunables kek secretkey - shards <- genShards esk tunables - _ <- esk `deepseq` setpercent 25 - _ <- sis `deepseq` setpercent 50 - let step = 50 `div` length shards - let percentsteps = map setpercent [50+step, 50+step*2..100] - storeShards storagelocations sis (zip percentsteps shards) - case r of - StoreSuccess -> showInfo ui "Success" "Your secret key successfully encrypted and backed up." - StoreFailure s -> showError ui ("There was a problem storing your encrypted secret key: " ++ s) - StoreAlreadyExists -> do - showError ui $ unlines - [ "Another secret key is already being stored under the name you entered." - , "Please try again with a different name." - ] - backup storagelocations ui tunables secretkeysource secretkey + go theirname where + go theirname = do + Name othername <- fromMaybe (error "aborting on no othername") + <$> promptName ui "Enter other name" + othernamedesc Nothing validateName + let name = Name (theirname <> " " <> othername) + kek <- promptkek name + let sis = shardIdents tunables name secretkeysource + let cost = getCreationCost kek <> getCreationCost sis + r <- withProgress ui "Encrypting and storing data" + (encryptdesc cost) $ \setpercent -> do + let esk = encrypt tunables kek secretkey + shards <- genShards esk tunables + _ <- esk `deepseq` setpercent 25 + _ <- sis `deepseq` setpercent 50 + let step = 50 `div` length shards + let percentsteps = map setpercent [50+step, 50+step*2..100] + storeShards storagelocations sis (zip percentsteps shards) + case r of + StoreSuccess -> showInfo ui "Success" "Your secret key successfully encrypted and backed up." + StoreFailure s -> showError ui ("There was a problem storing your encrypted secret key: " ++ s) + StoreAlreadyExists -> do + showError ui $ unlines + [ "Another secret key is already being stored under the name you entered." + , "Please try again with a different name." + ] + go theirname promptkek name = do password <- fromMaybe (error "Aborting on no password") <$> promptPassword ui True "Enter password" passworddesc @@ -137,9 +139,11 @@ backup storagelocations ui tunables secretkeysource secretkey = do , "the backup of your " ++ keydesc ++ "." , "" , "Some suggestions:" + , "" , otherNameSuggestions , "" - , "Make sure to pick a name you will remember later." + , "Make sure to pick a name you will remember later," + , "when you restore your " ++ keydesc ++ "." ] passworddesc = unlines [ "Pick a password that will be used to protect your secret key." @@ -167,6 +171,7 @@ otherNameSuggestions = unlines $ map (" * " ++) , "Your first pet." , "Your favorite teacher." , "Your college roomate." + , "A place you like to visit." ] restore :: StorageLocations -> UI -> [Tunables] -> SecretKeySource -> IO () -- cgit v1.2.3