summaryrefslogtreecommitdiff
path: root/Data/OpenPGP/Util/Verify.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Data/OpenPGP/Util/Verify.hs')
-rw-r--r--Data/OpenPGP/Util/Verify.hs66
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)
6import Control.Monad 6import Control.Monad
7import qualified Data.ByteString as BS 7import qualified Data.ByteString as BS
8import qualified Data.ByteString.Lazy as LZ 8import qualified Data.ByteString.Lazy as LZ
9import Data.Monoid ( (<>) )
10
11import Data.OpenPGP.Util.Fingerprint (fingerprint)
12 9
13import qualified Crypto.PubKey.DSA as Vincent.DSA 10import qualified Crypto.PubKey.DSA as Vincent.DSA
14import qualified Crypto.PubKey.RSA as Vincent.RSA
15import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA 11import qualified Crypto.PubKey.RSA.PKCS15 as Vincent.RSA
16import Crypto.PubKey.HashDescr as Vincent
17
18import Crypto.Hash.MD5 as MD5
19import Crypto.Hash.SHA1 as SHA1
20import Crypto.Hash.SHA256 as SHA256
21import Crypto.Hash.SHA384 as SHA384
22import Crypto.Hash.SHA512 as SHA512
23import Crypto.Hash.SHA224 as SHA224
24import Crypto.Hash.RIPEMD160 as RIPEMD160
25
26hashBySymbol OpenPGP.MD5 = MD5.hashlazy
27hashBySymbol OpenPGP.SHA1 = SHA1.hashlazy
28hashBySymbol OpenPGP.SHA256 = SHA256.hashlazy
29hashBySymbol OpenPGP.SHA384 = SHA384.hashlazy
30hashBySymbol OpenPGP.SHA512 = SHA512.hashlazy
31hashBySymbol OpenPGP.SHA224 = SHA224.hashlazy
32hashBySymbol OpenPGP.RIPEMD160 = RIPEMD160.hashlazy
33
34
35toStrictBS :: LZ.ByteString -> BS.ByteString
36toStrictBS = BS.concat . LZ.toChunks
37
38toLazyBS :: BS.ByteString -> LZ.ByteString
39toLazyBS = LZ.fromChunks . (:[])
40
41hush :: Either a b -> Maybe b
42hush (Left _) = Nothing
43hush (Right x) = Just x
44
45fromJustMPI :: Maybe OpenPGP.MPI -> Integer
46fromJustMPI (Just (OpenPGP.MPI x)) = x
47fromJustMPI _ = error "Not a Just MPI, Data.OpenPGP.CryptoAPI"
48 12
13import Data.OpenPGP.Util.Base
49 14
50 15
51find_key :: OpenPGP.Message -> String -> Maybe OpenPGP.Packet
52find_key = OpenPGP.find_key fingerprint
53
54integerBytesize :: Integer -> Int
55integerBytesize i = fromIntegral $ LZ.length (encode (OpenPGP.MPI i)) - 2
56
57dsaKey :: OpenPGP.Packet -> Vincent.DSA.PublicKey 16dsaKey :: OpenPGP.Packet -> Vincent.DSA.PublicKey
58dsaKey k = Vincent.DSA.PublicKey 17dsaKey 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
62rsaKey :: OpenPGP.Packet -> Vincent.RSA.PublicKey
63rsaKey k =
64 Vincent.RSA.PublicKey (integerBytesize n) n (keyParam 'e' k)
65 where
66 n = keyParam 'n' k
67
68
69keyParam :: Char -> OpenPGP.Packet -> Integer
70keyParam c k = fromJustMPI $ lookup c (OpenPGP.key k)
71
72 21
73-- | Verify a message signature 22-- | Verify a message signature
74verify :: 23verify ::
@@ -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
105hashAlgoDesc OpenPGP.MD5 = Vincent.hashDescrMD5
106hashAlgoDesc OpenPGP.SHA1 = Vincent.hashDescrSHA1
107hashAlgoDesc OpenPGP.RIPEMD160 = Vincent.hashDescrRIPEMD160
108hashAlgoDesc OpenPGP.SHA256 = Vincent.hashDescrSHA256
109hashAlgoDesc OpenPGP.SHA384 = Vincent.hashDescrSHA384
110hashAlgoDesc OpenPGP.SHA512 = Vincent.hashDescrSHA512
111hashAlgoDesc OpenPGP.SHA224 = Vincent.hashDescrSHA224
112hashAlgoDesc _ =
113 error "Unsupported HashAlgorithm in hashAlgoDesc"
114
115