|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= < [email protected]> |
| 3 | +Date: Wed, 19 Jan 2022 19:05:53 +0000 |
| 4 | +Subject: crypto: change default check(Host|Email) behavior |
| 5 | + |
| 6 | +This changes the default behavior of the X509Certificate functions |
| 7 | +checkHost and checkEmail to match the default behavior of OpenSSL's |
| 8 | +X509_check_host and X509_check_email functions, respectively, which |
| 9 | +is also what RFC 2818 mandates for HTTPS. |
| 10 | + |
| 11 | +Refs: https://github.com./nodejs/node/pull/36804 |
| 12 | +Refs: https://github.com./nodejs/node/pull/41569 |
| 13 | + |
| 14 | +PR-URL: https://github.com./nodejs/node/pull/41600 |
| 15 | +Reviewed-By: Matteo Collina < [email protected]> |
| 16 | +Reviewed-By: Rich Trott < [email protected]> |
| 17 | +Reviewed-By: Filip Skokan < [email protected]> |
| 18 | +(cherry picked from commit 18365d8ee6a5fdeb8b46d1a0ec9b954d61ebca7e) |
| 19 | + |
| 20 | +diff --git a/doc/api/crypto.md b/doc/api/crypto.md |
| 21 | +index dff4142fd4a5e29c744b2e849b66b65088d4002b..175d89f54acb991d8f36230aacbfd0b46168a5dd 100644 |
| 22 | +--- a/doc/api/crypto.md |
| 23 | ++++ b/doc/api/crypto.md |
| 24 | +@@ -2511,14 +2511,14 @@ changes: |
| 25 | + |
| 26 | + Checks whether the certificate matches the given email address. |
| 27 | + |
| 28 | ++If the `'subject'` option is undefined or set to `'default'`, the certificate |
| 29 | ++subject is only considered if the subject alternative name extension either does |
| 30 | ++not exist or does not contain any email addresses. |
| 31 | ++ |
| 32 | + If the `'subject'` option is set to `'always'` and if the subject alternative |
| 33 | + name extension either does not exist or does not contain a matching email |
| 34 | + address, the certificate subject is considered. |
| 35 | + |
| 36 | +-If the `'subject'` option is set to `'default'`, the certificate subject is only |
| 37 | +-considered if the subject alternative name extension either does not exist or |
| 38 | +-does not contain any email addresses. |
| 39 | +- |
| 40 | + If the `'subject'` option is set to `'never'`, the certificate subject is never |
| 41 | + considered, even if the certificate contains no subject alternative names. |
| 42 | + |
| 43 | +@@ -2535,7 +2535,7 @@ changes: |
| 44 | + * `name` {string} |
| 45 | + * `options` {Object} |
| 46 | + * `subject` {string} `'default'`, `'always'`, or `'never'`. |
| 47 | +- **Default:** `'always'`. |
| 48 | ++ **Default:** `'default'`. |
| 49 | + * `wildcards` {boolean} **Default:** `true`. |
| 50 | + * `partialWildcards` {boolean} **Default:** `true`. |
| 51 | + * `multiLabelWildcards` {boolean} **Default:** `false`. |
| 52 | +@@ -2551,15 +2551,15 @@ or it might contain wildcards (e.g., `*.example.com`). Because host name |
| 53 | + comparisons are case-insensitive, the returned subject name might also differ |
| 54 | + from the given `name` in capitalization. |
| 55 | + |
| 56 | ++If the `'subject'` option is undefined or set to `'default'`, the certificate |
| 57 | ++subject is only considered if the subject alternative name extension either does |
| 58 | ++not exist or does not contain any DNS names. This behavior is consistent with |
| 59 | ++[RFC 2818][] ("HTTP Over TLS"). |
| 60 | ++ |
| 61 | + If the `'subject'` option is set to `'always'` and if the subject alternative |
| 62 | + name extension either does not exist or does not contain a matching DNS name, |
| 63 | + the certificate subject is considered. |
| 64 | + |
| 65 | +-If the `'subject'` option is set to `'default'`, the certificate subject is only |
| 66 | +-considered if the subject alternative name extension either does not exist or |
| 67 | +-does not contain any DNS names. This behavior is consistent with [RFC 2818][] |
| 68 | +-("HTTP Over TLS"). |
| 69 | +- |
| 70 | + If the `'subject'` option is set to `'never'`, the certificate subject is never |
| 71 | + considered, even if the certificate contains no subject alternative names. |
| 72 | + |
| 73 | +diff --git a/lib/internal/crypto/x509.js b/lib/internal/crypto/x509.js |
| 74 | +index cd20f6868da72ccfa65fabdcb572b3e3f2e8a8a5..e7098d17da6aacf4912fcca001702e3f43689548 100644 |
| 75 | +--- a/lib/internal/crypto/x509.js |
| 76 | ++++ b/lib/internal/crypto/x509.js |
| 77 | +@@ -65,8 +65,7 @@ function isX509Certificate(value) { |
| 78 | + function getFlags(options = {}) { |
| 79 | + validateObject(options, 'options'); |
| 80 | + const { |
| 81 | +- // TODO(tniessen): change the default to 'default' |
| 82 | +- subject = 'always', // Can be 'default', 'always', or 'never' |
| 83 | ++ subject = 'default', // Can be 'default', 'always', or 'never' |
| 84 | + wildcards = true, |
| 85 | + partialWildcards = true, |
| 86 | + multiLabelWildcards = false, |
| 87 | +diff --git a/test/parallel/test-x509-escaping.js b/test/parallel/test-x509-escaping.js |
| 88 | +index 99418e4c0bf21c26d5ba0ad9d617419abc625593..4e88d324cd3d5abe6b056d32ea40969531d31639 100644 |
| 89 | +--- a/test/parallel/test-x509-escaping.js |
| 90 | ++++ b/test/parallel/test-x509-escaping.js |
| 91 | +@@ -425,7 +425,7 @@ const { hasOpenSSL3 } = common; |
| 92 | + assert.strictEqual(certX509.subjectAltName, 'DNS:evil.example.com'); |
| 93 | + |
| 94 | + // The newer X509Certificate API allows customizing this behavior: |
| 95 | +- assert.strictEqual(certX509.checkHost(servername), servername); |
| 96 | ++ assert.strictEqual(certX509.checkHost(servername), undefined); |
| 97 | + assert.strictEqual(certX509.checkHost(servername, { subject: 'default' }), |
| 98 | + undefined); |
| 99 | + assert.strictEqual(certX509.checkHost(servername, { subject: 'always' }), |
0 commit comments