From 6c08038af8f800f8de03c53b162a6cd305ace4d7 Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 17 Apr 2014 23:19:20 -0400 Subject: more decryption --- KeyRing.hs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/KeyRing.hs b/KeyRing.hs index bda1958..6fac344 100644 --- a/KeyRing.hs +++ b/KeyRing.hs @@ -645,15 +645,13 @@ cachedContents secring pubring fd = do let fname = resolveInputFile secring pubring inp fmap S.concat $ mapM S.readFile fname -importPEMKey db' tup = do +importPEMKey doDecrypt db' tup = do try db' $ \(db',report0) -> do r <- doImport doDecrypt db' tup try r $ \(db'',report) -> do return $ KikiSuccess (db'', report0 ++ report) - where doDecrypt = todo - buildKeyDB :: (MappedPacket -> IO (KikiCondition Packet)) -> FilePath -> FilePath -> Maybe String -> KeyRingData @@ -720,7 +718,7 @@ buildKeyDB doDecrypt secring pubring grip0 keyring = do cmd = initializer rtyp return (n,subspec,ms,cmd) imports <- filterM (\(n,_,_,_) -> doesFileExist n) pems - db <- foldM importPEMKey (KikiSuccess (db,[])) imports + db <- foldM (importPEMKey doDecrypt) (KikiSuccess (db,[])) imports try db $ \(db,reportPEMs) -> do return $ KikiSuccess ( (db, grip, wk), reportWallets ++ reportPEMs ) @@ -1024,8 +1022,8 @@ subkeysForExport subspec (KeyData key _ _ subkeys) = do let subs tag = do e <- Map.elems subkeys guard $ doSearch key tag e - return $ subkeyPacket e - maybe [packet key] subs subspec + return $ subkeyMappedPacket e + maybe [key] subs subspec where doSearch key tag (SubKey sub_mp sigtrusts) = let (_,v,_) = findTag tag @@ -1097,10 +1095,11 @@ writeKeyToFile False "PEM" fname packet = return [(fname, ExportedSubkey)] algo -> return [(fname, UnableToExport algo $ fingerprint packet)] -writePEMKeys :: KeyDB - -> [(FilePath,Maybe String,[Packet],Maybe Initializer)] +writePEMKeys :: (MappedPacket -> IO (KikiCondition Packet)) + -> KeyDB + -> [(FilePath,Maybe String,[MappedPacket],Maybe Initializer)] -> IO (KikiCondition [(FilePath,KikiReportAction)]) -writePEMKeys db exports = do +writePEMKeys doDecrypt db exports = do ds <- mapM decryptKeys exports let ds' = map functorToEither ds if null (lefts ds') @@ -1111,11 +1110,9 @@ writePEMKeys db exports = do else do return (head $ lefts ds') where - doDecrypt = todo - decryptKeys (fname,subspec,[p],_) = do pun <- doDecrypt p - flip (maybe $ return BadPassphrase) pun $ \pun -> do + try pun $ \pun -> do return $ KikiSuccess (fname,pun) doDecrypt :: IORef (Map.Map KeyKey Packet) @@ -1235,7 +1232,8 @@ runKeyRing keyring = do ExitFailure num -> return (tup,FailedExternal num) ExitSuccess -> return (tup,ExternallyGeneratedFile) - v <- foldM importPEMKey (KikiSuccess (db,[])) $ do + v <- foldM (importPEMKey $ doDecrypt unkeysRef pws) + (KikiSuccess (db,[])) $ do ((f,subspec,ms,cmd),r) <- rs guard $ case r of ExternallyGeneratedFile -> True @@ -1254,7 +1252,7 @@ runKeyRing keyring = do r <- writeRingKeys keyring db wk secring pubring try' r $ \report_rings -> do - r <- writePEMKeys db exports + r <- writePEMKeys (doDecrypt unkeysRef pws) db exports try' r $ \report_pems -> do let rt = KeyRingRuntime -- cgit v1.2.3