Skip to content

Commit 858d743

Browse files
authored
Improve TLS docs, add javaseref shortcode (#637)
JAVA-3420
1 parent f9bf950 commit 858d743

File tree

11 files changed

+235
-59
lines changed

11 files changed

+235
-59
lines changed

docs/reference/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ canonifyURLs = false
66
disableHugoGeneratorInject = true
77
disableKinds = ["section", "taxonomy", "taxonomyTerm", "404"]
88

9+
[params]
10+
javaSeDocsUri = "https://docs.oracle.com/javase/8/docs/"
11+
912
[blackfriday]
1013
plainIdAnchors = true
1114

docs/reference/content/driver-reactive/reference/monitoring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ title = "Monitoring"
1010

1111
# JMX Monitoring
1212

13-
The driver uses [JMX](http://docs.oracle.com/javase/8/docs/technotes/guides/jmx/) to create
13+
The driver uses [JMX]({{< javaseref "technotes/guides/jmx/" >}}) to create
1414
[MXBeans](http://docs.oracle.com/javase/tutorial/jmx/mbeans/mxbeans.html) that allow an
1515
application or end user to monitor various aspects of the driver.
1616

docs/reference/content/driver-reactive/tutorials/aggregation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ collection.aggregate(
9797
### Explain an Aggregation
9898

9999
To [explain]({{< docsref "reference/command/explain/" >}}) an aggregation pipeline, call the
100-
[`AggregatePublisher.explain()`]({{< apiref "mongodb-driver-reactivestreams" "com/mongodb/reactivestreams/client/AggregatePublisher.html#explain()"
101-
> >}})
100+
[`AggregatePublisher.explain()`]
101+
({{< apiref "mongodb-driver-reactivestreams" "com/mongodb/reactivestreams/client/AggregatePublisher.html#explain()" >}})
102102
method:
103103

104104
```java
@@ -110,4 +110,4 @@ collection.aggregate(
110110
.subscribe(new PrintDocumentSubscriber());
111111
```
112112

113-
The driver supports explain of aggregation pipelines starting with MongoDB 3.6.
113+
The driver supports explain of aggregation pipelines starting with MongoDB 3.6.

docs/reference/content/driver-reactive/tutorials/ssl.md

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import com.mongodb.reactivestreams.client.MongoClients;
5858
import com.mongodb.reactivestreams.client.MongoClient;
5959
```
6060

61-
To specify the [`javax.net.ssl.SSLContext`](https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html) with
61+
To specify the [`javax.net.ssl.SSLContext`]({{< javaseref "api/javax/net/ssl/SSLContext.html" >}}) with
6262
[`MongoClientSettings`]({{< apiref "mongodb-driver-core" "com/mongodb/MongoClientSettings" >}}), set the `sslContext` property, as in:
6363

6464
```java
@@ -79,7 +79,7 @@ server's SSL certificate(s) matches the hostname(s) provided when
7979
constructing a [`MongoClient()`]({{< apiref "mongodb-driver-reactivestreams" "com/mongodb/reactivestreams/client/MongoClient.html" >}}).
8080

8181
If your application needs to disable hostname verification, you must explicitly indicate
82-
this in `MongoClientSettings`]({{< apiref "mongodb-driver-core" "com/mongodb/MongoClientSettings" >}})
82+
this in [`MongoClientSettings`]({{< apiref "mongodb-driver-core" "com/mongodb/MongoClientSettings" >}})
8383

8484
```java
8585
MongoClientSettings settings = MongoClientSettings.builder()
@@ -90,42 +90,117 @@ MongoClientSettings settings = MongoClientSettings.builder()
9090
.build();
9191
```
9292

93-
## JVM System Properties for TLS/SSL
93+
## Common TLS/SSL Configuration Tasks
94+
<p></p>
95+
### Configure Trust Store and Key Store
96+
One may either configure trust stores and key stores specific to the client via
97+
[`javax.net.ssl.SSLContext.init(KeyManager[] km, TrustManager[] tm, SecureRandom random)`]
98+
({{< javaseref "api/javax/net/ssl/SSLContext.html#init-javax.net.ssl.KeyManager:A-javax.net.ssl.TrustManager:A-java.security.SecureRandom-" >}}),
99+
or set the JVM default ones.
100+
101+
#### Set the Default Trust Store
94102

95103
A typical application will need to set several JVM system properties to
96-
ensure that the client is able to validate the TLS/SSL certificate
104+
ensure that the client is able to *validate* the TLS/SSL certificate
97105
presented by the server:
98106

99107
- `javax.net.ssl.trustStore`:
100-
The path to a trust store containing the certificate of the
101-
signing authority
108+
The path to a trust store containing the certificate of the
109+
signing authority
110+
(see `<path to trust store>` below)
102111

103112
- `javax.net.ssl.trustStorePassword`:
104-
The password to access this trust store
113+
The password to access this trust store
114+
(see `<trust store password>` below)
105115

106116
The trust store is typically created with the
107-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
117+
[`keytool`]({{< javaseref "technotes/tools/unix/keytool.html" >}})
108118
command line program provided as part of the JDK. For example:
109119

110120
```bash
111121
keytool -importcert -trustcacerts -file <path to certificate authority file>
112-
-keystore <path to trust store> -storepass <password>
122+
-keystore <path to trust store> -storepass <trust store password>
113123
```
124+
125+
#### Set the Default Key Store
126+
114127
A typical application will also need to set several JVM system
115-
properties to ensure that the client presents an TLS/SSL certificate to the
128+
properties to ensure that the client *presents* an TLS/SSL [client certificate](https://docs.mongodb.com/manual/tutorial/configure-ssl/#set-up-mongod-and-mongos-with-client-certificate-validation) to the
116129
MongoDB server:
117130

118131
- `javax.net.ssl.keyStore`
119-
The path to a key store containing the client's TLS/SSL certificates
132+
The path to a key store containing the client's TLS/SSL certificates
133+
(see `<path to key store>` below)
120134

121135
- `javax.net.ssl.keyStorePassword`
122-
The password to access this key store
136+
The password to access this key store
137+
(see `<trust store password>` below)
123138

124139
The key store is typically created with the
125-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
140+
[`keytool`]({{< javaseref "technotes/tools/unix/keytool.html" >}})
126141
or the [`openssl`](https://www.openssl.org/docs/apps/openssl.html)
127-
command line program.
142+
command line program. For example, if you have a file with the client certificate and its private key
143+
(may be in the PEM format)
144+
and want to create a key store in the [PKCS #12](https://www.rfc-editor.org/rfc/rfc7292) format,
145+
you can do the following:
146+
147+
```sh
148+
openssl pkcs12 -export -in <path to client certificate & private key file>
149+
-out <path to key store> -passout pass:<trust store password>
150+
```
128151

129152
For more information on configuring a Java application for TLS/SSL, please
130-
refer to the [`JSSE Reference Guide`](http://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSS
131-
ERefGuide.html).
153+
refer to the [`JSSE Reference Guide`]({{< javaseref "technotes/guides/security/jsse/JSSERefGuide.html" >}}).
154+
155+
156+
### Forcing TLS 1.2
157+
158+
Some applications may want to force only the TLS 1.2 protocol. To do this, set the `jdk.tls.client.protocols` system property to "TLSv1.2".
159+
160+
Java runtime environments prior to Java 8 started to enable the TLS 1.2 protocol only in later updates, as shown in the previous section. For the driver to force the use of the TLS 1.2 protocol with a Java runtime environment prior to Java 8, ensure that the update has TLS 1.2 enabled.
161+
162+
163+
### OCSP
164+
165+
{{% note %}}
166+
The Java driver cannot enable OCSP by default on a per MongoClient basis.
167+
{{% /note %}}
168+
169+
#### Client-driven OCSP
170+
171+
An application will need to set JVM system and security properties to ensure that client-driven OCSP is enabled:
172+
173+
- `com.sun.net.ssl.checkRevocation`:
174+
When set to `true`, this system property enables revocation checking.
175+
176+
- `ocsp.enable`:
177+
When set to `true`, this security property enables client-driven OCSP.
178+
179+
To configure an application to use client-driven OCSP, the application must already be set up to connect to a server using TLS. Setting these system properties is required to enable client-driven OCSP.
180+
181+
{{% note %}}
182+
The support for TLS provided by the JDK utilizes “hard fail” behavior in the case of an unavailable OCSP responder in contrast to the mongo shell and drivers that utilize “soft fail” behavior.
183+
{{% /note %}}
184+
185+
#### OCSP Stapling
186+
187+
{{% note class="important" %}}
188+
The following exception may occur when using OCSP stapling with Java runtime environments that use the TLS 1.3 protocol (Java 11 and higher use TLS 1.3 by default):
189+
190+
`javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request`
191+
192+
The exception is due to a known issue with TLS 1.3 in Java 11 and higher. To avoid this exception when using a Java runtime environments using the TLS 1.3 protocol, you can force the application to use the TLS 1.2 protocol. To do this, set the `jdk.tls.client.protocols` system property to "TLSv1.2".
193+
{{% /note %}}
194+
195+
An application will need to set several JVM system properties to set up OCSP stapling:
196+
197+
- `jdk.tls.client.enableStatusRequestExtension`:
198+
When set to `true` (its default value), this enables OCSP stapling.
199+
200+
- `com.sun.net.ssl.checkRevocation`:
201+
When set to `true`, this enables revocation checking. If this property is not set to `true`, then the connection will be allowed to proceed regardless of the presence or status of the revocation information.
202+
203+
To configure an application to use OCSP stapling, the application must already be set up to connect to a server using TLS, and the server must be set up to staple an OCSP response to the certificate it returns as part of the the TLS handshake.
204+
205+
For more information on configuring a Java application to use OCSP, please
206+
refer to the [`Client-Driven OCSP and OCSP Stapling`]({{< javaseref "technotes/guides/security/jsse/ocsp.html" >}}).

docs/reference/content/driver-scala/reference/monitoring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ title = "Monitoring"
1010

1111
# JMX Monitoring
1212

13-
The driver uses [JMX](http://docs.oracle.com/javase/8/docs/technotes/guides/jmx/) to create
13+
The driver uses [JMX]({{< javaseref "technotes/guides/jmx/" >}}) to create
1414
[MXBeans](http://docs.oracle.com/javase/tutorial/jmx/mbeans/mxbeans.html) that allow an
1515
application or end user to monitor various aspects of the driver.
1616

docs/reference/content/driver-scala/tutorials/ssl.md

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ val client = MongoClients.create(settings)
4848
import javax.net.ssl.SSLContext
4949
```
5050

51-
To specify the [`javax.net.ssl.SSLContext`](https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html) with
51+
To specify the [`javax.net.ssl.SSLContext`]({{< javaseref "api/javax/net/ssl/SSLContext.html" >}}) with
5252
[`MongoClientSettings`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/MongoClientSettings$.html" >}}), set the `sslContext` property, as in:
5353

5454
```scala
@@ -69,7 +69,7 @@ server's SSL certificate(s) matches the hostname(s) provided when
6969
constructing a [`MongoClient()`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/MongoClient$.html" >}}).
7070

7171
If your application needs to disable hostname verification, you must explicitly indicate
72-
this in `MongoClientSettings`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/MongoClientSettings$.html" >}})
72+
this in [`MongoClientSettings`]({{< apiref "mongo-scala-driver" "org/mongodb/scala/MongoClientSettings$.html" >}})
7373

7474
```scala
7575
val settings = MongoClientSettings.builder()
@@ -80,42 +80,117 @@ val settings = MongoClientSettings.builder()
8080
.build()
8181
```
8282

83-
## JVM System Properties for TLS/SSL
83+
## Common TLS/SSL Configuration Tasks
84+
<p></p>
85+
### Configure Trust Store and Key Store
86+
One may either configure trust stores and key stores specific to the client via
87+
[`javax.net.ssl.SSLContext.init(KeyManager[] km, TrustManager[] tm, SecureRandom random)`]
88+
({{< javaseref "api/javax/net/ssl/SSLContext.html#init-javax.net.ssl.KeyManager:A-javax.net.ssl.TrustManager:A-java.security.SecureRandom-" >}}),
89+
or set the JVM default ones.
90+
91+
#### Set the Default Trust Store
8492

8593
A typical application will need to set several JVM system properties to
86-
ensure that the client is able to validate the TLS/SSL certificate
94+
ensure that the client is able to *validate* the TLS/SSL certificate
8795
presented by the server:
8896

8997
- `javax.net.ssl.trustStore`:
90-
The path to a trust store containing the certificate of the
91-
signing authority
98+
The path to a trust store containing the certificate of the
99+
signing authority
100+
(see `<path to trust store>` below)
92101

93102
- `javax.net.ssl.trustStorePassword`:
94-
The password to access this trust store
103+
The password to access this trust store
104+
(see `<trust store password>` below)
95105

96106
The trust store is typically created with the
97-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
107+
[`keytool`]({{< javaseref "technotes/tools/unix/keytool.html" >}})
98108
command line program provided as part of the JDK. For example:
99109

100110
```bash
101111
keytool -importcert -trustcacerts -file <path to certificate authority file>
102-
-keystore <path to trust store> -storepass <password>
112+
-keystore <path to trust store> -storepass <trust store password>
103113
```
114+
115+
#### Set the Default Key Store
116+
104117
A typical application will also need to set several JVM system
105-
properties to ensure that the client presents an TLS/SSL certificate to the
118+
properties to ensure that the client *presents* an TLS/SSL [client certificate](https://docs.mongodb.com/manual/tutorial/configure-ssl/#set-up-mongod-and-mongos-with-client-certificate-validation) to the
106119
MongoDB server:
107120

108121
- `javax.net.ssl.keyStore`
109-
The path to a key store containing the client's TLS/SSL certificates
122+
The path to a key store containing the client's TLS/SSL certificates
123+
(see `<path to key store>` below)
110124

111125
- `javax.net.ssl.keyStorePassword`
112-
The password to access this key store
126+
The password to access this key store
127+
(see `<trust store password>` below)
113128

114129
The key store is typically created with the
115-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
130+
[`keytool`]({{< javaseref "technotes/tools/unix/keytool.html" >}})
116131
or the [`openssl`](https://www.openssl.org/docs/apps/openssl.html)
117-
command line program.
132+
command line program. For example, if you have a file with the client certificate and its private key
133+
(may be in the PEM format)
134+
and want to create a key store in the [PKCS #12](https://www.rfc-editor.org/rfc/rfc7292) format,
135+
you can do the following:
136+
137+
```sh
138+
openssl pkcs12 -export -in <path to client certificate & private key file>
139+
-out <path to key store> -passout pass:<trust store password>
140+
```
118141

119142
For more information on configuring a Java application for TLS/SSL, please
120-
refer to the [`JSSE Reference Guide`](http://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSS
121-
ERefGuide.html).
143+
refer to the [`JSSE Reference Guide`]({{< javaseref "technotes/guides/security/jsse/JSSERefGuide.html" >}}).
144+
145+
146+
### Forcing TLS 1.2
147+
148+
Some applications may want to force only the TLS 1.2 protocol. To do this, set the `jdk.tls.client.protocols` system property to "TLSv1.2".
149+
150+
Java runtime environments prior to Java 8 started to enable the TLS 1.2 protocol only in later updates, as shown in the previous section. For the driver to force the use of the TLS 1.2 protocol with a Java runtime environment prior to Java 8, ensure that the update has TLS 1.2 enabled.
151+
152+
153+
### OCSP
154+
155+
{{% note %}}
156+
The Java driver cannot enable OCSP by default on a per MongoClient basis.
157+
{{% /note %}}
158+
159+
#### Client-driven OCSP
160+
161+
An application will need to set JVM system and security properties to ensure that client-driven OCSP is enabled:
162+
163+
- `com.sun.net.ssl.checkRevocation`:
164+
When set to `true`, this system property enables revocation checking.
165+
166+
- `ocsp.enable`:
167+
When set to `true`, this security property enables client-driven OCSP.
168+
169+
To configure an application to use client-driven OCSP, the application must already be set up to connect to a server using TLS. Setting these system properties is required to enable client-driven OCSP.
170+
171+
{{% note %}}
172+
The support for TLS provided by the JDK utilizes “hard fail” behavior in the case of an unavailable OCSP responder in contrast to the mongo shell and drivers that utilize “soft fail” behavior.
173+
{{% /note %}}
174+
175+
#### OCSP Stapling
176+
177+
{{% note class="important" %}}
178+
The following exception may occur when using OCSP stapling with Java runtime environments that use the TLS 1.3 protocol (Java 11 and higher use TLS 1.3 by default):
179+
180+
`javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request`
181+
182+
The exception is due to a known issue with TLS 1.3 in Java 11 and higher. To avoid this exception when using a Java runtime environments using the TLS 1.3 protocol, you can force the application to use the TLS 1.2 protocol. To do this, set the `jdk.tls.client.protocols` system property to "TLSv1.2".
183+
{{% /note %}}
184+
185+
An application will need to set several JVM system properties to set up OCSP stapling:
186+
187+
- `jdk.tls.client.enableStatusRequestExtension`:
188+
When set to `true` (its default value), this enables OCSP stapling.
189+
190+
- `com.sun.net.ssl.checkRevocation`:
191+
When set to `true`, this enables revocation checking. If this property is not set to `true`, then the connection will be allowed to proceed regardless of the presence or status of the revocation information.
192+
193+
To configure an application to use OCSP stapling, the application must already be set up to connect to a server using TLS, and the server must be set up to staple an OCSP response to the certificate it returns as part of the the TLS handshake.
194+
195+
For more information on configuring a Java application to use OCSP, please
196+
refer to the [`Client-Driven OCSP and OCSP Stapling`]({{< javaseref "technotes/guides/security/jsse/ocsp.html" >}}).

docs/reference/content/driver/reference/monitoring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ title = "Monitoring"
1010

1111
# JMX Monitoring
1212

13-
The driver uses [JMX](http://docs.oracle.com/javase/8/docs/technotes/guides/jmx/) to create
13+
The driver uses [JMX]({{< javaseref "technotes/guides/jmx/" >}}) to create
1414
[MXBeans](http://docs.oracle.com/javase/tutorial/jmx/mbeans/mxbeans.html) that allow an
1515
application or end user to monitor various aspects of the driver.
1616

0 commit comments

Comments
 (0)