packages feed

crypton-x509-validation 1.10.2 → 1.10.3

raw patch · 6 files changed

+400/−91 lines, 6 filesdep ~cryptondep ~crypton-x509dep ~crypton-x509-storePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: crypton, crypton-x509, crypton-x509-store

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,19 @@ # ChangeLog for crypton-x509-validation +## 1.10.3++MD2 and MD5 signatures are rejected, and certification paths are built+with backtracking.++* Harden certificate validation+  [#44](https://github.com/kazu-yamamoto/crypton-certificate/pull/44)+* Accept and encode valid structures in crypton-x509+  [#46](https://github.com/kazu-yamamoto/crypton-certificate/pull/46)+* Build certification paths with backtracking and implement CRL distribution points+  [#48](https://github.com/kazu-yamamoto/crypton-certificate/pull/48)+* Small fixes for EC keys, RSA verification and EKU+  [#50](https://github.com/kazu-yamamoto/crypton-certificate/pull/50)+ ## 1.10.2  * Fix host name validation with iPAddress SANs: an IP address is
Data/X509/Validation.hs view
@@ -38,7 +38,9 @@     module Data.X509.Validation.Signature, ) where +import Control.Applicative ((<|>)) import Control.Monad (when)+import Control.Monad.State.Strict (State, evalState, get, put) import Data.ASN1.Types import Data.Bits import Data.ByteString (ByteString, unpack)@@ -276,8 +278,10 @@ validatePure validationTime hooks checks store (fqhn, _) (CertificateChain (top : rchain)) =     hookFilterReason         hooks-        (doLeafChecks |> doCheckChain 0 top rchain |> doCheckNameConst top rchain)+        (doLeafChecks |> chainFailures |> maybe [] doCheckNameConst mpath)   where+    (chainFailures, mpath) = evalState (doCheckChain 0 top rchain) maxSignatureChecks+     isExhaustive :: Bool     isExhaustive = checkExhaustive checks @@ -292,50 +296,93 @@       where         topCert = getCertificate top +    -- Failures of the first path that succeeds, or else of the first+    -- path tried, with the certificates from the current one to the trust+    -- anchor if the path reaches one.     doCheckChain-        :: Int -> SignedCertificate -> [SignedCertificate] -> [FailedReason]+        :: Int+        -> SignedCertificate+        -> [SignedCertificate]+        -> State Int ([FailedReason], Maybe [SignedCertificate])     doCheckChain level current chain-        | level > maxChainDepth = [AuthorityTooDeep]-        | otherwise = doCheckChain' level current chain--    doCheckChain'-        :: Int -> SignedCertificate -> [SignedCertificate] -> [FailedReason]-    doCheckChain' level current chain =-        doCheckCertificate (getCertificate current)-            -- check if we have a trusted certificate in the store belonging to this issuer.-            |> ( case findCertificate (certIssuerDN cert) store of-                    Just trustedSignedCert -> checkSignature current trustedSignedCert-                    Nothing-                        | isSelfSigned cert -> [SelfSigned] |> checkSignature current current-                        | null chain -> [UnknownCA]-                        | otherwise ->-                            case findIssuer (certIssuerDN cert) chain of-                                Nothing -> [UnknownCA]-                                Just (issuer, remaining) ->-                                    checkCA level (getCertificate issuer)-                                        |> checkSignature current issuer-                                        |> doCheckChain (level + 1) issuer remaining-               )+        | level > maxChainDepth = return ([AuthorityTooDeep], Nothing)+        | otherwise =+            fmap (fmap (current :))+                <$> (doCheckCertificate cert `andThen` issuerChecks)       where-        cert :: Certificate         cert = getCertificate current-    -- in a strict ordering check the next certificate has to be the issuer.-    -- otherwise we dynamically reorder the chain to have the necessary certificate-    findIssuer+        issuerDN = certIssuerDN cert+        anchors = findCertificates issuerDN store+        issuerChecks+            | null anchors && isSelfSigned cert = do+                r <- checkSignatureM current current+                return ([SelfSigned] |> r, Nothing)+            | otherwise =+                firstSuccess $+                    map anchorCheck anchors+                        ++ [chainCheck i r | (i, r) <- findIssuers issuerDN chain]+        anchorCheck anchor+            -- an anchor that is not a CA may only be the certificate itself+            | checkCAConstraints checks+                && anchor /= current+                && notCA (getCertificate anchor) =+                return ([NotAnAuthority], Nothing)+            | otherwise = do+                r <- checkSignatureM current anchor+                return (r, Just [anchor])+        chainCheck issuer remaining = do+            r <- checkSignatureM current issuer+            (checkCA level (getCertificate issuer) |> r)+                `andThen` doCheckChain (level + 1) issuer remaining++    -- Runs the next step unless the failures stop the validation.+    andThen+        :: [FailedReason]+        -> State Int ([FailedReason], Maybe p)+        -> State Int ([FailedReason], Maybe p)+    andThen fs next+        | null fs || isExhaustive = (\(fs', p) -> (fs ++ fs', p)) <$> next+        | otherwise = return (fs, Nothing)++    firstSuccess+        :: [State Int ([FailedReason], Maybe p)]+        -> State Int ([FailedReason], Maybe p)+    firstSuccess = go Nothing+      where+        go failed [] = return $ fromMaybe ([UnknownCA], Nothing) failed+        go failed (m : ms) = do+            r@(fs, _) <- m+            if null fs then return r else go (failed <|> Just r) ms++    -- A signature check spends the budget, which bounds path building.+    checkSignatureM+        :: SignedCertificate -> SignedCertificate -> State Int [FailedReason]+    checkSignatureM signedCert signingCert = do+        budget <- get+        if budget <= 0+            then return [UnknownCA]+            else do+                put (budget - 1)+                return $ checkSignature signedCert signingCert++    -- Issuer candidates in the chain with the remaining certificates.  In+    -- a strict ordering check the next certificate has to be the issuer.+    findIssuers         :: DistinguishedName         -> [SignedCertificate]-        -> Maybe (SignedCertificate, [SignedCertificate])-    findIssuer issuerDN chain-        | checkStrictOrdering checks =-            case chain of-                [] -> error "not possible"-                (c : cs)-                    | matchSubjectIdentifier issuerDN (getCertificate c) -> Just (c, cs)-                    | otherwise -> Nothing+        -> [(SignedCertificate, [SignedCertificate])]+    findIssuers issuerDN chain+        | checkStrictOrdering checks = case chain of+            c : cs | matches c -> [(c, cs)]+            _ -> []         | otherwise =-            case break (matchSubjectIdentifier issuerDN . getCertificate) chain of-                (before, x : after) -> Just (x, before ++ after)-                _ -> Nothing+            [ (c, before ++ after)+            | (before, c : after) <- zip (inits chain) (tails chain)+            , matches c+            ]+      where+        matches = matchSubjectIdentifier issuerDN . getCertificate+     matchSubjectIdentifier :: DistinguishedName -> Certificate -> Bool     matchSubjectIdentifier = hookMatchSubjectIssuer hooks @@ -396,7 +443,10 @@             Just (Left e) -> Just (Left e)             Nothing -> Nothing         mpurposes = case extensionGetE $ certExtensions cert of-            Just (Right (ExtExtendedKeyUsage keyPurposes)) -> Just (Right keyPurposes)+            -- anyExtendedKeyUsage does not restrict the purposes+            Just (Right (ExtExtendedKeyUsage keyPurposes))+                | KeyUsagePurpose_Unknown [2, 5, 29, 37, 0] `elem` keyPurposes -> Nothing+                | otherwise -> Just (Right keyPurposes)             Just (Left e) -> Just (Left e)             Nothing -> Nothing         -- compare a list of things to an expected list. the expected list@@ -417,34 +467,36 @@             , (True, doCriticalExtensionSweep cert)             ]     -- check signature of 'signedCert' against the 'signingCert'+    -- The signature algorithm must also match the signed one in the TBS.     checkSignature         :: SignedCertificate -> SignedCertificate -> [FailedReason]-    checkSignature signedCert signingCert =-        case verifySignedSignature signedCert (certPubKey $ getCertificate signingCert) of-            SignaturePass -> []-            SignatureFailed r -> [InvalidSignature r]+    checkSignature signedCert signingCert+        | signedAlg (getSigned signedCert) /= certSignatureAlg (getCertificate signedCert) =+            [InvalidSignature SignatureInvalid]+        | otherwise =+            case verifySignedSignature signedCert (certPubKey $ getCertificate signingCert) of+                SignaturePass -> []+                SignatureFailed r -> [InvalidSignature r] -    -- Failures to build the chain are reported by 'doCheckChain'.-    doCheckNameConst :: SignedCertificate -> [SignedCertificate] -> [FailedReason]-    doCheckNameConst current0 chain0 = case loop (0 :: Int) current0 chain0 [] of-        Left errs -> errs-        Right ts -> checkNameConstraints ts+    -- The path runs from the leaf to the trust anchor.+    doCheckNameConst :: [SignedCertificate] -> [FailedReason]+    doCheckNameConst path = case reverse path of+        anchor : rest ->+            checkNameConstraints $+                getNameConstSpec (getCertificate anchor) False+                    : zipWith spec [length rest - 1, length rest - 2 ..] rest+        [] -> []       where-        loop level current chain acc-            | level > maxChainDepth = Left []-            | otherwise = case findCertificate issuer store of-                Just anchor -> Right $ getNameConstSpec (getCertificate anchor) False : spec : acc-                Nothing-                    | null chain -> Left []-                    | otherwise -> case findIssuer issuer chain of-                        Nothing -> Left []-                        Just (issuer', remaining) -> loop (level + 1) issuer' remaining (spec : acc)-          where-            cert = getCertificate current-            issuer = certIssuerDN cert-            isLeaf = level == 0-            spec = getNameConstSpec cert (isLeaf && checkFQHN checks)+        -- the level counts from the leaf+        spec level c = getNameConstSpec (getCertificate c) (level == 0 && checkFQHN checks) +-- | Whether BasicConstraints says the certificate is not a CA.+notCA :: Certificate -> Bool+notCA cert = case extensionGetE (certExtensions cert) of+    Just (Right (ExtBasicConstraints False _)) -> True+    Just (Left _) -> True+    _ -> False+ isSelfSigned :: Certificate -> Bool isSelfSigned cert = certSubjectDN cert == certIssuerDN cert @@ -452,6 +504,10 @@ maxChainDepth :: Int maxChainDepth = 20 +-- | The maximum number of signatures checked while building paths.+maxSignatureChecks :: Int+maxSignatureChecks = 100+ data NameConstSpec = NameConstSpec     { ncNames :: Either String [AltName]     -- ^ names subject to name constraints@@ -581,7 +637,7 @@     matchDomain name = case splitDot name of         l             | any (== "") l -> [InvalidName name]-            | head l == "*" -> wildcardMatch (drop 1 l)+            | take 1 l == ["*"] -> wildcardMatch (drop 1 l)             | l == splitDot fqhn -> [] -- success: we got a match             | otherwise -> [NameMismatch fqhn] @@ -596,9 +652,10 @@     --     -- e.g. *.*.server.com will try to litteraly match the '*' subdomain of server.com     ---    -- Also '*' is not accepted as a valid wildcard+    -- Also '*' and a wildcard for a single label such as '*.com' are not+    -- accepted as valid wildcards     wildcardMatch l-        | null l = [InvalidWildcard] -- '*' is always invalid+        | length l < 2 = [InvalidWildcard]         | l == drop 1 (splitDot fqhn) = [] -- success: we got a match         | otherwise = [NameMismatch fqhn] @@ -610,8 +667,11 @@  -- | return true if the 'subject' certificate's issuer match -- the 'issuer' certificate's subject+-- | Names are compared in their canonical form (RFC 5280 7.1). matchSI :: DistinguishedName -> Certificate -> Bool-matchSI issuerDN issuer = certSubjectDN issuer == issuerDN+matchSI issuerDN issuer =+    canonicalDistinguishedName (certSubjectDN issuer)+        == canonicalDistinguishedName issuerDN  exhaustive :: Bool -> [FailedReason] -> [FailedReason] -> [FailedReason] exhaustive isExhaustive l1 l2
Data/X509/Validation/Signature.hs view
@@ -86,11 +86,17 @@     -> SignatureVerification verifySignature alg pubkey cdata signature     | not (acceptablePubKey pubkey) = SignatureFailed SignatureInvalid+    | weakHash alg = SignatureFailed SignatureUnimplemented     | otherwise =         -- degenerate keys or encodings must not throw from pure code         either (const $ SignatureFailed SignatureInvalid) id $             tryPure (`seq` ()) (verifySignature' alg pubkey cdata signature) +-- | MD2 and MD5 are broken for signatures.+weakHash :: SignatureALG -> Bool+weakHash (SignatureALG h _) = h `elem` [HashMD2, HashMD5]+weakHash _ = False+ -- | Reject key parameters that are invalid or too costly to verify with. acceptablePubKey :: PubKey -> Bool acceptablePubKey (PubKeyRSA (RSA.PublicKey _ n e)) =@@ -122,6 +128,7 @@         | hashALG == HashSHA384 = Just $ PSS.verify (PSS.defaultPSSParams SHA384) key         | hashALG == HashSHA512 = Just $ PSS.verify (PSS.defaultPSSParams SHA512) key         | hashALG == HashSHA224 = Just $ PSS.verify (PSS.defaultPSSParams SHA224) key+        | hashALG == HashSHA1 = Just $ PSS.verify (PSS.defaultPSSParams SHA1) key         | otherwise = Nothing     verifyF _ = Nothing verifySignature' (SignatureALG hashALG pubkeyALG) pubkey cdata signature@@ -144,27 +151,24 @@      dsaToSignature :: ByteString -> Maybe DSA.Signature     dsaToSignature b =-        case decodeASN1' BER b of-            Left _ -> Nothing-            Right asn1 ->-                case asn1 of-                    Start Sequence : IntVal r : IntVal s : End Sequence : _ ->-                        Just $ DSA.Signature{DSA.sign_r = r, DSA.sign_s = s}-                    _ ->-                        Nothing+        case decodeASN1' DER b of+            Right [Start Sequence, IntVal r, IntVal s, End Sequence] ->+                Just $ DSA.Signature{DSA.sign_r = r, DSA.sign_s = s}+            _ -> Nothing      dsaVerify hsh key b a =         case dsaToSignature a of             Nothing -> False             Just dsaSig -> DSA.verify hsh key dsaSig b -    rsaVerify HashMD2 = RSA.verify (Just MD2)-    rsaVerify HashMD5 = RSA.verify (Just MD5)-    rsaVerify HashSHA1 = RSA.verify (Just SHA1)-    rsaVerify HashSHA224 = RSA.verify (Just SHA224)-    rsaVerify HashSHA256 = RSA.verify (Just SHA256)-    rsaVerify HashSHA384 = RSA.verify (Just SHA384)-    rsaVerify HashSHA512 = RSA.verify (Just SHA512)+    rsaVerify HashMD2 = rsaVerifyWith MD2+    rsaVerify HashMD5 = rsaVerifyWith MD5+    rsaVerify HashSHA1 = rsaVerifyWith SHA1+    rsaVerify HashSHA224 = rsaVerifyWith SHA224+    rsaVerify HashSHA256 = rsaVerifyWith SHA256+    rsaVerify HashSHA384 = rsaVerifyWith SHA384+    rsaVerify HashSHA512 = rsaVerifyWith SHA512+    rsaVerifyWith h key msg = RSA.verifyDigest key (hashWith h msg) verifySignature' (SignatureALG_IntrinsicHash pubkeyALG) pubkey cdata signature     | pubkeyToAlg pubkey == pubkeyALG = doVerify pubkey     | otherwise = SignatureFailed SignaturePubkeyMismatch@@ -197,7 +201,7 @@     ecPubKeyCurveName key >>= verifyCurve (pubkeyEC_pub key)   where     verifyCurve pub curveName = Just $ \msg sigBS ->-        case decodeASN1' BER sigBS of+        case decodeASN1' DER sigBS of             Left _ -> False             Right [Start Sequence, IntVal r, IntVal s, End Sequence] ->                 let curve = ECC.getCurveByName curveName
Tests/Certificate.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE GADTs #-}+{-# LANGUAGE TypeOperators #-}  -- | Types and functions used to build test certificates. module Certificate (@@ -29,6 +30,7 @@     mkLeaf, ) where +import Crypto.Hash (hashWith) import Crypto.Hash.Algorithms import Crypto.Number.Serialize @@ -157,9 +159,11 @@ getPubKey (AlgDSA _ _) key = PubKeyDSA key getPubKey (AlgEC name _) key = PubKeyEC (PubKeyEC_Named name pub)   where-    ECC.Point x y = ECDSA.public_q key     pub = SerializedPoint bs-    bs = B.cons 4 (i2ospOf_ bytes x `B.append` i2ospOf_ bytes y)+    -- a generated public key is never the point at infinity+    bs = case ECDSA.public_q key of+        ECC.Point x y -> B.cons 4 (i2ospOf_ bytes x `B.append` i2ospOf_ bytes y)+        ECC.PointO -> B.singleton 0     bits = ECC.curveSizeBits (ECC.getCurveByName name)     bytes = (bits + 7) `div` 8 getPubKey AlgEd25519 key = PubKeyEd25519 key@@ -181,7 +185,7 @@  doSign :: Alg pub priv -> priv -> B.ByteString -> IO B.ByteString doSign (AlgRSA _ hash) key msg = do-    result <- RSA.signSafer (Just $ getHashAlgorithm hash) key msg+    result <- RSA.signSaferDigest key (hashWith (getHashAlgorithm hash) msg)     case result of         Left err -> error ("doSign(AlgRSA): " ++ show err)         Right sigBits -> return sigBits
Tests/Tests.hs view
@@ -6,6 +6,7 @@ import Crypto.Hash.Algorithms  import qualified Crypto.PubKey.DSA as DSA+import qualified Crypto.PubKey.ECC.ECDSA as ECDSA import qualified Crypto.PubKey.ECC.Types as ECC import qualified Crypto.PubKey.RSA as RSA import qualified Crypto.PubKey.RSA.PSS as PSS@@ -16,7 +17,6 @@ import Data.ASN1.Types  import Data.Default-import Data.Monoid import Data.String (fromString) import Data.X509 import Data.X509.CertificateStore@@ -833,12 +833,232 @@                 @?= SignatureFailed SignatureInvalid         ] +-- | Validity period around the current date.+currentValidity :: IO (DateTime, DateTime)+currentValidity = do+    today <- timeGetDate <$> timeCurrent+    let d y = mkDateTime $ today `dateAddPeriod` mempty{periodYears = y}+    return (d (-1), d 1)++-- | Validates a chain against a store for www.example.com.+validateExample :: CertificateStore -> [SignedCertificate] -> IO [FailedReason]+validateExample store chain =+    validate+        HashSHA256+        defaultHooks+        defaultChecks+        store+        def+        ("www.example.com", fromString ":443")+        (CertificateChain chain)++exampleSAN :: ExtensionRaw+exampleSAN = sanExt [AltNameDNS "www.example.com"]++-- | A trust anchor that is not a CA can only validate itself.+testNonCAAnchor :: IO (RData pub priv) -> TestTree+testNonCAAnchor res =+    testGroup+        "non-CA anchor"+        [ testWithRes res "as issuer" $ \rd -> do+            anchor <-+                mkCertificate 2 50 (mkDn "NotCA Root") (present rd) [notCA] Self (keys1 rd)+            leaf <-+                mkCertificate+                    2+                    51+                    (mkDn "leaf")+                    (present rd)+                    [exampleSAN]+                    (CA anchor)+                    (keys2 rd)+            actual <- validateExample (mkStore [anchor]) [pairSignedCert leaf]+            actual @?= [NotAnAuthority]+        , testWithRes res "as itself" $ \rd -> do+            self <-+                mkCertificate+                    2+                    52+                    (mkDn "self")+                    (present rd)+                    [notCA, exampleSAN]+                    Self+                    (keys3 rd)+            actual <- validateExample (mkStore [self]) [pairSignedCert self]+            actual @?= []+        ]+  where+    notCA = mkExtension True $ ExtBasicConstraints False Nothing++-- | The outer signature algorithm must match the one in the TBS.+testSignatureAlgMismatch :: TestTree+testSignatureAlgMismatch = testCase "signature algorithm mismatch" $ do+    validity <- currentValidity+    let alg = AlgEC ECC.SEC_p256r1 hashSHA256+    rootPair <-+        generateKeys alg >>= mkCA 1 "Mismatch Root" validity (Just bc) Nothing Self+    let rootCert = signedObject $ getSigned $ pairSignedCert rootPair+        cert =+            Certificate+                { certVersion = 2+                , certSerial = 2+                , certSignatureAlg = SignatureALG HashSHA384 PubKeyALG_EC+                , certIssuerDN = certSubjectDN rootCert+                , certValidity = validity+                , certSubjectDN = mkDn "leaf"+                , certPubKey = certPubKey rootCert+                , certExtensions = Extensions (Just [exampleSAN])+                }+        sign raw = do+            sig <- ECDSA.sign (pairKey rootPair) SHA256 raw+            let der =+                    encodeASN1'+                        DER+                        [ Start Sequence+                        , IntVal (ECDSA.sign_r sig)+                        , IntVal (ECDSA.sign_s sig)+                        , End Sequence+                        ]+            return (der, SignatureALG HashSHA256 PubKeyALG_EC)+    leaf <- objectToSignedExactF sign cert+    actual <- validateExample (mkStore [rootPair]) [leaf]+    actual @?= [InvalidSignature SignatureInvalid]+  where+    bc = ExtBasicConstraints True Nothing++-- | Certificates signed with MD5 are rejected.+testWeakHash :: TestTree+testWeakHash = testCase "MD5 signature" $ do+    validity <- currentValidity+    keys <- generateKeys (AlgRSA 1024 hashMD5)+    rootPair <- mkCA 1 "MD5 Root" validity (Just bc) Nothing Self keys+    leaf <- mkCertificate 2 2 (mkDn "leaf") validity [exampleSAN] (CA rootPair) keys+    actual <- validateExample (mkStore [rootPair]) [pairSignedCert leaf]+    actual @?= [InvalidSignature SignatureUnimplemented]+  where+    bc = ExtBasicConstraints True Nothing++-- | A root re-keyed under the same name: both are kept in the store.+testSameNameRoots :: IO (RData pub priv) -> TestTree+testSameNameRoots res = testWithRes res "same-name roots" $ \rd -> do+    old <- mkCertificate 2 60 (mkDn "Same Root") (present rd) [caBC] Self (keys1 rd)+    new <- mkCertificate 2 61 (mkDn "Same Root") (present rd) [caBC] Self (keys2 rd)+    leaf <-+        mkCertificate 2 62 (mkDn "leaf") (present rd) [exampleSAN] (CA old) (keys3 rd)+    actual <- validateExample (mkStore [old, new]) [pairSignedCert leaf]+    actual @?= []++-- | The first intermediate with the issuer name is not the issuer.+testBacktracking :: IO (RData pub priv) -> TestTree+testBacktracking res = testWithRes res "backtracking" $ \rd -> do+    other <-+        mkCertificate 2 70 (mkDn "Other Root") (present rd) [caBC] Self (keys1 rd)+    wrong <-+        mkCertificate 2 71 (mkDn "Same CA") (present rd) [caBC] (CA other) (keys2 rd)+    right <-+        mkCertificate+            2+            72+            (mkDn "Same CA")+            (present rd)+            [caBC]+            (CA (root rd))+            (keys3 rd)+    leaf <-+        mkCertificate 2 73 (mkDn "leaf") (present rd) [exampleSAN] (CA right) (keys1 rd)+    actual <-+        validateExample+            (mkStore [root rd, other])+            (map pairSignedCert [leaf, wrong, right])+    actual @?= []++-- | Many certificates with the same names do not make path building+-- exponential.+testPathBudget :: IO (RData pub priv) -> TestTree+testPathBudget res =+    localOption (mkTimeout 10000000) $+        testWithRes res "path budget" $ \rd -> do+            a0 <- mkCertificate 2 80 (mkDn "Loop A") (present rd) [caBC] Self (keys1 rd)+            let mk dn i issuer = mkCertificate 2 i (mkDn dn) (present rd) [caBC] (CA issuer) (keys1 rd)+            bs@(b1 : _) <- mapM (mk "Loop B" 90 . const a0) [1 .. 6 :: Int]+            as@(a1 : _) <- mapM (\i -> mk "Loop A" (100 + i) b1) [1 .. 6]+            leaf <-+                mkCertificate+                    2+                    99+                    (mkDn "leaf")+                    (present rd)+                    [exampleSAN]+                    (CA a1)+                    (keys2 rd)+            -- "Loop A" issued by "Loop B" and vice versa, all with one key+            let chain = leaf : concat (zipWith (\x y -> [x, y]) as bs)+            actual <- validateExample (rootStore rd) (map pairSignedCert chain)+            assertBool "unexpected success" $ not (null actual)++-- | Issuer names are compared in canonical form.+testCanonicalIssuer :: TestTree+testCanonicalIssuer = testCase "canonical issuer name" $ do+    validity <- currentValidity+    let alg = AlgEC ECC.SEC_p256r1 hashSHA256+    rootPair <-+        generateKeys alg+            >>= mkCA+                1+                "Case Root"+                validity+                (Just $ ExtBasicConstraints True Nothing)+                Nothing+                Self+    let rootCert = signedObject $ getSigned $ pairSignedCert rootPair+        sigAlg = SignatureALG HashSHA256 PubKeyALG_EC+        cert =+            Certificate+                { certVersion = 2+                , certSerial = 2+                , certSignatureAlg = sigAlg+                , certIssuerDN =+                    DistinguishedName+                        [(getObjectID DnCommonName, asn1CharacterString Printable "CASE  root")]+                , certValidity = validity+                , certSubjectDN = mkDn "leaf"+                , certPubKey = certPubKey rootCert+                , certExtensions = Extensions (Just [exampleSAN])+                }+        sign raw = do+            sig <- ECDSA.sign (pairKey rootPair) SHA256 raw+            let der =+                    encodeASN1'+                        DER+                        [ Start Sequence+                        , IntVal (ECDSA.sign_r sig)+                        , IntVal (ECDSA.sign_s sig)+                        , End Sequence+                        ]+            return (der, sigAlg)+    leaf <- objectToSignedExactF sign cert+    actual <- validateExample (mkStore [rootPair]) [leaf]+    actual @?= []+ -- | Regression tests that do not depend on the signature algorithm. treeRegression :: TestTree treeRegression = withResource (initData AlgEd25519) freeData $ \res ->     testGroup         "regression"         [ testGroup+            "hardening"+            [ testNonCAAnchor res+            , testSignatureAlgMismatch+            , testWeakHash+            ]+        , testGroup+            "path building"+            [ testSameNameRoots res+            , testBacktracking res+            , testPathBudget res+            , testCanonicalIssuer+            ]+        , testGroup             "name-constraints"             [ testNameConstraints                 res@@ -1336,6 +1556,7 @@                     True                     [NameMismatch "example.com"]                 , testSubjectAltName res "*.example.com" "www.example.com" True []+                , testSubjectAltName res "*.com" "example.com" True [NameMismatch "example.com"]                 , testSubjectAltName res "*.example.com" "www.EXAMPLE.com" True []                 , testSubjectAltName res "*.example.com" "www2.example.com" True []                 , testSubjectAltName@@ -1536,6 +1757,12 @@                 [p1, p3]                 [p2, p3]                 [LeafKeyPurposeNotAllowed]+            , testLeafKeyPurpose+                res+                "anyExtendedKeyUsage"+                [p1, KeyUsagePurpose_Unknown [2, 5, 29, 37, 0]]+                [p2, p3]+                []             ]         , testExhaustive             res
crypton-x509-validation.cabal view
@@ -1,6 +1,6 @@ cabal-version:      >=1.10 name:               crypton-x509-validation-version:            1.10.2+version:            1.10.3 license:            BSD3 license-file:       LICENSE copyright:          Vincent Hanquez <vincent@snarc.org>@@ -17,7 +17,7 @@ source-repository head     type:     git     location: https://github.com/kazu-yamamoto/crypton-certificate-    subdir:   x509-validation+    subdir:   crypton-x509-validation  library     exposed-modules:  Data.X509.Validation@@ -34,12 +34,12 @@         base >=3 && <5,         bytestring,         containers,-        crypton >=2.1.8 && <2.3,+        crypton >=2.2.0 && <2.3,         crypton-asn1-types >=0.4.1 && <0.5,         crypton-asn1-encoding >=0.10.0 && <0.11,         crypton-pem >=0.2.4 && <0.4,-        crypton-x509 >=1.10.2 && <1.11,-        crypton-x509-store >=1.10 && <1.11,+        crypton-x509 >=1.10.3 && <1.11,+        crypton-x509-store >=1.10.1 && <1.11,         data-default,         iproute >=1.2.2,         mtl,