summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kiki.hs32
1 files changed, 28 insertions, 4 deletions
diff --git a/kiki.hs b/kiki.hs
index fef214c..e6e0630 100644
--- a/kiki.hs
+++ b/kiki.hs
@@ -1213,6 +1213,17 @@ show_all db = do
1213 let Message packets = flattenKeys True db 1213 let Message packets = flattenKeys True db
1214 putStrLn $ listKeys packets 1214 putStrLn $ listKeys packets
1215 1215
1216show_pem keyspec wkgrip db = do
1217 let s = parseSpec wkgrip keyspec
1218 flip (maybe $ warn (keyspec ++ ": not found") >> return ())
1219 (selectKey s db)
1220 $ \k -> do
1221 let rsa = pkcs8 . fromJust $ rsaKeyFromPacket k
1222 der = encodeASN1 DER (toASN1 rsa [])
1223 qq = Base64.encode (L.unpack der)
1224 putStrLn $
1225 writePEM "PUBLIC KEY" qq -- ("TODO "++show keyspec)
1226
1216parseSpec :: String -> String -> (KeySpec,Maybe String) 1227parseSpec :: String -> String -> (KeySpec,Maybe String)
1217parseSpec grip spec = (topspec,subspec) 1228parseSpec grip spec = (topspec,subspec)
1218 where 1229 where
@@ -1506,6 +1517,7 @@ main = do
1506 , ("--autosign",0) 1517 , ("--autosign",0)
1507 , ("--show-wk",0) 1518 , ("--show-wk",0)
1508 , ("--show-all",0) 1519 , ("--show-all",0)
1520 , ("--show-pem",1)
1509 ] 1521 ]
1510 args 1522 args
1511 args' = if map (take 1) (take 1 vargs) == ["-"] 1523 args' = if map (take 1) (take 1 vargs) == ["-"]
@@ -1605,11 +1617,12 @@ main = do
1605 1617
1606 flip (maybe $ return ()) ret_db . const $ do 1618 flip (maybe $ return ()) ret_db . const $ do
1607 -- On last pass, interpret --show-* commands. 1619 -- On last pass, interpret --show-* commands.
1608 let shspec = Map.fromList [("--show-wk", show_wk secfile grip) 1620 let shspec = Map.fromList [("--show-wk", const $ show_wk secfile grip)
1609 ,("--show-all",show_all )] 1621 ,("--show-all",const $ show_all)
1610 shargs = mapMaybe (\x -> listToMaybe x >>= \x ->Map.lookup x shspec) sargs 1622 ,("--show-pem",\[x] -> show_pem x $ maybe "" id grip) ]
1623 shargs = mapMaybe (\(x:xs) -> (,xs) <$> Map.lookup x shspec) sargs
1611 1624
1612 forM_ shargs $ \cmd -> cmd use_db 1625 forM_ shargs $ \(cmd,args) -> cmd args use_db
1613 return $ ret_db 1626 return $ ret_db
1614 1627
1615 return() 1628 return()
@@ -2159,6 +2172,17 @@ isTopKey _ = False
2159filterMatches :: KeySpec -> [(KeyKey,KeyData)] -> [(KeyKey,KeyData)] 2172filterMatches :: KeySpec -> [(KeyKey,KeyData)] -> [(KeyKey,KeyData)]
2160filterMatches spec ks = filter (matchSpec spec) ks 2173filterMatches spec ks = filter (matchSpec spec) ks
2161 2174
2175selectKey :: (KeySpec,Maybe String) -> KeyDB -> Maybe Packet
2176selectKey (spec,mtag) db = do
2177 -- Note: Because of the behavior of flattenKeys,
2178 -- selectKey cannot return a SecretKeyPacket
2179 let Message ps = flattenKeys True db
2180 ys = snd $ seek_key spec ps
2181 flip (maybe (listToMaybe ys)) mtag $ \tag -> do
2182 let (subspec,ys1) = (KeyTag y tag,ys1) where y:ys1 = ys
2183 zs = snd $ seek_key subspec ys1
2184 listToMaybe zs
2185
2162matchSpec (KeyGrip grip) (_,KeyData p _ _ _) 2186matchSpec (KeyGrip grip) (_,KeyData p _ _ _)
2163 | matchpr grip (packet p)==grip = True 2187 | matchpr grip (packet p)==grip = True
2164 | otherwise = False 2188 | otherwise = False