Skip to content

Commit 732f18b

Browse files
bjoriajdavis
authored andcommitted
Improve TLS documentations
1 parent 41b0afe commit 732f18b

5 files changed

+116
-18
lines changed

doc/mongoc_advanced_connections.page

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,28 @@ main (int argc,
9898

9999
<section id="SSL">
100100
<info><link type="guide" xref="index#advanced-connections" /></info>
101-
<title>Connecting to a server that requires SSL</title>
102-
<p>These are instructions for configuring TLS/SSL connections.</p>
101+
<title>Connecting to a server over SSL</title>
102+
<p>These are instructions for configuring TLS/SSL connections.</p>
103103
<listing>
104104
<title>Basic Configuration</title>
105105
<p>To run a server locally (on port 27017, for example):</p>
106106
<screen><code>$ mongod --port 27017 --sslMode requireSSL --sslPEMKeyFile server.pem --sslCAFile ca.pem </code></screen>
107107
<p>Add <code>/?ssl=true</code> to the end of a client URI.</p>
108108
<screen><code>mongoc_client_t *client = NULL;
109109
client = mongoc_client_new ("mongodb://localhost:27017/?ssl=true");</code></screen></listing>
110-
<listing><title>Specifying Client Certificates and CA Files</title>
111-
<p>The C Driver can be configured to present a client certificate using a <code>mongoc_ssl_opt_t</code>:</p>
110+
<listing><title>Specifying Client Certificate</title>
111+
<p>MongoDB requires client certificates by default, unless the <code>--sslAllowConnectionsWithoutCertificates</code> is provided. The C Driver can be configured to present a client certificate using a <code>mongoc_ssl_opt_t</code>:</p>
112112
<screen><code>const mongoc_ssl_opt_t *ssl_default = mongoc_ssl_opt_get_default ();
113113
mongoc_ssl_opts_t ssl_opts = { 0 };
114-
mongoc_client_t client = mongoc_client_new ("mongodb://localhost:27017/?ssl=true");
115114

116115
/* optionally copy in a custom trust directory or file; otherwise the default is used. */
117116
memcpy (&amp;ssl_opts, ssl_default, sizeof ssl_opts);
118117
ssl_opts.pem_file = "client.pem"
119-
ssl_opts.ca_file = "ca.pem"
120-
ssl_weak.weak_cert_validation = false;
121118

122-
mongoc_client_set_ssl_opts (client, &amp;ssl_opts);</code></screen></listing>
119+
mongoc_client_set_ssl_opts (client, &amp;ssl_opts);</code></screen></listing>.
120+
<p>The client certificate provided by <code>pem_file</code> must be issued by one of the server trusted Certificate Authorities listed in <code>--sslCAFile</code>, or issued by a CA in the native certificate store on the server when omitted.</p>
121+
<p>To verify the server certificate against a specific CA, provide a PEM armored file with a CA certificate, or contatinated list of CA certificates using the <code>ca_file</code> option, or <code>c_rehash</code> directory structure of CAs, pointed to using the <code>ca_dir</code> option. When no <code>ca_file</code> or <code>ca_dir</code> is provided, the driver will use CAs provided by the native platform certificate store.</p>
122+
<p>See <link type="seealso" xref="mongoc_ssl_opt_t"><code>mongoc_ssl_opt_t</code></link> for more information on the various SSL related options.</p>
123123
</section>
124124

125125

doc/mongoc_client_pool_set_ssl_opts.page

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mongoc_client_pool_set_ssl_opts (mongoc_client_pool_t *pool,
1919
#endif]]></code></synopsis>
2020
<p>This function is identical to <code xref="mongoc_client_set_ssl_opts">mongoc_client_set_ssl_opts()</code> except for client pools. It ensures that all clients retrieved from <code xref="mongoc_client_pool_pop">mongoc_client_pool_pop()</code> or <code xref="mongoc_client_pool_try_pop">mongoc_client_pool_try_pop()</code> are configured with the same SSL settings.</p>
2121
<p>It is a programming error to call this function after retrieving a client from the client pool.</p>
22-
<p>Beginning in version 1.2.0, once a pool has any SSL options set, all connections use SSL, even if "ssl=true" is omitted from the MongoDB URI. Before, SSL options were ignored unless "ssl=true" was included in the URI.</p>
22+
<p>Beginning in version 1.2.0, once a pool has any SSL options set, all connections use SSL, even if <code>ssl=true</code> is omitted from the MongoDB URI. Before, SSL options were ignored unless <code>ssl=true</code> was included in the URI.</p>
2323
</section>
2424

2525
<section id="parameters">

doc/mongoc_client_set_ssl_opts.page

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ mongoc_client_set_ssl_opts (mongoc_client_t *client,
1717
const mongoc_ssl_opt_t *opts);
1818
#endif]]></code></synopsis>
1919
<p>Sets the SSL options to use when connecting to SSL enabled MongoDB servers.</p>
20-
<p>Beginning in version 1.2.0, once a client has any SSL options set, all connections use SSL, even if "ssl=true" is omitted from the MongoDB URI. Before, SSL options were ignored unless "ssl=true" was included in the URI.</p>
20+
<p>Beginning in version 1.2.0, once a client has any SSL options set, all connections use SSL, even if <code>ssl=true</code> is omitted from the MongoDB URI. Before, SSL options were ignored unless <code>ssl=true</code> was included in the URI.</p>
2121
<p>The <code>mongoc_ssl_opt_t</code> struct is copied by the client along with the strings it points to (<code>pem_file</code>, <code>pem_pwd</code>, <code>ca_file</code>, <code>ca_dir</code>, and <code>crl_file</code>) so they don't have to remain valid after the call to <code>mongoc_client_set_ssl_opts</code>.</p>
2222
<p>It is a programming error to call this function on a client from a <code xref="mongoc_client_pool_t">mongoc_client_pool_t</code>. Instead, call <code xref="mongoc_client_pool_set_ssl_opts">mongoc_client_pool_set_ssl_opts</code> on the pool before popping any clients.</p>
2323
</section>

doc/mongoc_installing.page.in

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
<title>Supported Platforms</title>
1313

14-
<p>The MongoDB C Driver is continuously tested on GNU/Linux, Windows 7, Mac OS X 10.10, and Solaris 11 (Intel and Sparc), with GCC, Clang, and Visual Studio 2010, 2013, and 2015.</p>
15-
<p>The driver supports the following operating systems and CPU architectures:</p>
14+
<p>The MongoDB C Driver is <link href="https://evergreen.mongodb.com/waterfall/mongo-c-driver">continuously tested</link> on variety of platforms including:</p>
1615

1716
<table>
1817
<tr>
@@ -24,10 +23,9 @@
2423
<td>
2524
<list>
2625
<item><p>GNU/Linux</p></item>
27-
<item><p>Solaris 11</p></item>
28-
<item><p>Mac OS X 10.6 and newer</p></item>
29-
<item><p>Windows Vista, 7, and 8</p></item>
30-
<item><p>FreeBSD</p></item>
26+
<item><p>Solaris</p></item>
27+
<item><p>Mac OS X</p></item>
28+
<item><p>Microsoft Windows</p></item>
3129
</list>
3230
</td>
3331
<td>
@@ -36,6 +34,9 @@
3634
<item><p>ARM</p></item>
3735
<item><p>PPC</p></item>
3836
<item><p>SPARC</p></item>
37+
<item><p>aarch64</p></item>
38+
<item><p>s390x</p></item>
39+
<item><p>ppc64le</p></item>
3940
</list>
4041
</td>
4142
<td>
@@ -50,6 +51,8 @@
5051
</tr>
5152
</table>
5253

54+
<p>The driver is also known to work on FreeBSD, and should work on any POSIX compatible platform with a working c89 (or later) compiler.</p>
55+
5356
</section>
5457

5558
<section id="package-manager">
@@ -158,6 +161,23 @@ $ export LDFLAGS="-L/usr/local/opt/openssl/lib"
158161
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"</screen>
159162
</section>
160163
</section>
164+
<section id="nativetls-macos">
165+
<title>Native TLS Support on Mac OS X / Darwin (Secure Transport)</title>
166+
<p>
167+
The MongoDB C Driver supports the Darwin native TLS and crypto libraries.
168+
Using the native libraries there is no need to install OpenSSL. By
169+
default however, the driver will compile against OpenSSL if it
170+
detects it being available. If OpenSSL is not available, it will
171+
fallback on the native libraries.
172+
</p>
173+
<p>
174+
To compile against the Darwin native TLS and crypto libraries, even when
175+
OpenSSL is available, configure the driver like so:
176+
</p>
177+
<screen>
178+
$ ./configure --enable-ssl=darwin
179+
</screen>
180+
</section>
161181
<section id="building-osx">
162182
<title>Building on OS X</title>
163183
<p>Download the latest release tarball:</p>
@@ -217,7 +237,24 @@ cmake -G "Visual Studio 14 2015 Win64" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver
217237
msbuild.exe ALL_BUILD.vcxproj
218238
msbuild.exe INSTALL.vcxproj</screen>
219239

240+
220241
<p>All of the MongoDB C Driver's components will now be found in <code>C:\mongo-c-driver</code>.</p>
242+
243+
<section id="nativetls-windows">
244+
<title>Native TLS Support on Windows (Secure Channel)</title>
245+
<p>
246+
The MongoDB C Driver supports the Windows native TLS and crypto libraries.
247+
Using the native libraries there is no need to install OpenSSL. By
248+
default however, the driver will compile against OpenSSL if it
249+
detects it being available. If OpenSSL is not available, it will
250+
fallback on the native libraries.
251+
</p>
252+
<p>
253+
To compile against the Windows native TLS and crypto libraries, even when
254+
OpenSSL is available, configure the driver like so:
255+
</p>
256+
<screen>cmake -G "Visual Studio 14 2015 Win64" "-DENABLE_SSL=WINDOWS" "-DCMAKE_INSTALL_PREFIX=C:\mongo-c-driver" "-DBSON_ROOT_DIR=C:\mongo-c-driver"</screen>
257+
</section>
221258
</section>
222259

223260
</page>

doc/mongoc_ssl_opt_t.page

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,76 @@
2020
const char *ca_dir;
2121
const char *crl_file;
2222
bool weak_cert_validation;
23-
void *padding [8];
23+
bool allow_invalid_hostname;
24+
void *padding [7];
2425
} mongoc_ssl_opt_t;
2526
]]></code>
2627
</section>
2728

2829
<section id="desc">
2930
<title>Description</title>
3031
<p>This structure is used to set the SSL options for a <code xref="mongoc_client_t">mongoc_client_t</code> or <code xref="mongoc_client_pool_t">mongoc_client_pool_t</code>.</p>
31-
<p>Beginning in version 1.2.0, once a pool or client has any SSL options set, all connections use SSL, even if "ssl=true" is omitted from the MongoDB URI. Before, SSL options were ignored unless "ssl=true" was included in the URI.</p>
32+
<p>Beginning in version 1.2.0, once a pool or client has any SSL options set, all connections use SSL, even if <code>ssl=true</code> is omitted from the MongoDB URI. Before, SSL options were ignored unless <code>ssl=true</code> was included in the URI.</p>
33+
<p>As of 1.4.0, the <code xref="mongoc_client_pool_set_ssl_opts">mongoc_client_pool_set_ssl_opts</code> and <code xref="mongoc_client_set_ssl_opts">mongoc_client_set_ssl_opts</code> will not only shallow copy the struct, but will also copy the <code>const char*</code>. It is therefore no longer needed to make sure the values remain valid after setting them.</p>.
34+
</section>
35+
36+
<section id="client-authentication">
37+
<title>Client Authentication</title>
38+
<p>When MongoDB is started with SSL enabled, it will by default require the client o provide a client certificate issued by a certificate authority specified by <code>--sslCAFile</code>, or an authority trusted by the native certificate store in use on the server.</p>
39+
<p>To provide the client certificate, the user must configure the <code>pem_file</code> to point at a PEM armored certificate.</p>
40+
<screen><code mime="text/x-csrc"><![CDATA[mongoc_ssl_opts_t ssl_opts = { 0 };
41+
42+
ssl_opts.pem_file = "/path/to/client-certificate.pem"
43+
44+
/* Then set the client ssl_opts, when using a single client mongoc_client_t */
45+
mongoc_client_pool_set_ssl_opts (pool, &ssl_opts);
46+
/* or, set the pool ssl_opts, when using a the thread safe mongoc_client_pool_t */
47+
mongoc_client_set_ssl_opts (client, &ssl_opts);]]></code></screen>
48+
</section>
49+
50+
<section id="certificate-verification">
51+
<title>Server Certificate Verification</title>
52+
<p>The MongoDB C Driver will automatically verify the validity of the server certificate, such as issued by configured Certificate Authority, hostname validation, and expiration.</p>
53+
<p>To overwrite this behaviour, it is possible to disable hostname validation, and/or allow otherwise invalid certificates. This behaviour is controlled using the <code>allow_invalid_hostname</code> and <code>weak_cert_validation</code> fields. By default, both are set to <code>false</code>. It is not recommended to change these defaults as it exposes the client to <em>Man In The Middle</em> attacks (when <code>allow_invalid_hostname</code> is set) and otherwise invalid certificates when <code>weak_cert_validation</code> is set to <code>true</code>.</p>
54+
</section>
55+
56+
<section id="nativetls-linux">
57+
<title>Native TLS Support on Linux (OpenSSL)</title>
58+
<p>The MongoDB C Driver supports the dominating TLS library (OpenSSL) and crypto libraries (OpenSSL's libcrypto) on Linux and Unix platforms.</p>
59+
<p>Support for OpenSSL 1.1 and later was added in 1.4.0.</p>
60+
<p>When compiled against OpenSSL, the driver will attempt to load the system default certificate store, as configured by the distribution, if the <code>ca_file</code> and <code>ca_dir</code> are not set.</p>
61+
</section>
62+
63+
<section id="nativetls-windows">
64+
<title>Native TLS Support on Windows (Secure Channel)</title>
65+
<p>The MongoDB C Driver supports the Windows native TLS library (Secure
66+
Channel, or SChannel), and its native crypto library (Cryptography API:
67+
Next Generation, or CNG).</p>
68+
<p>When compiled against the Windows native libraries, the <code>ca_dir</code>
69+
option is not supported, and will issue an error if used.</p>
70+
<p>Encrypted PEM files (e.g., requiring <code>pem_pwd</code>) are also not
71+
supported, and will result in error when attempting to load them.</p>
72+
<p>When <code>ca_file</code> is provided, the driver will only allow server
73+
certificates issued by the authority (or authorities) provided. When no
74+
<code>ca_file</code> is provided, the driver will look up the Certificate
75+
Authority using the <sys>System Local Machine Root</sys> certificate
76+
store to confirm the provided certificate.</p>
77+
<p>When <code>crl_file</code> is provided, the driver will import the
78+
revocation list to the <sys>System Local Machine Root</sys> certificate
79+
store.</p>
80+
</section>
81+
82+
<section id="nativetls-darwin">
83+
<title>Native TLS Support on Mac OS X / Darwin (Secure Transport)</title>
84+
<p>The MongoDB C Driver supports the Darwin (OS X, macOS, iOS, etc.) native
85+
TLS library (Secure Transport), and its native crypto library (Common
86+
Crypto, or CC).</p>
87+
<p>When compiled against Secure Transport, the <code>ca_dir</code>
88+
option is not supported, and will issue an error if used.</p>
89+
<p>When <code>ca_file</code> is provided, the driver will only allow server
90+
certificates issued by the authority (or authorities) provided. When no
91+
<code>ca_file</code> is provided, the driver will use the Certificate
92+
Authorities in the currently unlocked keychains.</p>
3293
</section>
3394

3495
<links type="topic" groups="function" style="2column">

0 commit comments

Comments
 (0)