You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: translate modern tls options to ssl, update documentation
We now prefer the `tls` variants of SSL/TLS options. For now, we
detect these and translate them internally to the old option names.
Documentation has been updated to prefer these types, and mention
that the `sslVariants` are deprecated
NODE-2359
@@ -41,7 +41,7 @@ In the following example, the connection string specifies the user ``dave``\ , p
41
41
await client.close();
42
42
}
43
43
}
44
-
44
+
45
45
// Runs your code
46
46
run();
47
47
@@ -78,7 +78,7 @@ In the following example, the connection string specifies the user ``dave``\ , p
78
78
await client.close();
79
79
}
80
80
}
81
-
81
+
82
82
// Runs your code
83
83
run();
84
84
@@ -115,7 +115,7 @@ In the following example, the connection string specifies the user ``dave``\ , p
115
115
await client.close();
116
116
}
117
117
}
118
-
118
+
119
119
// Runs your code
120
120
run();
121
121
@@ -153,7 +153,7 @@ In the following example, the connection string specifies the user ``dave``\ , p
153
153
await client.close();
154
154
}
155
155
}
156
-
156
+
157
157
// Runs your code
158
158
run();
159
159
@@ -163,11 +163,11 @@ In the following example, the connection string specifies the user ``dave``\ , p
163
163
X509
164
164
----
165
165
166
-
With :manual:`X.509 </core/security-x.509>` mechanism, MongoDB uses the X.509 certificate presented during SSL negotiation to authenticate a user whose name is derived from the distinguished name of the X.509 certificate.
166
+
With :manual:`X.509 </core/security-x.509>` mechanism, MongoDB uses the X.509 certificate presented during TLS negotiation to authenticate a user whose name is derived from the distinguished name of the X.509 certificate.
167
167
168
-
X.509 authentication requires the use of SSL connections with certificate validation and is available in MongoDB 2.6 and newer.
168
+
X.509 authentication requires the use of TLS connections with certificate validation and is available in MongoDB 2.6 and newer.
169
169
170
-
To connect using the X.509 authentication mechanism, specify ``MONGODB-X509`` as the mechanism in the :manual:`URI ConnectionString </reference/connection-string/>` , ``ssl=true``\ , and the username. Use ``enodeURIComponent`` to encode the username string.
170
+
To connect using the X.509 authentication mechanism, specify ``MONGODB-X509`` as the mechanism in the :manual:`URI ConnectionString </reference/connection-string/>` , ``tls=true``\ , and the username. Use ``enodeURIComponent`` to encode the username string.
171
171
172
172
In addition to the connection string, pass to the new ``MongoClient`` a connections options for the ``server`` with the X.509 certificate and other :doc:`TLS/SSL connections </tutorials/connect/tls>` options.
173
173
@@ -176,19 +176,13 @@ In addition to the connection string, pass to the new ``MongoClient`` a connecti
In the following example, the connection string specifies two of the replica set members running on ``localhost:27017`` and ``localhost:27018`` and the name of the replica set (\ ``foo``\ ).
32
+
In the following example, the connection string specifies two of the replica set members running on ``localhost:27017`` and ``localhost:27018`` and the name of the replica set (\ ``foo``\ ).
Copy file name to clipboardExpand all lines: docs/guide/tutorials/connect/tls.txt
+48-88Lines changed: 48 additions & 88 deletions
Original file line number
Diff line number
Diff line change
@@ -7,14 +7,14 @@ The Node.js driver supports TLS/SSL connections to MongoDB that support TLS/SSL
7
7
No Certificate Validation
8
8
-------------------------
9
9
10
-
If the MongoDB instance does not perform any validation of the certificate chain, include the ``ssl=true`` in the :manual:`URI ConnectionString </reference/connection-string/>` .
10
+
If the MongoDB instance does not perform any validation of the certificate chain, include the ``tls=true`` in the :manual:`URI ConnectionString </reference/connection-string/>` .
11
11
12
12
.. code-block:: js
13
13
14
14
const { MongoClient } = require('mongodb');
15
15
16
16
// Connection URL
17
-
const url = 'mongodb://localhost:27017?ssl=true';
17
+
const url = 'mongodb://localhost:27017?tls=true';
18
18
19
19
// Create a new MongoClient
20
20
const client = new MongoClient(url);
@@ -39,54 +39,38 @@ Validate Server Certificate
39
39
40
40
If the MongoDB instance presents a certificate, to validate the server's certificate, pass the following when creating a ``MongoClient``\ :
41
41
42
-
* A :manual:`URI ConnectionString </reference/connection-string/>` that includes ``ssl=true`` setting,
42
+
* A :manual:`URI ConnectionString </reference/connection-string/>` that includes ``tls=true`` setting,
43
43
44
-
* A connections options with the certificate for the Certificate Authority (\ ``sslCA``\ ) and the ``sslValidate`` setting set to ``true``
44
+
* A connections options with the certificate for the Certificate Authority (\ ``tlsCAFile``\ )
const client = new MongoClient('mongodb://localhost:27017?tls=true', {
51
+
tlsCAFile: `${__dirname}/certs/ca.pem`)
60
52
});
61
53
62
54
Disable Hostname Verification
63
55
-----------------------------
64
56
65
57
By default, the driver ensures that the hostname included in the
66
-
server's SSL certificate(s) matches the hostname(s) provided in the URI connection string. If you need to disable the hostname verification, but otherwise validate the server's certificate, pass to the new ``MongoClient``\ :
58
+
server's TLS certificate(s) matches the hostname(s) provided in the URI connection string. If you need to disable the hostname verification, but otherwise validate the server's certificate, pass to the new ``MongoClient``\ :
67
59
68
60
69
-
*
70
-
A :manual:`URI ConnectionString </reference/connection-string/>` that includes ``ssl=true`` setting,
61
+
*
62
+
A :manual:`URI ConnectionString </reference/connection-string/>` that includes ``tls=true`` setting,
71
63
72
-
*
73
-
A connections options with the certificate for the Certificate Authority (\ ``sslCA``\ ) and the ``sslValidate`` setting set to ``true`` but ``checkServerIdentity`` set to ``false``.
64
+
*
65
+
A connections options with the certificate for the Certificate Authority (\ ``tlsCAFile``\ ) but ``tlsAllowInvalidHostnames`` set to ``true``.
const client = new MongoClient('mongodb://localhost:27017?tls=true', {
72
+
tlsCAFile: `${__dirname}/certs/ca.pem`),
73
+
tlsAllowInvalidHostnames: true
90
74
});
91
75
92
76
Validate Server Certificate and Present Valid Certificate
@@ -96,61 +80,41 @@ If the MongoDB server performs certificate validation, the client must pass its
96
80
certificate to the server. To pass the client's certificate as well as to validate the server's certificate, pass to the new ``MongoClient``\ :
97
81
98
82
99
-
*
100
-
A :manual:`URI ConnectionString </reference/connection-string/>` that includes ``ssl=true`` setting,
83
+
*
84
+
A :manual:`URI ConnectionString </reference/connection-string/>` that includes ``tls=true`` setting,
101
85
102
-
*
103
-
A connections options with the ``sslValidate`` setting set to ``true``\ , the certificate for the Certificate Authority (\ ``sslCA``\ ), the client's certificate (\ ``sslCert``\ ) and private key file (\ ``sslKey``\ ). If the client's key file is encrypted, include the password (\ ``sslPass``\ ).
86
+
*
87
+
A connections options with the certificate for the Certificate Authority (\ ``tlsCAFile``\ ), the client's certificate (\ ``tlsCertificateKeyFile``\ ). If the client's key file is encrypted, include the password (\ ``tlsCertificateKeyFilePassword``\ ).
:manual:`X.509 </core/security-x.509>` authentication requires the use of TLS/SSL connections with certificate validation. MongoDB uses the X.509 certificate presented during SSL negotiation to authenticate a user whose name is derived from the distinguished name of the X.509 certificate.
103
+
:manual:`X.509 </core/security-x.509>` authentication requires the use of TLS/SSL connections with certificate validation. MongoDB uses the X.509 certificate presented during TLS negotiation to authenticate a user whose name is derived from the distinguished name of the X.509 certificate.
130
104
131
-
To connect using the X.509 authentication mechanism, specify ``MONGODB-X509`` as the mechanism in the :manual:`URI ConnectionString </reference/connection-string/>` , ``ssl=true``\ , and the username. Use ``enodeURIComponent`` to encode the username string.
105
+
To connect using the X.509 authentication mechanism, specify ``MONGODB-X509`` as the mechanism in the :manual:`URI ConnectionString </reference/connection-string/>` , ``tls=true``\ , and the username. Use ``enodeURIComponent`` to encode the username string.
132
106
133
107
In addition to the connection string, pass to the new ``MongoClient``
134
108
a connections options with the X.509 certificate and other :doc:`TLS/SSL connections </tutorials/connect/tls>` options.
135
109
136
110
.. code-block:: js
137
111
138
112
const { MongoClient } = require('mongodb');
139
-
const fs = require('fs');
140
113
141
-
// User name
142
114
const userName = 'CN=client,OU=kerneluser,O=10Gen,L=New York City,ST=New York,C=US';
@@ -165,35 +129,31 @@ The following TLS/SSL options are available.
165
129
- Type
166
130
- Default
167
131
- Description
168
-
* - ``ssl``
132
+
* - ``tls``
169
133
- boolean
170
134
- ``false``
171
-
- Use tls/ssl connection. See :manual:`tls </reference/connection-string/#urioption.tls>`
172
-
* - ``sslValidate``
135
+
- Use TLS connections.
136
+
* - ``tlsInsecure``
173
137
- boolean
174
138
- ``false``
175
-
- Validate mongod server certificate against ca. Is equivalent to :manual:`tlsInsecure </reference/connection-string/#urioption.tlsInsecure>`
176
-
* - ``sslCA``
177
-
- Buffer[]|string[]
178
-
-
179
-
- Array of valid certificates for Certificate Authority either as Buffers or Strings.
180
-
* - ``sslCRL``
181
-
- Buffer[]|string[]
182
-
-
183
-
- Certificate Revocation Lists. See `tls.createSecureContext <https://nodejs.org/dist/latest-v10.x/docs/api/tls.html#tls_tls_createsecurecontext_options>`_
184
-
* - ``sslCert``
185
-
- Buffer|string
186
-
-
187
-
- String or buffer containing the client certificate.
188
-
* - ``sslKey``
189
-
- Buffer|string
190
-
-
191
-
- String or buffer containing the certificate private key we wish to present
192
-
* - ``sslPass``
139
+
- Relax TLS constraints as much as possible (e.g. allowing invalid certificates or hostname mismatches); drivers must document the exact constraints which are relaxed by this option being true
140
+
* - ``tlsCAFile``
141
+
- string[]
142
+
-
143
+
- Path to file with either a single or bundle of certificate authorities to be considered trusted when making a TLS connection
144
+
* - ``tlsCertificateKeyFile``
145
+
- string
146
+
-
147
+
- Path to the client certificate file or the client private key file; in the case that they both are needed, the files should be concatenated
148
+
* - ``tlsCertificateKeyFilePassword``
193
149
- Buffer|string
194
-
-
150
+
-
195
151
- String or buffer containing the client certificate password.
196
-
* - ``checkServerIdentity``
197
-
- function/boolean
198
-
- true
199
-
- If a function, overrides built-in `tls.checkServerIdentity <https://nodejs.org/dist/latest-v10.x/docs/api/tls.html#tls_tls_checkserveridentity_hostname_cert>`_. See `tls.connect <https://nodejs.org/dist/latest-v10.x/docs/api/tls.html#tls_tls_connect_options_callback>`_. If ``false``, automatically verifies all certificates and servernames.
152
+
* - ``tlsAllowInvalidCertificates``
153
+
- boolean
154
+
- false
155
+
- Specifies whether or not the driver should error when the server’s TLS certificate is invalid
156
+
* - ``tlsAllowInvalidHostnames``
157
+
- boolean
158
+
- false
159
+
- Specifies whether or not the driver should error when there is a mismatch between the server’s hostname and the hostname specified by the TLS certificate
0 commit comments