Appendix C - OpenSSL Client Certificates for Testing¶
Disclaimer
This page is provided for testing purposes only and the certificates are for testing purposes only.
The following tutorial provides some basic steps for creating test x.509 certificates.
- Do not use these certificates for production. Instead, follow your security policies.
- For information on OpenSSL, refer to the official OpenSSL docs. Although this tutorial uses OpenSSL, the material should not be taken as an authoritative reference on OpenSSL.
Prerequisite¶
The procedure outlined on this page uses the test intermediate authority
certificate and key mongodb-test-ia.crt
and
mongodb-test-ia.key
created in
Appendix A - OpenSSL CA Certificate for Testing.
Procedure¶
The following procedure outlines the steps to create test certificates for MongoDB clients. For steps to create test certificates for MongoDB servers, see Appendix B - OpenSSL Server Certificates for Testing.
A. Create the OpenSSL Configuration File¶
Create a test configuration file
openssl-test-client.cnf
for your client with the following content:Optional. You can update the default Distinguished Name (DN) values. Ensure that client certificates differ from server certificates with regards to at least one of the following attributes: Organization (
O
), the Organizational Unit (OU
) or the Domain Component (DC
).
B. Generate the Test PEM File for Client¶
Create the test key file
mongodb-test-client.key
.Create the test certificate signing request
mongodb-test-client.csr
. When asked for Distinguished Name values, enter the appropriate values for your test certificate:Important
The client certificate subject must differ to a server certificate subject with regards to at least one of the following attributes: Organization (O), the Organizational Unit (OU) or the Domain Component (DC).
Create the test client certificate
mongodb-test-client.crt
.Create the test PEM file for the client.
You can use the test PEM file to configure the
mongo
shell for TLS/SSL testing. For example, to connect to amongod
or amongos
:For MongoDB 4.2 or greater, include the following options for the client:
For MongoDB 4.0 and earlier, include the following options for the client:
- On macOS,
If you are testing with Keychain Access to manage certificates, create a PKCS 12 file to add to Keychain Access instead of a PEM file:
Once added to Keychain Access, instead of specifying the Certificate Key file, you can use the
--tlsCertificateSelector
to specify the certificate to use. If the CA file is also in Keychain Access, you can omit--tlsCAFile
as well as in the following example:For MongoDB 4.2 or greater
Although still available,
--ssl
and--sslCertificateSelector
are deprecated as of MongoDB 4.2.For MongoDB 4.0 and earlier
For adding certificates to Keychain Access, refer to your official documentation for Keychain Access.