2010-12-06 08:07:05 +00:00
|
|
|
module Tests.Certificate
|
|
|
|
( arbitraryX509
|
2011-11-11 22:53:17 +00:00
|
|
|
, arbitraryX509WithPublicKey
|
2010-12-06 08:07:05 +00:00
|
|
|
) where
|
|
|
|
|
|
|
|
import Test.QuickCheck
|
|
|
|
import qualified Data.Certificate.X509 as X509
|
2011-11-11 22:53:17 +00:00
|
|
|
import qualified Data.Certificate.X509.Cert as Cert
|
|
|
|
import Data.Time.Calendar (fromGregorian)
|
|
|
|
import Data.Time.Clock (secondsToDiffTime)
|
|
|
|
|
|
|
|
import Tests.PubKey
|
2010-12-06 08:07:05 +00:00
|
|
|
|
|
|
|
readableChar :: Gen Char
|
|
|
|
readableChar = elements (['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'])
|
|
|
|
|
2010-12-14 23:27:02 +00:00
|
|
|
arbitraryDN = return []
|
2010-12-06 08:07:05 +00:00
|
|
|
|
|
|
|
arbitraryTime = do
|
|
|
|
year <- choose (1951, 2050)
|
|
|
|
month <- choose (1, 12)
|
|
|
|
day <- choose (1, 30)
|
|
|
|
hour <- choose (0, 23)
|
|
|
|
minute <- choose (0, 59)
|
|
|
|
second <- choose (0, 59)
|
|
|
|
z <- arbitrary
|
2011-11-11 22:53:17 +00:00
|
|
|
return (fromGregorian year month day
|
|
|
|
, secondsToDiffTime (hour * 3600 + minute * 60 + second)
|
|
|
|
, z)
|
2010-12-06 08:07:05 +00:00
|
|
|
|
2011-02-20 17:42:05 +00:00
|
|
|
arbitraryX509Cert pubKey = do
|
|
|
|
version <- choose (1,3)
|
|
|
|
serial <- choose (0,2^24)
|
2010-12-06 08:07:05 +00:00
|
|
|
issuerdn <- arbitraryDN
|
|
|
|
subjectdn <- arbitraryDN
|
|
|
|
time1 <- arbitraryTime
|
|
|
|
time2 <- arbitraryTime
|
2011-11-11 22:53:17 +00:00
|
|
|
let sigalg = X509.SignatureALG X509.HashMD5 X509.PubKeyALG_RSA
|
|
|
|
return $ Cert.Certificate
|
2010-12-06 08:07:05 +00:00
|
|
|
{ X509.certVersion = version
|
|
|
|
, X509.certSerial = serial
|
2010-12-14 23:27:02 +00:00
|
|
|
, X509.certSignatureAlg = sigalg
|
2010-12-06 08:07:05 +00:00
|
|
|
, X509.certIssuerDN = issuerdn
|
|
|
|
, X509.certSubjectDN = subjectdn
|
|
|
|
, X509.certValidity = (time1, time2)
|
|
|
|
, X509.certPubKey = pubKey
|
|
|
|
, X509.certExtensions = Nothing
|
|
|
|
}
|
2011-02-20 08:35:14 +00:00
|
|
|
|
2011-11-11 22:53:17 +00:00
|
|
|
arbitraryX509WithPublicKey pubKey = do
|
2011-11-14 22:09:54 +00:00
|
|
|
cert <- arbitraryX509Cert (X509.PubKeyRSA pubKey)
|
2011-02-20 08:35:14 +00:00
|
|
|
sig <- resize 40 $ listOf1 arbitrary
|
2011-11-11 22:53:17 +00:00
|
|
|
let sigalg = X509.SignatureALG X509.HashMD5 X509.PubKeyALG_RSA
|
2011-05-09 08:06:45 +00:00
|
|
|
return (X509.X509 cert Nothing Nothing sigalg sig)
|
2011-11-11 22:53:17 +00:00
|
|
|
|
|
|
|
arbitraryX509 = do
|
2011-11-14 22:09:54 +00:00
|
|
|
let pubKey = fst $ getGlobalRSAPair
|
|
|
|
arbitraryX509WithPublicKey pubKey
|