network-conduit-tls 0.5.0 → 0.6.0
raw patch · 3 files changed
+40/−12 lines, 3 filesdep ~network-conduit
Dependency ranges changed: network-conduit
Files
- Data/Conduit/Network/TLS.hs +21/−10
- Data/Conduit/Network/TLS/Internal.hs +16/−0
- network-conduit-tls.cabal +3/−2
Data/Conduit/Network/TLS.hs view
@@ -1,7 +1,13 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Data.Conduit.Network.TLS- ( TLSConfig (..)+ ( TLSConfig+ , tlsConfig+ , tlsHost+ , tlsPort+ , tlsCertificate+ , tlsKey+ , tlsNeedLocalAddr , runTCPServerTLS ) where @@ -19,10 +25,11 @@ import qualified Data.Certificate.X509 as X509 import Data.Conduit.Network (HostPreference, Application, bindPort, sinkSocket, acceptSafe) import Data.Conduit.Network.Internal (AppData (..))+import Data.Conduit.Network.TLS.Internal import Data.Conduit (($$), yield) import qualified Data.Conduit.List as CL import Data.Either (rights)-import Network.Socket (sClose)+import Network.Socket (sClose, getSocketName) import Network.Socket.ByteString (recv) import Control.Exception (bracket, finally) import Control.Concurrent (forkIO)@@ -30,12 +37,12 @@ import qualified Network.TLS.Extra as TLSExtra import Crypto.Random (newGenIO, SystemRandom) -data TLSConfig = TLSConfig- { tlsHost :: HostPreference- , tlsPort :: Int- , tlsCertificate :: FilePath- , tlsKey :: FilePath- }+tlsConfig :: HostPreference+ -> Int -- ^ port+ -> FilePath -- ^ certificate+ -> FilePath -- ^ key+ -> TLSConfig+tlsConfig a b c d = TLSConfig a b c d False runTCPServerTLS :: TLSConfig -> Application IO -> IO () runTCPServerTLS TLSConfig{..} app = do@@ -48,10 +55,13 @@ where serve certs key lsocket = do (socket, addr) <- acceptSafe lsocket- _ <- forkIO $ handle socket addr+ mlocal <- if tlsNeedLocalAddr+ then fmap Just $ getSocketName socket+ else return Nothing+ _ <- forkIO $ handle socket addr mlocal return () where- handle socket addr = do+ handle socket addr mlocal = do gen <- newGenIO ctx <- TLS.serverWith params@@ -69,6 +79,7 @@ in src , appSink = CL.mapM_ $ TLS.sendData ctx . L.fromChunks . return , appSockAddr = addr+ , appLocalAddr = mlocal }
+ Data/Conduit/Network/TLS/Internal.hs view
@@ -0,0 +1,16 @@+{-# OPTIONS_HADDOCK not-home #-}+module Data.Conduit.Network.TLS.Internal+ ( TLSConfig (..)+ ) where++import Prelude hiding (FilePath)+import Data.Conduit.Network (HostPreference)+import Filesystem.Path.CurrentOS (FilePath)++data TLSConfig = TLSConfig+ { tlsHost :: HostPreference+ , tlsPort :: Int+ , tlsCertificate :: FilePath+ , tlsKey :: FilePath+ , tlsNeedLocalAddr :: Bool+ }
network-conduit-tls.cabal view
@@ -1,5 +1,5 @@ name: network-conduit-tls-version: 0.5.0+version: 0.6.0 synopsis: Create TLS-aware network code with conduits description: Uses the tls package for a pure-Haskell implementation. homepage: https://github.com/snoyberg/conduit@@ -13,6 +13,7 @@ library exposed-modules: Data.Conduit.Network.TLS+ Data.Conduit.Network.TLS.Internal build-depends: base >= 4 && < 5 , yaml >= 0.8 , system-filepath >= 0.4@@ -21,7 +22,7 @@ , certificate >= 1.2 , pem >= 0.1 , tls >= 0.9- , network-conduit >= 0.6+ , network-conduit >= 0.6.1 , conduit >= 0.5 , network , transformers