summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kiki.hs21
-rw-r--r--lib/Kiki.hs20
2 files changed, 0 insertions, 41 deletions
diff --git a/kiki.hs b/kiki.hs
index fb4b878..eb997ac 100644
--- a/kiki.hs
+++ b/kiki.hs
@@ -30,22 +30,13 @@ import Foreign.C.Types (CTime(..))
30import System.Environment 30import System.Environment
31import System.Exit 31import System.Exit
32import System.IO (hPutStrLn,stderr) 32import System.IO (hPutStrLn,stderr)
33#if defined(VERSION_memory)
34import qualified Data.ByteString.Char8 as S8 33import qualified Data.ByteString.Char8 as S8
35import Data.ByteArray.Encoding 34import Data.ByteArray.Encoding
36#elif defined(VERSION_dataenc)
37import qualified Codec.Binary.Base64 as Base64
38#endif
39import qualified Codec.Archive.Tar as Tar 35import qualified Codec.Archive.Tar as Tar
40import qualified Codec.Archive.Tar.Entry as Tar 36import qualified Codec.Archive.Tar.Entry as Tar
41#if !defined(VERSION_cryptonite)
42import qualified Crypto.Hash.RIPEMD160 as RIPEMD160
43import qualified Crypto.Hash.SHA256 as SHA256
44#else
45import Crypto.Hash.Algorithms (RIPEMD160(..)) 37import Crypto.Hash.Algorithms (RIPEMD160(..))
46import Crypto.Hash 38import Crypto.Hash
47import Data.ByteArray (convert) 39import Data.ByteArray (convert)
48#endif
49import qualified Data.ByteString as S 40import qualified Data.ByteString as S
50import qualified Data.ByteString.Lazy as L 41import qualified Data.ByteString.Lazy as L
51import qualified Data.ByteString.Lazy.Char8 as Char8 42import 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 ()
323show_torhash pubkey _ = do 310show_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
37import System.Posix.Types (FileMode) 37import System.Posix.Types (FileMode)
38import System.Posix.IO as Posix (createPipe) 38import System.Posix.IO as Posix (createPipe)
39import System.Posix.User 39import System.Posix.User
40#if defined(VERSION_memory)
41import Data.ByteArray.Encoding 40import Data.ByteArray.Encoding
42import qualified Data.ByteString.Char8 as S8 41import qualified Data.ByteString.Char8 as S8
43#elif defined(VERSION_dataenc)
44import qualified Codec.Binary.Base64 as Base64
45#endif
46import qualified Data.ByteString.Lazy as L 42import qualified Data.ByteString.Lazy as L
47import qualified Data.ByteString.Lazy.Char8 as Char8 43import qualified Data.ByteString.Lazy.Char8 as Char8
48import qualified Data.Map.Strict as Map 44import 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)
623sortOn :: Ord b => (a -> b) -> [a] -> [a]
624sortOn f =
625 map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x))
626#endif
627
628pemFromPacket :: Monad m => Packet -> m String 612pemFromPacket :: Monad m => Packet -> m String
629pemFromPacket k = do 613pemFromPacket 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