Skip to content

Commit 2ab662b

Browse files
Allow optional TLS params
Merge pull request #129 from darrell-roberts/master for issue #126.
2 parents 5980bc1 + e3ce869 commit 2ab662b

File tree

1 file changed

+14
-9
lines changed
  • Database/MongoDB/Transport

1 file changed

+14
-9
lines changed

Database/MongoDB/Transport/Tls.hs

+14-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ barely tested. The current implementation doesn't verify server's identity.
2222
It only allows you to connect to a mongodb server using TLS protocol.
2323
-}
2424
module Database.MongoDB.Transport.Tls
25-
(connect)
25+
( connect
26+
, connectWithTlsParams
27+
)
2628
where
2729

2830
import Data.IORef
29-
import Data.Monoid
31+
3032
import qualified Data.ByteString as ByteString
3133
import qualified Data.ByteString.Lazy as Lazy.ByteString
3234
import Data.Default.Class (def)
33-
import Control.Applicative ((<$>))
3435
import Control.Exception (bracketOnError)
3536
import Control.Monad (when, unless)
3637
import System.IO
@@ -45,15 +46,19 @@ import Database.MongoDB.Query (access, slaveOk, retrieveServerData)
4546

4647
-- | Connect to mongodb using TLS
4748
connect :: HostName -> PortID -> IO Pipe
48-
connect host port = bracketOnError (connectTo host port) hClose $ \handle -> do
49-
50-
let params = (TLS.defaultParamsClient host "")
49+
connect host port = connectWithTlsParams params host port
50+
where
51+
params = (TLS.defaultParamsClient host "")
5152
{ TLS.clientSupported = def
52-
{ TLS.supportedCiphers = TLS.ciphersuite_default}
53+
{ TLS.supportedCiphers = TLS.ciphersuite_default }
5354
, TLS.clientHooks = def
54-
{ TLS.onServerCertificate = \_ _ _ _ -> return []}
55+
{ TLS.onServerCertificate = \_ _ _ _ -> return [] }
5556
}
56-
context <- TLS.contextNew handle params
57+
58+
-- | Connect to mongodb using TLS using provided TLS client parameters
59+
connectWithTlsParams :: TLS.ClientParams -> HostName -> PortID -> IO Pipe
60+
connectWithTlsParams clientParams host port = bracketOnError (connectTo host port) hClose $ \handle -> do
61+
context <- TLS.contextNew handle clientParams
5762
TLS.handshake context
5863

5964
conn <- tlsConnection context

0 commit comments

Comments
 (0)