summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Paul Weber <singpolyma@singpolyma.net>2012-04-24 17:51:02 -0500
committerStephen Paul Weber <singpolyma@singpolyma.net>2012-04-24 17:51:02 -0500
commitecc7c859118e022b1f3d8fff5b74702d4c0bab71 (patch)
tree29b2d117da8c39adbd52b8f86a09da0dad09c2ac
parent4df371631b16d753dd262171ec82c3ebaea42a10 (diff)
Some fixes for signature verification
-rw-r--r--Data/OpenPGP/Crypto.hs13
-rw-r--r--tests/suite.hs15
2 files changed, 23 insertions, 5 deletions
diff --git a/Data/OpenPGP/Crypto.hs b/Data/OpenPGP/Crypto.hs
index c213651..f9d1074 100644
--- a/Data/OpenPGP/Crypto.hs
+++ b/Data/OpenPGP/Crypto.hs
@@ -40,13 +40,16 @@ find_key (OpenPGP.Message (x@(OpenPGP.PublicKeyPacket {}):xs)) keyid =
40 find_key_ x xs keyid 40 find_key_ x xs keyid
41find_key (OpenPGP.Message (x@(OpenPGP.SecretKeyPacket {}):xs)) keyid = 41find_key (OpenPGP.Message (x@(OpenPGP.SecretKeyPacket {}):xs)) keyid =
42 find_key_ x xs keyid 42 find_key_ x xs keyid
43find_key (OpenPGP.Message (_:xs)) keyid =
44 find_key (OpenPGP.Message xs) keyid
43find_key _ _ = Nothing 45find_key _ _ = Nothing
44 46
45find_key_ :: OpenPGP.Packet -> [OpenPGP.Packet] -> String -> Maybe OpenPGP.Packet 47find_key_ :: OpenPGP.Packet -> [OpenPGP.Packet] -> String -> Maybe OpenPGP.Packet
46find_key_ x xs keyid = 48find_key_ x xs keyid
47 if thisid == keyid then Just x else find_key (OpenPGP.Message xs) keyid 49 | thisid == keyid = Just x
48 where thisid = reverse $ 50 | otherwise = find_key (OpenPGP.Message xs) keyid
49 take (length keyid) (reverse (fingerprint x)) 51 where
52 thisid = reverse $ take (length keyid) (reverse (fingerprint x))
50 53
51keyfield_as_octets :: OpenPGP.Packet -> Char -> [Word8] 54keyfield_as_octets :: OpenPGP.Packet -> Char -> [Word8]
52keyfield_as_octets k f = 55keyfield_as_octets k f =
@@ -65,7 +68,7 @@ emsa_pkcs1_v1_5_hash_padding _ =
65 68
66hash :: OpenPGP.HashAlgorithm -> [Word8] -> [Word8] 69hash :: OpenPGP.HashAlgorithm -> [Word8] -> [Word8]
67hash OpenPGP.MD5 = MD5.hash 70hash OpenPGP.MD5 = MD5.hash
68hash OpenPGP.SHA1 = reverse . drop 2 . LZ.unpack . encode . OpenPGP.MPI . SHA1.toInteger . SHA1.hash 71hash OpenPGP.SHA1 = drop 2 . LZ.unpack . encode . OpenPGP.MPI . SHA1.toInteger . SHA1.hash
69hash OpenPGP.SHA256 = SHA256.hash 72hash OpenPGP.SHA256 = SHA256.hash
70hash OpenPGP.SHA384 = SHA384.hash 73hash OpenPGP.SHA384 = SHA384.hash
71hash OpenPGP.SHA512 = SHA512.hash 74hash OpenPGP.SHA512 = SHA512.hash
diff --git a/tests/suite.hs b/tests/suite.hs
index 59b9c03..d1b232c 100644
--- a/tests/suite.hs
+++ b/tests/suite.hs
@@ -29,6 +29,13 @@ testFingerprint fp kf = do
29 let (OpenPGP.Message [packet]) = decode bs 29 let (OpenPGP.Message [packet]) = decode bs
30 assertEqual ("for " ++ fp) kf (OpenPGP.fingerprint packet) 30 assertEqual ("for " ++ fp) kf (OpenPGP.fingerprint packet)
31 31
32testVerifyMessage :: FilePath -> FilePath -> Assertion
33testVerifyMessage keyring message = do
34 keys <- fmap decode $ LZ.readFile $ "tests/data/" ++ keyring
35 m <- fmap decode $ LZ.readFile $ "tests/data/" ++ message
36 let verification = OpenPGP.verify keys m 0
37 assertEqual (keyring ++ " for " ++ message) True verification
38
32prop_s2k_count :: Word8 -> Bool 39prop_s2k_count :: Word8 -> Bool
33prop_s2k_count c = 40prop_s2k_count c =
34 c == OpenPGP.encode_s2k_count (OpenPGP.decode_s2k_count c) 41 c == OpenPGP.encode_s2k_count (OpenPGP.decode_s2k_count c)
@@ -130,6 +137,14 @@ tests =
130 testCase "000027-006.public_key" (testFingerprint "000027-006.public_key" "1EB20B2F5A5CC3BEAFD6E5CB7732CF988A63EA86"), 137 testCase "000027-006.public_key" (testFingerprint "000027-006.public_key" "1EB20B2F5A5CC3BEAFD6E5CB7732CF988A63EA86"),
131 testCase "000035-006.public_key" (testFingerprint "000035-006.public_key" "CB7933459F59C70DF1C3FBEEDEDC3ECF689AF56D") 138 testCase "000035-006.public_key" (testFingerprint "000035-006.public_key" "CB7933459F59C70DF1C3FBEEDEDC3ECF689AF56D")
132 ], 139 ],
140 testGroup "Message verification group" [
141 --testCase "uncompressed-ops-dsa" (testVerifyMessage "pubring.gpg" "uncompressed-ops-dsa.gpg"),
142 --testCase "uncompressed-ops-dsa-sha384" (testVerifyMessage "pubring.gpg" "uncompressed-ops-dsa-sha384.txt.gpg"),
143 testCase "uncompressed-ops-rsa" (testVerifyMessage "pubring.gpg" "uncompressed-ops-rsa.gpg"),
144 testCase "compressedsig" (testVerifyMessage "pubring.gpg" "compressedsig.gpg"),
145 testCase "compressedsig-zlib" (testVerifyMessage "pubring.gpg" "compressedsig-zlib.gpg"),
146 testCase "compressedsig-bzip2" (testVerifyMessage "pubring.gpg" "compressedsig-bzip2.gpg")
147 ],
133 testGroup "S2K count" [ 148 testGroup "S2K count" [
134 testProperty "S2K count encode reverses decode" prop_s2k_count 149 testProperty "S2K count encode reverses decode" prop_s2k_count
135 ] 150 ]