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.
51 lines
1.3 KiB
51 lines
1.3 KiB
|
14 years ago
|
{-# Language NoMonomorphismRestriction #-}
|
||
|
14 years ago
|
{-# OPTIONS_HADDOCK hide #-}
|
||
|
14 years ago
|
module Data.Conduit.TLS
|
||
|
14 years ago
|
( tlsinit
|
||
|
14 years ago
|
-- , conduitStdout
|
||
|
14 years ago
|
, module TLS
|
||
|
|
, module TLSExtra
|
||
|
|
)
|
||
|
|
where
|
||
|
|
|
||
|
14 years ago
|
import Control.Monad(liftM)
|
||
|
14 years ago
|
import Control.Monad.IO.Class
|
||
|
14 years ago
|
|
||
|
|
import Crypto.Random
|
||
|
|
|
||
|
14 years ago
|
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
|
|
||
|
14 years ago
|
tlsinit
|
||
|
14 years ago
|
:: (MonadIO m, MonadIO m1) =>
|
||
|
14 years ago
|
TLSParams
|
||
|
|
-> Handle -> m ( Source m1 BS.ByteString
|
||
|
|
, Sink BS.ByteString m1 ()
|
||
|
14 years ago
|
, BS.ByteString -> IO ()
|
||
|
|
, TLSCtx Handle
|
||
|
|
)
|
||
|
14 years ago
|
tlsinit tlsParams handle = do
|
||
|
|
gen <- liftIO $ (newGenIO :: IO SystemRandom) -- TODO: Find better random source?
|
||
|
|
clientContext <- client tlsParams gen handle
|
||
|
|
handshake clientContext
|
||
|
14 years ago
|
let src = sourceState
|
||
|
|
clientContext
|
||
|
|
(\con -> StateOpen con `liftM` recvData con)
|
||
|
|
let snk = sinkState
|
||
|
|
clientContext
|
||
|
14 years ago
|
(\con bs -> sendData con (BL.fromChunks [bs])
|
||
|
14 years ago
|
>> return (StateProcessing con))
|
||
|
14 years ago
|
(\_ -> return ())
|
||
|
14 years ago
|
return ( src
|
||
|
14 years ago
|
, snk
|
||
|
14 years ago
|
, \s -> sendData clientContext $ BL.fromChunks [s]
|
||
|
|
, clientContext
|
||
|
|
)
|
||
|
14 years ago
|
|