diff options
-rw-r--r-- | kiki.hs | 21 | ||||
-rw-r--r-- | lib/Kiki.hs | 20 |
2 files changed, 0 insertions, 41 deletions
@@ -30,22 +30,13 @@ import Foreign.C.Types (CTime(..)) | |||
30 | import System.Environment | 30 | import System.Environment |
31 | import System.Exit | 31 | import System.Exit |
32 | import System.IO (hPutStrLn,stderr) | 32 | import System.IO (hPutStrLn,stderr) |
33 | #if defined(VERSION_memory) | ||
34 | import qualified Data.ByteString.Char8 as S8 | 33 | import qualified Data.ByteString.Char8 as S8 |
35 | import Data.ByteArray.Encoding | 34 | import Data.ByteArray.Encoding |
36 | #elif defined(VERSION_dataenc) | ||
37 | import qualified Codec.Binary.Base64 as Base64 | ||
38 | #endif | ||
39 | import qualified Codec.Archive.Tar as Tar | 35 | import qualified Codec.Archive.Tar as Tar |
40 | import qualified Codec.Archive.Tar.Entry as Tar | 36 | import qualified Codec.Archive.Tar.Entry as Tar |
41 | #if !defined(VERSION_cryptonite) | ||
42 | import qualified Crypto.Hash.RIPEMD160 as RIPEMD160 | ||
43 | import qualified Crypto.Hash.SHA256 as SHA256 | ||
44 | #else | ||
45 | import Crypto.Hash.Algorithms (RIPEMD160(..)) | 37 | import Crypto.Hash.Algorithms (RIPEMD160(..)) |
46 | import Crypto.Hash | 38 | import Crypto.Hash |
47 | import Data.ByteArray (convert) | 39 | import Data.ByteArray (convert) |
48 | #endif | ||
49 | import qualified Data.ByteString as S | 40 | import qualified Data.ByteString as S |
50 | import qualified Data.ByteString.Lazy as L | 41 | import qualified Data.ByteString.Lazy as L |
51 | import qualified Data.ByteString.Lazy.Char8 as Char8 | 42 | import qualified Data.ByteString.Lazy.Char8 as Char8 |
@@ -281,11 +272,7 @@ dnsPresentationFromPacket k = do | |||
281 | let RSAKey (MPI n) (MPI e) = fromJust $ rsaKeyFromPacket k | 272 | let RSAKey (MPI n) (MPI e) = fromJust $ rsaKeyFromPacket k |
282 | dnskey = DNS.RSA n e | 273 | dnskey = DNS.RSA n e |
283 | bin = runPut (DNS.putRSA dnskey) | 274 | bin = runPut (DNS.putRSA dnskey) |
284 | #if defined(VERSION_memory) | ||
285 | qq = S8.unpack $ convertToBase Base64 (L.toStrict bin) | 275 | qq = S8.unpack $ convertToBase Base64 (L.toStrict bin) |
286 | #elif defined(VERSION_dataenc) | ||
287 | qq = Base64.encode (L.unpack bin) | ||
288 | #endif | ||
289 | ttl = 24*60*60 -- 24 hours in seconds | 276 | ttl = 24*60*60 -- 24 hours in seconds |
290 | flags = 256 -- (ZONE-key = bit7) TODO: is this a zone key or a key-signing key? | 277 | flags = 256 -- (ZONE-key = bit7) TODO: is this a zone key or a key-signing key? |
291 | algo = 8 -- RSASHA256 -- TODO: support other algorithm | 278 | algo = 8 -- RSASHA256 -- TODO: support other algorithm |
@@ -323,11 +310,7 @@ show_torhash :: FilePath -> p -> IO () | |||
323 | show_torhash pubkey _ = do | 310 | show_torhash pubkey _ = do |
324 | bs <- Char8.readFile pubkey | 311 | bs <- Char8.readFile pubkey |
325 | let parsekey f dta = do | 312 | let parsekey f dta = do |
326 | #if defined(VERSION_memory) | ||
327 | let mdta = fmap L.fromStrict $ functorToMaybe $ convertFromBase Base64 (Char8.toStrict dta) | 313 | let mdta = fmap L.fromStrict $ functorToMaybe $ convertFromBase Base64 (Char8.toStrict dta) |
328 | #elif defined(VERSION_dataenc) | ||
329 | let mdta = L.pack <$> Base64.decode (Char8.unpack dta) | ||
330 | #endif | ||
331 | e <- decodeASN1 DER <$> mdta | 314 | e <- decodeASN1 DER <$> mdta |
332 | asn1 <- either (const Nothing) (Just) e | 315 | asn1 <- either (const Nothing) (Just) e |
333 | k <- either (const Nothing) (Just . fst) (fromASN1 asn1) | 316 | k <- either (const Nothing) (Just . fst) (fromASN1 asn1) |
@@ -358,11 +341,7 @@ show_cert keyspec wkgrip db = do | |||
358 | -} | 341 | -} |
359 | let cs = mapMaybe x509cert $ (sigs >>= hashed_subpackets) | 342 | let cs = mapMaybe x509cert $ (sigs >>= hashed_subpackets) |
360 | ds = map decodeBlob $ map (ParsedCert k (posixSecondsToUTCTime $ fromIntegral $ timestamp k)) cs | 343 | ds = map decodeBlob $ map (ParsedCert k (posixSecondsToUTCTime $ fromIntegral $ timestamp k)) cs |
361 | #if defined(VERSION_memory) | ||
362 | qqs = map (S8.unpack . convertToBase Base64 . L.toStrict) ds | 344 | qqs = map (S8.unpack . convertToBase Base64 . L.toStrict) ds |
363 | #elif defined(VERSION_dataenc) | ||
364 | qqs = map (Base64.encode . L.unpack) ds | ||
365 | #endif | ||
366 | pems = map (writePEM PemCertificate) qqs | 345 | pems = map (writePEM PemCertificate) qqs |
367 | forM_ pems putStrLn | 346 | forM_ pems putStrLn |
368 | _ -> void $ warn (keyspec ++ ": ambiguous") | 347 | _ -> void $ warn (keyspec ++ ": ambiguous") |
diff --git a/lib/Kiki.hs b/lib/Kiki.hs index 5481241..7cb373c 100644 --- a/lib/Kiki.hs +++ b/lib/Kiki.hs | |||
@@ -37,12 +37,8 @@ import System.Posix.Files | |||
37 | import System.Posix.Types (FileMode) | 37 | import System.Posix.Types (FileMode) |
38 | import System.Posix.IO as Posix (createPipe) | 38 | import System.Posix.IO as Posix (createPipe) |
39 | import System.Posix.User | 39 | import System.Posix.User |
40 | #if defined(VERSION_memory) | ||
41 | import Data.ByteArray.Encoding | 40 | import Data.ByteArray.Encoding |
42 | import qualified Data.ByteString.Char8 as S8 | 41 | import qualified Data.ByteString.Char8 as S8 |
43 | #elif defined(VERSION_dataenc) | ||
44 | import qualified Codec.Binary.Base64 as Base64 | ||
45 | #endif | ||
46 | import qualified Data.ByteString.Lazy as L | 42 | import qualified Data.ByteString.Lazy as L |
47 | import qualified Data.ByteString.Lazy.Char8 as Char8 | 43 | import qualified Data.ByteString.Lazy.Char8 as Char8 |
48 | import qualified Data.Map.Strict as Map | 44 | import qualified Data.Map.Strict as Map |
@@ -74,18 +70,12 @@ cipherFromString s = | |||
74 | _ -> error $ "known ciphers: "++unwords (map ciphername ciphers) | 70 | _ -> error $ "known ciphers: "++unwords (map ciphername ciphers) |
75 | {- | 71 | {- |
76 | where | 72 | where |
77 | #if defined(VERSION_memory) | ||
78 | unhex hx = case convertFromBase Base16 (S8.pack hx) of | 73 | unhex hx = case convertFromBase Base16 (S8.pack hx) of |
79 | Left e -> do | 74 | Left e -> do |
80 | -- Useful for debugging but insecure generally ;) | 75 | -- Useful for debugging but insecure generally ;) |
81 | -- putStrLn $ "convertFromBase error for input "++show hx++": "++show e | 76 | -- putStrLn $ "convertFromBase error for input "++show hx++": "++show e |
82 | return Nothing | 77 | return Nothing |
83 | Right bs -> return $ Just $ S8.unpack bs | 78 | Right bs -> return $ Just $ S8.unpack bs |
84 | #elif defined(VERSION_dataenc) | ||
85 | unhex hx = maybe (return () {- putStrLn $ "dataenc error for input "++show hx -}) | ||
86 | return | ||
87 | $ fmap (map $ chr . fromIntegral) $ Base16.decode hx | ||
88 | #endif | ||
89 | -} | 79 | -} |
90 | 80 | ||
91 | 81 | ||
@@ -619,21 +609,11 @@ showA addr = if null bracket then pre else drop 1 pre | |||
619 | where (pre,bracket) = break (==']') (show addr) | 609 | where (pre,bracket) = break (==']') (show addr) |
620 | 610 | ||
621 | 611 | ||
622 | #if !MIN_VERSION_base(4,8,0) | ||
623 | sortOn :: Ord b => (a -> b) -> [a] -> [a] | ||
624 | sortOn f = | ||
625 | map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x)) | ||
626 | #endif | ||
627 | |||
628 | pemFromPacket :: Monad m => Packet -> m String | 612 | pemFromPacket :: Monad m => Packet -> m String |
629 | pemFromPacket k = do | 613 | pemFromPacket k = do |
630 | let rsa = pkcs8 . fromJust $ rsaKeyFromPacket k | 614 | let rsa = pkcs8 . fromJust $ rsaKeyFromPacket k |
631 | der = encodeASN1 DER (toASN1 rsa []) | 615 | der = encodeASN1 DER (toASN1 rsa []) |
632 | #if defined(VERSION_memory) | ||
633 | qq = S8.unpack $ convertToBase Base64 (L.toStrict der) | 616 | qq = S8.unpack $ convertToBase Base64 (L.toStrict der) |
634 | #elif defined(VERSION_dataenc) | ||
635 | qq = Base64.encode (L.unpack der) | ||
636 | #endif | ||
637 | return $ | 617 | return $ |
638 | writePEM PemPublicKey qq -- ("TODO "++show keyspec) | 618 | writePEM PemPublicKey qq -- ("TODO "++show keyspec) |
639 | 619 | ||