Skip to content

Commit 1f65f18

Browse files
committed
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 5febe41 commit 1f65f18

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
@@ -1184,6 +1184,9 @@ argument.
11841184
added: v0.11.13
11851185
changes:
11861186
- version: REPLACEME
1187+
pr-url: REPLACEME
1188+
description: The `ca:` option now supports `BEGIN TRUSTED CERTIFICATE`.
1189+
- version: v11.4.0
11871190
pr-url: https://github.com/nodejs/node/pull/24405
11881191
description: The `minVersion` and `maxVersion` can be used to restrict
11891192
the allowed TLS protocol versions.
@@ -1225,8 +1228,8 @@ changes:
12251228
certificate can match or chain to.
12261229
For self-signed certificates, the certificate is its own CA, and must be
12271230
provided.
1228-
For PEM encoded certificates, supported types are "X509 CERTIFICATE", and
1229-
"CERTIFICATE".
1231+
For PEM encoded certificates, supported types are "TRUSTED CERTIFICATE",
1232+
"X509 CERTIFICATE", and "CERTIFICATE".
12301233
* `cert` {string|string[]|Buffer|Buffer[]} Cert chains in PEM format. One cert
12311234
chain should be provided per private key. Each cert chain should consist of
12321235
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
@@ -800,7 +800,7 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
800800
return;
801801

802802
X509_STORE* cert_store = SSL_CTX_get_cert_store(sc->ctx_.get());
803-
while (X509* x509 = PEM_read_bio_X509(
803+
while (X509* x509 = PEM_read_bio_X509_AUX(
804804
bio.get(), nullptr, NoPasswordCallback, nullptr)) {
805805
if (cert_store == root_cert_store) {
806806
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)