X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Rakka%2FAuthorization.hs;h=04beabae3cb676cd138d1a0b447c818ba1ee5d0c;hb=522dde5470584bb3f82cb0b4179233724d2408d0;hp=8da8afe95a590ca44552084ee92f9a95672d17db;hpb=9f49e3384f1925d295355e5f60e94a8ca95039ea;p=Rakka.git diff --git a/Rakka/Authorization.hs b/Rakka/Authorization.hs index 8da8afe..04beaba 100644 --- a/Rakka/Authorization.hs +++ b/Rakka/Authorization.hs @@ -8,7 +8,8 @@ module Rakka.Authorization import qualified Codec.Binary.Base64 as B64 import qualified Codec.Binary.UTF8.String as UTF8 import Control.Concurrent.STM -import qualified Data.Digest.SHA1 as SHA1 +import Control.Monad.Trans +import Data.Digest.SHA2 import Data.Map (Map) import qualified Data.Map as M hiding (Map) import Data.Maybe @@ -42,32 +43,33 @@ mkAuthDB lsdir } -isValidPair :: AuthDB -> String -> String -> IO Bool +isValidPair :: MonadIO m => AuthDB -> String -> String -> m Bool isValidPair adb name pass - = let hash = SHA1.hash (UTF8.encode pass) + = let hash = toOctets $ sha256 $ UTF8.encode pass in - atomically $ do m <- readTVar (adbUserMap adb) - return (M.lookup name m == Just hash) + liftIO $ atomically $ do m <- readTVar (adbUserMap adb) + return (M.lookup name m == Just hash) loadUserMap :: FilePath -> IO UserMap loadUserMap path = do exist <- doesFileExist path - if exist then - readFile path - >>= - return . initMap . M.fromList . map decodePair . fromJust . deserializeStringPairs - else - return M.empty + m <- if exist then + readFile path + >>= + return . M.fromList . map decodePair . fromJust . deserializeStringPairs + else + return M.empty + return (initMap m) where decodePair :: (String, String) -> (String, [Word8]) decodePair (name, b64Hash) - = (UTF8.decodeString name, B64.decode b64Hash) + = (UTF8.decodeString name, fromJust $ B64.decode b64Hash) initMap :: UserMap -> UserMap initMap m | M.null m = let name = "root" - hash = SHA1.hash [] + hash = toOctets $ sha256 ([] :: [Word8]) in M.singleton name hash | otherwise = m