summaryrefslogtreecommitdiffhomepage
path: root/CmdLine.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-09-23 17:42:45 -0400
committerJoey Hess <joeyh@joeyh.name>2016-09-23 17:42:45 -0400
commit823ebff934cf2e23afae199c24cc599983209438 (patch)
tree7588b3693dcff7f3b773ceb68b01eea989ccf250 /CmdLine.hs
parentc2aa90a92349be09d88270c3ee6d4b7fddbf4768 (diff)
downloadkeysafe-823ebff934cf2e23afae199c24cc599983209438.tar.gz
Added --chaff-max-delay option for slower chaffing.
This commit was sponsored by Jeff Goeke-Smith on Patreon.
Diffstat (limited to 'CmdLine.hs')
-rw-r--r--CmdLine.hs57
1 files changed, 40 insertions, 17 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
index 4011f56..bb68623 100644
--- a/CmdLine.hs
+++ b/CmdLine.hs
@@ -8,6 +8,7 @@ module CmdLine where
import Types
import Types.Storage
import Types.Server (HostName)
+import Types.Cost (Seconds(..))
import Tunables
import qualified Gpg
import Options.Applicative
@@ -27,6 +28,7 @@ data CmdLine = CmdLine
, name :: Maybe Name
, othername :: Maybe Name
, serverConfig :: ServerConfig
+ , chaffMaxDelay :: Maybe Seconds
}
data Mode = Backup | Restore | UploadQueued | AutoStart | Server | BackupServer FilePath | RestoreServer FilePath | Chaff HostName | Benchmark | Test
@@ -43,13 +45,14 @@ parse = CmdLine
<$> optional parseMode
<*> optional (gpgswitch <|> fileswitch)
<*> localstorageswitch
- <*> localstoragedirectoryopt
+ <*> optional localstoragedirectoryopt
<*> guiswitch
<*> testmodeswitch
- <*> optional (ShareParams <$> totalobjects <*> neededobjects)
- <*> nameopt
- <*> othernameopt
+ <*> optional parseShareParams
+ <*> optional nameopt
+ <*> optional othernameopt
<*> parseServerConfig
+ <*> optional chaffmaxdelayopt
where
gpgswitch = GpgKey . KeyId . T.pack <$> strOption
( long "gpgkeyid"
@@ -65,7 +68,7 @@ parse = CmdLine
( long "store-local"
<> help "Store data locally. (The default is to store data in the cloud.)"
)
- localstoragedirectoryopt = optional $ LocalStorageDirectory <$> option str
+ localstoragedirectoryopt = LocalStorageDirectory <$> option str
( long "store-directory"
<> metavar "DIR"
<> help "Where to store data locally. (default: ~/.keysafe/objects/)"
@@ -78,26 +81,21 @@ parse = CmdLine
( long "gui"
<> help "Use GUI interface for interaction. Default is to use readline interface when run in a terminal, and GUI otherwise."
)
- totalobjects = option auto
- ( long "totalshares"
- <> metavar "M"
- <> help ("Configure the number of shares to split encrypted secret key into. (default: " ++ show (totalObjects (shareParams defaultTunables)) ++ ") (When this option is used to back up a key, it must also be provided at restore time.)")
- )
- neededobjects = option auto
- ( long "neededshares"
- <> metavar "N"
- <> help ("Configure the number of shares needed to restore. (default: " ++ show (neededObjects (shareParams defaultTunables)) ++ ") (When this option is used to back up a key, it must also be provided at restore time.)")
- )
- nameopt = optional $ Name . BU8.fromString <$> strOption
+ nameopt = option nameOption
( long "name"
<> metavar "N"
<> help "Specify name used for key backup/restore, avoiding the usual prompt."
)
- othernameopt = optional $ Name . BU8.fromString <$> strOption
+ othernameopt = option nameOption
( long "othername"
<> metavar "N"
<> help "Specify other name used for key backup/restore, avoiding the usual prompt."
)
+ chaffmaxdelayopt = option secondsOption
+ ( long "chaff-max-delay"
+ <> metavar "SECONDS"
+ <> help "Specify a delay between chaff uploads. Will delay a random amount between 0 and this many seconds."
+ )
parseMode :: Parser Mode
parseMode =
@@ -145,6 +143,25 @@ parseMode =
<> help "Run test suite."
)
+parseShareParams :: Parser ShareParams
+parseShareParams = ShareParams <$> totalobjects <*> neededobjects
+ where
+ totalobjects = option auto
+ ( long "totalshares"
+ <> metavar "M"
+ <> help ("Configure the number of shares to split encrypted secret key into. "
+ ++ showdefault totalObjects ++ neededboth)
+ )
+ neededobjects = option auto
+ ( long "neededshares"
+ <> metavar "N"
+ <> help ("Configure the number of shares needed to restore. "
+ ++ showdefault neededObjects ++ neededboth)
+ )
+ showdefault f = "(default: " ++ show (f (shareParams defaultTunables)) ++ ")"
+ neededboth = " (When this option is used to back up a key, it must also be provided at restore time.)"
+
+
parseServerConfig :: Parser ServerConfig
parseServerConfig = ServerConfig
<$> option auto
@@ -193,3 +210,9 @@ customizeShareParams :: CmdLine -> Tunables -> Tunables
customizeShareParams cmdline t = case customShareParams cmdline of
Nothing -> t
Just ps -> t { shareParams = ps }
+
+secondsOption :: ReadM Seconds
+secondsOption = Seconds . toRational <$> (auto :: ReadM Double)
+
+nameOption :: ReadM Name
+nameOption = Name . BU8.fromString <$> auto