Skip to content

Commit 8e65162

Browse files
committed
DOCSP-46939: tlsCertificateKeyFilePassword option (#165)
(cherry picked from commit 193132c)
1 parent 4fe750b commit 8e65162

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

source/fundamentals/authentication.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ authentication mechanism by using the following placeholders:
296296

297297
- ``path to CA certificate``: The filepath for your CA file
298298
- ``path to private client key``: The filepath for your certificate key file
299+
- ``password for client key``: The password used to decrypt the client key
299300
- ``db``: The authentication database associated with the user
300301

301302
The following code shows how to reference your certificates in your
@@ -308,7 +309,10 @@ connect to MongoDB:
308309
:start-after: start-x509
309310
:end-before: end-x509
310311

311-
.. TODO To learn more about enabling TLS on a connection, see :ref:`rust-tls`.
312+
.. tip::
313+
314+
To learn more about enabling TLS on a connection, see
315+
the :ref:`rust-connect-tls` guide.
312316

313317
Additional Information
314318
----------------------

source/fundamentals/connections/connection-options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ connected to the server.
192192
| If you do not set this option, the ``Client`` instance does not
193193
attempt to verify its identity to the server.
194194

195+
* - **tlsCertificateKeyFilePassword**
196+
- String
197+
- None
198+
- Specifies the password to decrypt the private key
199+
in your certificate file, if the key is encrypted.
200+
195201
* - **tlsInsecure**
196202
- Boolean
197203
- ``false``

source/fundamentals/connections/tls.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ instance and a ``Client`` instance that is configured for TLS:
181181
1. Creates variables to reference the certificate filepaths in
182182
``PathBuf`` instances.
183183

184-
#. Instantiates a ``TlsOptions`` struct and sets the ``ca_file_path`` and
185-
``cert_key_file_path`` fields to the relevant filepaths.
184+
#. Creates a variable to store the password used to decrypt the
185+
client key.
186+
187+
#. Instantiates a ``TlsOptions`` struct and sets the ``ca_file_path``,
188+
``cert_key_file_path``, and ``tls_certificate_key_file_password`` fields
189+
to configure the TLS-enabled connection.
186190

187191
#. Passes the ``TlsOptions`` instance to the ``Enabled`` variant of the
188192
``Tls`` enum.

source/includes/fundamentals/code-snippets/auth.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ async fn main() -> mongodb::error::Result<()> {
7676
let uri = format!(
7777
"mongodb://<hostname>:<port>/?tlsCAFile={tlsCAFile}&tlsCertificateKeyFile={tlsCertificateKeyFile}",
7878
tlsCAFile = "<path to CA certificate>",
79-
tlsCertificateKeyFile = "<path to private client key>"
79+
tlsCertificateKeyFile = "<path to private client key>",
80+
tlsCertificateKeyFilePassword = "<password for client key>"
8081
);
8182
let mut client_options = ClientOptions::parse(uri).await?;
8283
let x509_cred = Credential::builder().mechanism(AuthMechanism::MongoDbAws).build();

source/includes/fundamentals/code-snippets/tls.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ async fn main() -> mongodb::error::Result<()> {
99

1010
let ca_file = PathBuf::from(r"<path to CA certificate>");
1111
let key_file = PathBuf::from(r"<path to client certificate>");
12+
let key_password = b"<password for client key>".to_vec();
1213

13-
let tls_opts = TlsOptions::builder().ca_file_path(ca_file).cert_key_file_path(key_file).build();
14+
let tls_opts = TlsOptions::builder()
15+
.ca_file_path(ca_file)
16+
.cert_key_file_path(key_file)
17+
.tls_certificate_key_file_password(key_password)
18+
.build();
1419

1520
client_options.tls = Some(Tls::Enabled(tls_opts));
1621
let _client = Client::with_options(client_options)?;

0 commit comments

Comments
 (0)