summaryrefslogtreecommitdiff
path: root/KeyRing.hs
diff options
context:
space:
mode:
Diffstat (limited to 'KeyRing.hs')
-rw-r--r--KeyRing.hs21
1 files changed, 18 insertions, 3 deletions
diff --git a/KeyRing.hs b/KeyRing.hs
index 776ded3..50702ae 100644
--- a/KeyRing.hs
+++ b/KeyRing.hs
@@ -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 )
135import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null, putStr ) 135import qualified Data.ByteString as S ( ByteString, unpack, splitAt, concat, cons, spanEnd, hGetContents, readFile, breakSubstring, drop, length, null, putStr )
136import qualified Crypto.Types.PubKey.ECC as ECC
137import qualified Codec.Binary.Base32 as Base32 136import qualified Codec.Binary.Base32 as Base32
138import qualified Codec.Binary.Base64 as Base64 137import qualified Codec.Binary.Base64 as Base64
138#if !defined(VERSION_cryptonite)
139import qualified Crypto.Hash.SHA1 as SHA1 139import qualified Crypto.Hash.SHA1 as SHA1
140import qualified Crypto.Types.PubKey.ECC as ECC
141#else
142import qualified Crypto.Hash as Vincent
143import Data.ByteArray (convert)
144import qualified Crypto.PubKey.ECC.Types as ECC
145#endif
140import qualified Data.X509 as X509 146import qualified Data.X509 as X509
141import qualified Crypto.PubKey.RSA as RSA 147import qualified Crypto.PubKey.RSA as RSA
142import qualified Codec.Compression.GZip as GZip 148import qualified Codec.Compression.GZip as GZip
@@ -173,8 +179,7 @@ import Debug.Trace
173#endif 179#endif
174import Network.Socket -- (SockAddr) 180import Network.Socket -- (SockAddr)
175import qualified Data.ByteString.Lazy.Char8 as Char8 181import qualified Data.ByteString.Lazy.Char8 as Char8
176 182import Compat
177
178 183
179import TimeUtil 184import TimeUtil
180import PEM 185import PEM
@@ -1441,7 +1446,14 @@ torhash :: Packet -> String
1441torhash key = fromMaybe "" $ derToBase32 <$> derRSA key 1446torhash key = fromMaybe "" $ derToBase32 <$> derRSA key
1442 1447
1443derToBase32 :: ByteString -> String 1448derToBase32 :: ByteString -> String
1449#if !defined(VERSION_cryptonite)
1444derToBase32 = map toLower . Base32.encode . S.unpack . SHA1.hashlazy 1450derToBase32 = map toLower . Base32.encode . S.unpack . SHA1.hashlazy
1451#else
1452derToBase32 = 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
1446derRSA :: Packet -> Maybe ByteString 1458derRSA :: Packet -> Maybe ByteString
1447derRSA rsa = do 1459derRSA rsa = do
@@ -1480,6 +1492,8 @@ spemCert _ = Nothing
1480toStrict :: L.ByteString -> S.ByteString 1492toStrict :: L.ByteString -> S.ByteString
1481toStrict = foldr1 (<>) . L.toChunks 1493toStrict = foldr1 (<>) . L.toChunks
1482 1494
1495-- No instance for (ASN1Object RSA.PublicKey)
1496
1483parseCertBlob comp bs = do 1497parseCertBlob 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