-}
module Crypto.Macaroon.Verifier (
Verified(..)
- , CaveatVerifier(..)
+ , CaveatVerifier
, (<???>)
+ , verifyMacaroon
, verifySig
, verifyExact
, verifyFun
- , verifyCavs
- -- , module Data.Attoparsec.ByteString
, module Data.Attoparsec.ByteString.Char8
+ , verifyCavs
) where
hash s c = toBytes (hmac s (vid c `BS.append` cid c) :: HMAC SHA256)
derivedKey = toBytes (hmac "macaroons-key-generator" k :: HMAC SHA256)
+verifyMacaroon :: Key -> [CaveatVerifier] -> Macaroon -> Verified
+verifyMacaroon secret verifiers m = verifySig secret m `mappend` verifyCavs verifiers m
+
+
verifyCavs :: [CaveatVerifier] -> Macaroon -> Verified
verifyCavs verifiers m = foldMap (\c -> fromMaybe Failed $ foldMap (($ c) . vFun) verifiers) (caveats m)
sigs = testProperty "Signatures" $ \sm -> verifySig (secret sm) (macaroon sm) == Ok
firstParty = testGroup "First party caveats" [
- testGroup "Pure verifiers" [
+ testGroup "Pure verifiers" [
testProperty "Zero caveat" $
forAll (sublistOf allvs) (\vs -> Ok == verifyCavs vs m)
, testProperty "One caveat" $
, Failed === verifyCavs vs m3
])
]
+ , testGroup "Pure verifiers with sig" [
+ testProperty "Zero caveat" $
+ forAll (sublistOf allvs) (\vs -> Ok == verifyMacaroon sec vs m)
+ , testProperty "One caveat" $
+ forAll (sublistOf allvs) (\vs -> disjoin [
+ Ok == verifyMacaroon sec vs m2 .&&. any (`elem` vs) [exTC,funTCPre] .&&. (exTZ `notElem` vs)
+ , Failed === verifyMacaroon sec vs m2
+ ])
+ , testProperty "Two Exact" $
+ forAll (sublistOf allvs) (\vs -> disjoin [
+ Ok == verifyMacaroon sec vs m3 .&&.
+ any (`elem` vs) [exTC,funTCPre] .&&. (exTZ `notElem` vs) .&&.
+ any (`elem` vs) [exV42,funTV43lte] .&&. (exV43 `notElem` vs)
+ , Failed === verifyMacaroon sec vs m3
+ ])
+ ]
]