Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf868fd

Browse filesBrowse files
bnoordhuisRafaelGSS
authored andcommitted
tls: add "ca" property to certificate object
The objects returned by getPeerCertificate() now have an additional "ca" boolean property that indicates whether the certificate is a Certificate Authority certificate or not. Fixes: #44905 PR-URL: #44935 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 0e9bad9 commit bf868fd
Copy full SHA for bf868fd

File tree

Expand file treeCollapse file tree

4 files changed

+12
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+12
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/tls.md‎

Copy file name to clipboardExpand all lines: doc/api/tls.md
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,9 @@ certificate.
11731173

11741174
<!-- YAML
11751175
changes:
1176+
- version: REPLACEME
1177+
pr-url: https://github.com/nodejs/node/pull/44935
1178+
description: Add "ca" property.
11761179
- version:
11771180
- v17.2.0
11781181
- v16.14.0
@@ -1186,6 +1189,7 @@ changes:
11861189
A certificate object has properties corresponding to the fields of the
11871190
certificate.
11881191

1192+
* `ca` {boolean} `true` if a Certificate Authority (CA), `false` otherwise.
11891193
* `raw` {Buffer} The DER encoded X.509 certificate data.
11901194
* `subject` {Object} The certificate subject, described in terms of
11911195
Country (`C`), StateOrProvince (`ST`), Locality (`L`), Organization (`O`),
Collapse file

‎src/crypto/crypto_common.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_common.cc
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace node {
2727
using v8::Array;
2828
using v8::ArrayBuffer;
2929
using v8::BackingStore;
30+
using v8::Boolean;
3031
using v8::Context;
3132
using v8::EscapableHandleScope;
3233
using v8::Integer;
@@ -1260,6 +1261,8 @@ MaybeLocal<Object> X509ToObject(
12601261
BIOPointer bio(BIO_new(BIO_s_mem()));
12611262
CHECK(bio);
12621263

1264+
// X509_check_ca() returns a range of values. Only 1 means "is a CA"
1265+
auto is_ca = Boolean::New(env->isolate(), 1 == X509_check_ca(cert));
12631266
if (!Set<Value>(context,
12641267
info,
12651268
env->subject_string(),
@@ -1275,7 +1278,8 @@ MaybeLocal<Object> X509ToObject(
12751278
!Set<Value>(context,
12761279
info,
12771280
env->infoaccess_string(),
1278-
GetInfoAccessString(env, bio, cert))) {
1281+
GetInfoAccessString(env, bio, cert)) ||
1282+
!Set<Boolean>(context, info, env->ca_string(), is_ca)) {
12791283
return MaybeLocal<Object>();
12801284
}
12811285

Collapse file

‎src/env_properties.h‎

Copy file name to clipboardExpand all lines: src/env_properties.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
V(bytes_parsed_string, "bytesParsed") \
5858
V(bytes_read_string, "bytesRead") \
5959
V(bytes_written_string, "bytesWritten") \
60+
V(ca_string, "ca") \
6061
V(cached_data_produced_string, "cachedDataProduced") \
6162
V(cached_data_rejected_string, "cachedDataRejected") \
6263
V(cached_data_string, "cachedData") \
Collapse file

‎test/parallel/test-tls-peer-certificate.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-tls-peer-certificate.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ connect({
5252
debug('peerCert:\n', peerCert);
5353

5454
assert.ok(peerCert.issuerCertificate);
55+
assert.strictEqual(peerCert.ca, false);
56+
assert.strictEqual(peerCert.issuerCertificate.ca, true);
5557
assert.strictEqual(peerCert.subject.emailAddress, 'ry@tinyclouds.org');
5658
assert.strictEqual(peerCert.serialNumber, '147D36C1C2F74206DE9FAB5F2226D78ADB00A426');
5759
assert.strictEqual(peerCert.exponent, '0x10001');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.