]>
Commit | Line | Data |
---|---|---|
7f9f7386 JT |
1 | {-# LANGUAGE FlexibleInstances #-} |
2 | {-# LANGUAGE OverloadedStrings #-} | |
3 | {-# LANGUAGE RankNTypes #-} | |
4 | {-# LANGUAGE TypeSynonymInstances #-} | |
5 | {-# LANGUAGE UndecidableInstances #-} | |
b92e3c15 JT |
6 | {-| |
7 | Module : Crypto.Macaroon.Verifier | |
8 | Copyright : (c) 2015 Julien Tanguy | |
9 | License : BSD3 | |
10 | ||
11 | Maintainer : julien.tanguy@jhome.fr | |
12 | Stability : experimental | |
13 | Portability : portable | |
14 | ||
15 | ||
16 | ||
17 | -} | |
6f3c0dca | 18 | module Crypto.Macaroon.Verifier ( |
7f9f7386 | 19 | verify |
be278da9 | 20 | , VerifierResult(..) |
7f9f7386 | 21 | , ValidationError(ValidatorError, ParseError) |
6f3c0dca | 22 | ) where |
b92e3c15 JT |
23 | |
24 | ||
a11f20be JT |
25 | import Control.Applicative |
26 | import Control.Monad hiding (forM) | |
7f9f7386 | 27 | import Control.Monad.IO.Class |
c830f7c2 JT |
28 | import Data.Attoparsec.ByteString |
29 | import Data.Attoparsec.ByteString.Char8 | |
b92e3c15 | 30 | import Data.Bool |
a11f20be | 31 | import Data.Traversable |
c830f7c2 | 32 | import qualified Data.ByteString as BS |
7f9f7386 | 33 | import Data.Either.Combinators |
b92e3c15 JT |
34 | |
35 | import Crypto.Macaroon.Internal | |
7f9f7386 | 36 | import Crypto.Macaroon.Verifier.Internal |
b92e3c15 JT |
37 | |
38 | ||
6f3c0dca | 39 | |
86f38823 JT |
40 | -- | Verify a Macaroon's signature and caveats, given the corresponding Secret |
41 | -- and verifiers. | |
42 | -- | |
43 | -- A verifier is a function of type | |
be278da9 | 44 | -- @'MonadIO' m => 'Caveat' -> m VerifierResult@. |
86f38823 JT |
45 | -- |
46 | -- It should return: | |
47 | -- | |
be278da9 | 48 | -- * 'Unrelated' if the caveat is not related to the verifier |
86f38823 | 49 | -- (for instance a time verifier is given an action caveat); |
be278da9 | 50 | -- * 'Refused' ('ParseError' reason) if the verifier is related to the |
86f38823 | 51 | -- caveat, but failed to parse it completely; |
be278da9 | 52 | -- * 'Refused' ('ValidatorError' reason) if the verifier is related to the |
86f38823 | 53 | -- caveat, parsed it and invalidated it; |
be278da9 | 54 | -- * 'Verified' if the verifier has successfully verified the |
86f38823 | 55 | -- given caveat |
be278da9 | 56 | verify :: (Functor m, MonadIO m) => Secret -> [Caveat -> m VerifierResult] -> Macaroon -> m (Either ValidationError Macaroon) |
7f9f7386 JT |
57 | verify secret verifiers m = join <$> forM (verifySig secret m) (verifyCavs verifiers) |
58 |