From aa5bf4e7ba36a07898a8ffaf9c6b25d973fb05d6 Mon Sep 17 00:00:00 2001 From: joe Date: Wed, 30 Apr 2014 23:01:07 -0400 Subject: Support default passphrase specification --- KeyRing.hs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/KeyRing.hs b/KeyRing.hs index db9e9c3..a88a0a7 100644 --- a/KeyRing.hs +++ b/KeyRing.hs @@ -171,13 +171,11 @@ data InputFile = HomeSec -- type UsageTag = String type Initializer = String -type PassWordFile = InputFile +type PasswordFile = InputFile --- TODO: This should become a simple enum. --- The parameter to PEMFile will be subsumed by --- the KF_Match fill/spill KeyFilter styles. The parameter --- to KeyRingFile will be subsumbed by kPassphrases -data FileType = KeyRingFile (Maybe PassWordFile) +data FileType = KeyRingFile (Maybe PasswordFile) + -- ^ PasswordFile parameter is deprecated in favor + -- of kPassphrases. TODO: remove it. | PEMFile | WalletFile -- (Maybe UsageTag) | Hosts @@ -225,7 +223,7 @@ ispem :: FileType -> Bool ispem (PEMFile {}) = True ispem _ = False -pwfile :: FileType -> Maybe PassWordFile +pwfile :: FileType -> Maybe PasswordFile pwfile (KeyRingFile f) = f pwfile _ = Nothing @@ -1661,14 +1659,20 @@ makeMemoizingDecrypter operation ctx = do guard $ isNothing $ passSpecKeySpec spec passSpecRingFile spec) (kPassphrases operation) + defpw <- do + Traversable.mapM (cachedContents ctx . passSpecPassFile) + $ listToMaybe $ filter (\sp -> isNothing (passSpecRingFile sp) + && isNothing (passSpecKeySpec sp)) + $ kPassphrases operation unkeysRef <- newIORef Map.empty - return $ doDecrypt unkeysRef (pws `Map.union` pws2) + return $ doDecrypt unkeysRef (pws `Map.union` pws2) defpw where doDecrypt :: IORef (Map.Map KeyKey Packet) -> Map.Map FilePath (IO S.ByteString) + -> Maybe (IO S.ByteString) -> MappedPacket -> IO (KikiCondition Packet) - doDecrypt unkeysRef pws mp = do + doDecrypt unkeysRef pws defpw mp = do unkeys <- readIORef unkeysRef let wk = packet mp kk = keykey wk -- cgit v1.2.3