Skip to content

Commit fd61149

Browse files
committed
Address RR feedback
1 parent cb4999f commit fd61149

File tree

2 files changed

+95
-100
lines changed

2 files changed

+95
-100
lines changed

source/connect.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ Transport Layer Security (TLS)
102102
------------------------------
103103

104104
The following sections describe how to connect to MongoDB
105-
while enabling the TLS protocol.
105+
while enabling the TLS protocol. To learn more about using TLS with the {+driver-short+},
106+
see :ref:`kotlin-sync-tls`.
106107

107108
Enable TLS
108109
~~~~~~~~~~
@@ -111,7 +112,7 @@ The following tabs demonstrate how to enable TLS on a connection:
111112

112113
.. include:: /includes/connect/tls-tabs.rst
113114

114-
To learn more about enabling TLS, see :ref:`tls-enable` in
115+
To learn more about enabling TLS, see :ref:`kotlin-sync-tls-enable` in
115116
the TLS configuration guide.
116117

117118
Disable Hostname Verification

source/connect/tls.txt

Lines changed: 92 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.. _kotlin-sync-enable-tls:
1+
.. _kotlin-sync-tls:
22

3-
==============================
4-
Enable TLS/SSL on a Connection
5-
==============================
3+
==========================
4+
Enable TLS on a Connection
5+
==========================
66

77
.. facet::
88
:name: genre
@@ -20,52 +20,48 @@ Enable TLS/SSL on a Connection
2020
Overview
2121
--------
2222

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+}/com/mongodb/ConnectionString.html>`__
28-
or `MongoClientSettings <{+core-api+}/com/mongodb/MongoClientSettings.html>`__.
23+
In this guide, you can learn how to use the
24+
:wikipedia:`TLS <w/index.php?title=Transport_Layer_Security&oldid=1239598620>`
25+
security protocol when connecting to MongoDB by using the {+driver-short+}.
2926

30-
.. note:: Debugging TLS/SSL
27+
.. note:: Debugging TLS
3128

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
29+
If you experience trouble setting up your TLS connection, you can
30+
use the ``-Djavax.net.debug=all`` system property to view helpful
31+
log statements. See `Debugging SSL/TLS connections
3532
<https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/ReadDebug.html>`__
36-
for more information.
33+
in the Java language documentation for more information.
3734

38-
.. _tls-enable:
35+
.. _kotlin-sync-tls-enable:
3936

40-
Enable TLS/SSL
41-
--------------
37+
Enable TLS
38+
----------
4239

43-
You can enable TLS/SSL for the connection to your MongoDB instance
44-
in two different ways: through a parameter in your connection string, or
45-
using a method in the ``MongoClientSettings.Builder`` class.
40+
You can enable TLS on a connection to your MongoDB instance
41+
in the following ways:
42+
43+
- Setting the ``tls`` parameter in your connection string
44+
- Using the ``enabled()`` method from the ``SslSettings.Builder`` class when creating a
45+
``MongoClientSettings`` instance
4646

4747
.. note:: DNS Seedlist Protocol Enables TLS
4848

4949
If you connect by using the DNS seedlist protocol, indicated by the
5050
``mongodb+srv`` prefix in your connection string, the driver
51-
automatically enables TLS/SSL. To disable it, set the ``tls``
52-
parameter value to ``false`` in your connection string, or set the
53-
``enabled`` property to ``false`` in the ``SslSettings.Builder``
54-
block when creating a ``MongoClientSettings`` instance.
51+
automatically enables TLS.
5552

5653
To learn more about connection behavior when you use a DNS seedlist,
57-
see the :manual:`SRV Connection Format </reference/connection-string/#std-label-connections-dns-seedlist>`
58-
section in the Server manual.
54+
see the :manual:`SRV Connection Format </reference/connection-string/#srv-connection-format>`
55+
section of the Connection Strings guide in the Server manual.
5956

6057
.. tabs::
6158

62-
.. tab:: ConnectionString
59+
.. tab:: Connection String
6360
:tabid: connectionstring
6461

65-
To enable TLS/SSL on a connection with a `ConnectionString
66-
<{+api+}/apidocs/mongodb-driver-core/com/mongodb/ConnectionString.html>`__, assign the connection string
67-
parameter ``tls`` a value of ``true`` in the connection string passed to
68-
``MongoClient.create()``:
62+
To enable TLS on a connection by using a connection string, set the connection string
63+
parameter ``tls`` to ``true`` in the connection string passed to
64+
``MongoClient.create()``, as shown in the following code:
6965

7066
.. literalinclude:: /includes/connect/tls.kt
7167
:start-after: start-tls-connection-string
@@ -77,11 +73,9 @@ using a method in the ``MongoClientSettings.Builder`` class.
7773
.. tab:: MongoClientSettings
7874
:tabid: mongoclientsettings
7975

80-
To configure your ``MongoClient``'s TLS/SSL connection options using the
81-
``MongoClientSettings.Builder`` class, call the
82-
`applyToSslSettings() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/MongoClientSettings.Builder.html#applyToSslSettings(com.mongodb.Block)>`__
83-
method. Set the ``enabled`` property to ``true`` in the ``SslSettings.Builder``
84-
block to enable TLS/SSL:
76+
To enable TLS within a ``MongoClientSettings`` instance, use the
77+
``applyToSslSettings()`` builder method. Set the ``enabled`` property to ``true``
78+
in the ``SslSettings.Builder`` block, as shown in the following code:
8579

8680
.. literalinclude:: /includes/connect/tls.kt
8781
:start-after: start-tls-mongo-client-settings
@@ -95,55 +89,49 @@ using a method in the ``MongoClientSettings.Builder`` class.
9589
Configure Certificates
9690
----------------------
9791

98-
{+language+} applications that initiate TLS/SSL requests require access to
99-
cryptographic certificates that prove identity for the application
100-
itself and other applications with which the application
101-
interacts. You can configure access to these certificates in your application with
102-
the following mechanisms:
103-
104-
- The JVM trust store and JVM key store
105-
- A client-specific trust store and key store
106-
107-
.. note::
92+
{+language+} applications that initiate TLS requests require access to
93+
cryptographic certificates that prove the application's identity and verify
94+
other applications with which the {+language+} application interacts. You can configure
95+
access to these certificates in your application in the following ways:
10896

109-
The following sections are based on the documentation for Oracle JDK,
110-
so some parts may be inapplicable to your JDK or to the custom TLS/SSL
111-
implementation you use.
97+
- Using a JVM trust store and JVM key store
98+
- Using a client-specific trust store and key store
11299

113-
.. _tls-configure-jvm-truststore:
100+
.. _kotlin-sync-tls-configure-jvm-truststore:
114101

115102
Configure the JVM Trust Store
116103
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117104

118105
.. note::
119106

120107
By default, the JRE includes many commonly used public certificates
121-
from signing authorities like `Let's Encrypt
122-
<https://letsencrypt.org/>`__. As a result, you can connect to
123-
instances of :atlas:`MongoDB Atlas </?jmp=docs_driver_kotlin>` (or any other
108+
from signing authorities such as `Let's Encrypt
109+
<https://letsencrypt.org/>`__. As a result, you can connect to a
110+
:atlas:`MongoDB Atlas </>` instance, or any other
124111
server whose certificate is signed by an authority in the JRE's default
125-
certificate store) with TLS/SSL without configuring the trust store.
112+
certificate store, with TLS enabled without configuring the trust store.
126113

127114
The JVM trust store saves certificates that securely identify other
128-
applications with which your {+language+} application interacts. Using these
115+
applications with which your {+language+} application interacts. By using these
129116
certificates, your application can prove that the connection to another
130117
application is genuine and secure from tampering by third parties.
131118

132119
If your MongoDB instance uses a certificate that is signed by an
133120
authority that is not present in the JRE's default certificate store,
134-
your application must configure two system properties to initiate
135-
SSL/TLS requests. These properties ensure that your application can
136-
validate the TLS/SSL certificate presented by a connected MongoDB instance.
121+
your application must configure the following system properties to initiate
122+
TLS requests.
137123

138-
- ``javax.net.ssl.trustStore``: the path to a trust store containing the
139-
certificate of the signing authority
124+
- ``javax.net.ssl.trustStore``: Path to a trust store containing the client's TLS
125+
certificates
140126

141-
- ``javax.net.ssl.trustStorePassword``: the password to access the trust
127+
- ``javax.net.ssl.trustStorePassword``: Password to access the trust
142128
store defined in ``javax.net.ssl.trustStore``
143129

144-
You can create a trust store with the `keytool
145-
<https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html>`__
146-
command line tool provided as part of the JDK:
130+
These properties ensure that your application can
131+
validate the TLS certificate presented by a connected MongoDB instance.
132+
133+
You can create a trust store by using the `keytool <https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html>`__
134+
command line tool from the JDK as shown in the following terminal command:
147135

148136
.. code-block:: console
149137

@@ -160,53 +148,48 @@ Configure the JVM Key Store
160148
instance to validate client certificates.
161149

162150
The JVM key store saves certificates that securely identify your {+language+}
163-
application to other applications. Using these certificates, other
151+
application to other applications. By using these certificates, other
164152
applications can prove that the connection to your application is
165153
genuine and secure from tampering by third parties.
166154

167-
An application that initiates TLS/SSL requests needs to set two JVM system
168-
properties to ensure that the client presents a TLS/SSL certificate to
155+
An application that initiates TLS requests must set the following JVM system
156+
properties to ensure that the client presents a TLS certificate to
169157
the MongoDB server:
170158

171-
- ``javax.net.ssl.keyStore``: the path to a key store containing the client's
159+
- ``javax.net.ssl.keyStore``: Path to a key store containing the client's
172160
TLS/SSL certificates
173161

174-
- ``javax.net.ssl.keyStorePassword``: the password to access the key store
162+
- ``javax.net.ssl.keyStorePassword``: Password to access the key store
175163
defined in ``javax.net.ssl.keyStore``
176164

177-
You can create a key store with the `keytool
165+
You can create a key store by using the `keytool
178166
<https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html>`__
179167
or `openssl <https://www.openssl.org/docs/manmaster/man1/openssl.html>`__
180168
command line tool.
181169

182-
For more information on configuring a {+language+} application to use TLS/SSL,
183-
please see the `JSSE Reference Guide
184-
<https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html>`__.
170+
To learn more about configuring a {+language+} application to use TLS,
171+
see the `JSSE Reference Guide <https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html>`__
172+
in the Java language documentation.
185173

186174
.. _tls-disable-hostname-verification:
187175

188176
Configure a Client-Specific Trust Store and Key Store
189177
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190178

191-
You can configure a client-specific trust store and key store using the
179+
You can configure a client-specific trust store and key store by using the
192180
``init()`` method of the ``SSLContext`` class.
193181

194-
You can find an example showing how to configure a client with an ``SSLContext``
195-
instance in the
196-
:ref:`Customize TLS/SSL Configuration with an SSLContext section of this guide <tls-custom-sslContext>`.
197-
198-
For more information on the ``SSLContext`` class, see the API
199-
documentation for `SSL Context <https://docs.oracle.com/en/java/javase/16/docs/api/java.base/javax/net/ssl/SSLContext.html>`__.
182+
Find an example showing how to configure a client to use an ``SSLContext``
183+
instance in the :ref:`Customize TLS Configuration with an SSLContext section of this guide <kotlin-sync-tls-custom-sslContext>`.
200184

201185
Disable Hostname Verification
202186
-----------------------------
203187

204188
By default, the driver ensures that the hostname included in the server's
205-
TLS/SSL certificates matches the hostnames provided when constructing
189+
TLS certificates matches the hostnames provided when constructing
206190
a ``MongoClient``. To disable hostname verification for your
207-
application, you can explicitly disable this by setting the
208-
``invalidHostNameAllowed`` property of the builder to ``true`` in the
209-
``applytoSslSettings()`` builder lambda:
191+
application, set the ``invalidHostNameAllowed`` property of the builder to ``true`` in the
192+
``applytoSslSettings()`` builder block:
210193

211194
.. literalinclude:: /includes/connect/tls.kt
212195
:start-after: start-disable-hostname-verification
@@ -217,12 +200,11 @@ application, you can explicitly disable this by setting the
217200

218201
.. warning::
219202

220-
Disabling hostname verification can make your configuration
221-
`insecure <https://tlseminar.github.io/docs/mostdangerous.pdf>`__.
222-
Disable hostname verification only for testing purposes or
223-
when there is no other alternative.
203+
Disabling hostname verification makes your application insecure and potentially
204+
vulnerable to expired certificates and foreign processes posing as valid client
205+
instances.
224206

225-
.. _tls-restrict-tls-1.2:
207+
.. _kotlin-sync-tls-restrict-tls-1.2:
226208

227209
Restrict Connections to TLS 1.2 Only
228210
------------------------------------
@@ -237,16 +219,16 @@ To restrict your application to use only the TLS 1.2 protocol, set the
237219
the TLS 1.2 protocol, upgrade to a later release to connect by using
238220
TLS 1.2.
239221

240-
.. _tls-custom-sslContext:
222+
.. _kotlin-sync-tls-custom-sslContext:
241223

242-
Customize TLS/SSL Configuration through the Java SE SSLContext
243-
--------------------------------------------------------------
224+
Customize TLS Configuration through the Java SE SSLContext
225+
----------------------------------------------------------
244226

245-
If your TLS/SSL configuration requires customization, you can
227+
If your TLS configuration requires customization, you can
246228
set the ``sslContext`` property of your ``MongoClient`` by
247229
passing an `SSLContext
248230
<https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html>`__
249-
object to the builder in the ``applyToSslSettings()`` lambda:
231+
object to the ``context()`` method builder in the ``applyToSslSettings()`` block:
250232

251233
.. literalinclude:: /includes/connect/tls.kt
252234
:start-after: start-ssl-context
@@ -255,6 +237,9 @@ object to the builder in the ``applyToSslSettings()`` lambda:
255237
:copyable:
256238
:dedent:
257239

240+
For more information on the ``SSLContext`` class, see the API
241+
documentation for `SSL Context <https://docs.oracle.com/en/java/javase/16/docs/api/java.base/javax/net/ssl/SSLContext.html>`__.
242+
258243
Online Certificate Status Protocol (OCSP)
259244
-----------------------------------------
260245

@@ -263,12 +248,12 @@ revoked. A certificate authority can add an X.509 certificate to the
263248
Certificate Revocation List (CRL) before the expiry time to invalidate
264249
the certificate. When a client sends an X.509 certificate during the TLS
265250
handshake, the CA's revocation server checks the CRL and returns a status
266-
of "good", "revoked", or "unknown".
251+
of ``good``, ``revoked``, or ``unknown``.
267252

268253
The driver supports the following variations of OCSP:
269254

270-
- **Client-Driven OCSP**
271-
- **OCSP Stapling**
255+
- Client-Driven OCSP
256+
- OCSP Stapling
272257

273258
The following sections describe the differences between them and how to enable
274259
them for your application.
@@ -338,3 +323,12 @@ For more information about OCSP, check out the following resources:
338323

339324
- Oracle JDK 8 Documentation on `how to enable OCSP for an application <https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/ocsp.html>`__
340325
- :rfc:`Official IETF specification for OCSP (RFC 6960) <6960>`
326+
327+
API Documentation
328+
-----------------
329+
330+
For more information about any of the methods or types discussed in this guide,
331+
see the following API documentation:
332+
333+
- `ConnectionString <{+core-api+}/com/mongodb/ConnectionString.html>`__
334+
- `MongoClientSettings <{+core-api+}/com/mongodb/MongoClientSettings.html>`__

0 commit comments

Comments
 (0)