| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2478b47 commit 076ec47
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2471,11 +2471,16 @@ added: v15.6.0 | |||
| 2471 | 2471 | ||
| 2472 | 2472 | <!-- YAML | |
| 2473 | 2473 | added: v15.6.0 | |
| 2474 | + changes: | ||
| 2475 | + - version: REPLACEME | ||
| 2476 | + pr-url: https://github.com/nodejs/node/pull/41569 | ||
| 2477 | + description: The subject option can now be set to `'default'`. | ||
| 2474 | 2478 | --> | |
| 2475 | 2479 | ||
| 2476 | 2480 | * `email` {string} | |
| 2477 | 2481 | * `options` {Object} | |
| 2478 | - * `subject` {string} `'always'` or `'never'`. **Default:** `'always'`. | ||
| 2482 | + * `subject` {string} `'default'`, `'always'`, or `'never'`. | ||
| 2483 | + **Default:** `'always'`. | ||
| 2479 | 2484 | * `wildcards` {boolean} **Default:** `true`. | |
| 2480 | 2485 | * `partialWildcards` {boolean} **Default:** `true`. | |
| 2481 | 2486 | * `multiLabelWildcards` {boolean} **Default:** `false`. | |
@@ -2485,15 +2490,31 @@ added: v15.6.0 | |||
| 2485 | 2490 | ||
| 2486 | 2491 | Checks whether the certificate matches the given email address. | |
| 2487 | 2492 | ||
| 2493 | + If the `'subject'` option is set to `'always'` and if the subject alternative | ||
| 2494 | + name extension either does not exist or does not contain a matching email | ||
| 2495 | + address, the certificate subject is considered. | ||
| 2496 | + | ||
| 2497 | + If the `'subject'` option is set to `'default`', the certificate subject is only | ||
| 2498 | + considered if the subject alternative name extension either does not exist or | ||
| 2499 | + does not contain any email addresses. | ||
| 2500 | + | ||
| 2501 | + If the `'subject'` option is set to `'never'`, the certificate subject is never | ||
| 2502 | + considered, even if the certificate contains no subject alternative names. | ||
| 2503 | + | ||
| 2488 | 2504 | ### `x509.checkHost(name[, options])` | |
| 2489 | 2505 | ||
| 2490 | 2506 | <!-- YAML | |
| 2491 | 2507 | added: v15.6.0 | |
| 2508 | + changes: | ||
| 2509 | + - version: REPLACEME | ||
| 2510 | + pr-url: https://github.com/nodejs/node/pull/41569 | ||
| 2511 | + description: The subject option can now be set to `'default'`. | ||
| 2492 | 2512 | --> | |
| 2493 | 2513 | ||
| 2494 | 2514 | * `name` {string} | |
| 2495 | 2515 | * `options` {Object} | |
| 2496 | - * `subject` {string} `'always'` or `'never'`. **Default:** `'always'`. | ||
| 2516 | + * `subject` {string} `'default'`, `'always'`, or `'never'`. | ||
| 2517 | + **Default:** `'always'`. | ||
| 2497 | 2518 | * `wildcards` {boolean} **Default:** `true`. | |
| 2498 | 2519 | * `partialWildcards` {boolean} **Default:** `true`. | |
| 2499 | 2520 | * `multiLabelWildcards` {boolean} **Default:** `false`. | |
@@ -2509,6 +2530,18 @@ or it might contain wildcards (e.g., `*.example.com`). Because host name | |||
| 2509 | 2530 | comparisons are case-insensitive, the returned subject name might also differ | |
| 2510 | 2531 | from the given `name` in capitalization. | |
| 2511 | 2532 | ||
| 2533 | + If the `'subject'` option is set to `'always'` and if the subject alternative | ||
| 2534 | + name extension either does not exist or does not contain a matching DNS name, | ||
| 2535 | + the certificate subject is considered. | ||
| 2536 | + | ||
| 2537 | + If the `'subject'` option is set to `'default'`, the certificate subject is only | ||
| 2538 | + considered if the subject alternative name extension either does not exist or | ||
| 2539 | + does not contain any DNS names. This behavior is consistent with [RFC 2818][] | ||
| 2540 | + ("HTTP Over TLS"). | ||
| 2541 | + | ||
| 2542 | + If the `'subject'` option is set to `'never'`, the certificate subject is never | ||
| 2543 | + considered, even if the certificate contains no subject alternative names. | ||
| 2544 | + | ||
| 2512 | 2545 | ### `x509.checkIP(ip[, options])` | |
| 2513 | 2546 | ||
| 2514 | 2547 | <!-- YAML | |
@@ -5933,6 +5966,7 @@ See the [list of SSL OP Flags][] for details. | |||
| 5933 | 5966 | [OpenSSL's SPKAC implementation]: https://www.openssl.org/docs/man1.1.0/apps/openssl-spkac.html | |
| 5934 | 5967 | [RFC 1421]: https://www.rfc-editor.org/rfc/rfc1421.txt | |
| 5935 | 5968 | [RFC 2412]: https://www.rfc-editor.org/rfc/rfc2412.txt | |
| 5969 | + [RFC 2818]: https://www.rfc-editor.org/rfc/rfc2818.txt | ||
| 5936 | 5970 | [RFC 3526]: https://www.rfc-editor.org/rfc/rfc3526.txt | |
| 5937 | 5971 | [RFC 3610]: https://www.rfc-editor.org/rfc/rfc3610.txt | |
| 5938 | 5972 | [RFC 4055]: https://www.rfc-editor.org/rfc/rfc4055.txt | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,8 @@ function isX509Certificate(value) { | |||
| 65 | 65 | function getFlags(options = {}) { | |
| 66 | 66 | validateObject(options, 'options'); | |
| 67 | 67 | const { | |
| 68 | - subject = 'always', // Can be 'always' or 'never' | ||
| 68 | + // TODO(tniessen): change the default to 'default' | ||
| 69 | + subject = 'always', // Can be 'default', 'always', or 'never' | ||
| 69 | 70 | wildcards = true, | |
| 70 | 71 | partialWildcards = true, | |
| 71 | 72 | multiLabelWildcards = false, | |
@@ -78,6 +79,7 @@ function getFlags(options = {}) { | |||
| 78 | 79 | validateBoolean(multiLabelWildcards, 'options.multiLabelWildcards'); | |
| 79 | 80 | validateBoolean(singleLabelSubdomains, 'options.singleLabelSubdomains'); | |
| 80 | 81 | switch (subject) { | |
| 82 | + case 'default': /* Matches OpenSSL's default, no flags. */ break; | ||
| 81 | 83 | case 'always': flags |= X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT; break; | |
| 82 | 84 | case 'never': flags |= X509_CHECK_FLAG_NEVER_CHECK_SUBJECT; break; | |
| 83 | 85 | default: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -424,6 +424,15 @@ const { hasOpenSSL3 } = common; | |||
| 424 | 424 | assert.strictEqual(certX509.subject, `CN=${servername}`); | |
| 425 | 425 | assert.strictEqual(certX509.subjectAltName, 'DNS:evil.example.com'); | |
| 426 | 426 | ||
| 427 | + // The newer X509Certificate API allows customizing this behavior: | ||
| 428 | + assert.strictEqual(certX509.checkHost(servername), servername); | ||
| 429 | + assert.strictEqual(certX509.checkHost(servername, { subject: 'default' }), | ||
| 430 | + undefined); | ||
| 431 | + assert.strictEqual(certX509.checkHost(servername, { subject: 'always' }), | ||
| 432 | + servername); | ||
| 433 | + assert.strictEqual(certX509.checkHost(servername, { subject: 'never' }), | ||
| 434 | + undefined); | ||
| 435 | + | ||
| 427 | 436 | // Try connecting to a server that uses the self-signed certificate. | |
| 428 | 437 | const server = tls.createServer({ key, cert }, common.mustNotCall()); | |
| 429 | 438 | server.listen(common.mustCall(() => { | |
@@ -454,6 +463,15 @@ const { hasOpenSSL3 } = common; | |||
| 454 | 463 | assert.strictEqual(certX509.subject, `CN=${servername}`); | |
| 455 | 464 | assert.strictEqual(certX509.subjectAltName, 'IP Address:1.2.3.4'); | |
| 456 | 465 | ||
| 466 | + // The newer X509Certificate API allows customizing this behavior: | ||
| 467 | + assert.strictEqual(certX509.checkHost(servername), servername); | ||
| 468 | + assert.strictEqual(certX509.checkHost(servername, { subject: 'default' }), | ||
| 469 | + servername); | ||
| 470 | + assert.strictEqual(certX509.checkHost(servername, { subject: 'always' }), | ||
| 471 | + servername); | ||
| 472 | + assert.strictEqual(certX509.checkHost(servername, { subject: 'never' }), | ||
| 473 | + undefined); | ||
| 474 | + | ||
| 457 | 475 | // Connect to a server that uses the self-signed certificate. | |
| 458 | 476 | const server = tls.createServer({ key, cert }, common.mustCall((socket) => { | |
| 459 | 477 | socket.destroy(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments