blob: 0d1636cb9d9be3c7b22caa4c31ea2c00c8dedb78 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
{-# LANGUAGE OverloadedStrings #-}
{-|
Module : Crypto.Macaroon.Verifier
Copyright : (c) 2015 Julien Tanguy
License : BSD3
Maintainer : julien.tanguy@jhome.fr
Stability : experimental
Portability : portable
-}
module Crypto.Macaroon.Verifier where
import Crypto.Hash
import Data.Bool
import qualified Data.ByteString as BS
import Data.Byteable
import Data.Foldable
import Crypto.Macaroon.Internal
-- | Opaque datatype for now. Might need more explicit errors
data Result = Success | Failure deriving (Show,Eq)
verifySig :: Key -> Macaroon -> Result
verifySig k m = bool Failure Success $
signature m == foldl' hash (toBytes (hmac derivedKey (identifier m) :: HMAC SHA256)) (caveats m)
where
hash s c = toBytes (hmac s (vid c `BS.append` cid c) :: HMAC SHA256)
derivedKey = toBytes (hmac "macaroons-key-generator" k :: HMAC SHA256)
|