diff options
author | 2012-07-26 03:38:20 -0400 | |
---|---|---|
committer | 2012-07-26 03:38:20 -0400 | |
commit | b36804d6486b342bee7f5b4b621228bc193c4844 (patch) | |
tree | efa7db5a8b412e8038228de923a0d53adbd5bda8 /Utility/WebApp.hs | |
parent | 3ac2cf09e56cb1918312a31e0884d56829a14c32 (diff) |
generate random token and launch webapp using it
Diffstat (limited to 'Utility/WebApp.hs')
-rw-r--r-- | Utility/WebApp.hs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Utility/WebApp.hs b/Utility/WebApp.hs index 614a57cea..cded83229 100644 --- a/Utility/WebApp.hs +++ b/Utility/WebApp.hs @@ -22,6 +22,9 @@ import Data.ByteString.Lazy import Data.CaseInsensitive as CI import Network.Socket import Control.Exception +import Crypto.Random +import Data.Digest.Pure.SHA +import Data.ByteString.Lazy as L localhost :: String localhost = "localhost" @@ -102,3 +105,13 @@ logRequest req = do lookupRequestField :: CI Ascii -> Request -> Ascii lookupRequestField k req = fromMaybe "" . lookup k $ requestHeaders req + +{- Generates a 512 byte random token, suitable to be used for an + - authentication secret. -} +genRandomToken :: IO String +genRandomToken = do + g <- newGenIO :: IO SystemRandom + return $ + case genBytes 512 g of + Left e -> error $ "failed to generate secret token: " ++ show e + Right (s, _) -> showDigest $ sha512 $ L.fromChunks [s] |