diff options
Diffstat (limited to 'KeyRing.hs')
-rw-r--r-- | KeyRing.hs | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -133,10 +133,16 @@ import qualified Data.ByteString.Lazy as L ( unpack, null, readFile, writeFile | |||
133 | , ByteString, toChunks, hGetContents, hPut, concat, fromChunks, splitAt | 133 | , ByteString, toChunks, hGetContents, hPut, concat, fromChunks, splitAt |
134 | , index ) | 134 | , index ) |
135 | import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null, putStr ) | 135 | import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null, putStr ) |
136 | import qualified Crypto.Types.PubKey.ECC as ECC | ||
137 | import qualified Codec.Binary.Base32 as Base32 | 136 | import qualified Codec.Binary.Base32 as Base32 |
138 | import qualified Codec.Binary.Base64 as Base64 | 137 | import qualified Codec.Binary.Base64 as Base64 |
138 | #if !defined(VERSION_cryptonite) | ||
139 | import qualified Crypto.Hash.SHA1 as SHA1 | 139 | import qualified Crypto.Hash.SHA1 as SHA1 |
140 | import qualified Crypto.Types.PubKey.ECC as ECC | ||
141 | #else | ||
142 | import qualified Crypto.Hash as Vincent | ||
143 | import Data.ByteArray (convert) | ||
144 | import qualified Crypto.PubKey.ECC.Types as ECC | ||
145 | #endif | ||
140 | import qualified Data.X509 as X509 | 146 | import qualified Data.X509 as X509 |
141 | import qualified Crypto.PubKey.RSA as RSA | 147 | import qualified Crypto.PubKey.RSA as RSA |
142 | import qualified Codec.Compression.GZip as GZip | 148 | import qualified Codec.Compression.GZip as GZip |
@@ -173,8 +179,7 @@ import Debug.Trace | |||
173 | #endif | 179 | #endif |
174 | import Network.Socket -- (SockAddr) | 180 | import Network.Socket -- (SockAddr) |
175 | import qualified Data.ByteString.Lazy.Char8 as Char8 | 181 | import qualified Data.ByteString.Lazy.Char8 as Char8 |
176 | 182 | import Compat | |
177 | |||
178 | 183 | ||
179 | import TimeUtil | 184 | import TimeUtil |
180 | import PEM | 185 | import PEM |
@@ -1441,7 +1446,14 @@ torhash :: Packet -> String | |||
1441 | torhash key = fromMaybe "" $ derToBase32 <$> derRSA key | 1446 | torhash key = fromMaybe "" $ derToBase32 <$> derRSA key |
1442 | 1447 | ||
1443 | derToBase32 :: ByteString -> String | 1448 | derToBase32 :: ByteString -> String |
1449 | #if !defined(VERSION_cryptonite) | ||
1444 | derToBase32 = map toLower . Base32.encode . S.unpack . SHA1.hashlazy | 1450 | derToBase32 = map toLower . Base32.encode . S.unpack . SHA1.hashlazy |
1451 | #else | ||
1452 | derToBase32 = map toLower . Base32.encode . S.unpack . sha1 | ||
1453 | where | ||
1454 | sha1 :: L.ByteString -> S.ByteString | ||
1455 | sha1 x = convert (Vincent.hashlazy x :: Vincent.Digest Vincent.SHA1) | ||
1456 | #endif | ||
1445 | 1457 | ||
1446 | derRSA :: Packet -> Maybe ByteString | 1458 | derRSA :: Packet -> Maybe ByteString |
1447 | derRSA rsa = do | 1459 | derRSA rsa = do |
@@ -1480,6 +1492,8 @@ spemCert _ = Nothing | |||
1480 | toStrict :: L.ByteString -> S.ByteString | 1492 | toStrict :: L.ByteString -> S.ByteString |
1481 | toStrict = foldr1 (<>) . L.toChunks | 1493 | toStrict = foldr1 (<>) . L.toChunks |
1482 | 1494 | ||
1495 | -- No instance for (ASN1Object RSA.PublicKey) | ||
1496 | |||
1483 | parseCertBlob comp bs = do | 1497 | parseCertBlob comp bs = do |
1484 | asn1 <- either (const Nothing) Just | 1498 | asn1 <- either (const Nothing) Just |
1485 | $ decodeASN1 DER bs | 1499 | $ decodeASN1 DER bs |
@@ -1936,6 +1950,7 @@ writePEM typ dta = pem | |||
1936 | [ ["-----BEGIN " <> typ <> "-----"] | 1950 | [ ["-----BEGIN " <> typ <> "-----"] |
1937 | , split64s dta | 1951 | , split64s dta |
1938 | , ["-----END " <> typ <> "-----"] ] | 1952 | , ["-----END " <> typ <> "-----"] ] |
1953 | split64s :: String -> [String] | ||
1939 | split64s "" = [] | 1954 | split64s "" = [] |
1940 | split64s dta = line : split64s rest where (line,rest) = splitAt 64 dta | 1955 | split64s dta = line : split64s rest where (line,rest) = splitAt 64 dta |
1941 | 1956 | ||