Skip to content

Commit 4d4e2d4

Browse files
committed
Improve TLS docs, add javaseref shortcode
JAVA-3420
1 parent f9bf950 commit 4d4e2d4

File tree

10 files changed

+61
-106
lines changed

10 files changed

+61
-106
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/ssl.md

Lines changed: 4 additions & 41 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,5 @@ MongoClientSettings settings = MongoClientSettings.builder()
9090
.build();
9191
```
9292

93-
## JVM System Properties for TLS/SSL
94-
95-
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
97-
presented by the server:
98-
99-
- `javax.net.ssl.trustStore`:
100-
The path to a trust store containing the certificate of the
101-
signing authority
102-
103-
- `javax.net.ssl.trustStorePassword`:
104-
The password to access this trust store
105-
106-
The trust store is typically created with the
107-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
108-
command line program provided as part of the JDK. For example:
109-
110-
```bash
111-
keytool -importcert -trustcacerts -file <path to certificate authority file>
112-
-keystore <path to trust store> -storepass <password>
113-
```
114-
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
116-
MongoDB server:
117-
118-
- `javax.net.ssl.keyStore`
119-
The path to a key store containing the client's TLS/SSL certificates
120-
121-
- `javax.net.ssl.keyStorePassword`
122-
The password to access this key store
123-
124-
The key store is typically created with the
125-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
126-
or the [`openssl`](https://www.openssl.org/docs/apps/openssl.html)
127-
command line program.
128-
129-
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).
93+
## Common TLS/SSL Configuration Tasks
94+
See [Java Driver Common TLS/SSL Configuration Tasks]({{< relref "driver/tutorials/ssl.md#common-tls-ssl-configuration-tasks" >}}).

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: 4 additions & 41 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,5 @@ val settings = MongoClientSettings.builder()
8080
.build()
8181
```
8282

83-
## JVM System Properties for TLS/SSL
84-
85-
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
87-
presented by the server:
88-
89-
- `javax.net.ssl.trustStore`:
90-
The path to a trust store containing the certificate of the
91-
signing authority
92-
93-
- `javax.net.ssl.trustStorePassword`:
94-
The password to access this trust store
95-
96-
The trust store is typically created with the
97-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
98-
command line program provided as part of the JDK. For example:
99-
100-
```bash
101-
keytool -importcert -trustcacerts -file <path to certificate authority file>
102-
-keystore <path to trust store> -storepass <password>
103-
```
104-
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
106-
MongoDB server:
107-
108-
- `javax.net.ssl.keyStore`
109-
The path to a key store containing the client's TLS/SSL certificates
110-
111-
- `javax.net.ssl.keyStorePassword`
112-
The password to access this key store
113-
114-
The key store is typically created with the
115-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
116-
or the [`openssl`](https://www.openssl.org/docs/apps/openssl.html)
117-
command line program.
118-
119-
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).
83+
## Common TLS/SSL Configuration Tasks
84+
See [Java Driver Common TLS/SSL Configuration Tasks]({{< relref "driver/tutorials/ssl.md#common-tls-ssl-configuration-tasks" >}}).

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

docs/reference/content/driver/tutorials/gridfs.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ To upload data into GridFS, you can upload from an `InputStream` or write data t
7979

8080
### UploadFromStream
8181

82-
The [`GridFSBucket.uploadFromStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSBucket.html#openUploadStream(java.lang.String,com.mongodb.client.gridfs.model.GridFSUploadOptions)" >}}) method reads the contents of an [`InputStream`](http://docs.oracle.com/javase/8/docs/api/index.html?java/io/InputStream.html) and saves it to the `GridFSBucket`.
82+
The [`GridFSBucket.uploadFromStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSBucket.html#openUploadStream(java.lang.String,com.mongodb.client.gridfs.model.GridFSUploadOptions)" >}}) method reads the contents of an [`InputStream`]({{< javaseref "api/java/io/InputStream.html" >}}) and saves it to the `GridFSBucket`.
8383

8484
You can use the [`GridFSUploadOptions`]({{< apiref "mongodb-driver-core" "com/mongodb/client/gridfs/model/GridFSUploadOptions" >}}) to configure the chunk size or include additional metadata.
8585

@@ -104,7 +104,7 @@ try {
104104
### OpenUploadStream
105105

106106
You can write data to a [`GridFSUploadStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSUploadStream.html" >}}) which extends
107-
[`OutputStream`](http://docs.oracle.com/javase/8/docs/api/index.html?java/io/OutputStream.html). The
107+
[`OutputStream`]({{< javaseref "api/java/io/OutputStream.html" >}}). The
108108
[`GridFSBucket.openUploadStream `]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSBucket.html#openUploadStream(java.lang.String,com.mongodb.client.gridfs.model.GridFSUploadOptions)" >}})
109109
method returns a [`GridFSUploadStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSUploadStream.html" >}}).
110110

@@ -154,7 +154,7 @@ There are various ways to download data from GridFS.
154154

155155
### DownloadToStream
156156

157-
The [`downloadToStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSBucket.html#downloadToStream(org.bson.types.ObjectId,java.io.OutputStream)" >}}) method reads the contents from MongoDB and writes the data directly to the provided [`OutputStream`](http://docs.oracle.com/javase/8/docs/api/index.html?java/io/OutputStream.html).
157+
The [`downloadToStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSBucket.html#downloadToStream(org.bson.types.ObjectId,java.io.OutputStream)" >}}) method reads the contents from MongoDB and writes the data directly to the provided [`OutputStream`]({{< javaseref "api/java/io/OutputStream.html" >}}).
158158

159159
To download a file by its file `_id`, pass the `_id` to the method. The
160160
following example downloads a file by its file `_id` into the provided
@@ -193,7 +193,7 @@ try {
193193
### OpenDownloadStream
194194

195195

196-
The [`openDownloadStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSBucket.html#openDownloadStream(org.bson.types.ObjectId)" >}}) method returns a [`GridFSDownloadStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSDownloadStream.html" >}}) which extends [`InputStream`](http://docs.oracle.com/javase/8/docs/api/index.html?java/io/InputStream.html).
196+
The [`openDownloadStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSBucket.html#openDownloadStream(org.bson.types.ObjectId)" >}}) method returns a [`GridFSDownloadStream`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/gridfs/GridFSDownloadStream.html" >}}) which extends [`InputStream`]({{< javaseref "api/java/io/InputStream.html" >}}).
197197

198198
The following example reads from the `GridFSBucket` via the returned `InputStream`:
199199

docs/reference/content/driver/tutorials/jndi.md

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

1111
## Java Naming and Directory Interface (JNDI)
1212

13-
The driver includes a [JNDI](http://docs.oracle.com/javase/8/docs/technotes/guides/jndi/index.html) ObjectFactory implementation,
13+
The driver includes a [JNDI]({{< javaseref "technotes/guides/jndi/index.html" >}}) ObjectFactory implementation,
1414
[`MongoClientFactory`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/MongoClientFactory" >}}) ([`legacy version`]({{< apiref "mongodb-driver-legacy" "com/mongodb/client/jndi/MongoClientFactory" >}})), that returns `MongoClient` instances based on a
1515
[connection string](http://docs.mongodb.org/manual/reference/connection-string/).
1616

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

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

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

6565
```java
@@ -112,7 +112,7 @@ import com.mongodb.MongoClientSettings;
112112
import com.mongodb.MongoClient;
113113
```
114114

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

118118
```java
@@ -130,7 +130,7 @@ server's SSL certificate(s) matches the hostname(s) provided when
130130
constructing a [`MongoClient()`]({{< apiref "mongodb-driver-sync" "com/mongodb/client/MongoClient.html" >}}).
131131

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

135135
```java
136136
MongoClientSettings settings = MongoClientSettings.builder()
@@ -141,45 +141,70 @@ MongoClientSettings settings = MongoClientSettings.builder()
141141
.build();
142142
```
143143

144-
## JVM System Properties for TLS/SSL
144+
## Common TLS/SSL Configuration Tasks <!-- Care when renaming, this section is referred to in driver-reactive/tutorials/ssl.md and driver-scala/tutorials/ssl.md -->
145+
This section is common for
146+
[Java Driver]({{< relref "driver/index.md" >}}),
147+
[Reactive Streams Driver]({{< relref "driver-reactive/index.md" >}}),
148+
[Scala Driver]({{< relref "driver-scala/index.md" >}}).
149+
### Configure Trust Store and Key Store
150+
One may either configure trust stores and key stores specific to the client via
151+
[`javax.net.ssl.SSLContext.init(KeyManager[] km, TrustManager[] tm, SecureRandom random)`]
152+
({{< javaseref "api/javax/net/ssl/SSLContext.html#init-javax.net.ssl.KeyManager:A-javax.net.ssl.TrustManager:A-java.security.SecureRandom-" >}}),
153+
or set the JVM default ones.
154+
155+
#### Set the Default Trust Store
145156

146157
A typical application will need to set several JVM system properties to
147-
ensure that the client is able to validate the TLS/SSL certificate
158+
ensure that the client is able to *validate* the TLS/SSL certificate
148159
presented by the server:
149160

150161
- `javax.net.ssl.trustStore`:
151162
The path to a trust store containing the certificate of the
152163
signing authority
164+
(see `<path to trust store>` below)
153165

154166
- `javax.net.ssl.trustStorePassword`:
155167
The password to access this trust store
168+
(see `<trust store password>` below)
156169

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

161174
```bash
162175
keytool -importcert -trustcacerts -file <path to certificate authority file>
163-
-keystore <path to trust store> -storepass <password>
176+
-keystore <path to trust store> -storepass <trust store password>
164177
```
178+
179+
#### Set the Default Key Store
180+
165181
A typical application will also need to set several JVM system
166-
properties to ensure that the client presents an TLS/SSL certificate to the
182+
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
167183
MongoDB server:
168184

169185
- `javax.net.ssl.keyStore`
170186
The path to a key store containing the client's TLS/SSL certificates
187+
(see `<path to key store>` below)
171188

172189
- `javax.net.ssl.keyStorePassword`
173190
The password to access this key store
191+
(see `<trust store password>` below)
174192

175193
The key store is typically created with the
176-
[`keytool`](http://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html)
194+
[`keytool`]({{< javaseref "technotes/tools/unix/keytool.html" >}})
177195
or the [`openssl`](https://www.openssl.org/docs/apps/openssl.html)
178-
command line program.
196+
command line program. For example, if you have a file with the client certificate and its private key
197+
(may be in the PEM format)
198+
and want to create a key store in the [PKCS #12](https://www.rfc-editor.org/rfc/rfc7292) format,
199+
you can do the following:
200+
201+
```sh
202+
openssl pkcs12 -export -in <path to client certificate & private key file>
203+
-out <path to key store> -passout pass:<trust store password>
204+
```
179205

180206
For more information on configuring a Java application for TLS/SSL, please
181-
refer to the [`JSSE Reference Guide`](http://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSS
182-
ERefGuide.html).
207+
refer to the [`JSSE Reference Guide`]({{< javaseref "technotes/guides/security/jsse/JSSERefGuide.html" >}}).
183208

184209

185210
### Forcing TLS 1.2
@@ -189,13 +214,13 @@ Some applications may want to force only the TLS 1.2 protocol. To do this, set t
189214
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.
190215

191216

192-
## OCSP
217+
### OCSP
193218

194219
{{% note %}}
195220
The Java driver cannot enable OCSP by default on a per MongoClient basis.
196221
{{% /note %}}
197222

198-
### Client-driven OCSP
223+
#### Client-driven OCSP
199224

200225
An application will need to set JVM system and security properties to ensure that client-driven OCSP is enabled:
201226

@@ -211,7 +236,7 @@ To configure an application to use client-driven OCSP, the application must alre
211236
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.
212237
{{% /note %}}
213238

214-
### OCSP Stapling
239+
#### OCSP Stapling
215240

216241
{{% note class="important" %}}
217242
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):
@@ -232,4 +257,4 @@ An application will need to set several JVM system properties to set up OCSP sta
232257
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.
233258

234259
For more information on configuring a Java application to use OCSP, please
235-
refer to the "Client-driven OCSP and OCSP Stapling" section in the [`JSSE Reference Guide`](https://docs.oracle.com/javase/9/security/java-secure-socket-extension-jsse-reference-guide.htm).
260+
refer to the [`Client-Driven OCSP and OCSP Stapling`]({{< javaseref "technotes/guides/security/jsse/ocsp.html" >}}).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ .Site.Params.javaSeDocsUri }}{{ .Get 0 }}

0 commit comments

Comments
 (0)