Skip to content

Commit 9099f8f

Browse files
committed
clean up TLS docs
- rename SSL to TLS where appropriate - consolidate TLS documentation into one guide, linked to from "Advanced Connections", mongoc_ssl_opt_t, and URI options - fix incorrectly documented tlscertificateauthorityfile URI option
1 parent 542a330 commit 9099f8f

17 files changed

+175
-137
lines changed

src/libmongoc/doc/advanced-connections.rst

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ Include username and password like so:
109109
110110
mongoc_uri_t *uri = mongoc_uri_new ("mongodb://user:pass@%2Ftmp%2Fmongodb-27017.sock");
111111
112-
Connecting to a server over SSL
112+
113+
Connecting to a server over TLS
113114
-------------------------------
114115

115116
These are instructions for configuring TLS/SSL connections.
@@ -118,33 +119,28 @@ To run a server locally (on port 27017, for example):
118119

119120
.. code-block:: none
120121
121-
$ mongod --port 27017 --sslMode requireSSL --sslPEMKeyFile server.pem --sslCAFile ca.pem
122+
$ mongod --port 27017 --tlsMode requireTLS --tlsCertificateKeyFile server.pem --tlsCAFile ca.pem
122123
123-
Add ``/?ssl=true`` to the end of a client URI.
124+
Add ``/?tls=true`` to the end of a client URI.
124125

125126
.. code-block:: none
126127
127128
mongoc_client_t *client = NULL;
128-
client = mongoc_client_new ("mongodb://localhost:27017/?ssl=true");
129+
client = mongoc_client_new ("mongodb://localhost:27017/?tls=true");
129130
130-
MongoDB requires client certificates by default, unless the ``--sslAllowConnectionsWithoutCertificates`` is provided. The C Driver can be configured to present a client certificate using a ``mongoc_ssl_opt_t``:
131+
MongoDB requires client certificates by default, unless the ``--tlsAllowConnectionsWithoutCertificates`` is provided. The C Driver can be configured to present a client certificate using the URI option ``tlsCertificateKeyFile``, which may be referenced through the constant ``MONGOC_URI_TLSCERTIFICATEKEYFILE``.
131132

132133
.. code-block:: none
133134
134-
const mongoc_ssl_opt_t *ssl_default = mongoc_ssl_opt_get_default ();
135-
mongoc_ssl_opt_t ssl_opts = { 0 };
136-
137-
/* optionally copy in a custom trust directory or file; otherwise the default is used. */
138-
memcpy (&ssl_opts, ssl_default, sizeof ssl_opts);
139-
ssl_opts.pem_file = "client.pem"
140-
141-
mongoc_client_set_ssl_opts (client, &ssl_opts);
135+
mongoc_client_t *client = NULL;
136+
mongoc_uri_t *uri = mongoc_uri_new ("mongodb://localhost:27017/?tls=true");
137+
mongoc_uri_set_option_as_utf8 (uri, MONGOC_URI_TLSCERTIFICATEKEYFILE, "client.pem");
142138
143-
The client certificate provided by ``pem_file`` must be issued by one of the server trusted Certificate Authorities listed in ``--sslCAFile``, or issued by a CA in the native certificate store on the server when omitted.
139+
client = mongoc_client_new_from_uri (uri);
144140
145-
To verify the server certificate against a specific CA, provide a PEM armored file with a CA certificate, or concatenated list of CA certificates using the ``ca_file`` option, or ``c_rehash`` directory structure of CAs, pointed to using the ``ca_dir`` option. When no ``ca_file`` or ``ca_dir`` is provided, the driver will use CAs provided by the native platform certificate store.
141+
The client certificate provided by ``tlsCertificateKeyFile`` must be issued by one of the server trusted Certificate Authorities listed in ``--tlsCAFile``, or issued by a CA in the native certificate store on the server when omitted.
146142

147-
See :doc:`mongoc_ssl_opt_t` for more information on the various SSL related options.
143+
See :doc:`configuring_tls` for more information on the various TLS related options.
148144

149145
Compressing data to and from MongoDB
150146
------------------------------------

src/libmongoc/doc/authentication.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ MongoDB Enterprise Edition supports the ``SASL PLAIN`` authentication mechanism,
155155

156156
.. note::
157157

158-
``SASL PLAIN`` is a clear-text authentication mechanism. It is strongly recommended to connect to MongoDB using SSL with certificate validation when using the ``PLAIN`` mechanism.
158+
``SASL PLAIN`` is a clear-text authentication mechanism. It is strongly recommended to connect to MongoDB using TLS with certificate validation when using the ``PLAIN`` mechanism.
159159

160160
.. code-block:: none
161161
@@ -172,13 +172,13 @@ X.509 Certificate Authentication
172172

173173
.. note::
174174

175-
The MongoDB C Driver must be compiled with SSL support for X.509 authentication support. Once this is done, start a server with the following options:
175+
The MongoDB C Driver must be compiled with TLS support for X.509 authentication support. Once this is done, start a server with the following options:
176176

177177
.. code-block:: none
178178
179-
$ mongod --sslMode requireSSL --sslPEMKeyFile server.pem --sslCAFile ca.pem
179+
$ mongod --tlsMode requireTLS --tlsCertificateKeyFile server.pem --tlsCAFile ca.pem
180180
181-
The ``MONGODB-X509`` mechanism authenticates a username derived from the distinguished subject name of the X.509 certificate presented by the driver during SSL negotiation. This authentication method requires the use of SSL connections with certificate validation.
181+
The ``MONGODB-X509`` mechanism authenticates a username derived from the distinguished subject name of the X.509 certificate presented by the driver during TLS negotiation. This authentication method requires the use of TLS connections with certificate validation.
182182

183183
.. code-block:: none
184184

src/libmongoc/doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
'**': ['globaltoc.html', 'customindexlink.html', 'searchbox.html'],
5050
'errors': [], # Make more room for the big table.
5151
'mongoc_uri_t': [], # Make more room for the big table.
52+
'configuring_tls': [], # Make more room for the big table.
5253
}
5354

5455

src/libmongoc/doc/configuring_tls.rst

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
:man_page: configuring_tls
2+
3+
Configuring TLS
4+
===============
5+
6+
Building libmongoc with TLS support
7+
-----------------------------------
8+
9+
By default, libmongoc will attempt to find a supported TLS library and enable TLS support. This is controlled by the cmake flag ``ENABLE_SSL``, which is set to ``AUTO`` by default. Valid values are:
10+
11+
- ``AUTO`` the default behavior. Link to the system's native TLS library, or attempt to find OpenSSL.
12+
- ``DARWIN`` link to Secure Transport, the native TLS library on macOS.
13+
- ``WINDOWS`` link to Secure Channel, the native TLS on Windows.
14+
- ``OPENSSL`` link to OpenSSL (libssl). An optional install path may be specified with ``OPENSSL_ROOT``.
15+
- ``LIBRESSL`` link to LibreSSL's libtls. (LibreSSL's compatible libssl may be linked to by setting ``OPENSSL``).
16+
- ``OFF`` disable TLS support.
17+
18+
Configuration with URI options
19+
------------------------------
20+
21+
Enable TLS by including ``tls=true`` the URI.
22+
23+
.. code:: c
24+
25+
mongoc_uri_t *uri = mongoc_uri_new ("mongodb://localhost:27017/");
26+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_TLS, true);
27+
28+
mongoc_client_t *client = mongoc_client_new_from_uri (uri);
29+
30+
31+
The following URI options may be used to further configure TLS:
32+
33+
.. include:: includes/tls-options.txt
34+
35+
Configuration with mongoc_ssl_opt_t
36+
-----------------------------------
37+
38+
Alternatively, the :symbol:`mongoc_ssl_opt_t` struct may be used to configure TLS with :symbol:`mongoc_client_set_ssl_opts()` or :symbol:`mongoc_client_pool_set_ssl_opts()`. Most of the configurable options can be using the Connection URI.
39+
40+
=============================== ===============================
41+
**mongoc_ssl_opt_t key** **URI key**
42+
=============================== ===============================
43+
pem_file tlsClientCertificateKeyFile
44+
pem_pwd tlsClientCertificateKeyPassword
45+
ca_file tlsCAFile
46+
weak_cert_validation tlsAllowInvalidCertificates
47+
allow_invalid_hostname tlsAllowInvalidHostnames
48+
=============================== ===============================
49+
50+
The only exclusions are ``crl_file`` and ``ca_dir``. Those may only be set with :symbol:`mongoc_ssl_opt_t`.
51+
52+
Client Authentication
53+
---------------------
54+
55+
When MongoDB is started with TLS enabled, it will by default require the client to provide a client certificate issued by a certificate authority specified by ``--tlsCAFile``, or an authority trusted by the native certificate store in use on the server.
56+
57+
To provide the client certificate, set the ``tlscertificatekeyfile`` in the URI to a PEM armored certificate file.
58+
59+
.. code-block:: c
60+
61+
mongoc_uri_t *uri = mongoc_uri_new ("mongodb://localhost:27017/");
62+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_TLS, true);
63+
mongoc_uri_set_option_as_utf8 (uri, MONGOC_URI_TLSCERTIFICATEKEYFILE, "/path/to/client-certificate.pem");
64+
65+
mongoc_client_t *client = mongoc_client_new_from_uri (uri);
66+
67+
Server Certificate Verification
68+
-------------------------------
69+
70+
The MongoDB C Driver will automatically verify the validity of the server certificate, such as issued by configured Certificate Authority, hostname validation, and expiration.
71+
72+
To overwrite this behaviour, it is possible to disable hostname validation, and/or allow otherwise invalid certificates. This behaviour is controlled using the ``tlsallowinvalidhostnames`` and ``tlsallowinvalidcertificates`` options. By default, both are set to ``false``. It is not recommended to change these defaults as it exposes the client to *Man In The Middle* attacks (when ``tlsallowinvalidhostnames`` is set) and otherwise invalid certificates when ``tlsallowinvalidcertificates`` is set to ``true``.
73+
74+
OpenSSL
75+
-------
76+
77+
The MongoDB C Driver uses OpenSSL, if available, on Linux and Unix platforms (besides macOS). Industry best practices and some regulations require the use of TLS 1.1 or newer, which requires at least OpenSSL 1.0.1. Check your OpenSSL version like so::
78+
79+
$ openssl version
80+
81+
Ensure your system's OpenSSL is a recent version (at least 1.0.1), or install a recent version in a non-system path and build against it with::
82+
83+
cmake -DOPENSSL_ROOT_DIR=/absolute/path/to/openssl
84+
85+
When compiled against OpenSSL, the driver will attempt to load the system default certificate store, as configured by the distribution. That can be overridden by setting the ``tlscafile`` URI option or with the fields ``ca_file`` and ``ca_dir`` in the :symbol:`mongoc_ssl_opt_t`.
86+
87+
LibreSSL / libtls
88+
-----------------
89+
90+
The MongoDB C Driver supports LibreSSL through the use of OpenSSL compatibility checks when configured to compile against ``openssl``. It also supports the new ``libtls`` library when configured to build against ``libressl``.
91+
92+
Native TLS Support on Windows (Secure Channel)
93+
----------------------------------------------
94+
95+
The MongoDB C Driver supports the Windows native TLS library (Secure Channel, or SChannel), and its native crypto library (Cryptography API: Next Generation, or CNG).
96+
97+
When compiled against the Windows native libraries, the ``ca_dir`` option of a :symbol:`mongoc_ssl_opt_t` is not supported, and will issue an error if used.
98+
99+
Encrypted PEM files (e.g., setting ``tlscertificatekeypassword``) are also not supported, and will result in error when attempting to load them.
100+
101+
When ``tlscafile`` is set, the driver will only allow server certificates issued by the authority (or authorities) provided. When no ``tlscafile`` is set, the driver will look up the Certificate Authority using the ``System Local Machine Root`` certificate store to confirm the provided certificate or the ``Current user certificate store`` if the ``System Local Machine Root`` certificate store is unavailable.
102+
103+
When ``crl_file`` is set with :symbol:`mongoc_ssl_opt_t`, the driver will import the revocation list to the ``System Local Machine Root`` certificate store.
104+
105+
.. _Secure Transport:
106+
107+
Native TLS Support on macOS / Darwin (Secure Transport)
108+
-------------------------------------------------------
109+
110+
The MongoDB C Driver supports the Darwin (OS X, macOS, iOS, etc.) native TLS library (Secure Transport), and its native crypto library (Common Crypto, or CC).
111+
112+
When compiled against Secure Transport, the ``ca_dir`` option of a :symbol:`mongoc_ssl_opt_t` is not supported, and will issue an error if used.
113+
114+
When ``tlscafile`` is set, the driver will only allow server certificates issued by the authority (or authorities) provided. When no ``tlscafile`` is set, the driver will use the Certificate Authorities in the currently unlocked keychains.

src/libmongoc/doc/errors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ See also: :doc:`Handling Errors in libbson <bson:errors>`.
1919
+-----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2020
| | ``MONGOC_ERROR_CLIENT_AUTHENTICATE`` | Wrong credentials, or failure sending or receiving authentication messages. |
2121
+-----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
22-
| | ``MONGOC_ERROR_CLIENT_NO_ACCEPTABLE_PEER`` | You tried an SSL connection but the driver was not built with SSL. |
22+
| | ``MONGOC_ERROR_CLIENT_NO_ACCEPTABLE_PEER`` | You tried an TLS connection but the driver was not built with TLS. |
2323
+-----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2424
| | ``MONGOC_ERROR_CLIENT_IN_EXHAUST`` | You began iterating an exhaust cursor, then tried to begin another operation with the same :symbol:`mongoc_client_t`. |
2525
+-----------------------------------------+---------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

src/libmongoc/doc/guides.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Guides
77
:titlesonly:
88
:maxdepth: 1
99

10+
configuring_tls
1011
mongoc-common-task-examples
1112
advanced-connections
1213
connection-pooling
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.. list-table::
2+
:header-rows: 1
3+
4+
* - Constant
5+
- Key
6+
- Description
7+
* - MONGOC_URI_TLS
8+
- tls
9+
- {true|false}, indicating if TLS must be used.
10+
* - MONGOC_URI_TLSCERTIFICATEKEYFILE
11+
- tlscertificatekeyfile
12+
- Path to PEM formatted Private Key, with its Public Certificate concatenated at the end.
13+
* - MONGOC_URI_TLSCERTIFICATEKEYPASSWORD
14+
- tlscertificatekeypassword
15+
- The password, if any, to use to unlock encrypted Private Key.
16+
* - MONGOC_URI_TLSCAFILE
17+
- tlscafile
18+
- One, or a bundle of, Certificate Authorities whom should be considered to be trusted.
19+
* - MONGOC_URI_TLSALLOWINVALIDCERTIFICATES
20+
- tlsallowinvalidcertificates
21+
- Accept and ignore certificate verification errors (e.g. untrusted issuer, expired, etc.)
22+
* - MONGOC_URI_TLSALLOWINVALIDHOSTNAMES
23+
- tlsallowinvalidhostnames
24+
- Ignore hostname verification of the certificate (e.g. Man In The Middle, using valid certificate, but issued for another hostname)
25+
* - MONGOC_URI_TLSINSECURE
26+
- tlsinsecure
27+
- {true|false}, indicating if insecure TLS options should be used. Currently this implies MONGOC_URI_TLSALLOWINVALIDCERTIFICATES and MONGOC_URI_TLSALLOWINVALIDHOSTNAMES.

src/libmongoc/doc/installing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Building on Unix
7878
Prerequisites for libmongoc
7979
^^^^^^^^^^^^^^^^^^^^^^^^^^^
8080

81-
OpenSSL is required for authentication or for SSL connections to MongoDB. Kerberos or LDAP support requires Cyrus SASL.
81+
OpenSSL is required for authentication or for TLS connections to MongoDB. Kerberos or LDAP support requires Cyrus SASL.
8282

8383
To install all optional dependencies on RedHat / Fedora:
8484

src/libmongoc/doc/mongoc_client_pool_set_ssl_opts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ it points to (``pem_file``, ``pem_pwd``, ``ca_file``, ``ca_dir``, and
2424
``crl_file``) so they don't have to remain valid after the call to
2525
``mongoc_client_pool_set_ssl_opts``.
2626

27-
A call to ``mongoc_client_pool_set_ssl_opts`` overrides all SSL options set
27+
A call to ``mongoc_client_pool_set_ssl_opts`` overrides all TLS options set
2828
through the connection string with which the ``mongoc_client_pool_t`` was
2929
constructed.
3030

src/libmongoc/doc/mongoc_client_set_ssl_opts.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Synopsis
1414
const mongoc_ssl_opt_t *opts);
1515
#endif
1616
17-
Sets the SSL options to use when connecting to SSL enabled MongoDB servers.
17+
Sets the TLS (SSL) options to use when connecting to TLS enabled MongoDB servers.
1818

1919
The ``mongoc_ssl_opt_t`` struct is copied by the client along with the strings
2020
it points to (``pem_file``, ``pem_pwd``, ``ca_file``, ``ca_dir``, and
2121
``crl_file``) so they don't have to remain valid after the call to
2222
``mongoc_client_set_ssl_opts``.
2323

24-
A call to ``mongoc_client_set_ssl_opts`` overrides all SSL options set through
24+
A call to ``mongoc_client_set_ssl_opts`` overrides all TLS options set through
2525
the connection string with which the ``mongoc_client_t`` was constructed.
2626

2727
It is a programming error to call this function on a client from a

0 commit comments

Comments
 (0)