diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-24 17:51:02 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-24 17:51:02 -0500 |
commit | ecc7c859118e022b1f3d8fff5b74702d4c0bab71 (patch) | |
tree | 29b2d117da8c39adbd52b8f86a09da0dad09c2ac | |
parent | 4df371631b16d753dd262171ec82c3ebaea42a10 (diff) |
Some fixes for signature verification
-rw-r--r-- | Data/OpenPGP/Crypto.hs | 13 | ||||
-rw-r--r-- | tests/suite.hs | 15 |
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 |
41 | find_key (OpenPGP.Message (x@(OpenPGP.SecretKeyPacket {}):xs)) keyid = | 41 | find_key (OpenPGP.Message (x@(OpenPGP.SecretKeyPacket {}):xs)) keyid = |
42 | find_key_ x xs keyid | 42 | find_key_ x xs keyid |
43 | find_key (OpenPGP.Message (_:xs)) keyid = | ||
44 | find_key (OpenPGP.Message xs) keyid | ||
43 | find_key _ _ = Nothing | 45 | find_key _ _ = Nothing |
44 | 46 | ||
45 | find_key_ :: OpenPGP.Packet -> [OpenPGP.Packet] -> String -> Maybe OpenPGP.Packet | 47 | find_key_ :: OpenPGP.Packet -> [OpenPGP.Packet] -> String -> Maybe OpenPGP.Packet |
46 | find_key_ x xs keyid = | 48 | find_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 | ||
51 | keyfield_as_octets :: OpenPGP.Packet -> Char -> [Word8] | 54 | keyfield_as_octets :: OpenPGP.Packet -> Char -> [Word8] |
52 | keyfield_as_octets k f = | 55 | keyfield_as_octets k f = |
@@ -65,7 +68,7 @@ emsa_pkcs1_v1_5_hash_padding _ = | |||
65 | 68 | ||
66 | hash :: OpenPGP.HashAlgorithm -> [Word8] -> [Word8] | 69 | hash :: OpenPGP.HashAlgorithm -> [Word8] -> [Word8] |
67 | hash OpenPGP.MD5 = MD5.hash | 70 | hash OpenPGP.MD5 = MD5.hash |
68 | hash OpenPGP.SHA1 = reverse . drop 2 . LZ.unpack . encode . OpenPGP.MPI . SHA1.toInteger . SHA1.hash | 71 | hash OpenPGP.SHA1 = drop 2 . LZ.unpack . encode . OpenPGP.MPI . SHA1.toInteger . SHA1.hash |
69 | hash OpenPGP.SHA256 = SHA256.hash | 72 | hash OpenPGP.SHA256 = SHA256.hash |
70 | hash OpenPGP.SHA384 = SHA384.hash | 73 | hash OpenPGP.SHA384 = SHA384.hash |
71 | hash OpenPGP.SHA512 = SHA512.hash | 74 | hash 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 | ||
32 | testVerifyMessage :: FilePath -> FilePath -> Assertion | ||
33 | testVerifyMessage 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 | |||
32 | prop_s2k_count :: Word8 -> Bool | 39 | prop_s2k_count :: Word8 -> Bool |
33 | prop_s2k_count c = | 40 | prop_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 | ] |