hs-tls/Tests/Certificate.hs

61 lines
1.7 KiB
Haskell
Raw Normal View History

2010-12-06 08:07:05 +00:00
module Tests.Certificate
( arbitraryX509
, arbitraryX509WithPublicKey
2010-12-06 08:07:05 +00:00
) where
import Test.QuickCheck
import qualified Data.Certificate.X509 as X509
import qualified Data.Certificate.X509.Cert as Cert
2010-12-06 08:07:05 +00:00
import Control.Monad
import Data.Time.Calendar (fromGregorian)
import Data.Time.Clock (secondsToDiffTime)
import qualified Data.ByteString as B
import Tests.PubKey
2010-12-06 08:07:05 +00:00
readableChar :: Gen Char
readableChar = elements (['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'])
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
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
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
, 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
arbitraryX509WithPublicKey pubKey = do
cert <- arbitraryX509Cert (X509.PubKeyRSA pubKey)
2011-02-20 08:35:14 +00:00
sig <- resize 40 $ listOf1 arbitrary
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)
arbitraryX509 = do
let pubKey = fst $ getGlobalRSAPair
arbitraryX509WithPublicKey pubKey