summaryrefslogtreecommitdiff
path: root/lib/KeyRing.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/KeyRing.hs')
-rw-r--r--lib/KeyRing.hs47
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/KeyRing.hs b/lib/KeyRing.hs
index 07badb6..554c4ad 100644
--- a/lib/KeyRing.hs
+++ b/lib/KeyRing.hs
@@ -188,10 +188,12 @@ x509cert _ = Nothing
188 188
189 189
190 190
191{-
191getStr :: SingleKeySpec -> String 192getStr :: SingleKeySpec -> String
192getStr (FingerprintMatch x) = x 193getStr (FingerprintMatch x) = x
193getStr (SubstringMatch _ x) = x 194getStr (SubstringMatch _ x) = x
194getStr _ = "" 195getStr _ = ""
196-}
195 197
196-- | Spec 198-- | Spec
197-- 199--
@@ -235,6 +237,8 @@ data SpecError = SpecENone String
235 -- circ = Just GroupIDField 237 -- circ = Just GroupIDField
236 238
237-- | parseSpec3 - Parse a key specification. 239-- | parseSpec3 - Parse a key specification.
240--
241-- TODO: This is currently unused.
238parseSpec3 :: Maybe MatchingField -> String -> Either SpecError Spec 242parseSpec3 :: Maybe MatchingField -> String -> Either SpecError Spec
239parseSpec3 maybeExpecting spec@(wordsBy '/' -> fields) = 243parseSpec3 maybeExpecting spec@(wordsBy '/' -> fields) =
240 tooBigError maybeExpecting =<< applyContext maybeExpecting . fixUpSubstrMatch <$> 244 tooBigError maybeExpecting =<< applyContext maybeExpecting . fixUpSubstrMatch <$>
@@ -283,7 +287,7 @@ parseSpec3 maybeExpecting spec@(wordsBy '/' -> fields) =
283 287
284 adjustPos (SubstringMatch (Just KeyTypeField) _) Nothing = 0 288 adjustPos (SubstringMatch (Just KeyTypeField) _) Nothing = 0
285 adjustPos (SubstringMatch (Just UserIDField) _) Nothing = 1 289 adjustPos (SubstringMatch (Just UserIDField) _) Nothing = 1
286 adjustPos (SubstringMatch (Just GroupIDField) _) Nothing = 2 290 -- adjustPos (SubstringMatch (Just GroupIDField) _) Nothing = 2
287 adjustPos _ (Just i) = fromEnum i 291 adjustPos _ (Just i) = fromEnum i
288 292
289 gotIndex :: Int -> SingleKeySpec -> Int 293 gotIndex :: Int -> SingleKeySpec -> Int
@@ -296,7 +300,7 @@ parseSpec3 maybeExpecting spec@(wordsBy '/' -> fields) =
296 mismatch xs = case find (not . fst) (reverse xs) of 300 mismatch xs = case find (not . fst) (reverse xs) of
297 Just (_,(SubstringMatch mbF s,n)) -> SpecEMissMatch s mbF (toEnum n) 301 Just (_,(SubstringMatch mbF s,n)) -> SpecEMissMatch s mbF (toEnum n)
298 302
299 fixUpSubstrMatch (g,u,t) = (set GroupIDField g, set UserIDField u, set KeyTypeField t) 303 fixUpSubstrMatch (g,u,t) = ({- set GroupIDField -} g, set UserIDField u, set KeyTypeField t)
300 where 304 where
301 set field (SubstringMatch Nothing xs) = SubstringMatch (Just field) xs 305 set field (SubstringMatch Nothing xs) = SubstringMatch (Just field) xs
302 set _ EmptyMatch = AnyMatch 306 set _ EmptyMatch = AnyMatch
@@ -313,16 +317,17 @@ parseSpec3 maybeExpecting spec@(wordsBy '/' -> fields) =
313 applyContext (Just UserIDField) ((AnyMatch,u,x)) = (AnyMatch,u,x) 317 applyContext (Just UserIDField) ((AnyMatch,u,x)) = (AnyMatch,u,x)
314 applyContext (Just UserIDField) x = x 318 applyContext (Just UserIDField) x = x
315 319
316 applyContext (Just GroupIDField) ((AnyMatch,AnyMatch,x)) = (x,AnyMatch,AnyMatch) 320 -- applyContext (Just GroupIDField) ((AnyMatch,AnyMatch,x)) = (x,AnyMatch,AnyMatch)
317 applyContext (Just GroupIDField) ((AnyMatch,u,x)) = (u,AnyMatch,x) 321 -- applyContext (Just GroupIDField) ((AnyMatch,u,x)) = (u,AnyMatch,x)
318 applyContext (Just GroupIDField) x = x 322 -- applyContext (Just GroupIDField) x = x
319 323
320 --applyContext (Just UserIDField) (Right (g,u,x)) = Left $ 324 --applyContext (Just UserIDField) (Right (g,u,x)) = Left $
321 -- SpecEMissMatch (getStr g) (Just GroupIDField) UserIDField 325 -- SpecEMissMatch (getStr g) (Just GroupIDField) UserIDField
322 tooBigError _ s@(_,_,SubstringMatch (Just GroupIDField) str) = Left $ 326
323 SpecEMissMatch str (Just GroupIDField) KeyTypeField 327 -- tooBigError _ s@(_,_,SubstringMatch (Just GroupIDField) str) = Left $
324 tooBigError _ s@(_,SubstringMatch (Just GroupIDField) str,_) = Left $ 328 -- SpecEMissMatch str (Just GroupIDField) KeyTypeField
325 SpecEMissMatch str (Just GroupIDField) UserIDField 329 -- tooBigError _ s@(_,SubstringMatch (Just GroupIDField) str,_) = Left $
330 -- SpecEMissMatch str (Just GroupIDField) UserIDField
326 331
327 tooBigError Nothing x = return x 332 tooBigError Nothing x = return x
328 tooBigError (Just UserIDField) s@(g,u,t) | g /= AnyMatch = Left $ 333 tooBigError (Just UserIDField) s@(g,u,t) | g /= AnyMatch = Left $
@@ -382,10 +387,13 @@ parseSpec grip spec = (topspec,subspec)
382filterNewSubs :: FilePath -> (KeySpec,Maybe String) -> KeyData -> KeyData 387filterNewSubs :: FilePath -> (KeySpec,Maybe String) -> KeyData -> KeyData
383filterNewSubs fname spec (KeyData p sigs uids subs) = KeyData p sigs uids subs' 388filterNewSubs fname spec (KeyData p sigs uids subs) = KeyData p sigs uids subs'
384 where 389 where
385 matchAll = KeyGrip "" 390 matchAll = KeyFP 0 ""
391
392 subkeySpec (KeyFP ver grip,Nothing) = (matchAll, KeyFP ver grip)
393 subkeySpec (topspec,Just mtag) = (topspec , KeyTag (packet p) mtag)
394 subkeySpec (KeyTag p tag, Nothing) = (matchAll, KeyTag p tag)
395 subkeySpec (KeyUidMatch u, Nothing) = (KeyUidMatch u, matchAll)
386 396
387 subkeySpec (KeyGrip grip,Nothing) = (matchAll, KeyGrip grip)
388 subkeySpec (topspec,Just mtag) = (topspec , KeyTag (packet p) mtag)
389 397
390 match spec mps 398 match spec mps
391 = not . null 399 = not . null
@@ -420,13 +428,13 @@ selectPublicKeyAndSigs (spec,mtag) db =
420 where 428 where
421 topresult kd = (keyPacket kd, map (packet .fst) $ keySigAndTrusts kd) 429 topresult kd = (keyPacket kd, map (packet .fst) $ keySigAndTrusts kd)
422 430
423 findbyspec (KeyGrip g) kd = do 431 findbyspec (KeyFP ver g) kd = do
424 filter ismatch $ 432 filter ismatch $
425 topresult kd 433 topresult kd
426 : map (\(SubKey sub sigs)-> (packet sub, map (packet . fst) sigs)) 434 : map (\(SubKey sub sigs)-> (packet sub, map (packet . fst) sigs))
427 (Map.elems $ keySubKeys kd) 435 (Map.elems $ keySubKeys kd)
428 where 436 where
429 ismatch (p,sigs) = matchpr g p ==g 437 ismatch (p,sigs) = matchpr ver g p ==g
430 findbyspec spec kd = if matchSpec spec kd then [topresult kd] else [] 438 findbyspec spec kd = if matchSpec spec kd then [topresult kd] else []
431 439
432 findsubs tag (kk, KeyData topk _ _ subs) = Map.elems subs >>= gettag 440 findsubs tag (kk, KeyData topk _ _ subs) = Map.elems subs >>= gettag
@@ -674,7 +682,7 @@ isauth rt keydata = dont_have keydata && maybe False (`has_good_sig` keydata) wk
674 workingKey grip use_db = listToMaybe $ do 682 workingKey grip use_db = listToMaybe $ do
675 fp <- maybeToList grip 683 fp <- maybeToList grip
676 elm <- keyData use_db 684 elm <- keyData use_db
677 guard $ matchSpec (KeyGrip fp) elm 685 guard $ matchSpec (KeyFP 0 fp) elm
678 return $ keyPacket elm 686 return $ keyPacket elm
679 687
680mkarmor :: Access -> L.ByteString -> [Armor] 688mkarmor :: Access -> L.ByteString -> [Armor]
@@ -921,6 +929,9 @@ writeKeyToFile StreamInfo { typ = DNSPresentation } fname packet = do
921 return [(fname, ExportedSubkey)] 929 return [(fname, ExportedSubkey)]
922 algo -> return [(fname, UnableToExport algo $ show $ fingerprint packet)] 930 algo -> return [(fname, UnableToExport algo $ show $ fingerprint packet)]
923 931
932writeKeyToFile strm _ _ = error $ "writeKeyToFile: Unsupported file type: " ++ show (typ strm)
933
934
924writePEMKeys :: (PacketDecrypter) 935writePEMKeys :: (PacketDecrypter)
925 -> KeyDB 936 -> KeyDB
926 -> [(FilePath,Maybe String,[MappedPacket],StreamInfo)] 937 -> [(FilePath,Maybe String,[MappedPacket],StreamInfo)]
@@ -942,6 +953,9 @@ writePEMKeys doDecrypt db exports = do
942 pun <- doDecrypt p 953 pun <- doDecrypt p
943 try pun $ \pun -> do 954 try pun $ \pun -> do
944 return $ KikiSuccess (fname,stream,pun) 955 return $ KikiSuccess (fname,stream,pun)
956 decryptKeys (_, _, [] , _) = error "writePEMKeys: Key missing from keyring."
957 decryptKeys (_, _, (_:_:_), _) = error "writePEMKeys: Ambiguous key."
958
945 959
946initializeMissingPEMFiles :: 960initializeMissingPEMFiles ::
947 KeyRingOperation 961 KeyRingOperation
@@ -956,8 +970,6 @@ initializeMissingPEMFiles ::
956 , StreamInfo )]) 970 , StreamInfo )])
957 , [(FilePath,KikiReportAction)])) 971 , [(FilePath,KikiReportAction)]))
958initializeMissingPEMFiles operation ctx grip mwk transcode db = do 972initializeMissingPEMFiles operation ctx grip mwk transcode db = do
959 let decrypt = transcode (Unencrypted,S2K 100 "")
960
961 -- nonexistants - files missing from disk. 973 -- nonexistants - files missing from disk.
962 nonexistents <- 974 nonexistents <-
963 filterM (fmap not . doesFileExist . fst) 975 filterM (fmap not . doesFileExist . fst)
@@ -1197,5 +1209,6 @@ getHomeDir protohome = do
1197 \(forgive,fname) -> parseOptionFile fname 1209 \(forgive,fname) -> parseOptionFile fname
1198 let config = map (topair . words) args 1210 let config = map (topair . words) args
1199 where topair (x:xs) = (x,xs) 1211 where topair (x:xs) = (x,xs)
1212 topair _ = error "parseOptionFile yeilded an empty entry?"
1200 return $ lookup "default-key" config >>= listToMaybe 1213 return $ lookup "default-key" config >>= listToMaybe
1201 1214