| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e264c5c commit 4be8abe
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1404,23 +1404,24 @@ what this endpoint advertises to the peer as its own maximum. | |||
| 1404 | 1404 | added: REPLACEME | |
| 1405 | 1405 | --> | |
| 1406 | 1406 | ||
| 1407 | - * Type: {Object|undefined} | ||
| 1407 | + * Type: {crypto.X509Certificate|undefined} | ||
| 1408 | 1408 | ||
| 1409 | - The local certificate as an object with properties such as `subject`, | ||
| 1410 | - `issuer`, `valid_from`, `valid_to`, `fingerprint`, etc. Returns `undefined` | ||
| 1411 | - if the session is destroyed or no certificate is available. | ||
| 1409 | + The local certificate as a [`crypto.X509Certificate`][] instance. Server | ||
| 1410 | + sessions return the certificate configured for the negotiated SNI host. | ||
| 1411 | + Client sessions return `undefined` unless a client certificate was sent. | ||
| 1412 | + Returns `undefined` if the session is destroyed. | ||
| 1412 | 1413 | ||
| 1413 | 1414 | ### `session.peerCertificate` | |
| 1414 | 1415 | ||
| 1415 | 1416 | <!-- YAML | |
| 1416 | 1417 | added: REPLACEME | |
| 1417 | 1418 | --> | |
| 1418 | 1419 | ||
| 1419 | - * Type: {Object|undefined} | ||
| 1420 | + * Type: {crypto.X509Certificate|undefined} | ||
| 1420 | 1421 | ||
| 1421 | - The peer's certificate as an object with properties such as `subject`, | ||
| 1422 | - `issuer`, `valid_from`, `valid_to`, `fingerprint`, etc. Returns `undefined` | ||
| 1423 | - if the session is destroyed or the peer did not present a certificate. | ||
| 1422 | + The peer's certificate as a [`crypto.X509Certificate`][] instance. Returns | ||
| 1423 | + `undefined` if the peer did not present a certificate or the session is | ||
| 1424 | + destroyed. | ||
| 1424 | 1425 | ||
| 1425 | 1426 | ### `session.ephemeralKeyInfo` | |
| 1426 | 1427 | ||
@@ -4422,6 +4423,7 @@ throughput issues caused by flow control. | |||
| 4422 | 4423 | [`application.enableConnectProtocol`]: #sessionoptionsapplication | |
| 4423 | 4424 | [`application.enableDatagrams`]: #sessionoptionsapplication | |
| 4424 | 4425 | [`application.qpackMaxDTableCapacity`]: #sessionoptionsapplication | |
| 4426 | + [`crypto.X509Certificate`]: crypto.md#class-x509certificate | ||
| 4425 | 4427 | [`endpoint.busy`]: #endpointbusy | |
| 4426 | 4428 | [`endpoint.maxConnectionsPerHost`]: #endpointmaxconnectionsperhost | |
| 4427 | 4429 | [`endpoint.maxConnectionsTotal`]: #endpointmaxconnectionstotal | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -152,6 +152,10 @@ const { | |||
| 152 | 152 | isKeyObject, | |
| 153 | 153 | } = require('internal/crypto/keys'); | |
| 154 | 154 | ||
| 155 | + const { | ||
| 156 | + InternalX509Certificate, | ||
| 157 | + } = require('internal/crypto/x509'); | ||
| 158 | + | ||
| 155 | 159 | const { | |
| 156 | 160 | FileHandle, | |
| 157 | 161 | kHandle: kFileHandle, | |
@@ -3180,24 +3184,37 @@ class QuicSession { | |||
| 3180 | 3184 | } | |
| 3181 | 3185 | ||
| 3182 | 3186 | /** | |
| 3183 | - * The local certificate as an object, or undefined if not available. | ||
| 3184 | - * @type {object|undefined} | ||
| 3187 | + * The local certificate as a {@link crypto.X509Certificate}, or undefined | ||
| 3188 | + * if no local certificate is available. Server sessions return their | ||
| 3189 | + * configured certificate; client sessions return undefined unless a | ||
| 3190 | + * client certificate was sent. | ||
| 3191 | + * @type {crypto.X509Certificate|undefined} | ||
| 3185 | 3192 | */ | |
| 3186 | 3193 | get certificate() { | |
| 3187 | 3194 | assertIsQuicSession(this); | |
| 3188 | 3195 | if (this.destroyed) return undefined; | |
| 3189 | - return this.#inner.certificate ??= this.#handle.getCertificate(); | ||
| 3196 | + if (this.#inner.certificate === undefined) { | ||
| 3197 | + const handle = this.#handle.getCertificate(); | ||
| 3198 | + this.#inner.certificate = handle ? new InternalX509Certificate(handle) : null; | ||
| 3199 | + } | ||
| 3200 | + return this.#inner.certificate ?? undefined; | ||
| 3190 | 3201 | } | |
| 3191 | 3202 | ||
| 3192 | 3203 | /** | |
| 3193 | - * The peer's certificate as an object, or undefined if the peer did | ||
| 3194 | - * not present a certificate or the session is destroyed. | ||
| 3195 | - * @type {object|undefined} | ||
| 3204 | + * The peer's certificate as a {@link crypto.X509Certificate}, or undefined | ||
| 3205 | + * if the peer did not present a certificate or the session is destroyed. | ||
| 3206 | + * @type {crypto.X509Certificate|undefined} | ||
| 3196 | 3207 | */ | |
| 3197 | 3208 | get peerCertificate() { | |
| 3198 | 3209 | assertIsQuicSession(this); | |
| 3199 | 3210 | if (this.destroyed) return undefined; | |
| 3200 | - return this.#inner.peerCertificate ??= this.#handle.getPeerCertificate(); | ||
| 3211 | + if (this.#inner.peerCertificate === undefined) { | ||
| 3212 | + const handle = this.#handle.getPeerCertificate(); | ||
| 3213 | + this.#inner.peerCertificate = handle ? | ||
| 3214 | + new InternalX509Certificate(handle) : | ||
| 3215 | + null; | ||
| 3216 | + } | ||
| 3217 | + return this.#inner.peerCertificate ?? undefined; | ||
| 3201 | 3218 | } | |
| 3202 | 3219 | ||
| 3203 | 3220 | /** | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,11 +11,20 @@ | |||
| 11 | 11 | // All three cached. | |
| 12 | 12 | // All three return undefined after destroy. | |
| 13 | 13 | ||
| 14 | - import { hasQuic, skip, mustCall } from '../common/index.mjs'; | ||
| 14 | + import { hasQuic, skip, mustCall, hasCrypto } from '../common/index.mjs'; | ||
| 15 | + import * as fixtures from '../common/fixtures.mjs'; | ||
| 15 | 16 | import assert from 'node:assert'; | |
| 16 | 17 | ||
| 17 | 18 | const { ok, strictEqual } = assert; | |
| 18 | 19 | ||
| 20 | + if (!hasCrypto) | ||
| 21 | + skip('missing crypto'); | ||
| 22 | + | ||
| 23 | + const { X509Certificate } = await import('node:crypto'); | ||
| 24 | + | ||
| 25 | + // The QUIC test helpers configure both sides with the agent1 fixture cert, | ||
| 26 | + const expectedCert = new X509Certificate(fixtures.readKey('agent1-cert.pem')); | ||
| 27 | + | ||
| 19 | 28 | if (!hasQuic) { | |
| 20 | 29 | skip('QUIC is not enabled'); | |
| 21 | 30 | } | |
@@ -38,7 +47,10 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => { | |||
| 38 | 47 | ||
| 39 | 48 | // Own certificate. | |
| 40 | 49 | const cert = serverSession.certificate; | |
| 41 | - ok(cert); | ||
| 50 | + ok(cert instanceof X509Certificate); | ||
| 51 | + strictEqual(cert.subject, expectedCert.subject); | ||
| 52 | + strictEqual(cert.issuer, expectedCert.issuer); | ||
| 53 | + strictEqual(cert.fingerprint256, expectedCert.fingerprint256); | ||
| 42 | 54 | ||
| 43 | 55 | // Peer certificate (client's cert — not set in this | |
| 44 | 56 | // test since we don't use verifyClient, so it's undefined). | |
@@ -65,7 +77,10 @@ strictEqual(clientSession.path, path); | |||
| 65 | 77 | ||
| 66 | 78 | // Peer certificate (server's cert). | |
| 67 | 79 | const peerCert = clientSession.peerCertificate; | |
| 68 | - ok(peerCert); | ||
| 80 | + ok(peerCert instanceof X509Certificate); | ||
| 81 | + strictEqual(peerCert.subject, expectedCert.subject); | ||
| 82 | + strictEqual(peerCert.issuer, expectedCert.issuer); | ||
| 83 | + strictEqual(peerCert.fingerprint256, expectedCert.fingerprint256); | ||
| 69 | 84 | ||
| 70 | 85 | // Ephemeral key info (client only). | |
| 71 | 86 | const keyInfo = clientSession.ephemeralKeyInfo; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments