visaljs 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/THIRD_PARTY_LICENSES +31 -1
- package/cli.js +962 -68
- package/node/include/js_node.h +11 -1
- package/node/prelude/_http_common.js +29 -0
- package/node/prelude/async_hooks.js +50 -11
- package/node/prelude/child_process.js +31 -4
- package/node/prelude/console.js +311 -143
- package/node/prelude/crypto.js +6 -4
- package/node/prelude/dgram.js +1169 -0
- package/node/prelude/diagnostics_channel.js +3 -1
- package/node/prelude/dns.js +250 -45
- package/node/prelude/dns_promises.js +8 -2
- package/node/prelude/fs_promises.js +9 -1
- package/node/prelude/http.js +395 -86
- package/node/prelude/https.js +13 -4
- package/node/prelude/internal/console_class.js +7 -0
- package/node/prelude/internal/console_global.js +25 -0
- package/node/prelude/internal/crypto/key_encryption.js +217 -0
- package/node/prelude/internal/crypto/keys.js +161 -26
- package/node/prelude/internal/crypto/random.js +24 -0
- package/node/prelude/internal/crypto/util.js +2 -1
- package/node/prelude/internal/crypto_x509.js +161 -0
- package/node/prelude/internal/dns_classes.js +6 -0
- package/node/prelude/internal/dns_resolver.js +371 -0
- package/node/prelude/internal/errors.js +9 -0
- package/node/prelude/internal/events_on.js +82 -37
- package/node/prelude/internal/features.js +8 -4
- package/node/prelude/internal/fs_filehandle.js +10 -4
- package/node/prelude/internal/perf_histogram.js +1 -1
- package/node/prelude/internal/process_more.js +32 -17
- package/node/prelude/internal/process_signals.js +8 -2
- package/node/prelude/internal/punycode.ts +163 -0
- package/node/prelude/internal/readline.js +648 -274
- package/node/prelude/internal/readline_editor.js +1240 -0
- package/node/prelude/internal/string_width.js +43 -0
- package/node/prelude/internal/tls/common.js +145 -33
- package/node/prelude/internal/tls/wrap.js +182 -49
- package/node/prelude/internal/tls/x509.js +4 -1
- package/node/prelude/internal/udp.js +177 -0
- package/node/prelude/net.js +13 -1
- package/node/prelude/os.js +24 -6
- package/node/prelude/perf_hooks.js +37 -2
- package/node/prelude/punycode.js +2 -130
- package/node/prelude/readline.js +113 -4
- package/node/prelude/readline_promises.js +56 -32
- package/node/prelude/tls.js +21 -4
- package/node/prelude/util.js +3 -16
- package/node/src/host_dns.c +623 -0
- package/node/src/host_http.c +12 -0
- package/node/src/host_net.c +46 -0
- package/node/src/host_os.c +1 -6
- package/node/src/host_sys.c +70 -0
- package/node/src/host_udp.c +418 -0
- package/node/third_party/c-ares/LICENSE.md +24 -0
- package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
- package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
- package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
- package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
- package/node/third_party/c-ares/include/ares.h +1237 -0
- package/node/third_party/c-ares/include/ares_build.h +202 -0
- package/node/third_party/c-ares/include/ares_dns.h +127 -0
- package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
- package/node/third_party/c-ares/include/ares_nameser.h +510 -0
- package/node/third_party/c-ares/include/ares_version.h +47 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
- package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
- package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
- package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
- package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
- package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
- package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
- package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
- package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
- package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
- package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
- package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
- package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
- package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
- package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
- package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
- package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
- package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
- package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
- package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
- package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
- package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
- package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
- package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
- package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
- package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
- package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
- package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
- package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
- package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
- package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
- package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
- package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
- package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
- package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
- package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
- package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
- package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
- package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
- package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
- package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
- package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
- package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
- package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
- package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
- package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
- package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
- package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
- package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
- package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
- package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
- package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
- package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
- package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
- package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
- package/package.json +1 -1
- package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_builtins.h +5 -0
- package/runtime/include/js_crypto.h +11 -0
- package/runtime/include/js_gc.h +13 -10
- package/runtime/include/js_jobs.h +2 -0
- package/runtime/include/js_object.h +58 -0
- package/runtime/include/jscontext.h +1 -0
- package/runtime/src/crypto_internal.h +1 -0
- package/runtime/src/crypto_subtle.c +66 -7
- package/runtime/src/crypto_tls.c +265 -19
- package/runtime/src/gc.c +73 -92
- package/runtime/src/inspect.c +18 -1
- package/runtime/src/jobs.c +37 -22
- package/runtime/src/object.c +49 -2
- package/runtime/src/os.c +16 -6
- package/runtime/src/os.h +2 -0
- package/runtime/src/process.c +97 -10
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Node's getStringWidth and stripVTControlCharacters (internal/util/inspect): columns on a
|
|
2
|
+
// terminal, wide characters two, combining ones none, escape codes none; console.table, readline
|
|
3
|
+
// and util measure with them.
|
|
4
|
+
import { validateString } from "./errors.js";
|
|
5
|
+
|
|
6
|
+
/* ANSI escape codes, as Node's internal/util/inspect.js matches them: an OSC sequence (a terminal
|
|
7
|
+
hyperlink: ESC ] … BEL) whole, or a CSI sequence */
|
|
8
|
+
const ansi = new RegExp(
|
|
9
|
+
"(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))" +
|
|
10
|
+
"|[\\u001B\\u009B][[\\]()#;?]*" +
|
|
11
|
+
"(?:\\d{1,4}(?:[;:]\\d{0,4})*)?" +
|
|
12
|
+
"[\\dA-PR-TZcf-nq-uy=><~]", "g",
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
/** The string without its ANSI escape codes (colors, cursor movements, …). */
|
|
16
|
+
export function stripVTControlCharacters(str) {
|
|
17
|
+
validateString(str, "str");
|
|
18
|
+
if (!str.includes("\u001B") && !str.includes("\u009B")) return str; /* no escape introducer */
|
|
19
|
+
return str.replace(ansi, "");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const isFullWidthCodePoint = (code) => code >= 0x1100 && (code <= 0x115f || code === 0x2329 || code === 0x232a ||
|
|
24
|
+
(code >= 0x2e80 && code <= 0x3247 && code !== 0x303f) || (code >= 0x3250 && code <= 0x4dbf) || (code >= 0x4e00 && code <= 0xa4c6) ||
|
|
25
|
+
(code >= 0xa960 && code <= 0xa97c) || (code >= 0xac00 && code <= 0xd7a3) || (code >= 0xf900 && code <= 0xfaff) ||
|
|
26
|
+
(code >= 0xfe10 && code <= 0xfe19) || (code >= 0xfe30 && code <= 0xfe6b) || (code >= 0xff01 && code <= 0xff60) ||
|
|
27
|
+
(code >= 0xffe0 && code <= 0xffe6) || (code >= 0x1b000 && code <= 0x1b001) || (code >= 0x1f200 && code <= 0x1f251) ||
|
|
28
|
+
(code >= 0x1f300 && code <= 0x1f64f) || (code >= 0x20000 && code <= 0x3fffd));
|
|
29
|
+
|
|
30
|
+
const isZeroWidthCodePoint = (code) => code <= 0x1f || (code >= 0x7f && code <= 0x9f) || (code >= 0x300 && code <= 0x36f) ||
|
|
31
|
+
(code >= 0x200b && code <= 0x200f) || (code >= 0x20d0 && code <= 0x20ff) || (code >= 0xfe00 && code <= 0xfe0f) ||
|
|
32
|
+
(code >= 0xfe20 && code <= 0xfe2f) || (code >= 0xe0100 && code <= 0xe01ef);
|
|
33
|
+
|
|
34
|
+
export function getStringWidth(str, removeControlChars = true) {
|
|
35
|
+
let width = 0;
|
|
36
|
+
if (removeControlChars) str = stripVTControlCharacters(str);
|
|
37
|
+
for (const char of str.normalize("NFC")) {
|
|
38
|
+
const code = char.codePointAt(0);
|
|
39
|
+
if (isFullWidthCodePoint(code)) width += 2;
|
|
40
|
+
else if (!isZeroWidthCodePoint(code)) width++;
|
|
41
|
+
}
|
|
42
|
+
return width;
|
|
43
|
+
}
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
// as Node shows them: BoringSSL's reasons are OpenSSL's, its numbers aren't).
|
|
5
5
|
// Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
|
|
6
6
|
import {
|
|
7
|
-
fsReadFile, tlsCiphers, tlsContextAddCA, tlsContextAddRoots, tlsContextNew, tlsContextSetCert, tlsContextSetKey,
|
|
7
|
+
fsReadFile, tlsCiphers, tlsContextAddCA, tlsContextAddRoots, tlsContextNew, tlsContextSetCert, tlsContextSetKey, tlsContextSetSessions,
|
|
8
|
+
tlsContextAddCredential, tlsContextAllowPartialChain, tlsContextTicketKeys, tlsPkcs12, x509CheckKey,
|
|
8
9
|
} from "visaljs:host";
|
|
9
|
-
import { codeError, invalidArgType, invalidArgValue, notSupported, validateString } from "../errors.js";
|
|
10
|
+
import { codeError, invalidArgType, invalidArgValue, notSupported, outOfRange, validateInteger, validateString } from "../errors.js";
|
|
10
11
|
import { createPrivateKey } from "../crypto/keys.js";
|
|
11
12
|
import { kHandle } from "../crypto/util.js";
|
|
12
13
|
import { certificatesOf, parseCertificate } from "./x509.js";
|
|
@@ -58,14 +59,18 @@ const SSL_REASONS = {
|
|
|
58
59
|
NO_SHARED_CIPHER: 0xC1, PEER_DID_NOT_RETURN_A_CERTIFICATE: 0xC7, NO_APPLICATION_PROTOCOL: 0xEB,
|
|
59
60
|
UNSUPPORTED_PROTOCOL: 0x102, CERTIFICATE_VERIFY_FAILED: 0x86, NO_CIPHER_MATCH: 0xB9,
|
|
60
61
|
DECRYPTION_FAILED_OR_BAD_RECORD_MAC: 0x119, UNEXPECTED_MESSAGE: 0xF4, UNEXPECTED_RECORD: 0xF5, WRONG_CIPHER_RETURNED: 0x105,
|
|
61
|
-
BAD_SIGNATURE: 0x7B, NO_RENEGOTIATION: 0x153, UNSAFE_LEGACY_RENEGOTIATION_DISABLED: 0x152, RECORD_TOO_LARGE: 0x109,
|
|
62
|
+
BAD_SIGNATURE: 0x7B, NO_SHARED_SIGNATURE_ALGORITHMS: 0x178, NO_RENEGOTIATION: 0x153, UNSAFE_LEGACY_RENEGOTIATION_DISABLED: 0x152, RECORD_TOO_LARGE: 0x109,
|
|
62
63
|
TLSV1_ALERT_INAPPROPRIATE_FALLBACK: 0x480, INAPPROPRIATE_FALLBACK: 0x175, EXCESSIVE_MESSAGE_SIZE: 0x98,
|
|
63
64
|
};
|
|
64
65
|
|
|
66
|
+
/* BoringSSL's names for reasons OpenSSL names otherwise */
|
|
67
|
+
const OPENSSL_NAMES = { NO_COMMON_SIGNATURE_ALGORITHMS: "NO_SHARED_SIGNATURE_ALGORITHMS" };
|
|
68
|
+
|
|
65
69
|
/** The error a BoringSSL failure ([library, reason, name]) is reported as */
|
|
66
70
|
export function tlsFailure(err) {
|
|
67
71
|
if (!Array.isArray(err)) return sslError(0x0A0C0103, "internal error");
|
|
68
|
-
const [, code,
|
|
72
|
+
const [, code, boringName] = err;
|
|
73
|
+
const name = OPENSSL_NAMES[boringName] ?? boringName;
|
|
69
74
|
/* OpenSSL 3.5 calls the SSL 3 alerts "ssl/tls alert …", and TLS 1.3's "tlsv13 alert …" */
|
|
70
75
|
const reasonName = name.replace(/^SSLV3_ALERT_/, "SSL/TLS_ALERT_").replace(/^TLSV1_ALERT_(CERTIFICATE_REQUIRED|MISSING_EXTENSION)$/, "TLSV13_ALERT_$1");
|
|
71
76
|
const number = 0x0A000000 + (code >= 1000 ? code : SSL_REASONS[name] ?? code);
|
|
@@ -159,6 +164,8 @@ export function SecureContext(secureProtocol, secureOptions, minVersion, maxVers
|
|
|
159
164
|
if (maxVersion != null) throw codeError(TypeError, "ERR_TLS_PROTOCOL_VERSION_CONFLICT", `TLS protocol version ${maxVersion} conflicts with secureProtocol ${secureProtocol}`);
|
|
160
165
|
validateString(secureProtocol, "secureProtocol");
|
|
161
166
|
const method = METHODS[secureProtocol];
|
|
167
|
+
const disabled = /^(SSLv[23])_(?:client_|server_)?method$/.exec(secureProtocol);
|
|
168
|
+
if (disabled) throw codeError(TypeError, "ERR_TLS_INVALID_PROTOCOL_METHOD", `${disabled[1]} methods disabled`);
|
|
162
169
|
if (!method) throw codeError(TypeError, "ERR_TLS_INVALID_PROTOCOL_METHOD", `Unknown method: ${secureProtocol}`);
|
|
163
170
|
[min, max] = method;
|
|
164
171
|
} else {
|
|
@@ -184,16 +191,33 @@ function configure(c, options = {}, name = "options") {
|
|
|
184
191
|
if (typeof options !== "object" || options === null) throw invalidArgType(name, "of type object", options);
|
|
185
192
|
const { ca, cert, key, passphrase, pfx, ciphers = defaults.DEFAULT_CIPHERS, ecdhCurve = defaults.DEFAULT_ECDH_CURVE, sigalgs } = options;
|
|
186
193
|
if (ciphers !== undefined && ciphers !== null) validateString(ciphers, `${name}.ciphers`);
|
|
187
|
-
|
|
194
|
+
/* BoringSSL has no security levels, and rejects a list that sets one */
|
|
195
|
+
const list = (ciphers || defaults.DEFAULT_CIPHERS).split(":").map((c) => c.replace(/@SECLEVEL=\d+$/, ""));
|
|
188
196
|
const tls12 = list.filter((c) => c && !c.startsWith("TLS_") && !c.startsWith("!TLS_")).join(":");
|
|
189
197
|
const tls13 = list.filter((c) => c.startsWith("TLS_") || c.startsWith("!TLS_")).join(":");
|
|
190
198
|
if (tls12 === "" && tls13 === "") throw invalidArgValue(`${name}.ciphers`, "is invalid", list);
|
|
199
|
+
/* OpenSSL skips a TLS 1.3 suite it doesn't know, and fails a list of only those */
|
|
200
|
+
const suites = list.filter((c) => c.startsWith("TLS_"));
|
|
201
|
+
if (suites.length > 0 && !suites.some((c) => TLS13_SUITES.includes(c))) throw sslError(0x0A0000B9, "no cipher match");
|
|
191
202
|
if (ecdhCurve !== undefined) validateString(ecdhCurve, `${name}.ecdhCurve`);
|
|
192
203
|
if (sigalgs !== undefined && sigalgs !== null) {
|
|
193
204
|
validateString(sigalgs, `${name}.sigalgs`);
|
|
194
205
|
if (sigalgs === "") throw invalidArgValue(`${name}.sigalgs`, "is invalid", sigalgs);
|
|
195
206
|
}
|
|
196
|
-
|
|
207
|
+
validateEngineOptions(options, name);
|
|
208
|
+
validateCertificateCompression(options.certificateCompression, name);
|
|
209
|
+
const { dhparam, crl, sessionIdContext, ticketKeys, sessionTimeout } = options;
|
|
210
|
+
if (dhparam !== undefined && dhparam !== null) validateKeyOrCertOption(`${name}.dhparam`, dhparam);
|
|
211
|
+
for (const value of crl === undefined || crl === null ? [] : Array.isArray(crl) ? crl : [crl]) validateKeyOrCertOption(`${name}.crl`, value);
|
|
212
|
+
if (sessionIdContext !== undefined && sessionIdContext !== null) validateString(sessionIdContext, `${name}.sessionIdContext`);
|
|
213
|
+
if (ticketKeys !== undefined && ticketKeys !== null) {
|
|
214
|
+
if (!ArrayBuffer.isView(ticketKeys)) throw invalidArgType(`${name}.ticketKeys`, "an instance of Buffer, TypedArray, or DataView", ticketKeys);
|
|
215
|
+
if (ticketKeys.byteLength !== 48) throw invalidArgValue(`${name}.ticketKeys`, "must be exactly 48 bytes", ticketKeys.byteLength);
|
|
216
|
+
}
|
|
217
|
+
if (sessionTimeout !== undefined && sessionTimeout !== null) {
|
|
218
|
+
validateInteger(sessionTimeout, `${name}.sessionTimeout`);
|
|
219
|
+
if (sessionTimeout < 0 || sessionTimeout > 2 ** 31 - 1) throw outOfRange(`${name}.sessionTimeout`, `>= 0 && <= ${2 ** 31 - 1}`, sessionTimeout);
|
|
220
|
+
}
|
|
197
221
|
/* only TLS 1.3 suites given: only TLS 1.3 (Node's rule) */
|
|
198
222
|
if (tls12 === "" && c._minVersion < 0x0304 && c._maxVersion > 0x0303) c._minVersion = 0x0304;
|
|
199
223
|
const groups = ecdhCurve && ecdhCurve !== "auto" ? ecdhCurve : null;
|
|
@@ -204,6 +228,8 @@ function configure(c, options = {}, name = "options") {
|
|
|
204
228
|
throw tlsFailure(context);
|
|
205
229
|
}
|
|
206
230
|
c.context = context;
|
|
231
|
+
if (ticketKeys !== undefined && ticketKeys !== null) tlsContextTicketKeys(context, ticketKeys);
|
|
232
|
+
tlsContextSetSessions(context, sessionTimeout ?? null, sessionIdContext ?? null);
|
|
207
233
|
if (ca) {
|
|
208
234
|
for (const [i, value] of (Array.isArray(ca) ? ca : [ca]).entries()) {
|
|
209
235
|
validateKeyOrCertOption(`${name}.ca${Array.isArray(ca) ? `[${i}]` : ""}`, value);
|
|
@@ -213,37 +239,123 @@ function configure(c, options = {}, name = "options") {
|
|
|
213
239
|
} else {
|
|
214
240
|
addDefaultCAs(c);
|
|
215
241
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
242
|
+
if (options.allowPartialTrustChain) tlsContextAllowPartialChain(context);
|
|
243
|
+
const chains = [];
|
|
244
|
+
for (const [i, value] of (cert ? (Array.isArray(cert) ? cert : [cert]) : []).entries()) {
|
|
245
|
+
validateKeyOrCertOption(`${name}.cert${Array.isArray(cert) ? `[${i}]` : ""}`, value);
|
|
246
|
+
const found = certificatesOf(value);
|
|
247
|
+
if (found.length === 0) throw caLoadError();
|
|
248
|
+
chains.push(found);
|
|
249
|
+
}
|
|
250
|
+
const keys = [];
|
|
251
|
+
for (const k of key ? (Array.isArray(key) ? key : [key]) : []) {
|
|
252
|
+
const pem = k?.pem !== undefined ? k.pem : k;
|
|
253
|
+
const pass = k?.passphrase !== undefined ? k.passphrase : passphrase;
|
|
254
|
+
validateKeyOrCertOption(`${name}.key`, pem);
|
|
255
|
+
if (pass !== undefined && pass !== null) validateString(pass, `${name}.passphrase`);
|
|
256
|
+
keys.push(privateKeyOf(pass === undefined || pass === null ? pem : { key: pem, passphrase: pass }));
|
|
257
|
+
}
|
|
258
|
+
for (const value of pfx === undefined || pfx === null ? [] : Array.isArray(pfx) ? pfx : [pfx]) {
|
|
259
|
+
const [chain, keyObject] = loadPKCS12(c, value.buf || value, value.passphrase || passphrase);
|
|
260
|
+
chains.push(chain);
|
|
261
|
+
keys.push(keyObject);
|
|
262
|
+
}
|
|
263
|
+
setIdentities(c, chains, keys);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function privateKeyOf(key) {
|
|
267
|
+
try {
|
|
268
|
+
return createPrivateKey(key);
|
|
269
|
+
} catch (e) {
|
|
270
|
+
if (e.code === "ERR_VISALJS_UNSUPPORTED") throw e;
|
|
271
|
+
/* OpenSSL reads an encrypted PEM without a passphrase as with a wrong one */
|
|
272
|
+
if (e.code === "ERR_OSSL_BAD_DECRYPT" || e.code === "ERR_OSSL_PEM_BAD_DECRYPT") throw e;
|
|
273
|
+
if (e.code === "ERR_MISSING_PASSPHRASE" || e.code === "ERR_OSSL_CRYPTO_INTERRUPTED_OR_CANCELLED") {
|
|
274
|
+
throw sslError(0x1C800064, "bad decrypt", "Provider routines", "ERR_OSSL_BAD_DECRYPT");
|
|
223
275
|
}
|
|
224
|
-
|
|
225
|
-
if (tlsContextSetCert(c.context, ders) !== 0) throw sslError(0x068000A8, "wrong tag", "asn1 encoding routines", "ERR_OSSL_ASN1_WRONG_TAG");
|
|
226
|
-
c._certs = ders;
|
|
276
|
+
throw sslError(0x1E08010C, "unsupported", "DECODER routines", "ERR_OSSL_UNSUPPORTED");
|
|
227
277
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const keyMismatch = () => sslError(0x05800074, "key values mismatch", "x509 certificate routines", "ERR_OSSL_X509_KEY_VALUES_MISMATCH");
|
|
281
|
+
|
|
282
|
+
function checkKeyResult(r, keyObject) {
|
|
283
|
+
if (r === 2) throw keyMismatch();
|
|
284
|
+
if (r === 1) throw notSupported(`A ${keyObject.asymmetricKeyType} key for TLS`);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/* One key: the certificates given are its chain. More: each is the certificate it belongs to
|
|
288
|
+
* (with that entry's chain), as OpenSSL keeps one identity per key type and chooses by what
|
|
289
|
+
* the client accepts. */
|
|
290
|
+
function setIdentities(c, chains, keys) {
|
|
291
|
+
if (keys.length <= 1) {
|
|
292
|
+
if (chains.length > 0) {
|
|
293
|
+
const ders = chains.flat();
|
|
294
|
+
autoChain(c, ders);
|
|
295
|
+
if (tlsContextSetCert(c.context, ders) !== 0) throw sslError(0x068000A8, "wrong tag", "asn1 encoding routines", "ERR_OSSL_ASN1_WRONG_TAG");
|
|
296
|
+
c._certs = ders;
|
|
245
297
|
}
|
|
298
|
+
if (keys.length === 1) checkKeyResult(tlsContextSetKey(c.context, keys[0][kHandle]), keys[0]);
|
|
299
|
+
return;
|
|
246
300
|
}
|
|
301
|
+
for (const keyObject of keys) {
|
|
302
|
+
const chain = chains.find((ders) => x509CheckKey(ders[0], keyObject[kHandle]));
|
|
303
|
+
if (chain === undefined) throw keyMismatch();
|
|
304
|
+
autoChain(c, chain);
|
|
305
|
+
checkKeyResult(tlsContextAddCredential(c.context, chain, keyObject[kHandle]), keyObject);
|
|
306
|
+
if (c._certs.length === 0) c._certs = chain;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const STRING_OR_NONE = "of type string or one of null or undefined";
|
|
311
|
+
/* BoringSSL has no engines: Node's message for an OpenSSL built without them */
|
|
312
|
+
const noEngines = () => codeError(Error, "ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED", "Custom engines not supported by this OpenSSL");
|
|
313
|
+
|
|
314
|
+
function validateEngineOptions({ key, clientCertEngine, privateKeyIdentifier, privateKeyEngine }, name) {
|
|
315
|
+
if (privateKeyIdentifier !== undefined && privateKeyIdentifier !== null) {
|
|
316
|
+
if (privateKeyEngine === undefined || privateKeyEngine === null) throw invalidArgValue(`${name}.privateKeyEngine`, "is invalid", privateKeyEngine);
|
|
317
|
+
if (key) throw invalidArgValue(`${name}.privateKeyIdentifier`, "is invalid", privateKeyIdentifier);
|
|
318
|
+
if (typeof privateKeyIdentifier !== "string") throw invalidArgType(`${name}.privateKeyIdentifier`, STRING_OR_NONE, privateKeyIdentifier);
|
|
319
|
+
if (typeof privateKeyEngine !== "string") throw invalidArgType(`${name}.privateKeyEngine`, STRING_OR_NONE, privateKeyEngine);
|
|
320
|
+
throw noEngines();
|
|
321
|
+
}
|
|
322
|
+
if (typeof clientCertEngine === "string") throw noEngines();
|
|
323
|
+
if (clientCertEngine !== undefined && clientCertEngine !== null) throw invalidArgType(`${name}.clientCertEngine`, STRING_OR_NONE, clientCertEngine);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const COMPRESSION_ALGORITHMS = ["zlib", "brotli", "zstd"];
|
|
327
|
+
|
|
328
|
+
function validateCertificateCompression(algorithms, name) {
|
|
329
|
+
if (algorithms === undefined || algorithms === null) return;
|
|
330
|
+
if (!Array.isArray(algorithms)) throw invalidArgType(`${name}.certificateCompression`, "an instance of Array", algorithms);
|
|
331
|
+
if (algorithms.length > 3) throw invalidArgValue(`${name}.certificateCompression`, "can specify at most 3 algorithms", algorithms);
|
|
332
|
+
for (const [i, algorithm] of algorithms.entries()) {
|
|
333
|
+
if (!COMPRESSION_ALGORITHMS.includes(algorithm)) {
|
|
334
|
+
throw invalidArgValue(`${name}.certificateCompression[${i}]`, "must be 'zlib', 'brotli', or 'zstd'", algorithm);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/* tls.getCertificateCompressionAlgorithms() lists none */
|
|
338
|
+
if (algorithms.length > 0) throw notSupported("certificate compression (RFC 8879)");
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/* pbeWithSHAAnd128BitRC4, …40BitRC4, …128BitRC2-CBC, …40BitRC2-CBC (PKCS#12's PBE OIDs 1.2.840.113549.1.12.1.n):
|
|
342
|
+
* OpenSSL 3 decrypts them only with its legacy provider, which Node doesn't load */
|
|
343
|
+
const LEGACY_PBE = [1, 2, 5, 6].map((n) => Buffer.from([0x06, 0x0a, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01, n]));
|
|
344
|
+
|
|
345
|
+
/* BoringSSL's reasons → OpenSSL's words for them */
|
|
346
|
+
const PKCS12_REASONS = { INCORRECT_PASSWORD: "mac verify failure", BAD_PKCS12_DATA: "header too long" };
|
|
347
|
+
|
|
348
|
+
/** Node's SecureContext.loadPKCS12: the other certificates become CAs; the chain and its key, an identity */
|
|
349
|
+
function loadPKCS12(c, pfx, passphrase) {
|
|
350
|
+
const der = typeof pfx === "string" ? Buffer.from(pfx) : Buffer.from(pfx.buffer, pfx.byteOffset, pfx.byteLength);
|
|
351
|
+
if (LEGACY_PBE.some((oid) => der.includes(oid))) throw codeError(Error, "ERR_CRYPTO_UNSUPPORTED_OPERATION", "Unsupported PKCS12 PFX data");
|
|
352
|
+
const parts = tlsPkcs12(der, passphrase === undefined || passphrase === null ? null : String(passphrase));
|
|
353
|
+
if (typeof parts === "string") throw new Error(PKCS12_REASONS[parts] ?? parts.toLowerCase().replace(/_/g, " "));
|
|
354
|
+
const [key, cert, others] = parts;
|
|
355
|
+
if (key === null) throw new Error("Unable to load private key from PFX data");
|
|
356
|
+
if (cert === null) throw new Error("Unable to load certificate from PFX data");
|
|
357
|
+
for (const ca of others) addCA(c, ca);
|
|
358
|
+
return [[cert, ...others], createPrivateKey({ key, format: "der", type: "pkcs8" })];
|
|
247
359
|
}
|
|
248
360
|
|
|
249
361
|
/* OpenSSL sends a certificate's issuers too when its trust store has them (the `ca` option):
|