{-# Language OverloadedStrings #-}
module Client.Authentication.Ecdsa
( authenticationMode
, encodeUsername
, computeResponse
) where
import Control.Exception (displayException, try)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import System.Process (readProcess)
import Irc.Commands (AuthenticatePayload(..))
authenticationMode :: Text
authenticationMode = "ECDSA-NIST256P-CHALLENGE"
encodeUsername ::
Text ->
AuthenticatePayload
encodeUsername = AuthenticatePayload . Text.encodeUtf8
computeResponse ::
FilePath ->
Text ->
IO (Either String Text)
computeResponse privateKeyFile challenge =
do res <- try $ readProcess
"ecdsatool"
["sign", privateKeyFile, Text.unpack challenge]
""
return $! case words <$> res of
Right [resp] -> Right $! Text.pack resp
Right _ -> Left "bad sasl ecdsa response message"
Left e -> Left (displayException (e :: IOError))