From 75d4b3b8bc60ff1d7ccc3990833a4439c0af02bc Mon Sep 17 00:00:00 2001 From: James Crayne Date: Sun, 21 Jun 2015 06:00:12 -0400 Subject: Prompt on interactive passphrase entry. Also bumbed version up, due to breaking api of KeyRing module. (The funciton cachedContents now takes a prompt parameter.) --- KeyRing.hs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'KeyRing.hs') diff --git a/KeyRing.hs b/KeyRing.hs index 2571c55..75e19b3 100644 --- a/KeyRing.hs +++ b/KeyRing.hs @@ -132,7 +132,7 @@ import qualified Data.Map as Map import qualified Data.ByteString.Lazy as L ( unpack, null, readFile, writeFile , ByteString, toChunks, hGetContents, hPut, concat, fromChunks, splitAt , index ) -import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null ) +import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null, putStr ) import qualified Crypto.Types.PubKey.ECC as ECC import qualified Codec.Binary.Base32 as Base32 import qualified Codec.Binary.Base64 as Base64 @@ -1155,16 +1155,20 @@ doesInputFileExist ctx f = do -} -cachedContents :: InputFileContext -> InputFile -> IO (IO S.ByteString) -cachedContents ctx fd = do +cachedContents :: Maybe S.ByteString -> InputFileContext -> InputFile -> IO (IO S.ByteString) +cachedContents maybePrompt ctx fd = do ref <- newIORef Nothing - return $ get ref fd + return $ get maybePrompt ref fd where trimCR bs = fst $ S.spanEnd (\x -> x==10 || x==13) bs - get ref fd = do + get maybePrompt ref fd = do pw <- readIORef ref flip (flip maybe return) pw $ do + if fd == FileDesc 0 then case maybePrompt of + Just prompt -> S.putStr prompt + Nothing -> return () + else return () pw <- fmap trimCR $ readInputFileS ctx fd writeIORef ref (Just pw) return pw @@ -2015,15 +2019,16 @@ makeMemoizingDecrypter operation ctx keys = (Map.mapKeys (resolveForReport Nothing) -- see note (*) note above $ Map.filter (isJust . pwfile . typ) $ opFiles operation) -} + let prompt = Just "Enter possibly multi-line passphrase (Press CTRL-D when finished):\n" pws2 <- - Traversable.mapM (cachedContents ctx) + Traversable.mapM (cachedContents prompt ctx) $ Map.fromList $ mapMaybe (\spec -> (,passSpecPassFile spec) `fmap` do guard $ isNothing $ passSpecKeySpec spec passSpecRingFile spec) passspecs defpw <- do - Traversable.mapM (cachedContents ctx . passSpecPassFile) + Traversable.mapM (cachedContents prompt ctx . passSpecPassFile) $ listToMaybe $ filter (\sp -> isNothing (passSpecRingFile sp) && isNothing (passSpecKeySpec sp)) $ opPassphrases operation -- cgit v1.2.3