@@ -20,20 +20,24 @@ Enable TLS/SSL on a Connection
20
20
Overview
21
21
--------
22
22
23
- In this guide, you can learn how to connect to MongoDB instances with the
24
- `TLS/SSL <https://en.wikipedia.org/wiki/Transport_Layer_Security>`__
25
- security protocol using the underlying TLS/SSL support in the JDK. To
26
- configure your connection to use TLS/SSL, enable the TLS/SSL settings in
27
- either the `ConnectionString <{+core-api+}/ConnectionString.html>`__
28
- or `MongoClientSettings <{+core-api+}/MongoClientSettings.html>`__.
23
+ In this guide, you can learn how to use the **TLS protocol** to secure your
24
+ connection to a MongoDB deployment. TLS is a cryptographic protocol that
25
+ secures communication between your application and MongoDB. To configure
26
+ your connection to use TLS, enable the TLS option and provide your
27
+ certificates for validation when creating a client.
29
28
30
- .. note:: Debugging TLS/SSL
29
+ By default, the driver supports TLS/SSL connections to MongoDB
30
+ servers using the underlying support for TLS/SSL provided by the JDK.
31
+ This can be changed either by using the `Netty API
32
+ <https://netty.io/4.1/api/>`__ or the extensibility of the `Java SE
33
+ API <https://docs.oracle.com/javase/8/docs/api/>`__.
31
34
32
- If you experience trouble setting up your TLS/SSL connection, you can
33
- use the ``-Djavax.net.debug=all`` system property to view more
34
- log statements. See `the Oracle guide to debugging TLS/SSL connections
35
- <https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/ReadDebug.html>`__
36
- for more information.
35
+ .. tip:: Prefer Netty for Asynchronous Apps
36
+
37
+ We recommend using Netty for asychronous applications because it supports
38
+ asynchronous I/O and handles high connection volumes effectively. To
39
+ learn about using Netty to configure your TLS settings, see the
40
+ :ref:`kotlin-tls-netty-sslContext` section of this guide.
37
41
38
42
.. _tls-enable:
39
43
@@ -82,6 +86,14 @@ using a method in the ``MongoClientSettings.Builder`` class.
82
86
.. literalinclude:: /examples/generated/TlsTest.snippet.tls-mongoclient-settings.kt
83
87
:language: kotlin
84
88
89
+ .. note:: Debugging TLS/SSL
90
+
91
+ If you experience trouble setting up your TLS/SSL connection, you can
92
+ use the ``-Djavax.net.debug=all`` system property to view more
93
+ log statements. See `the Oracle guide to debugging TLS/SSL connections
94
+ <https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/ReadDebug.html>`__
95
+ for more information.
96
+
85
97
.. _tls_configure-certificates:
86
98
87
99
Configure Certificates
@@ -225,6 +237,38 @@ To restrict your application to use only the TLS 1.2 protocol, set the
225
237
the TLS 1.2 protocol, upgrade to a later release to connect by using
226
238
TLS 1.2.
227
239
240
+ .. _kotlin-tls-netty-sslContext:
241
+
242
+ Configure TLS/SSL by Using Netty SslContext
243
+ -------------------------------------------
244
+
245
+ Include the following import statements:
246
+
247
+ .. code-block:: kotlin
248
+ :copyable: true
249
+
250
+ import com.mongodb.MongoClientSettings
251
+ import com.mongodb.connection.SslSettings
252
+ import com.mongodb.connection.TransportSettings
253
+ import com.mongodb.kotlin.client.coroutine.MongoClient
254
+ import io.netty.handler.ssl.SslContextBuilder
255
+ import io.netty.handler.ssl.SslProvider
256
+
257
+ .. note:: Netty Package Version
258
+
259
+ The driver tests with Netty package version ``{+netty-version+}``
260
+
261
+ To instruct the driver to use
262
+ `io.netty.handler.ssl.SslContext <https://netty.io/4.1/api/io/netty/handler/ssl/SslContext.html>`__,
263
+ configure `NettyTransportSettings <{+core-api+}/connection/NettyTransportSettings.html>`__
264
+ when you define your ``MongoClientSettings``.
265
+
266
+ Use ``MongoClientSettings.Builder.transportSettings()``
267
+ and ``NettyTransportSettings.Builder.sslContext()`` to build your settings:
268
+
269
+ .. literalinclude:: /examples/generated/TlsTest.snippet.netty-tls-configuration.kt
270
+ :language: kotlin
271
+
228
272
.. _tls-custom-sslContext:
229
273
230
274
Customize TLS/SSL Configuration through the Java SE SSLContext
0 commit comments