Skip to content
Snippets Groups Projects
Commit cc2d2202 authored by Ramakrishnan Muthukrishnan's avatar Ramakrishnan Muthukrishnan
Browse files

take signing key path as the parameter instead of the key itself

This is to make sure that we don't leak keys in the argument and hence
in logs etc.
parent c5651f58
No related branches found
No related tags found
1 merge request!32Pass paths to secrets in commandline arguments instead of secrets
......@@ -76,6 +76,7 @@ import System.Exit
( exitFailure
)
import Data.Semigroup ((<>))
import qualified Data.Text.IO as TIO
data Issuer =
Trivial
......@@ -89,7 +90,7 @@ data Database =
data ServerConfig = ServerConfig
{ issuer :: Issuer
, signingKey :: Maybe Text
, signingKeyPath :: Maybe FilePath
, database :: Database
, databasePath :: Maybe Text
, endpoint :: Endpoint
......@@ -150,8 +151,8 @@ sample = ServerConfig
<> showDefault
<> value Trivial )
<*> optional (option str
( long "signing-key"
<> help "The base64 encoded signing key (ristretto only)"
( long "signing-key-path"
<> help "Path to base64 encoded signing key (ristretto only)"
<> showDefault ) )
<*> option auto
( long "database"
......@@ -205,18 +206,21 @@ logEndpoint endpoint =
getApp :: ServerConfig -> IO Application
getApp config =
let
getIssuer ServerConfig{ issuer, signingKey } =
case (issuer, signingKey) of
(Trivial, Nothing) -> Right trivialIssue
(Ristretto, Just key) -> Right $ ristrettoIssue key
_ -> Left "invalid options"
getIssuer ServerConfig{ issuer, signingKeyPath } = do
case (issuer, signingKeyPath) of
(Trivial, Nothing) -> return $ Right trivialIssue
(Ristretto, Just keyPath) -> do
key <- TIO.readFile keyPath
return $ Right $ ristrettoIssue key
_ -> return $ Left "invalid options"
getDatabase ServerConfig{ database, databasePath } =
case (database, databasePath) of
(Memory, Nothing) -> Right memory
(SQLite3, Just path) -> Right (getDBConnection path)
_ -> Left "invalid options"
in do
case getIssuer config of
issuer <- getIssuer config
case issuer of
Left err -> do
print err
exitFailure
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment