diff options
author | joe <joe@jerkface.net> | 2013-12-14 23:14:16 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2013-12-14 23:14:16 -0500 |
commit | 6b42fc6904d05979c409c0043d6d7b2eed22b58c (patch) | |
tree | 0cccb442aa3ab4f17ee54e63ae80ca240fbb5b8e /Data/OpenPGP/Util/Verify.hs | |
parent | ce0d32ef83ccf15198bdd5248faa02abbcf2f769 (diff) |
Refactoring.
Diffstat (limited to 'Data/OpenPGP/Util/Verify.hs')
-rw-r--r-- | Data/OpenPGP/Util/Verify.hs | 66 |
1 files changed, 1 insertions, 65 deletions
diff --git a/Data/OpenPGP/Util/Verify.hs b/Data/OpenPGP/Util/Verify.hs index 137c00f..2367570 100644 --- a/Data/OpenPGP/Util/Verify.hs +++ b/Data/OpenPGP/Util/Verify.hs | |||
@@ -6,69 +6,18 @@ import Data.Binary (encode) | |||
6 | import Control.Monad | 6 | import Control.Monad |
7 | import qualified Data.ByteString as BS | 7 | import qualified Data.ByteString as BS |
8 | import qualified Data.ByteString.Lazy as LZ | 8 | import qualified Data.ByteString.Lazy as LZ |
9 | import Data.Monoid ( (<>) ) | ||
10 | |||
11 | import Data.OpenPGP.Util.Fingerprint (fingerprint) | ||
12 | 9 | ||
13 | import qualified Crypto.PubKey.DSA as Vincent.DSA | 10 | import qualified Crypto.PubKey.DSA as Vincent.DSA |
14 | import qualified Crypto.PubKey.RSA as Vincent.RSA | ||
15 | import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA | 11 | import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA |
16 | import Crypto.PubKey.HashDescr as Vincent | ||
17 | |||
18 | import Crypto.Hash.MD5 as MD5 | ||
19 | import Crypto.Hash.SHA1 as SHA1 | ||
20 | import Crypto.Hash.SHA256 as SHA256 | ||
21 | import Crypto.Hash.SHA384 as SHA384 | ||
22 | import Crypto.Hash.SHA512 as SHA512 | ||
23 | import Crypto.Hash.SHA224 as SHA224 | ||
24 | import Crypto.Hash.RIPEMD160 as RIPEMD160 | ||
25 | |||
26 | hashBySymbol OpenPGP.MD5 = MD5.hashlazy | ||
27 | hashBySymbol OpenPGP.SHA1 = SHA1.hashlazy | ||
28 | hashBySymbol OpenPGP.SHA256 = SHA256.hashlazy | ||
29 | hashBySymbol OpenPGP.SHA384 = SHA384.hashlazy | ||
30 | hashBySymbol OpenPGP.SHA512 = SHA512.hashlazy | ||
31 | hashBySymbol OpenPGP.SHA224 = SHA224.hashlazy | ||
32 | hashBySymbol OpenPGP.RIPEMD160 = RIPEMD160.hashlazy | ||
33 | |||
34 | |||
35 | toStrictBS :: LZ.ByteString -> BS.ByteString | ||
36 | toStrictBS = BS.concat . LZ.toChunks | ||
37 | |||
38 | toLazyBS :: BS.ByteString -> LZ.ByteString | ||
39 | toLazyBS = LZ.fromChunks . (:[]) | ||
40 | |||
41 | hush :: Either a b -> Maybe b | ||
42 | hush (Left _) = Nothing | ||
43 | hush (Right x) = Just x | ||
44 | |||
45 | fromJustMPI :: Maybe OpenPGP.MPI -> Integer | ||
46 | fromJustMPI (Just (OpenPGP.MPI x)) = x | ||
47 | fromJustMPI _ = error "Not a Just MPI, Data.OpenPGP.CryptoAPI" | ||
48 | 12 | ||
13 | import Data.OpenPGP.Util.Base | ||
49 | 14 | ||
50 | 15 | ||
51 | find_key :: OpenPGP.Message -> String -> Maybe OpenPGP.Packet | ||
52 | find_key = OpenPGP.find_key fingerprint | ||
53 | |||
54 | integerBytesize :: Integer -> Int | ||
55 | integerBytesize i = fromIntegral $ LZ.length (encode (OpenPGP.MPI i)) - 2 | ||
56 | |||
57 | dsaKey :: OpenPGP.Packet -> Vincent.DSA.PublicKey | 16 | dsaKey :: OpenPGP.Packet -> Vincent.DSA.PublicKey |
58 | dsaKey k = Vincent.DSA.PublicKey | 17 | dsaKey k = Vincent.DSA.PublicKey |
59 | (Vincent.DSA.Params (keyParam 'p' k) (keyParam 'g' k) (keyParam 'q' k)) | 18 | (Vincent.DSA.Params (keyParam 'p' k) (keyParam 'g' k) (keyParam 'q' k)) |
60 | (keyParam 'y' k) | 19 | (keyParam 'y' k) |
61 | 20 | ||
62 | rsaKey :: OpenPGP.Packet -> Vincent.RSA.PublicKey | ||
63 | rsaKey k = | ||
64 | Vincent.RSA.PublicKey (integerBytesize n) n (keyParam 'e' k) | ||
65 | where | ||
66 | n = keyParam 'n' k | ||
67 | |||
68 | |||
69 | keyParam :: Char -> OpenPGP.Packet -> Integer | ||
70 | keyParam c k = fromJustMPI $ lookup c (OpenPGP.key k) | ||
71 | |||
72 | 21 | ||
73 | -- | Verify a message signature | 22 | -- | Verify a message signature |
74 | verify :: | 23 | verify :: |
@@ -100,16 +49,3 @@ verifyOne keys sig over = fmap (const sig) $ maybeKey >>= verification >>= guard | |||
100 | hash_algo = OpenPGP.hash_algorithm sig | 49 | hash_algo = OpenPGP.hash_algorithm sig |
101 | maybeKey = OpenPGP.signature_issuer sig >>= find_key keys | 50 | maybeKey = OpenPGP.signature_issuer sig >>= find_key keys |
102 | 51 | ||
103 | -- http://tools.ietf.org/html/rfc3447#page-43 | ||
104 | -- http://tools.ietf.org/html/rfc4880#section-5.2.2 | ||
105 | hashAlgoDesc OpenPGP.MD5 = Vincent.hashDescrMD5 | ||
106 | hashAlgoDesc OpenPGP.SHA1 = Vincent.hashDescrSHA1 | ||
107 | hashAlgoDesc OpenPGP.RIPEMD160 = Vincent.hashDescrRIPEMD160 | ||
108 | hashAlgoDesc OpenPGP.SHA256 = Vincent.hashDescrSHA256 | ||
109 | hashAlgoDesc OpenPGP.SHA384 = Vincent.hashDescrSHA384 | ||
110 | hashAlgoDesc OpenPGP.SHA512 = Vincent.hashDescrSHA512 | ||
111 | hashAlgoDesc OpenPGP.SHA224 = Vincent.hashDescrSHA224 | ||
112 | hashAlgoDesc _ = | ||
113 | error "Unsupported HashAlgorithm in hashAlgoDesc" | ||
114 | |||
115 | |||