diff options
Diffstat (limited to 'kiki.hs')
-rw-r--r-- | kiki.hs | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -39,7 +39,7 @@ import Data.Binary.Put (putWord32be,runPut,putByteString) | |||
39 | import Data.X509 -- (Certificate,SignedCertificate, decodeSignedObject, decodeSignedCertificate ) | 39 | import Data.X509 -- (Certificate,SignedCertificate, decodeSignedObject, decodeSignedCertificate ) |
40 | import Crypto.PubKey.RSA as RSA | 40 | import Crypto.PubKey.RSA as RSA |
41 | import qualified Codec.Compression.GZip as GZip | 41 | import qualified Codec.Compression.GZip as GZip |
42 | import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds ) | 42 | import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds, posixSecondsToUTCTime ) |
43 | import Data.Time.Clock ( UTCTime ) | 43 | import Data.Time.Clock ( UTCTime ) |
44 | import Data.Monoid ( (<>) ) | 44 | import 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 | ||
346 | show_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 | {- | ||
347 | show_cert certfile _ = do | 366 | show_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 | ||
389 | cannonical_eckey x y = 0x4:pad32(numToBytes x) ++ pad32(numToBytes y) :: [Word8] | 409 | cannonical_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 |