summaryrefslogtreecommitdiff
path: root/KeyRing.hs
diff options
context:
space:
mode:
Diffstat (limited to 'KeyRing.hs')
-rw-r--r--KeyRing.hs24
1 files changed, 18 insertions, 6 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index c2e209c..c7ea5fb 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -134,7 +134,7 @@ import System.FilePath ( takeDirectory )
134import System.IO (hPutStrLn,withFile,IOMode(..), Handle, hPutStr) 134import System.IO (hPutStrLn,withFile,IOMode(..), Handle, hPutStr)
135import Data.IORef 135import Data.IORef
136import System.Posix.IO ( fdToHandle ) 136import System.Posix.IO ( fdToHandle )
137import qualified Data.Traversable as Traversable ( mapM ) 137import qualified Data.Traversable as Traversable
138import Data.Traversable ( sequenceA ) 138import Data.Traversable ( sequenceA )
139#if ! MIN_VERSION_base(4,6,0) 139#if ! MIN_VERSION_base(4,6,0)
140import GHC.Exts ( Down(..) ) 140import GHC.Exts ( Down(..) )
@@ -204,7 +204,7 @@ data InputFile = HomeSec
204 -- ^ Contents will be read from the first descriptor and updated 204 -- ^ Contents will be read from the first descriptor and updated
205 -- content will be writen to the second. Note: Don't use Pipe 205 -- content will be writen to the second. Note: Don't use Pipe
206 -- for 'Wallet' files. (TODO: Wallet support) 206 -- for 'Wallet' files. (TODO: Wallet support)
207 deriving (Eq,Ord) 207 deriving (Eq,Ord,Show)
208 208
209-- type UsageTag = String 209-- type UsageTag = String
210type Initializer = String 210type Initializer = String
@@ -1199,6 +1199,9 @@ writeHostsFiles krd ctx (hostdbs0,hostdbs,u1,gpgnames,outgoing_names) = do
1199 return $ map (first $ resolveForReport $ Just ctx) rs 1199 return $ map (first $ resolveForReport $ Just ctx) rs
1200 return $ concat rss 1200 return $ concat rss
1201 1201
1202isSecretKey :: Packet -> Bool
1203isSecretKey (SecretKeyPacket {}) = True
1204isSecretKey _ = False
1202 1205
1203buildKeyDB :: InputFileContext -> Maybe String -> KeyRingOperation 1206buildKeyDB :: InputFileContext -> Maybe String -> KeyRingOperation
1204 -> IO (KikiCondition ((KeyDB 1207 -> IO (KikiCondition ((KeyDB
@@ -1238,7 +1241,11 @@ buildKeyDB ctx grip0 keyring = do
1238 1241
1239 -- KeyRings (todo: KikiCondition reporting?) 1242 -- KeyRings (todo: KikiCondition reporting?)
1240 (spilled,mwk,grip,accs,keys,unspilled) <- do 1243 (spilled,mwk,grip,accs,keys,unspilled) <- do
1244#if MIN_VERSION_containers(0,5,0)
1241 ringPackets <- Map.traverseWithKey readp ringMap 1245 ringPackets <- Map.traverseWithKey readp ringMap
1246#else
1247 ringPackets <- Traversable.traverse (uncurry readp) $ Map.mapWithKey (,) ringMap
1248#endif
1242 let _ = ringPackets :: Map.Map InputFile (StreamInfo, Message) 1249 let _ = ringPackets :: Map.Map InputFile (StreamInfo, Message)
1243 1250
1244 let grip = grip0 `mplus` (fingerprint <$> fstkey) 1251 let grip = grip0 `mplus` (fingerprint <$> fstkey)
@@ -1250,8 +1257,7 @@ buildKeyDB ctx grip0 keyring = do
1250 keys :: Map.Map KeyKey MappedPacket 1257 keys :: Map.Map KeyKey MappedPacket
1251 keys = Map.foldl slurpkeys Map.empty 1258 keys = Map.foldl slurpkeys Map.empty
1252 $ Map.mapWithKey filterSecrets ringPackets 1259 $ Map.mapWithKey filterSecrets ringPackets
1253 where isSecretKey (SecretKeyPacket {}) = True 1260 where
1254 isSecretKey _ = False
1255 filterSecrets f (_,Message ps) = 1261 filterSecrets f (_,Message ps) =
1256 filter (isSecretKey . packet) 1262 filter (isSecretKey . packet)
1257 $ zipWith (mappedPacketWithHint fname) ps [1..] 1263 $ zipWith (mappedPacketWithHint fname) ps [1..]
@@ -1284,7 +1290,11 @@ buildKeyDB ctx grip0 keyring = do
1284 r <- performManipulations doDecrypt rt1 mwk manip 1290 r <- performManipulations doDecrypt rt1 mwk manip
1285 try r $ \(rt2,report) -> do 1291 try r $ \(rt2,report) -> do
1286 return $ KikiSuccess (report,(info,flattenKeys acc $ rtKeyDB rt2)) 1292 return $ KikiSuccess (report,(info,flattenKeys acc $ rtKeyDB rt2))
1293#if MIN_VERSION_containers(0,5,0)
1287 in fmap sequenceA $ Map.traverseWithKey trans spilled 1294 in fmap sequenceA $ Map.traverseWithKey trans spilled
1295#else
1296 in fmap sequenceA $ Traversable.traverse (uncurry trans) $ Map.mapWithKey (,) spilled
1297#endif
1288 try transformed0 $ \transformed -> do 1298 try transformed0 $ \transformed -> do
1289 let db_rings = Map.foldlWithKey' mergeIt Map.empty transformed 1299 let db_rings = Map.foldlWithKey' mergeIt Map.empty transformed
1290 where 1300 where
@@ -1670,13 +1680,14 @@ writeRingKeys krd rt {- db wk secring pubring -} unspilled = do
1670 d <- sortByHint f keyMappedPacket (Map.elems db') 1680 d <- sortByHint f keyMappedPacket (Map.elems db')
1671 acc <- maybeToList $ Map.lookup f0 (rtRingAccess rt) 1681 acc <- maybeToList $ Map.lookup f0 (rtRingAccess rt)
1672 only_public <- maybeToList $ wantedForFill acc (fill stream) d 1682 only_public <- maybeToList $ wantedForFill acc (fill stream) d
1683 guard $ only_public || isSecretKey (keyPacket d)
1673 case fill stream of 1684 case fill stream of
1674 KF_Match usage -> do grip <- maybeToList $ rtGrip rt 1685 KF_Match usage -> do grip <- maybeToList $ rtGrip rt
1675 flattenTop f only_public 1686 flattenTop f only_public
1676 $ filterNewSubs f (parseSpec grip usage) d 1687 $ filterNewSubs f (parseSpec grip usage) d
1677 _ -> flattenTop f only_public d 1688 _ -> flattenTop f only_public d
1678 new_packets = filter isnew x 1689 new_packets = filter isnew x
1679 where isnew p = isNothing (Map.lookup f $ locations p) 1690 where isnew p = isNothing (Map.lookup (resolveForReport Nothing f0) $ locations p)
1680 guard (not $ null new_packets) 1691 guard (not $ null new_packets)
1681 return ((f0,isMutable stream),(new_packets,x)) 1692 return ((f0,isMutable stream),(new_packets,x))
1682 let (towrites,report) = (\f -> foldl f ([],[]) s) $ 1693 let (towrites,report) = (\f -> foldl f ([],[]) s) $
@@ -2404,7 +2415,8 @@ readPacketsFromFile ctx fname = do
2404 case decodeOrFail input of 2415 case decodeOrFail input of
2405 Right (_,_,msg ) -> msg 2416 Right (_,_,msg ) -> msg
2406 Left (_,_,_) -> 2417 Left (_,_,_) ->
2407 --trace (fname++": read fail") $ 2418 -- FIXME
2419 -- trace (fname++": read fail") $
2408 Message [] 2420 Message []
2409#else 2421#else
2410 return $ decode input 2422 return $ decode input