diff options
author | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-24 18:13:41 -0500 |
---|---|---|
committer | Stephen Paul Weber <singpolyma@singpolyma.net> | 2012-04-24 18:13:41 -0500 |
commit | 36811bfb9881f05a1ca37e0073b206e013c5fc1e (patch) | |
tree | 2eedd436f231066c0fd521dcf4ce124c6f4c543e /tests | |
parent | fb1dc48bcf701e0878730b279522ee810f548521 (diff) |
QuickCheck that we can verify our own signatures
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/secring.gpg | bin | 8644 -> 9329 bytes | |||
-rw-r--r-- | tests/suite.hs | 36 |
2 files changed, 29 insertions, 7 deletions
diff --git a/tests/data/secring.gpg b/tests/data/secring.gpg index 726ffe0..1359875 100644 --- a/tests/data/secring.gpg +++ b/tests/data/secring.gpg | |||
Binary files differ | |||
diff --git a/tests/suite.hs b/tests/suite.hs index b4bfc66..9480c0b 100644 --- a/tests/suite.hs +++ b/tests/suite.hs | |||
@@ -1,7 +1,7 @@ | |||
1 | import Test.Framework (defaultMain, testGroup, Test) | 1 | import Test.Framework (defaultMain, testGroup, Test) |
2 | import Test.Framework.Providers.HUnit | 2 | import Test.Framework.Providers.HUnit |
3 | import Test.Framework.Providers.QuickCheck2 | 3 | import Test.Framework.Providers.QuickCheck2 |
4 | import Test.QuickCheck () | 4 | import Test.QuickCheck |
5 | import Test.HUnit hiding (Test) | 5 | import Test.HUnit hiding (Test) |
6 | 6 | ||
7 | import Data.Word | 7 | import Data.Word |
@@ -9,6 +9,10 @@ import Data.Binary | |||
9 | import qualified Data.OpenPGP as OpenPGP | 9 | import qualified Data.OpenPGP as OpenPGP |
10 | import qualified Data.OpenPGP.Crypto as OpenPGP | 10 | import qualified Data.OpenPGP.Crypto as OpenPGP |
11 | import qualified Data.ByteString.Lazy as LZ | 11 | import qualified Data.ByteString.Lazy as LZ |
12 | import qualified Data.ByteString.Lazy.UTF8 as LZ (fromString) | ||
13 | |||
14 | instance Arbitrary OpenPGP.HashAlgorithm where | ||
15 | arbitrary = elements [OpenPGP.MD5, OpenPGP.SHA1, OpenPGP.SHA256, OpenPGP.SHA384, OpenPGP.SHA512] | ||
12 | 16 | ||
13 | testSerialization :: FilePath -> Assertion | 17 | testSerialization :: FilePath -> Assertion |
14 | testSerialization fp = do | 18 | testSerialization fp = do |
@@ -36,14 +40,27 @@ testVerifyMessage keyring message = do | |||
36 | let verification = OpenPGP.verify keys m 0 | 40 | let verification = OpenPGP.verify keys m 0 |
37 | assertEqual (keyring ++ " for " ++ message) True verification | 41 | assertEqual (keyring ++ " for " ++ message) True verification |
38 | 42 | ||
43 | prop_sign_and_verify :: OpenPGP.Message -> String -> OpenPGP.HashAlgorithm -> String -> String -> Bool | ||
44 | prop_sign_and_verify secring kid halgo filename msg = | ||
45 | let | ||
46 | m = OpenPGP.LiteralDataPacket { | ||
47 | OpenPGP.format = 'u', | ||
48 | OpenPGP.filename = filename, | ||
49 | OpenPGP.timestamp = 12341234, | ||
50 | OpenPGP.content = LZ.fromString msg | ||
51 | } | ||
52 | sig = OpenPGP.sign secring (OpenPGP.Message [m]) halgo kid 12341234 | ||
53 | in | ||
54 | OpenPGP.verify secring (OpenPGP.Message [m,sig]) 0 | ||
55 | |||
39 | prop_s2k_count :: Word8 -> Bool | 56 | prop_s2k_count :: Word8 -> Bool |
40 | prop_s2k_count c = | 57 | prop_s2k_count c = |
41 | c == OpenPGP.encode_s2k_count (OpenPGP.decode_s2k_count c) | 58 | c == OpenPGP.encode_s2k_count (OpenPGP.decode_s2k_count c) |
42 | 59 | ||
43 | tests :: [Test] | 60 | tests :: OpenPGP.Message -> [Test] |
44 | tests = | 61 | tests secring = |
45 | [ | 62 | [ |
46 | testGroup "Serialization group" [ | 63 | testGroup "Serialization" [ |
47 | testCase "000001-006.public_key" (testSerialization "000001-006.public_key"), | 64 | testCase "000001-006.public_key" (testSerialization "000001-006.public_key"), |
48 | testCase "000002-013.user_id" (testSerialization "000002-013.user_id"), | 65 | testCase "000002-013.user_id" (testSerialization "000002-013.user_id"), |
49 | -- Issue #11 -- testCase "000003-002.sig" (testSerialization "000003-002.sig"), | 66 | -- Issue #11 -- testCase "000003-002.sig" (testSerialization "000003-002.sig"), |
@@ -131,13 +148,13 @@ tests = | |||
131 | -- Issue #11 -- testCase "uncompressed-ops-dsa.gpg" (testSerialization "uncompressed-ops-dsa.gpg"), | 148 | -- Issue #11 -- testCase "uncompressed-ops-dsa.gpg" (testSerialization "uncompressed-ops-dsa.gpg"), |
132 | -- Issue #11 -- testCase "uncompressed-ops-rsa.gpg" (testSerialization "uncompressed-ops-rsa.gpg"), | 149 | -- Issue #11 -- testCase "uncompressed-ops-rsa.gpg" (testSerialization "uncompressed-ops-rsa.gpg"), |
133 | ], | 150 | ], |
134 | testGroup "Fingerprint group" [ | 151 | testGroup "Fingerprint" [ |
135 | testCase "000001-006.public_key" (testFingerprint "000001-006.public_key" "421F28FEAAD222F856C8FFD5D4D54EA16F87040E"), | 152 | testCase "000001-006.public_key" (testFingerprint "000001-006.public_key" "421F28FEAAD222F856C8FFD5D4D54EA16F87040E"), |
136 | testCase "000016-006.public_key" (testFingerprint "000016-006.public_key" "AF95E4D7BAC521EE9740BED75E9F1523413262DC"), | 153 | testCase "000016-006.public_key" (testFingerprint "000016-006.public_key" "AF95E4D7BAC521EE9740BED75E9F1523413262DC"), |
137 | testCase "000027-006.public_key" (testFingerprint "000027-006.public_key" "1EB20B2F5A5CC3BEAFD6E5CB7732CF988A63EA86"), | 154 | testCase "000027-006.public_key" (testFingerprint "000027-006.public_key" "1EB20B2F5A5CC3BEAFD6E5CB7732CF988A63EA86"), |
138 | testCase "000035-006.public_key" (testFingerprint "000035-006.public_key" "CB7933459F59C70DF1C3FBEEDEDC3ECF689AF56D") | 155 | testCase "000035-006.public_key" (testFingerprint "000035-006.public_key" "CB7933459F59C70DF1C3FBEEDEDC3ECF689AF56D") |
139 | ], | 156 | ], |
140 | testGroup "Message verification group" [ | 157 | testGroup "Message verification" [ |
141 | --testCase "uncompressed-ops-dsa" (testVerifyMessage "pubring.gpg" "uncompressed-ops-dsa.gpg"), | 158 | --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"), | 159 | --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"), | 160 | testCase "uncompressed-ops-rsa" (testVerifyMessage "pubring.gpg" "uncompressed-ops-rsa.gpg"), |
@@ -145,10 +162,15 @@ tests = | |||
145 | testCase "compressedsig-zlib" (testVerifyMessage "pubring.gpg" "compressedsig-zlib.gpg"), | 162 | testCase "compressedsig-zlib" (testVerifyMessage "pubring.gpg" "compressedsig-zlib.gpg"), |
146 | testCase "compressedsig-bzip2" (testVerifyMessage "pubring.gpg" "compressedsig-bzip2.gpg") | 163 | testCase "compressedsig-bzip2" (testVerifyMessage "pubring.gpg" "compressedsig-bzip2.gpg") |
147 | ], | 164 | ], |
165 | testGroup "Signing" [ | ||
166 | testProperty "Crypto signatures verify" (prop_sign_and_verify secring "FEF8AFA0F661C3EE") | ||
167 | ], | ||
148 | testGroup "S2K count" [ | 168 | testGroup "S2K count" [ |
149 | testProperty "S2K count encode reverses decode" prop_s2k_count | 169 | testProperty "S2K count encode reverses decode" prop_s2k_count |
150 | ] | 170 | ] |
151 | ] | 171 | ] |
152 | 172 | ||
153 | main :: IO () | 173 | main :: IO () |
154 | main = defaultMain tests | 174 | main = do |
175 | secring <- fmap decode $ LZ.readFile "tests/data/secring.gpg" | ||
176 | defaultMain (tests secring) | ||