-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,10 +81,10 @@ data OaConfig ty = | |
-- | Perform authenticated requests using a shared 'C.Manager' and | ||
-- a particular set of 'O.Cred's. | ||
newtype OAuthT ty m a = | ||
OAuthT { unOAuthT :: ReaderT (OaConfig ty) (StateT R.SystemRNG m) a } | ||
OAuthT { unOAuthT :: ReaderT (OaConfig ty) (StateT R.ChaChaDRG m) a } | ||
deriving ( Functor, Applicative, Monad | ||
, MonadReader (OaConfig ty) | ||
, MonadState R.SystemRNG | ||
, MonadState R.ChaChaDRG | ||
, E.MonadCatch | ||
, E.MonadThrow | ||
, MonadIO | ||
|
@@ -100,8 +100,8 @@ runOAuthT | |
OAuthT ty m a -> O.Cred ty -> O.Server -> O.ThreeLegged -> | ||
m a | ||
runOAuthT oat cr srv tl = do | ||
entropy <- liftIO R.createEntropyPool | ||
evalStateT (runReaderT (unOAuthT oat) (OaConfig cr srv tl)) (R.cprgCreate entropy) | ||
gen <- liftIO R.drgNew | ||
evalStateT (runReaderT (unOAuthT oat) (OaConfig cr srv tl)) gen | ||
|
||
runOAuth :: OAuth ty a -> O.Cred ty -> O.Server -> O.ThreeLegged -> IO a | ||
runOAuth = runOAuthT | ||
|
@@ -121,14 +121,14 @@ upgradeCred tok = liftM (Cred.upgradeCred tok . cred) ask | |
|
||
-- | Given a 'Cred.ResourceToken' of some kind, run an inner 'OAuthT' session | ||
-- with the same configuration but new credentials. | ||
upgrade :: (Cred.ResourceToken ty', Monad m) => O.Token ty' -> OAuthT ty' m a -> OAuthT ty m a | ||
upgrade :: (Cred.ResourceToken ty', Monad m, MonadIO m) => O.Token ty' -> OAuthT ty' m a -> OAuthT ty m a | ||
upgrade tok oat = do | ||
gen <- state R.cprgFork | ||
gen <- liftIO R.drgNew | ||
This comment has been minimized.
Sorry, something went wrong.
ibotty
Author
Owner
|
||
conf <- ask | ||
let conf' = conf { cred = Cred.upgradeCred tok (cred conf) } | ||
lift $ evalStateT (runReaderT (unOAuthT oat) conf') gen | ||
|
||
liftBasic :: MonadIO m => (R.SystemRNG -> OaConfig ty -> IO (a, R.SystemRNG)) -> OAuthT ty m a | ||
liftBasic :: MonadIO m => (R.ChaChaDRG -> OaConfig ty -> IO (a, R.ChaChaDRG)) -> OAuthT ty m a | ||
liftBasic f = do | ||
gen <- get | ||
conf <- ask | ||
|
@@ -208,7 +208,7 @@ requestTokenProtocol man getVerifier = runEitherT $ do | |
upE :: (Monad m, Functor m) => (e -> f) -> Either e b -> EitherT f m b | ||
upE f = liftE f . return | ||
-- This is just 'upgrade' played out in the EitherT monad. | ||
upgradeE :: (Monad m, Cred.ResourceToken ty') => | ||
upgradeE :: (Monad m, MonadIO m, Cred.ResourceToken ty') => | ||
Cred.Token ty' | ||
-> EitherT e (OAuthT ty' m) a -> EitherT e (OAuthT ty m) a | ||
upgradeE tok = EitherT . upgrade tok . runEitherT |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,8 @@ module Network.OAuth.Types.Params where | |
|
||
import Control.Applicative | ||
import Crypto.Random | ||
import Data.ByteArray.Encoding (Base(Base64), convertToBase) | ||
import qualified Data.ByteString as S | ||
import qualified Data.ByteString.Base64 as S64 | ||
import qualified Data.ByteString.Char8 as S8 | ||
import Data.Data | ||
import Data.Time | ||
|
@@ -178,20 +178,27 @@ emptyPin = OaPin { timestamp = Timestamp (UTCTime (ModifiedJulianDay 0) 0) | |
|
||
-- | Creates a new, unique, unpredictable 'OaPin'. This should be used quickly | ||
-- as dependent on the OAuth server settings it may expire. | ||
freshPin :: CPRG gen => gen -> IO (OaPin, gen) | ||
freshPin :: DRG gen => gen -> IO (OaPin, gen) | ||
freshPin gen = do | ||
t <- Timestamp <$> getCurrentTime | ||
return (OaPin { timestamp = t, nonce = n }, gen') | ||
where | ||
(n, gen') = withRandomBytes gen 8 S64.encode | ||
(n, gen') = withRandomBytes gen 8 (convertToBase Base64) | ||
|
||
-- | generate @len random bytes and mapped the bytes to the function @f. | ||
-- | ||
-- This is equivalent to use Control.Arrow 'first' with 'randomBytesGenerate' | ||
withRandomBytes :: DRG g => g -> Int -> (S.ByteString -> a) -> (a, g) | ||
withRandomBytes rng len f = (f bs, rng') | ||
where (bs, rng') = randomBytesGenerate len rng | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
ibotty
Author
Owner
|
||
-- | Uses 'emptyPin' to create an empty set of params 'Oa'. | ||
emptyOa :: Cred ty -> Oa ty | ||
emptyOa creds = | ||
Oa { credentials = creds, workflow = Standard, pin = emptyPin } | ||
|
||
-- | Uses 'freshPin' to create a fresh, default set of params 'Oa'. | ||
freshOa :: CPRG gen => Cred ty -> gen -> IO (Oa ty, gen) | ||
freshOa :: DRG gen => Cred ty -> gen -> IO (Oa ty, gen) | ||
freshOa creds gen = do | ||
(pinx, gen') <- freshPin gen | ||
return (Oa { credentials = creds, workflow = Standard, pin = pinx }, gen') | ||
|
1 comment
on commit a45ef30
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this seems quite clean and simple. Lets make some issues to track the components which are dependent on cryptonite
development, though.
drgNew
uses memory from a fresh entropy pool by itself.