You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB

14 years ago
{-# Language NoMonomorphismRestriction #-}
{-# OPTIONS_HADDOCK hide #-}
module Data.Conduit.TLS
14 years ago
( tlsinit
-- , conduitStdout
14 years ago
, module TLS
, module TLSExtra
)
where
import Control.Monad(liftM, when)
import Control.Monad.IO.Class
14 years ago
import Crypto.Random
import qualified Data.ByteString as BS
14 years ago
import qualified Data.ByteString.Lazy as BL
import Data.Conduit
import Network.TLS as TLS
import Network.TLS.Extra as TLSExtra
import System.IO(Handle)
14 years ago
tlsinit :: (MonadIO m, MonadIO m1) =>
Bool
-> TLSParams
14 years ago
-> Handle -> m ( Source m1 BS.ByteString
, Sink BS.ByteString m1 ()
, BS.ByteString -> IO ()
, TLSCtx Handle
)
tlsinit debug tlsParams handle = do
when debug . liftIO $ putStrLn "Debug mode enabled"
14 years ago
gen <- liftIO $ (newGenIO :: IO SystemRandom) -- TODO: Find better random source?
clientContext <- client tlsParams gen handle
handshake clientContext
let src = sourceState
clientContext
(\con -> do
dt <- recvData con
when debug (liftIO $ BS.putStrLn dt)
return $ StateOpen con dt)
let snk = sinkState
clientContext
(\con bs -> do
sendData con (BL.fromChunks [bs])
when debug (liftIO $ BS.putStrLn bs)
return (StateProcessing con))
14 years ago
(\_ -> return ())
return ( src
14 years ago
, snk
, \s -> do
when debug (liftIO $ BS.putStrLn s)
sendData clientContext $ BL.fromChunks [s]
, clientContext
)