-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
tls: use options in getCACertificates() with X509Certificate #59349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 25 commits
c4ca69e
ee04b40
1b8197b
187c86d
4048b54
eae9df7
e013568
195125f
b1eacfb
603967f
36e8a2e
62ec148
361c799
358b2bd
f9dfc62
cdf69dc
d978079
8cf2dbe
e6de951
da83ccf
10e9225
ab76b14
5e8dd7a
f84c311
a335306
319841f
fd0de18
95c07aa
e2879a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -2308,21 +2308,35 @@ const additionalCerts = ['-----BEGIN CERTIFICATE-----\n...']; | |||
| tls.setDefaultCACertificates([...currentCerts, ...additionalCerts]); | ||||
| ``` | ||||
|
|
||||
| ## `tls.getCACertificates([type])` | ||||
| ## `tls.getCACertificates([options])` | ||||
|
|
||||
| <!-- YAML | ||||
| added: | ||||
| - v23.10.0 | ||||
| - v22.15.0 | ||||
| --> | ||||
|
|
||||
| * `type` {string|undefined} The type of CA certificates that will be returned. Valid values | ||||
| are `"default"`, `"system"`, `"bundled"` and `"extra"`. | ||||
| **Default:** `"default"`. | ||||
| * Returns: {string\[]} An array of PEM-encoded certificates. The array may contain duplicates | ||||
| if the same certificate is repeatedly stored in multiple sources. | ||||
|
|
||||
| Returns an array containing the CA certificates from various sources, depending on `type`: | ||||
| changes: | ||||
| - version: | ||||
| - REPLACEME | ||||
| pr-url: https://github.com/nodejs/node/pull/59349 | ||||
| description: Added optional `options.type` parameter to `getCACertificates()`. | ||||
| --> | ||||
|
|
||||
| * `options` {string|Object|undefined} | ||||
jasnell marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| Optional. If a string, it is treated as the `type` of certificates to return. | ||||
| If an object, it may contain: | ||||
| * `type` {string} The type of CA certificates to return. One of `"default"`, `"system"`, `"bundled"`, or `"extra"`. | ||||
| **Default:** `"default"`. | ||||
| * `format` {string} The format of returned certificates. One of `"pem"`, `"der"`, or `"x509"`. | ||||
| **Default:** `"pem"`. | ||||
| * `"pem"` (alias: `"string"`): Returns an array of PEM-encoded certificate strings. | ||||
| * `"der"` (alias: `"buffer"`): Returns an array of certificate data as `Buffer` objects in DER format. | ||||
| * `"x509"`: Returns an array of [`X509Certificate`][x509certificate] instances. | ||||
|
|
||||
| * Returns: {Array} | ||||
| An array of certificate data in the specified format: | ||||
| * PEM strings when `format` is `"pem"` (or `"string"`). | ||||
| * `Buffer` objects containing DER data when `format` is `"der"` (or `"buffer"`). | ||||
| * [`X509Certificate`][x509certificate] instances when `format` is `"x509"`. | ||||
|
|
||||
| * `"default"`: return the CA certificates that will be used by the Node.js TLS clients by default. | ||||
| * When [`--use-bundled-ca`][] is enabled (default), or [`--use-openssl-ca`][] is not enabled, | ||||
|
|
@@ -2331,11 +2345,14 @@ Returns an array containing the CA certificates from various sources, depending | |||
| trusted store. | ||||
| * When [`NODE_EXTRA_CA_CERTS`][] is used, this would also include certificates loaded from the specified | ||||
| file. | ||||
|
|
||||
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the white spaces are still there? Can you remove them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I'll remove the white space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joyeecheung Removing that white space will cause a format error in the document..
haramj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
haramj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| if (!common.hasCrypto) | ||
| common.skip('missing crypto'); | ||
|
|
||
| const assert = require('assert'); | ||
| const tls = require('tls'); | ||
| const { X509Certificate } = require('crypto'); | ||
|
|
||
| { | ||
| const certs = tls.getCACertificates({ type: 'default', format: 'x509' }); | ||
| assert.ok(Array.isArray(certs)); | ||
| assert.ok(certs.length > 0); | ||
| for (const cert of certs) { | ||
| assert.ok(cert instanceof X509Certificate); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| const certs = tls.getCACertificates({ type: 'default', format: 'buffer' }); | ||
| assert.ok(Array.isArray(certs)); | ||
| assert.ok(certs.length > 0); | ||
| for (const cert of certs) { | ||
| assert.ok(Buffer.isBuffer(cert)); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| const certs = tls.getCACertificates({ type: 'default' }); | ||
| assert.ok(Array.isArray(certs)); | ||
| assert.ok(certs.length > 0); | ||
| for (const cert of certs) { | ||
| assert.strictEqual(typeof cert, 'string'); | ||
| assert.ok(cert.includes('-----BEGIN CERTIFICATE-----')); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| assert.throws(() => { | ||
| tls.getCACertificates({ type: 'default', format: 'invalid' }); | ||
| }, { | ||
| name: 'TypeError', | ||
| code: 'ERR_INVALID_ARG_VALUE', | ||
| message: /must be one of/ | ||
| }); | ||
| } | ||
|
|
||
| { | ||
| const certs = tls.getCACertificates({ format: 'buffer' }); | ||
| assert.ok(Array.isArray(certs)); | ||
| assert.ok(certs.length > 0); | ||
| for (const cert of certs) { | ||
| assert.ok(Buffer.isBuffer(cert)); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| assert.throws(() => { | ||
| tls.getCACertificates({ type: 'invalid', format: 'buffer' }); | ||
| }, { | ||
| name: 'TypeError', | ||
| code: 'ERR_INVALID_ARG_VALUE', | ||
| message: "The argument 'type' is invalid. Received 'invalid'" | ||
| }); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.