diff options
Diffstat (limited to 'src/js/node/tls.js')
-rw-r--r-- | src/js/node/tls.js | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/src/js/node/tls.js b/src/js/node/tls.js index bdf06faac..ef9232d7b 100644 --- a/src/js/node/tls.js +++ b/src/js/node/tls.js @@ -42,16 +42,16 @@ function isValidTLSArray(obj) { } function unfqdn(host) { - return RegExpPrototypeSymbolReplace.call(/[.]$/, host, ""); + return RegExpPrototypeSymbolReplace.$call(/[.]$/, host, ""); } // String#toLowerCase() is locale-sensitive so we use // a conservative version that only lowercases A-Z. function toLowerCase(c) { - return StringFromCharCode.call(32 + StringPrototypeCharCodeAt.call(c, 0)); + return StringFromCharCode.$call(32 + StringPrototypeCharCodeAt.$call(c, 0)); } function splitHost(host) { - return StringPrototypeSplit.call(RegExpPrototypeSymbolReplace.call(/[A-Z]/g, unfqdn(host), toLowerCase), "."); + return StringPrototypeSplit.$call(RegExpPrototypeSymbolReplace.$call(/[A-Z]/g, unfqdn(host), toLowerCase), "."); } function check(hostParts, pattern, wildcards) { @@ -63,14 +63,14 @@ function check(hostParts, pattern, wildcards) { if (hostParts.length !== patternParts.length) return false; // Pattern has empty components, e.g. "bad..example.com". - if (ArrayPrototypeIncludes.call(patternParts, "")) return false; + if (ArrayPrototypeIncludes.$call(patternParts, "")) return false; // RFC 6125 allows IDNA U-labels (Unicode) in names but we have no // good way to detect their encoding or normalize them so we simply // reject them. Control characters and blanks are rejected as well // because nothing good can come from accepting them. - const isBad = s => RegExpPrototypeExec.call(/[^\u0021-\u007F]/u, s) !== null; - if (ArrayPrototypeSome.call(patternParts, isBad)) return false; + const isBad = s => RegExpPrototypeExec.$call(/[^\u0021-\u007F]/u, s) !== null; + if (ArrayPrototypeSome.$call(patternParts, isBad)) return false; // Check host parts from right to left first. for (let i = hostParts.length - 1; i > 0; i -= 1) { @@ -79,12 +79,12 @@ function check(hostParts, pattern, wildcards) { const hostSubdomain = hostParts[0]; const patternSubdomain = patternParts[0]; - const patternSubdomainParts = StringPrototypeSplit.call(patternSubdomain, "*"); + const patternSubdomainParts = StringPrototypeSplit.$call(patternSubdomain, "*"); // Short-circuit when the subdomain does not contain a wildcard. // RFC 6125 does not allow wildcard substitution for components // containing IDNA A-labels (Punycode) so match those verbatim. - if (patternSubdomainParts.length === 1 || StringPrototypeIncludes.call(patternSubdomain, "xn--")) + if (patternSubdomainParts.length === 1 || StringPrototypeIncludes.$call(patternSubdomain, "xn--")) return hostSubdomain === patternSubdomain; if (!wildcards) return false; @@ -99,9 +99,9 @@ function check(hostParts, pattern, wildcards) { if (prefix.length + suffix.length > hostSubdomain.length) return false; - if (!StringPrototypeStartsWith.call(hostSubdomain, prefix)) return false; + if (!StringPrototypeStartsWith.$call(hostSubdomain, prefix)) return false; - if (!StringPrototypeEndsWith.call(hostSubdomain, suffix)) return false; + if (!StringPrototypeEndsWith.$call(hostSubdomain, suffix)) return false; return true; } @@ -118,12 +118,12 @@ function splitEscapedAltNames(altNames) { let currentToken = ""; let offset = 0; while (offset !== altNames.length) { - const nextSep = StringPrototypeIndexOf.call(altNames, ", ", offset); - const nextQuote = StringPrototypeIndexOf.call(altNames, '"', offset); + const nextSep = StringPrototypeIndexOf.$call(altNames, ", ", offset); + const nextQuote = StringPrototypeIndexOf.$call(altNames, '"', offset); if (nextQuote !== -1 && (nextSep === -1 || nextQuote < nextSep)) { // There is a quote character and there is no separator before the quote. - currentToken += StringPrototypeSubstring.call(altNames, offset, nextQuote); - const match = RegExpPrototypeExec.call(jsonStringPattern, StringPrototypeSubstring.call(altNames, nextQuote)); + currentToken += StringPrototypeSubstring.$call(altNames, offset, nextQuote); + const match = RegExpPrototypeExec.$call(jsonStringPattern, StringPrototypeSubstring.$call(altNames, nextQuote)); if (!match) { let error = new SyntaxError("ERR_TLS_CERT_ALTNAME_FORMAT: Invalid subject alternative name string"); error.name = ERR_TLS_CERT_ALTNAME_FORMAT; @@ -133,16 +133,16 @@ function splitEscapedAltNames(altNames) { offset = nextQuote + match[0].length; } else if (nextSep !== -1) { // There is a separator and no quote before it. - currentToken += StringPrototypeSubstring.call(altNames, offset, nextSep); - ArrayPrototypePush.call(result, currentToken); + currentToken += StringPrototypeSubstring.$call(altNames, offset, nextSep); + ArrayPrototypePush.$call(result, currentToken); currentToken = ""; offset = nextSep + 2; } else { - currentToken += StringPrototypeSubstring.call(altNames, offset); + currentToken += StringPrototypeSubstring.$call(altNames, offset); offset = altNames.length; } } - ArrayPrototypePush.call(result, currentToken); + ArrayPrototypePush.$call(result, currentToken); return result; } @@ -155,14 +155,14 @@ function checkServerIdentity(hostname, cert) { hostname = "" + hostname; if (altNames) { - const splitAltNames = StringPrototypeIncludes.call(altNames, '"') + const splitAltNames = StringPrototypeIncludes.$call(altNames, '"') ? splitEscapedAltNames(altNames) - : StringPrototypeSplit.call(altNames, ", "); - ArrayPrototypeForEach.call(splitAltNames, name => { - if (StringPrototypeStartsWith.call(name, "DNS:")) { - ArrayPrototypePush.call(dnsNames, StringPrototypeSlice.call(name, 4)); - } else if (StringPrototypeStartsWith.call(name, "IP Address:")) { - ArrayPrototypePush.call(ips, canonicalizeIP(StringPrototypeSlice.call(name, 11))); + : StringPrototypeSplit.$call(altNames, ", "); + ArrayPrototypeForEach.$call(splitAltNames, name => { + if (StringPrototypeStartsWith.$call(name, "DNS:")) { + ArrayPrototypePush.$call(dnsNames, StringPrototypeSlice.$call(name, 4)); + } else if (StringPrototypeStartsWith.$call(name, "IP Address:")) { + ArrayPrototypePush.$call(ips, canonicalizeIP(StringPrototypeSlice.$call(name, 11))); } }); } @@ -172,20 +172,20 @@ function checkServerIdentity(hostname, cert) { hostname = unfqdn(hostname); // Remove trailing dot for error messages. if (net.isIP(hostname)) { - valid = ArrayPrototypeIncludes.call(ips, canonicalizeIP(hostname)); - if (!valid) reason = `IP: ${hostname} is not in the cert's list: ` + ArrayPrototypeJoin.call(ips, ", "); + valid = ArrayPrototypeIncludes.$call(ips, canonicalizeIP(hostname)); + if (!valid) reason = `IP: ${hostname} is not in the cert's list: ` + ArrayPrototypeJoin.$call(ips, ", "); } else if (dnsNames.length > 0 || subject?.CN) { const hostParts = splitHost(hostname); const wildcard = pattern => check(hostParts, pattern, true); if (dnsNames.length > 0) { - valid = ArrayPrototypeSome.call(dnsNames, wildcard); + valid = ArrayPrototypeSome.$call(dnsNames, wildcard); if (!valid) reason = `Host: ${hostname}. is not in the cert's altnames: ${altNames}`; } else { // Match against Common Name only if no supported identifiers exist. const cn = subject.CN; - if (Array.isArray(cn)) valid = ArrayPrototypeSome.call(cn, wildcard); + if (Array.isArray(cn)) valid = ArrayPrototypeSome.$call(cn, wildcard); else if (cn) valid = wildcard(cn); if (!valid) reason = `Host: ${hostname}. is not cert's CN: ${cn}`; @@ -281,7 +281,7 @@ function translatePeerCertificate(c) { const info = c.infoAccess; c.infoAccess = { __proto__: null }; // XXX: More key validation? - RegExpPrototypeSymbolReplace.call(/([^\n:]*):([^\n]*)(?:\n|$)/g, info, (all, key, val) => { + RegExpPrototypeSymbolReplace.$call(/([^\n:]*):([^\n]*)(?:\n|$)/g, info, (all, key, val) => { if (val.charCodeAt(0) === 0x22) { // The translatePeerCertificate function is only // used on internally created legacy certificate @@ -290,7 +290,7 @@ function translatePeerCertificate(c) { // so this should never throw. val = JSONParse(val); } - if (key in c.infoAccess) ArrayPrototypePush.call(c.infoAccess[key], val); + if (key in c.infoAccess) ArrayPrototypePush.$call(c.infoAccess[key], val); else c.infoAccess[key] = [val]; }); } @@ -306,18 +306,15 @@ const TLSSocket = (function (InternalTLSSocket) { value: "TLSSocket", enumerable: false, }); - - return Object.defineProperty( - function Socket(options) { - return new InternalTLSSocket(options); - }, - Symbol.hasInstance, - { - value(instance) { - return instance instanceof InternalTLSSocket; - }, + function Socket(options) { + return new InternalTLSSocket(options); + } + Socket.prototype = InternalTLSSocket.prototype; + return Object.defineProperty(Socket, Symbol.hasInstance, { + value(instance) { + return instance instanceof InternalTLSSocket; }, - ); + }); })( class TLSSocket extends InternalTCPSocket { #secureContext; @@ -630,7 +627,7 @@ function getCiphers() { function convertProtocols(protocols) { const lens = new Array(protocols.length); const buff = Buffer.allocUnsafe( - ArrayPrototypeReduce.call( + ArrayPrototypeReduce.$call( protocols, (p, c, i) => { const len = Buffer.byteLength(c); |