Skip to content

Commit 390e050

Browse files
sam-githubBethGriggs
authored andcommitted
tls: support "BEGIN TRUSTED CERTIFICATE" for ca:
Support the same PEM certificate formats for the ca: option to tls.createSecureContext() that are supported by openssl when loading a CAfile. Fixes: #24761 PR-URL: #24733 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 016e352 commit 390e050

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

doc/api/tls.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,9 @@ argument.
10541054
<!-- YAML
10551055
added: v0.11.13
10561056
changes:
1057+
- version: REPLACEME
1058+
pr-url: REPLACEME
1059+
description: The `ca:` option now supports `BEGIN TRUSTED CERTIFICATE`.
10571060
- version: v11.4.0
10581061
pr-url: https://github.com/nodejs/node/pull/24405
10591062
description: The `minVersion` and `maxVersion` can be used to restrict
@@ -1092,8 +1095,8 @@ changes:
10921095
certificate can match or chain to.
10931096
For self-signed certificates, the certificate is its own CA, and must be
10941097
provided.
1095-
For PEM encoded certificates, supported types are "X509 CERTIFICATE", and
1096-
"CERTIFICATE".
1098+
For PEM encoded certificates, supported types are "TRUSTED CERTIFICATE",
1099+
"X509 CERTIFICATE", and "CERTIFICATE".
10971100
* `cert` {string|string[]|Buffer|Buffer[]} Cert chains in PEM format. One cert
10981101
chain should be provided per private key. Each cert chain should consist of
10991102
the PEM formatted certificate for a provided private `key`, followed by the

src/node_crypto.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
801801
return;
802802

803803
X509_STORE* cert_store = SSL_CTX_get_cert_store(sc->ctx_.get());
804-
while (X509* x509 = PEM_read_bio_X509(
804+
while (X509* x509 = PEM_read_bio_X509_AUX(
805805
bio.get(), nullptr, NoPasswordCallback, nullptr)) {
806806
if (cert_store == root_cert_store) {
807807
cert_store = NewRootCertStore();

test/parallel/test-tls-client-auth.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ connect({
254254
return cleanup();
255255
});
256256

257-
// Confirm lack of support for "BEGIN TRUSTED CERTIFICATE".
257+
// Confirm support for "BEGIN TRUSTED CERTIFICATE".
258258
connect({
259259
client: {
260260
key: client.key,
@@ -269,11 +269,11 @@ connect({
269269
requestCert: true,
270270
},
271271
}, function(err, pair, cleanup) {
272-
assert.strictEqual(err.code, 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY');
272+
assert.ifError(err);
273273
return cleanup();
274274
});
275275

276-
// Confirm lack of support for "BEGIN TRUSTED CERTIFICATE".
276+
// Confirm support for "BEGIN TRUSTED CERTIFICATE".
277277
connect({
278278
client: {
279279
key: client.key,
@@ -288,7 +288,7 @@ connect({
288288
requestCert: true,
289289
},
290290
}, function(err, pair, cleanup) {
291-
assert.strictEqual(err.code, 'ECONNRESET');
291+
assert.ifError(err);
292292
return cleanup();
293293
});
294294

0 commit comments

Comments
 (0)