From 13f3a96ae0a1417e15c9f969737c512ec71642f9 Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 14 Apr 2016 14:48:26 -0400 Subject: Updated build. --- kiki.hs | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'kiki.hs') diff --git a/kiki.hs b/kiki.hs index 2d926a8..316da90 100644 --- a/kiki.hs +++ b/kiki.hs @@ -29,8 +29,14 @@ import System.Environment import System.Exit import System.IO (hPutStrLn,stderr) import qualified Codec.Binary.Base64 as Base64 -import qualified Crypto.Hash.RIPEMD160 as RIPEMD160 +#if !defined(VERSION_cryptonite) +-- import qualified Crypto.Hash.RIPEMD160 as RIPEMD160 import qualified Crypto.Hash.SHA256 as SHA256 +#else +import Crypto.Hash.Algorithms (RIPEMD160(..)) +import Crypto.Hash +import Data.ByteArray (convert) +#endif import qualified Data.ByteString as S import qualified Data.ByteString.Lazy as L import qualified Data.ByteString.Lazy.Char8 as Char8 @@ -38,6 +44,7 @@ import qualified Data.Map as Map import Control.Arrow (first,second) import Data.Time.Clock.POSIX ( posixSecondsToUTCTime ) import Data.Monoid ( (<>) ) +import Data.Binary.Put import Data.OpenPGP.Util (verify,fingerprint) import ScanningParser @@ -50,6 +57,7 @@ import qualified CryptoCoins import ProcessUtils import qualified SSHKey as SSH import Text.Printf +import qualified DNSKey as DNS -- {-# ANN module ("HLint: ignore Eta reduce"::String) #-} -- {-# ANN module ("HLint: ignore Use camelCase"::String) #-} @@ -279,13 +287,15 @@ show_whose_key input_key db = (_:_) -> error "ambiguous" [] -> return () -show_pem keyspec wkgrip db = either warn putStrLn $ show_pem' keyspec wkgrip db +show_dns keyspec wkgrip db = either warn putStrLn $ show_pem' keyspec wkgrip db dnsPresentationFromPacket -show_pem' keyspec wkgrip db = do +show_pem keyspec wkgrip db = either warn putStrLn $ show_pem' keyspec wkgrip db pemFromPacket + +show_pem' keyspec wkgrip db keyfmt = do let s = parseSpec wkgrip keyspec flip (maybe . Left $ keyspec ++ ": not found") (selectPublicKey s db) - pemFromPacket + keyfmt pemFromPacket k = do let rsa = pkcs8 . fromJust $ rsaKeyFromPacket k @@ -294,6 +304,15 @@ pemFromPacket k = do return $ writePEM "PUBLIC KEY" qq -- ("TODO "++show keyspec) +dnsPresentationFromPacket k = do + let RSAKey (MPI n) (MPI e) = fromJust $ rsaKeyFromPacket k + dnskey = DNS.RSA n e + bin = runPut (DNS.putRSA dnskey) + qq = Base64.encode (L.unpack bin) + return $ + writePEM "FIXME PUBLIC KEY" qq -- ("TODO "++show keyspec) + + show_ssh keyspec wkgrip db = either warn putStrLn $ show_ssh' keyspec wkgrip db show_ssh' keyspec wkgrip db = do @@ -331,6 +350,8 @@ show_torhash pubkey _ = do asn1 <- either (const Nothing) (Just) e k <- either (const Nothing) (Just . fst) (fromASN1 asn1) return $ f (packetFromPublicRSAKey undefined) k + + addy :: String -> String addy hsh = take 16 hsh ++ ".onion " ++ hsh pkcs1 = fmap ( parsekey (\f (RSAKey n e) -> f n e) . pemBlob ) $ pemParser (Just "RSA PUBLIC KEY") @@ -421,8 +442,14 @@ bitcoinAddress network_id k = address Just (MPI x) = lookup 'x' (key k) Just (MPI y) = lookup 'y' (key k) pub = cannonical_eckey x y - hash = S.cons network_id . RIPEMD160.hash . SHA256.hash . S.pack $ pub - address = base58_encode hash +#if !defined(VERSION_cryptonite) + hsh = S.cons network_id . RIPEMD160.hash . SHA256.hash . S.pack $ pub +#else + hsh = S.cons network_id . ripemd160 . sha256 . S.pack $ pub + sha256 x = convert (Crypto.Hash.hash x :: Digest SHA256) :: S.ByteString + ripemd160 x = convert (Crypto.Hash.hash x :: Digest RIPEMD160) :: S.ByteString +#endif + address = base58_encode hsh whoseKey :: RSAPublicKey -> KeyDB -> [KeyData] whoseKey rsakey db = filter matchkey (Map.elems db) @@ -484,6 +511,11 @@ kiki_usage bExport bImport bSecret cmd = putStr $ ," Shows the fingerprint and UIDs of the key that owns the one that" ," is input on stdin in ssh-rsa format." ,"" + ," --dns SPEC" + ," Outputs the DNSKEY presentation format (RFC3110) of the public key" + ," corresponding to SPEC." + ," (See 'kiki help spec' for more information.)" + ,"" ," --pem SPEC" ," Outputs the PKCS #8 public key corresponding to SPEC." ," (See 'kiki help spec' for more information.)" @@ -1130,6 +1162,7 @@ kiki "show" args = do , ("--whose-key",0) , ("--key",1) , ("--pem",1) + , ("--dns",1) , ("--ssh",1) , ("--wip",1) , ("--cert",1) @@ -1180,6 +1213,7 @@ kiki "show" args = do ,("--whose-key", const $ show_whose_key input_key) ,("--key",\[x] -> show_id x $ fromMaybe "" grip) ,("--pem",\[x] -> show_pem x $ fromMaybe "" grip) + ,("--dns",\[x] -> show_dns x $ fromMaybe "" grip) ,("--ssh",\[x] -> show_ssh x $ fromMaybe "" grip) ,("--wip",\[x] -> show_wip x $ fromMaybe "" grip) ,("--cert",\[x] -> show_cert x $ fromMaybe "" grip) @@ -1253,6 +1287,7 @@ kiki "merge" args = do w:xs -> w:map (drop 1) xs [] -> [] (goods,bads) = partition acceptable ws + acceptable :: String -> Bool acceptable "spill" = True acceptable "fill" = True acceptable "sync" = True @@ -1496,7 +1531,7 @@ kiki "init-key" args = do goti <- doesFileExist (ipsecpathpub) when (not goti) $ do either warn (writeFile $ ipsecpathpub) - $ show_pem' "strongswan" grip (rtKeyDB rt) + $ show_pem' "strongswan" grip (rtKeyDB rt) pemFromPacket else return () @@ -1585,7 +1620,8 @@ interp vars raw = es >>= interp1 where gs = groupBy (\_ c -> c/='%') raw es = dropWhile null $ gobbleEscapes ("":gs) - where gobbleEscapes (a:"%":b:bs) = (a++b) : gobbleEscapes bs + where gobbleEscapes :: [String] -> [String] + gobbleEscapes (a:"%":b:bs) = (a++b) : gobbleEscapes bs gobbleEscapes (g:gs) = g : gobbleEscapes gs gobbleEscapes [] = [] interp1 ('%':'(':str) = fromMaybe "" (Map.lookup key vars) ++ drop 1 rest -- cgit v1.2.3