summaryrefslogtreecommitdiffhomepage
path: root/keysafe.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-18 17:06:51 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-18 17:06:51 -0400
commita774bc8d566c55564d008863b3c1be7d03a9fdde (patch)
treebc0df96863a8e1412770ead88344c130c19fe7b7 /keysafe.hs
parent845289fdd8fbbed2cbc7eaf7a3d31efe5a8aa80d (diff)
downloadkeysafe-a774bc8d566c55564d008863b3c1be7d03a9fdde.tar.gz
minor prompt flow
Diffstat (limited to 'keysafe.hs')
-rw-r--r--keysafe.hs57
1 files changed, 31 insertions, 26 deletions
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 ()