Skip to content

Commit 345c40b

Browse files
committed
tls: getPeerCertificate(detailed)
Add `raw` property to certificate, add mode to output full certificate chain.
1 parent b3ef289 commit 345c40b

File tree

7 files changed

+287
-151
lines changed

7 files changed

+287
-151
lines changed

doc/api/tls.markdown

+9-4
Original file line numberDiff line numberDiff line change
@@ -644,27 +644,32 @@ specified CAs, otherwise `false`
644644
The reason why the peer's certificate has not been verified. This property
645645
becomes available only when `tlsSocket.authorized === false`.
646646

647-
### tlsSocket.getPeerCertificate()
647+
### tlsSocket.getPeerCertificate([ detailed ])
648648

649649
Returns an object representing the peer's certificate. The returned object has
650-
some properties corresponding to the field of the certificate.
650+
some properties corresponding to the field of the certificate. If `detailed`
651+
argument is `true` - the full chain with `issuer` property will be returned,
652+
if `false` - only the top certificate without `issuer` property.
651653

652654
Example:
653655

654-
{ subject:
656+
{ subject:
655657
{ C: 'UK',
656658
ST: 'Acknack Ltd',
657659
L: 'Rhys Jones',
658660
O: 'node.js',
659661
OU: 'Test TLS Certificate',
660662
CN: 'localhost' },
661-
issuer:
663+
issuerInfo:
662664
{ C: 'UK',
663665
ST: 'Acknack Ltd',
664666
L: 'Rhys Jones',
665667
O: 'node.js',
666668
OU: 'Test TLS Certificate',
667669
CN: 'localhost' },
670+
issuer:
671+
{ ... another certificate ... },
672+
raw: < RAW DER buffer >,
668673
valid_from: 'Nov 11 09:52:22 2009 GMT',
669674
valid_to: 'Nov 6 09:52:22 2029 GMT',
670675
fingerprint: '2A:7A:C2:DD:E5:F9:CC:53:72:35:99:7A:02:5A:71:38:52:EC:8A:DF',

lib/_tls_common.js

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) {
134134
return null;
135135

136136
if (c.issuer) c.issuer = tls.parseCertString(c.issuer);
137+
if (c.issuerCertificate && c.issuerCertificate !== c) {
138+
c.issuerCertificate = translatePeerCertificate(c.issuerCertificate);
139+
}
137140
if (c.subject) c.subject = tls.parseCertString(c.subject);
138141
if (c.infoAccess) {
139142
var info = c.infoAccess;

lib/_tls_legacy.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,11 @@ CryptoStream.prototype.__defineGetter__('bytesWritten', function() {
378378
return this.socket ? this.socket.bytesWritten : 0;
379379
});
380380

381-
CryptoStream.prototype.getPeerCertificate = function() {
382-
if (this.pair.ssl)
383-
return common.translatePeerCertificate(this.pair.ssl.getPeerCertificate());
381+
CryptoStream.prototype.getPeerCertificate = function(detailed) {
382+
if (this.pair.ssl) {
383+
return common.translatePeerCertificate(
384+
this.pair.ssl.getPeerCertificate(detailed));
385+
}
384386

385387
return null;
386388
};

lib/_tls_wrap.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -473,9 +473,11 @@ TLSSocket.prototype.setSession = function(session) {
473473
this.ssl.setSession(session);
474474
};
475475

476-
TLSSocket.prototype.getPeerCertificate = function() {
477-
if (this.ssl)
478-
return common.translatePeerCertificate(this.ssl.getPeerCertificate());
476+
TLSSocket.prototype.getPeerCertificate = function(detailed) {
477+
if (this.ssl) {
478+
return common.translatePeerCertificate(
479+
this.ssl.getPeerCertificate(detailed));
480+
}
479481

480482
return null;
481483
};

src/env.h

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ namespace node {
120120
V(ipv6_lc_string, "ipv6") \
121121
V(ipv6_string, "IPv6") \
122122
V(issuer_string, "issuer") \
123+
V(issuercert_string, "issuerCertificate") \
123124
V(kill_signal_string, "killSignal") \
124125
V(mac_string, "mac") \
125126
V(mark_sweep_compact_string, "mark-sweep-compact") \
@@ -169,6 +170,7 @@ namespace node {
169170
V(priority_string, "priority") \
170171
V(processed_string, "processed") \
171172
V(prototype_string, "prototype") \
173+
V(raw_string, "raw") \
172174
V(rdev_string, "rdev") \
173175
V(readable_string, "readable") \
174176
V(received_shutdown_string, "receivedShutdown") \

0 commit comments

Comments
 (0)