@@ -22,11 +22,14 @@ barely tested. The current implementation doesn't verify server's identity.
2222It only allows you to connect to a mongodb server using TLS protocol.
2323-}
2424module Database.MongoDB.Transport.Tls
25- (connect)
25+ ( connect
26+ , connectWithTlsParams
27+ )
2628where
2729
2830import Data.IORef
2931import Data.Monoid
32+ import Data.Maybe (fromMaybe )
3033import qualified Data.ByteString as ByteString
3134import qualified Data.ByteString.Lazy as Lazy.ByteString
3235import Data.Default.Class (def )
@@ -45,15 +48,19 @@ import Database.MongoDB.Query (access, slaveOk, retrieveServerData)
4548
4649-- | Connect to mongodb using TLS
4750connect :: HostName -> PortID -> IO Pipe
48- connect host port = bracketOnError (connectTo host port) hClose $ \ handle -> do
49-
50- let params = (TLS. defaultParamsClient host " " )
51+ connect host port = connectWithTlsParams params host port
52+ where
53+ params = (TLS. defaultParamsClient host " " )
5154 { TLS. clientSupported = def
52- { TLS. supportedCiphers = TLS. ciphersuite_default}
55+ { TLS. supportedCiphers = TLS. ciphersuite_default }
5356 , TLS. clientHooks = def
54- { TLS. onServerCertificate = \ _ _ _ _ -> return [] }
57+ { TLS. onServerCertificate = \ _ _ _ _ -> return [] }
5558 }
56- context <- TLS. contextNew handle params
59+
60+ -- | Connect to mongodb using TLS using provided TLS client parameters
61+ connectWithTlsParams :: TLS. ClientParams -> HostName -> PortID -> IO Pipe
62+ connectWithTlsParams clientParams host port = bracketOnError (connectTo host port) hClose $ \ handle -> do
63+ context <- TLS. contextNew handle clientParams
5764 TLS. handshake context
5865
5966 conn <- tlsConnection context
@@ -62,6 +69,7 @@ connect host port = bracketOnError (connectTo host port) hClose $ \handle -> do
6269 sd <- access p slaveOk " admin" retrieveServerData
6370 return p
6471
72+
6573tlsConnection :: TLS. Context -> IO Transport
6674tlsConnection ctx = do
6775 restRef <- newIORef mempty
0 commit comments