Skip to content

Commit c1a3924

Browse files
committed
feat(NODE-5549): add ability to provide crl file
1 parent a0955bd commit c1a3924

File tree

8 files changed

+47
-12
lines changed

8 files changed

+47
-12
lines changed

.evergreen/config.in.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,6 @@ functions:
636636
export PROJECT_DIRECTORY="$(pwd)"
637637
export NODE_LTS_VERSION=${NODE_LTS_VERSION}
638638
export DRIVERS_TOOLS="${DRIVERS_TOOLS}"
639-
export SSL_CA_FILE="${SSL_CA_FILE}"
640-
export SSL_KEY_FILE="${SSL_KEY_FILE}"
641639
export MONGODB_URI="${MONGODB_URI}"
642640
643641
bash ${PROJECT_DIRECTORY}/.evergreen/run-tls-tests.sh

.evergreen/config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,6 @@ functions:
589589
export PROJECT_DIRECTORY="$(pwd)"
590590
export NODE_LTS_VERSION=${NODE_LTS_VERSION}
591591
export DRIVERS_TOOLS="${DRIVERS_TOOLS}"
592-
export SSL_CA_FILE="${SSL_CA_FILE}"
593-
export SSL_KEY_FILE="${SSL_KEY_FILE}"
594592
export MONGODB_URI="${MONGODB_URI}"
595593
596594
bash ${PROJECT_DIRECTORY}/.evergreen/run-tls-tests.sh

.evergreen/run-tls-tests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ set -o errexit # Exit the script with error if any of the commands fail
44

55
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
66

7-
export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
8-
export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
7+
export TLS_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem"
8+
export TLS_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem"
9+
export TLS_CRL_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/crl.pem"
910

1011
npm run check:tls

src/connection_string.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,9 @@ export const OPTIONS = {
10951095
tlsCAFile: {
10961096
type: 'string'
10971097
},
1098+
tlsCRLFile: {
1099+
type: 'string'
1100+
},
10981101
tlsCertificateKeyFile: {
10991102
type: 'string'
11001103
},

src/mongo_client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
117117
tlsCertificateKeyFilePassword?: string;
118118
/** Specifies the location of a local .pem file that contains the root certificate chain from the Certificate Authority. This file is used to validate the certificate presented by the mongod/mongos instance. */
119119
tlsCAFile?: string;
120+
/** Specifies the location of a local .crl file that contains the client revokation list. */
121+
tlsCRLFile?: string;
120122
/** Bypasses validation of the certificates presented by the mongod/mongos instance */
121123
tlsAllowInvalidCertificates?: boolean;
122124
/** Disables hostname validation of the certificate presented by the mongod/mongos instance. */
@@ -790,7 +792,7 @@ export interface MongoOptions
790792
* | nodejs native option | driver spec equivalent option name | driver option type |
791793
* |:----------------------|:----------------------------------------------|:-------------------|
792794
* | `ca` | `tlsCAFile` | `string` |
793-
* | `crl` | N/A | `string` |
795+
* | `crl` | `tlsCRLFile` | `string` |
794796
* | `cert` | `tlsCertificateKeyFile` | `string` |
795797
* | `key` | `tlsCertificateKeyFile` | `string` |
796798
* | `passphrase` | `tlsCertificateKeyFilePassword` | `string` |
@@ -814,8 +816,8 @@ export interface MongoOptions
814816
* `cert` and `key` fields will be undefined.
815817
*/
816818
tls: boolean;
817-
818819
tlsCAFile?: string;
820+
tlsCRLFile?: string;
819821
tlsCertificateKeyFile?: string;
820822

821823
/** @internal */

test/manual/tls_support.test.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ import {
88
MongoServerSelectionError
99
} from '../mongodb';
1010

11-
const REQUIRED_ENV = ['MONGODB_URI', 'SSL_KEY_FILE', 'SSL_CA_FILE'];
11+
const REQUIRED_ENV = ['MONGODB_URI', 'TLS_KEY_FILE', 'TLS_CA_FILE', 'TLS_CRL_FILE'];
1212

1313
describe('TLS Support', function () {
1414
for (const key of REQUIRED_ENV) {
1515
if (process.env[key] == null) {
16-
throw new Error(`skipping SSL tests, ${key} environment variable is not defined`);
16+
throw new Error(`skipping TLS tests, ${key} environment variable is not defined`);
1717
}
1818
}
1919

2020
const CONNECTION_STRING = process.env.MONGODB_URI as string;
21-
const TLS_CERT_KEY_FILE = process.env.SSL_KEY_FILE as string;
22-
const TLS_CA_FILE = process.env.SSL_CA_FILE as string;
21+
const TLS_CERT_KEY_FILE = process.env.TLS_KEY_FILE as string;
22+
const TLS_CA_FILE = process.env.TLS_CA_FILE as string;
23+
const TLS_CRL_FILE = process.env.TLS_CRL_FILE as string;
2324
const tlsSettings = {
2425
tls: true,
2526
tlsCertificateKeyFile: TLS_CERT_KEY_FILE,
@@ -114,6 +115,29 @@ describe('TLS Support', function () {
114115
});
115116
});
116117

118+
context('when providing tlsCRLFile', () => {
119+
context('when the file will revoke the certificate', () => {
120+
let client: MongoClient;
121+
beforeEach(() => {
122+
client = new MongoClient(CONNECTION_STRING, {
123+
tls: true,
124+
tlsCAFile: TLS_CA_FILE,
125+
tlsCRLFile: TLS_CRL_FILE,
126+
serverSelectionTimeoutMS: 5000,
127+
connectTimeoutMS: 5000
128+
});
129+
});
130+
afterEach(async () => {
131+
await client?.close();
132+
});
133+
134+
it('throws a MongoServerSelectionError', async () => {
135+
const err = await client.connect().catch(e => e);
136+
expect(err).to.be.instanceOf(MongoServerSelectionError);
137+
});
138+
});
139+
});
140+
117141
context('when tlsCertificateKeyFile is provided, but tlsCAFile is missing', () => {
118142
let client: MongoClient;
119143
beforeEach(() => {

test/unit/connection_string.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ describe('Connection String', function () {
438438
});
439439
});
440440

441+
context('when providing tlsCRLFile', function () {
442+
it('sets the tlsCRLFile option', function () {
443+
const options = parseOptions('mongodb://localhost/?tls=true&tlsCRLFile=path/to/file.crl');
444+
expect(options.tlsCRLFile).to.equal('path/to/file.crl');
445+
});
446+
});
447+
441448
context('when both tls and ssl options are provided', function () {
442449
context('when the options are provided in the URI', function () {
443450
context('when the options are equal', function () {

test/unit/mongo_client.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('MongoOptions', function () {
3535
const options = parseOptions('mongodb://localhost:27017/?ssl=true', {
3636
tlsCertificateKeyFile: filename,
3737
tlsCAFile: filename,
38+
tlsCRLFile: filename,
3839
tlsCertificateKeyFilePassword: 'tlsCertificateKeyFilePassword'
3940
});
4041
fs.unlinkSync(filename);
@@ -61,6 +62,7 @@ describe('MongoOptions', function () {
6162
expect(options).to.not.have.property('cert');
6263
expect(options).to.have.property('tlsCertificateKeyFile', filename);
6364
expect(options).to.have.property('tlsCAFile', filename);
65+
expect(options).to.have.property('tlsCRLFile', filename);
6466
expect(options).has.property('passphrase', 'tlsCertificateKeyFilePassword');
6567
expect(options).has.property('tls', true);
6668
});

0 commit comments

Comments
 (0)