summaryrefslogtreecommitdiff
path: root/kiki.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2014-05-11 19:54:19 -0400
committerjoe <joe@jerkface.net>2014-05-11 19:54:19 -0400
commitadec571e0f7e7474575303905f109d4348573a00 (patch)
treed1ea8f8a4745e60bd6a4cab358d7cf2280f8cf68 /kiki.hs
parent25c5eca6053af9c9c89d735ae795b603212fb1f0 (diff)
show --cert, certificate import bug fixes
Diffstat (limited to 'kiki.hs')
-rw-r--r--kiki.hs24
1 files changed, 22 insertions, 2 deletions
diff --git a/kiki.hs b/kiki.hs
index 063c42c..f1568aa 100644
--- a/kiki.hs
+++ b/kiki.hs
@@ -39,7 +39,7 @@ import Data.Binary.Put (putWord32be,runPut,putByteString)
39import Data.X509 -- (Certificate,SignedCertificate, decodeSignedObject, decodeSignedCertificate ) 39import Data.X509 -- (Certificate,SignedCertificate, decodeSignedObject, decodeSignedCertificate )
40import Crypto.PubKey.RSA as RSA 40import Crypto.PubKey.RSA as RSA
41import qualified Codec.Compression.GZip as GZip 41import qualified Codec.Compression.GZip as GZip
42import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds ) 42import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds, posixSecondsToUTCTime )
43import Data.Time.Clock ( UTCTime ) 43import Data.Time.Clock ( UTCTime )
44import Data.Monoid ( (<>) ) 44import Data.Monoid ( (<>) )
45 45
@@ -343,7 +343,26 @@ show_torhash pubkey _ = do
343 keys = catMaybes $ scanAndParse (pkcs1 <> pkcs8 <> cert) $ Char8.lines bs 343 keys = catMaybes $ scanAndParse (pkcs1 <> pkcs8 <> cert) $ Char8.lines bs
344 mapM_ (putStrLn . addy . torhash) keys 344 mapM_ (putStrLn . addy . torhash) keys
345 345
346show_cert keyspec wkgrip db = do
347 let s = parseSpec wkgrip keyspec
348 putStrLn $ "parsed spec: "++show s
349 case selectPublicKeyAndSigs s db of
350 [] -> void $ warn (keyspec ++ ": not found")
351 [(k,sigs)] -> do
352 {-
353 let rsa = pkcs8 . fromJust $ rsaKeyFromPacket k
354 der = encodeASN1 DER (toASN1 rsa [])
355 qq = Base64.encode (L.unpack der)
356 putStrLn $ writePEM "PUBLIC KEY (TODO: CERT)" qq -- ("TODO "++show keyspec)
357 -}
358 let cs = mapMaybe x509cert $ (sigs >>= hashed_subpackets)
359 ds = map decodeBlob $ map (ParsedCert k (posixSecondsToUTCTime $ fromIntegral $ timestamp k)) cs
360 qqs = map (Base64.encode . L.unpack) ds
361 pems = map (writePEM "CERTIFICATE") qqs
362 forM_ pems putStrLn
363 _ -> void $ warn (keyspec ++ ": ambiguous")
346 364
365{-
347show_cert certfile _ = do 366show_cert certfile _ = do
348 bs <- Char8.readFile certfile 367 bs <- Char8.readFile certfile
349 let dta = scanAndParse (fmap pemBlob $ pemParser $ Just "CERTIFICATE") $ Char8.lines bs 368 let dta = scanAndParse (fmap pemBlob $ pemParser $ Just "CERTIFICATE") $ Char8.lines bs
@@ -385,6 +404,7 @@ show_cert certfile _ = do
385 putStrLn "" 404 putStrLn ""
386 putStrLn $ "prefix = " ++ hexL v 405 putStrLn $ "prefix = " ++ hexL v
387 return () 406 return ()
407-}
388 408
389cannonical_eckey x y = 0x4:pad32(numToBytes x) ++ pad32(numToBytes y) :: [Word8] 409cannonical_eckey x y = 0x4:pad32(numToBytes x) ++ pad32(numToBytes y) :: [Word8]
390 where 410 where
@@ -935,7 +955,7 @@ kiki "show" args = do
935 ,("--pem",\[x] -> show_pem x $ fromMaybe "" grip) 955 ,("--pem",\[x] -> show_pem x $ fromMaybe "" grip)
936 ,("--ssh",\[x] -> show_ssh x $ fromMaybe "" grip) 956 ,("--ssh",\[x] -> show_ssh x $ fromMaybe "" grip)
937 ,("--wip",\[x] -> show_wip x $ fromMaybe "" grip) 957 ,("--wip",\[x] -> show_wip x $ fromMaybe "" grip)
938 ,("--cert",\[x] -> show_cert x) 958 ,("--cert",\[x] -> show_cert x $ fromMaybe "" grip)
939 ,("--torhash",\[x] -> show_torhash x) 959 ,("--torhash",\[x] -> show_torhash x)
940 ] 960 ]
941 shargs = mapMaybe (\(x:xs) -> (,xs) <$> Map.lookup x shspec) sargs 961 shargs = mapMaybe (\(x:xs) -> (,xs) <$> Map.lookup x shspec) sargs