File tree Expand file tree Collapse file tree 8 files changed +136
-28
lines changed
Expand file tree Collapse file tree 8 files changed +136
-28
lines changed Original file line number Diff line number Diff line change @@ -314,6 +314,33 @@ import {
314314 const r00ts : readonly string [ ] = rootCertificates ;
315315}
316316
317+ // Certificate DN fields are optional and can be string or string[] (multi-valued)
318+ {
319+ const tlsSocket = connect ( { } ) ;
320+ const peerCert = tlsSocket . getPeerCertificate ( ) ;
321+ const subject = peerCert . subject ;
322+
323+ // Fields are optional and may be string or string[]
324+ const cn : string | string [ ] | undefined = subject . CN ;
325+ const ou : string | string [ ] | undefined = subject . OU ;
326+ const o : string | string [ ] | undefined = subject . O ;
327+
328+ // Type narrowing with Array.isArray
329+ if ( Array . isArray ( subject . OU ) ) {
330+ const ous : string [ ] = subject . OU ;
331+ } else {
332+ const ou : string | undefined = subject . OU ;
333+ }
334+
335+ // Arbitrary DN attributes via index signature
336+ const email : string | string [ ] | undefined = subject [ "emailAddress" ] ;
337+ const dc : string | string [ ] | undefined = subject [ "DC" ] ;
338+
339+ // Issuer has the same shape
340+ const issuer = peerCert . issuer ;
341+ const issuerCN : string | string [ ] | undefined = issuer . CN ;
342+ }
343+
317344{
318345 const _options : TlsOptions = { } ;
319346 const _server = new Server ( _options , ( socket ) => { } ) ;
Original file line number Diff line number Diff line change @@ -15,31 +15,31 @@ declare module "node:tls" {
1515 import * as stream from "stream" ;
1616 const CLIENT_RENEG_LIMIT : number ;
1717 const CLIENT_RENEG_WINDOW : number ;
18- interface Certificate {
18+ interface Certificate extends NodeJS . Dict < string | string [ ] > {
1919 /**
2020 * Country code.
2121 */
22- C : string ;
22+ C ? : string | string [ ] ;
2323 /**
2424 * Street.
2525 */
26- ST : string ;
26+ ST ? : string | string [ ] ;
2727 /**
2828 * Locality.
2929 */
30- L : string ;
30+ L ? : string | string [ ] ;
3131 /**
3232 * Organization.
3333 */
34- O : string ;
34+ O ? : string | string [ ] ;
3535 /**
3636 * Organizational unit.
3737 */
38- OU : string ;
38+ OU ? : string | string [ ] ;
3939 /**
4040 * Common name.
4141 */
42- CN : string ;
42+ CN ? : string | string [ ] ;
4343 }
4444 interface PeerCertificate {
4545 /**
Original file line number Diff line number Diff line change @@ -325,6 +325,33 @@ import {
325325 const r00ts : readonly string [ ] = rootCertificates ;
326326}
327327
328+ // Certificate DN fields are optional and can be string or string[] (multi-valued)
329+ {
330+ const tlsSocket = connect ( { } ) ;
331+ const peerCert = tlsSocket . getPeerCertificate ( ) ;
332+ const subject = peerCert . subject ;
333+
334+ // Fields are optional and may be string or string[]
335+ const cn : string | string [ ] | undefined = subject . CN ;
336+ const ou : string | string [ ] | undefined = subject . OU ;
337+ const o : string | string [ ] | undefined = subject . O ;
338+
339+ // Type narrowing with Array.isArray
340+ if ( Array . isArray ( subject . OU ) ) {
341+ const ous : string [ ] = subject . OU ;
342+ } else {
343+ const ou : string | undefined = subject . OU ;
344+ }
345+
346+ // Arbitrary DN attributes via index signature
347+ const email : string | string [ ] | undefined = subject [ "emailAddress" ] ;
348+ const dc : string | string [ ] | undefined = subject [ "DC" ] ;
349+
350+ // Issuer has the same shape
351+ const issuer = peerCert . issuer ;
352+ const issuerCN : string | string [ ] | undefined = issuer . CN ;
353+ }
354+
328355{
329356 const _options : TlsOptions = { } ;
330357 const _server = new Server ( _options , ( socket ) => { } ) ;
Original file line number Diff line number Diff line change @@ -15,31 +15,31 @@ declare module "tls" {
1515 import * as stream from "stream" ;
1616 const CLIENT_RENEG_LIMIT : number ;
1717 const CLIENT_RENEG_WINDOW : number ;
18- interface Certificate {
18+ interface Certificate extends NodeJS . Dict < string | string [ ] > {
1919 /**
2020 * Country code.
2121 */
22- C : string ;
22+ C ? : string | string [ ] ;
2323 /**
2424 * Street.
2525 */
26- ST : string ;
26+ ST ? : string | string [ ] ;
2727 /**
2828 * Locality.
2929 */
30- L : string ;
30+ L ? : string | string [ ] ;
3131 /**
3232 * Organization.
3333 */
34- O : string ;
34+ O ? : string | string [ ] ;
3535 /**
3636 * Organizational unit.
3737 */
38- OU : string ;
38+ OU ? : string | string [ ] ;
3939 /**
4040 * Common name.
4141 */
42- CN : string ;
42+ CN ? : string | string [ ] ;
4343 }
4444 interface PeerCertificate {
4545 /**
Original file line number Diff line number Diff line change @@ -329,6 +329,33 @@ import {
329329 const r00ts : readonly string [ ] = rootCertificates ;
330330}
331331
332+ // Certificate DN fields are optional and can be string or string[] (multi-valued)
333+ {
334+ const tlsSocket = connect ( { } ) ;
335+ const peerCert = tlsSocket . getPeerCertificate ( ) ;
336+ const subject = peerCert . subject ;
337+
338+ // Fields are optional and may be string or string[]
339+ const cn : string | string [ ] | undefined = subject . CN ;
340+ const ou : string | string [ ] | undefined = subject . OU ;
341+ const o : string | string [ ] | undefined = subject . O ;
342+
343+ // Type narrowing with Array.isArray
344+ if ( Array . isArray ( subject . OU ) ) {
345+ const ous : string [ ] = subject . OU ;
346+ } else {
347+ const ou : string | undefined = subject . OU ;
348+ }
349+
350+ // Arbitrary DN attributes via index signature
351+ const email : string | string [ ] | undefined = subject [ "emailAddress" ] ;
352+ const dc : string | string [ ] | undefined = subject [ "DC" ] ;
353+
354+ // Issuer has the same shape
355+ const issuer = peerCert . issuer ;
356+ const issuerCN : string | string [ ] | undefined = issuer . CN ;
357+ }
358+
332359{
333360 const _options : TlsOptions = { } ;
334361 const _server = new Server ( _options , ( socket ) => { } ) ;
Original file line number Diff line number Diff line change @@ -15,31 +15,31 @@ declare module "tls" {
1515 import * as stream from "stream" ;
1616 const CLIENT_RENEG_LIMIT : number ;
1717 const CLIENT_RENEG_WINDOW : number ;
18- interface Certificate {
18+ interface Certificate extends NodeJS . Dict < string | string [ ] > {
1919 /**
2020 * Country code.
2121 */
22- C : string ;
22+ C ? : string | string [ ] ;
2323 /**
2424 * Street.
2525 */
26- ST : string ;
26+ ST ? : string | string [ ] ;
2727 /**
2828 * Locality.
2929 */
30- L : string ;
30+ L ? : string | string [ ] ;
3131 /**
3232 * Organization.
3333 */
34- O : string ;
34+ O ? : string | string [ ] ;
3535 /**
3636 * Organizational unit.
3737 */
38- OU : string ;
38+ OU ? : string | string [ ] ;
3939 /**
4040 * Common name.
4141 */
42- CN : string ;
42+ CN ? : string | string [ ] ;
4343 }
4444 interface PeerCertificate {
4545 /**
Original file line number Diff line number Diff line change @@ -329,6 +329,33 @@ import {
329329 const r00ts : readonly string [ ] = rootCertificates ;
330330}
331331
332+ // Certificate DN fields are optional and can be string or string[] (multi-valued)
333+ {
334+ const tlsSocket = connect ( { } ) ;
335+ const peerCert = tlsSocket . getPeerCertificate ( ) ;
336+ const subject = peerCert . subject ;
337+
338+ // Fields are optional and may be string or string[]
339+ const cn : string | string [ ] | undefined = subject . CN ;
340+ const ou : string | string [ ] | undefined = subject . OU ;
341+ const o : string | string [ ] | undefined = subject . O ;
342+
343+ // Type narrowing with Array.isArray
344+ if ( Array . isArray ( subject . OU ) ) {
345+ const ous : string [ ] = subject . OU ;
346+ } else {
347+ const ou : string | undefined = subject . OU ;
348+ }
349+
350+ // Arbitrary DN attributes via index signature
351+ const email : string | string [ ] | undefined = subject [ "emailAddress" ] ;
352+ const dc : string | string [ ] | undefined = subject [ "DC" ] ;
353+
354+ // Issuer has the same shape
355+ const issuer = peerCert . issuer ;
356+ const issuerCN : string | string [ ] | undefined = issuer . CN ;
357+ }
358+
332359{
333360 const _options : TlsOptions = { } ;
334361 const _server = new Server ( _options , ( socket ) => { } ) ;
Original file line number Diff line number Diff line change @@ -15,31 +15,31 @@ declare module "tls" {
1515 import * as stream from "stream" ;
1616 const CLIENT_RENEG_LIMIT : number ;
1717 const CLIENT_RENEG_WINDOW : number ;
18- interface Certificate {
18+ interface Certificate extends NodeJS . Dict < string | string [ ] > {
1919 /**
2020 * Country code.
2121 */
22- C : string ;
22+ C ? : string | string [ ] ;
2323 /**
2424 * Street.
2525 */
26- ST : string ;
26+ ST ? : string | string [ ] ;
2727 /**
2828 * Locality.
2929 */
30- L : string ;
30+ L ? : string | string [ ] ;
3131 /**
3232 * Organization.
3333 */
34- O : string ;
34+ O ? : string | string [ ] ;
3535 /**
3636 * Organizational unit.
3737 */
38- OU : string ;
38+ OU ? : string | string [ ] ;
3939 /**
4040 * Common name.
4141 */
42- CN : string ;
42+ CN ? : string | string [ ] ;
4343 }
4444 interface PeerCertificate {
4545 /**
You can’t perform that action at this time.
0 commit comments