| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,9 @@ const { | |||
| 25 | 25 | ArrayIsArray, | |
| 26 | 26 | ArrayPrototypeFilter, | |
| 27 | 27 | ArrayPrototypeJoin, | |
| 28 | + ArrayPrototypePush, | ||
| 28 | 29 | ObjectCreate, | |
| 30 | + StringPrototypeReplace, | ||
| 29 | 31 | StringPrototypeSplit, | |
| 30 | 32 | StringPrototypeStartsWith, | |
| 31 | 33 | } = primordials; | |
@@ -392,12 +394,13 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) { | |||
| 392 | 394 | c.infoAccess = ObjectCreate(null); | |
| 393 | 395 | ||
| 394 | 396 | // XXX: More key validation? | |
| 395 | - info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, (all, key, val) => { | ||
| 396 | - if (key in c.infoAccess) | ||
| 397 | - c.infoAccess[key].push(val); | ||
| 398 | - else | ||
| 399 | - c.infoAccess[key] = [val]; | ||
| 400 | - }); | ||
| 397 | + StringPrototypeReplace(info, /([^\n:]*):([^\n]*)(?:\n|$)/g, | ||
| 398 | + (all, key, val) => { | ||
| 399 | + if (key in c.infoAccess) | ||
| 400 | + ArrayPrototypePush(c.infoAccess[key], val); | ||
| 401 | + else | ||
| 402 | + c.infoAccess[key] = [val]; | ||
| 403 | + }); | ||
| 401 | 404 | } | |
| 402 | 405 | return c; | |
| 403 | 406 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,10 +22,18 @@ | |||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | ||
| 24 | 24 | const { | |
| 25 | + ArrayPrototypeForEach, | ||
| 26 | + ArrayPrototypeJoin, | ||
| 27 | + ArrayPrototypePush, | ||
| 28 | + FunctionPrototype, | ||
| 25 | 29 | ObjectAssign, | |
| 26 | 30 | ObjectDefineProperty, | |
| 27 | 31 | ObjectSetPrototypeOf, | |
| 32 | + ReflectApply, | ||
| 28 | 33 | RegExp, | |
| 34 | + RegExpPrototypeTest, | ||
| 35 | + StringPrototypeReplace, | ||
| 36 | + StringPrototypeSlice, | ||
| 29 | 37 | Symbol, | |
| 30 | 38 | SymbolFor, | |
| 31 | 39 | } = primordials; | |
@@ -96,7 +104,7 @@ const kPskIdentityHint = Symbol('pskidentityhint'); | |||
| 96 | 104 | const kPendingSession = Symbol('pendingSession'); | |
| 97 | 105 | const kIsVerified = Symbol('verified'); | |
| 98 | 106 | ||
| 99 | - const noop = () => {}; | ||
| 107 | + const noop = FunctionPrototype; | ||
| 100 | 108 | ||
| 101 | 109 | let ipServernameWarned = false; | |
| 102 | 110 | let tlsTracingWarned = false; | |
@@ -408,7 +416,8 @@ function onerror(err) { | |||
| 408 | 416 | owner.destroy(err); | |
| 409 | 417 | } else if (owner._tlsOptions.isServer && | |
| 410 | 418 | owner._rejectUnauthorized && | |
| 411 | - /peer did not return a certificate/.test(err.message)) { | ||
| 419 | + RegExpPrototypeTest(/peer did not return a certificate/, | ||
| 420 | + err.message)) { | ||
| 412 | 421 | // Ignore server's authorization errors | |
| 413 | 422 | owner.destroy(); | |
| 414 | 423 | } else { | |
@@ -496,14 +505,14 @@ function TLSSocket(socket, opts) { | |||
| 496 | 505 | // distinguishable from regular ones. | |
| 497 | 506 | this.encrypted = true; | |
| 498 | 507 | ||
| 499 | - net.Socket.call(this, { | ||
| 508 | + ReflectApply(net.Socket, this, [{ | ||
| 500 | 509 | handle: this._wrapHandle(wrap), | |
| 501 | 510 | allowHalfOpen: socket ? socket.allowHalfOpen : tlsOptions.allowHalfOpen, | |
| 502 | 511 | pauseOnCreate: tlsOptions.pauseOnConnect, | |
| 503 | 512 | manualStart: true, | |
| 504 | 513 | highWaterMark: tlsOptions.highWaterMark, | |
| 505 | 514 | onread: !socket ? tlsOptions.onread : null, | |
| 506 | - }); | ||
| 515 | + }]); | ||
| 507 | 516 | ||
| 508 | 517 | // Proxy for API compatibility | |
| 509 | 518 | this.ssl = this._handle; // C++ TLSWrap object | |
@@ -535,7 +544,7 @@ const proxiedMethods = [ | |||
| 535 | 544 | function makeMethodProxy(name) { | |
| 536 | 545 | return function methodProxy(...args) { | |
| 537 | 546 | if (this._parent[name]) | |
| 538 | - return this._parent[name].apply(this._parent, args); | ||
| 547 | + return ReflectApply(this._parent[name], this._parent, args); | ||
| 539 | 548 | }; | |
| 540 | 549 | } | |
| 541 | 550 | for (const proxiedMethod of proxiedMethods) { | |
@@ -993,12 +1002,12 @@ TLSSocket.prototype.getCertificate = function() { | |||
| 993 | 1002 | function makeSocketMethodProxy(name) { | |
| 994 | 1003 | return function socketMethodProxy(...args) { | |
| 995 | 1004 | if (this._handle) | |
| 996 | - return this._handle[name].apply(this._handle, args); | ||
| 1005 | + return ReflectApply(this._handle[name], this._handle, args); | ||
| 997 | 1006 | return null; | |
| 998 | 1007 | }; | |
| 999 | 1008 | } | |
| 1000 | 1009 | ||
| 1001 | - [ | ||
| 1010 | + ArrayPrototypeForEach([ | ||
| 1002 | 1011 | 'getCipher', | |
| 1003 | 1012 | 'getSharedSigalgs', | |
| 1004 | 1013 | 'getEphemeralKeyInfo', | |
@@ -1009,7 +1018,7 @@ function makeSocketMethodProxy(name) { | |||
| 1009 | 1018 | 'getTLSTicket', | |
| 1010 | 1019 | 'isSessionReused', | |
| 1011 | 1020 | 'enableTrace', | |
| 1012 | - ].forEach((method) => { | ||
| 1021 | + ], (method) => { | ||
| 1013 | 1022 | TLSSocket.prototype[method] = makeSocketMethodProxy(method); | |
| 1014 | 1023 | }); | |
| 1015 | 1024 | ||
@@ -1209,7 +1218,7 @@ function Server(options, listener) { | |||
| 1209 | 1218 | } | |
| 1210 | 1219 | ||
| 1211 | 1220 | // constructor call | |
| 1212 | - net.Server.call(this, options, tlsConnectionListener); | ||
| 1221 | + ReflectApply(net.Server, this, [options, tlsConnectionListener]); | ||
| 1213 | 1222 | ||
| 1214 | 1223 | if (listener) { | |
| 1215 | 1224 | this.on('secureConnection', listener); | |
@@ -1309,10 +1318,10 @@ Server.prototype.setSecureContext = function(options) { | |||
| 1309 | 1318 | if (options.sessionIdContext) { | |
| 1310 | 1319 | this.sessionIdContext = options.sessionIdContext; | |
| 1311 | 1320 | } else { | |
| 1312 | - this.sessionIdContext = crypto.createHash('sha1') | ||
| 1313 | - .update(process.argv.join(' ')) | ||
| 1314 | - .digest('hex') | ||
| 1315 | - .slice(0, 32); | ||
| 1321 | + this.sessionIdContext = StringPrototypeSlice( | ||
| 1322 | + crypto.createHash('sha1') | ||
| 1323 | + .update(ArrayPrototypeJoin(process.argv, ' ')) | ||
| 1324 | + .digest('hex'), 0, 32); | ||
| 1316 | 1325 | } | |
| 1317 | 1326 | ||
| 1318 | 1327 | if (options.sessionTimeout) | |
@@ -1399,10 +1408,10 @@ Server.prototype.setOptions = deprecate(function(options) { | |||
| 1399 | 1408 | if (options.sessionIdContext) { | |
| 1400 | 1409 | this.sessionIdContext = options.sessionIdContext; | |
| 1401 | 1410 | } else { | |
| 1402 | - this.sessionIdContext = crypto.createHash('sha1') | ||
| 1403 | - .update(process.argv.join(' ')) | ||
| 1404 | - .digest('hex') | ||
| 1405 | - .slice(0, 32); | ||
| 1411 | + this.sessionIdContext = StringPrototypeSlice( | ||
| 1412 | + crypto.createHash('sha1') | ||
| 1413 | + .update(ArrayPrototypeJoin(process.argv, ' ')) | ||
| 1414 | + .digest('hex'), 0, 32); | ||
| 1406 | 1415 | } | |
| 1407 | 1416 | if (options.pskCallback) this[kPskCallback] = options.pskCallback; | |
| 1408 | 1417 | if (options.pskIdentityHint) this[kPskIdentityHint] = options.pskIdentityHint; | |
@@ -1414,11 +1423,12 @@ Server.prototype.addContext = function(servername, context) { | |||
| 1414 | 1423 | throw new ERR_TLS_REQUIRED_SERVER_NAME(); | |
| 1415 | 1424 | } | |
| 1416 | 1425 | ||
| 1417 | - const re = new RegExp('^' + | ||
| 1418 | - servername.replace(/([.^$+?\-\\[\]{}])/g, '\\$1') | ||
| 1419 | - .replace(/\*/g, '[^.]*') + | ||
| 1420 | - '$'); | ||
| 1421 | - this._contexts.push([re, tls.createSecureContext(context).context]); | ||
| 1426 | + const re = new RegExp('^' + StringPrototypeReplace( | ||
| 1427 | + StringPrototypeReplace(servername, /([.^$+?\-\\[\]{}])/g, '\\$1'), | ||
| 1428 | + /\*/g, '[^.]*' | ||
| 1429 | + ) + '$'); | ||
| 1430 | + ArrayPrototypePush(this._contexts, | ||
| 1431 | + [re, tls.createSecureContext(context).context]); | ||
| 1422 | 1432 | }; | |
| 1423 | 1433 | ||
| 1424 | 1434 | Server.prototype[EE.captureRejectionSymbol] = function( | |
@@ -1429,16 +1439,16 @@ Server.prototype[EE.captureRejectionSymbol] = function( | |||
| 1429 | 1439 | sock.destroy(err); | |
| 1430 | 1440 | break; | |
| 1431 | 1441 | default: | |
| 1432 | - net.Server.prototype[SymbolFor('nodejs.rejection')] | ||
| 1433 | - .call(this, err, event, sock); | ||
| 1442 | + ReflectApply(net.Server.prototype[SymbolFor('nodejs.rejection')], this, | ||
| 1443 | + [err, event, sock]); | ||
| 1434 | 1444 | } | |
| 1435 | 1445 | }; | |
| 1436 | 1446 | ||
| 1437 | 1447 | function SNICallback(servername, callback) { | |
| 1438 | 1448 | const contexts = this.server._contexts; | |
| 1439 | 1449 | ||
| 1440 | 1450 | for (const elem of contexts) { | |
| 1441 | - if (elem[0].test(servername)) { | ||
| 1451 | + if (RegExpPrototypeTest(elem[0], servername)) { | ||
| 1442 | 1452 | callback(null, elem[1]); | |
| 1443 | 1453 | return; | |
| 1444 | 1454 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,23 +2,27 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | ArrayIsArray, | |
| 5 | + ArrayPrototypePush, | ||
| 6 | + StringPrototypeIndexOf, | ||
| 7 | + StringPrototypeSlice, | ||
| 8 | + StringPrototypeSplit, | ||
| 5 | 9 | ObjectCreate, | |
| 6 | 10 | } = primordials; | |
| 7 | 11 | ||
| 8 | 12 | // Example: | |
| 9 | 13 | // C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org | |
| 10 | 14 | function parseCertString(s) { | |
| 11 | 15 | const out = ObjectCreate(null); | |
| 12 | - for (const part of s.split('\n')) { | ||
| 13 | - const sepIndex = part.indexOf('='); | ||
| 16 | + for (const part of StringPrototypeSplit(s, '\n')) { | ||
| 17 | + const sepIndex = StringPrototypeIndexOf(part, '='); | ||
| 14 | 18 | if (sepIndex > 0) { | |
| 15 | - const key = part.slice(0, sepIndex); | ||
| 16 | - const value = part.slice(sepIndex + 1); | ||
| 19 | + const key = StringPrototypeSlice(part, 0, sepIndex); | ||
| 20 | + const value = StringPrototypeSlice(part, sepIndex + 1); | ||
| 17 | 21 | if (key in out) { | |
| 18 | 22 | if (!ArrayIsArray(out[key])) { | |
| 19 | 23 | out[key] = [out[key]]; | |
| 20 | 24 | } | |
| 21 | - out[key].push(value); | ||
| 25 | + ArrayPrototypePush(out[key], value); | ||
| 22 | 26 | } else { | |
| 23 | 27 | out[key] = value; | |
| 24 | 28 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,12 +24,22 @@ | |||
| 24 | 24 | const { | |
| 25 | 25 | Array, | |
| 26 | 26 | ArrayIsArray, | |
| 27 | + ArrayPrototypeIncludes, | ||
| 28 | + ArrayPrototypeJoin, | ||
| 29 | + ArrayPrototypePush, | ||
| 30 | + ArrayPrototypeReduce, | ||
| 31 | + ArrayPrototypeSome, | ||
| 27 | 32 | ObjectDefineProperty, | |
| 28 | 33 | ObjectFreeze, | |
| 34 | + RegExpPrototypeTest, | ||
| 29 | 35 | StringFromCharCode, | |
| 30 | 36 | StringPrototypeCharCodeAt, | |
| 37 | + StringPrototypeEndsWith, | ||
| 38 | + StringPrototypeIncludes, | ||
| 31 | 39 | StringPrototypeReplace, | |
| 40 | + StringPrototypeSlice, | ||
| 32 | 41 | StringPrototypeSplit, | |
| 42 | + StringPrototypeStartsWith, | ||
| 33 | 43 | } = primordials; | |
| 34 | 44 | ||
| 35 | 45 | const { | |
@@ -107,7 +117,7 @@ ObjectDefineProperty(exports, 'rootCertificates', { | |||
| 107 | 117 | // ("\x06spdy/2\x08http/1.1\x08http/1.0") | |
| 108 | 118 | function convertProtocols(protocols) { | |
| 109 | 119 | const lens = new Array(protocols.length); | |
| 110 | - const buff = Buffer.allocUnsafe(protocols.reduce((p, c, i) => { | ||
| 120 | + const buff = Buffer.allocUnsafe(ArrayPrototypeReduce(protocols, (p, c, i) => { | ||
| 111 | 121 | const len = Buffer.byteLength(c); | |
| 112 | 122 | if (len > 255) { | |
| 113 | 123 | throw new ERR_OUT_OF_RANGE('The byte length of the protocol at index ' + | |
@@ -138,7 +148,7 @@ exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) { | |||
| 138 | 148 | }; | |
| 139 | 149 | ||
| 140 | 150 | function unfqdn(host) { | |
| 141 | - return host.replace(/[.]$/, ''); | ||
| 151 | + return StringPrototypeReplace(host, /[.]$/, ''); | ||
| 142 | 152 | } | |
| 143 | 153 | ||
| 144 | 154 | // String#toLowerCase() is locale-sensitive so we use | |
@@ -165,15 +175,15 @@ function check(hostParts, pattern, wildcards) { | |||
| 165 | 175 | return false; | |
| 166 | 176 | ||
| 167 | 177 | // Pattern has empty components, e.g. "bad..example.com". | |
| 168 | - if (patternParts.includes('')) | ||
| 178 | + if (ArrayPrototypeIncludes(patternParts, '')) | ||
| 169 | 179 | return false; | |
| 170 | 180 | ||
| 171 | 181 | // RFC 6125 allows IDNA U-labels (Unicode) in names but we have no | |
| 172 | 182 | // good way to detect their encoding or normalize them so we simply | |
| 173 | 183 | // reject them. Control characters and blanks are rejected as well | |
| 174 | 184 | // because nothing good can come from accepting them. | |
| 175 | - const isBad = (s) => /[^\u0021-\u007F]/u.test(s); | ||
| 176 | - if (patternParts.some(isBad)) | ||
| 185 | + const isBad = (s) => RegExpPrototypeTest(/[^\u0021-\u007F]/u, s); | ||
| 186 | + if (ArrayPrototypeSome(patternParts, isBad)) | ||
| 177 | 187 | return false; | |
| 178 | 188 | ||
| 179 | 189 | // Check host parts from right to left first. | |
@@ -184,12 +194,13 @@ function check(hostParts, pattern, wildcards) { | |||
| 184 | 194 | ||
| 185 | 195 | const hostSubdomain = hostParts[0]; | |
| 186 | 196 | const patternSubdomain = patternParts[0]; | |
| 187 | - const patternSubdomainParts = patternSubdomain.split('*'); | ||
| 197 | + const patternSubdomainParts = StringPrototypeSplit(patternSubdomain, '*'); | ||
| 188 | 198 | ||
| 189 | 199 | // Short-circuit when the subdomain does not contain a wildcard. | |
| 190 | 200 | // RFC 6125 does not allow wildcard substitution for components | |
| 191 | 201 | // containing IDNA A-labels (Punycode) so match those verbatim. | |
| 192 | - if (patternSubdomainParts.length === 1 || patternSubdomain.includes('xn--')) | ||
| 202 | + if (patternSubdomainParts.length === 1 || | ||
| 203 | + StringPrototypeIncludes(patternSubdomain, 'xn--')) | ||
| 193 | 204 | return hostSubdomain === patternSubdomain; | |
| 194 | 205 | ||
| 195 | 206 | if (!wildcards) | |
@@ -208,10 +219,10 @@ function check(hostParts, pattern, wildcards) { | |||
| 208 | 219 | if (prefix.length + suffix.length > hostSubdomain.length) | |
| 209 | 220 | return false; | |
| 210 | 221 | ||
| 211 | - if (!hostSubdomain.startsWith(prefix)) | ||
| 222 | + if (!StringPrototypeStartsWith(hostSubdomain, prefix)) | ||
| 212 | 223 | return false; | |
| 213 | 224 | ||
| 214 | - if (!hostSubdomain.endsWith(suffix)) | ||
| 225 | + if (!StringPrototypeEndsWith(hostSubdomain, suffix)) | ||
| 215 | 226 | return false; | |
| 216 | 227 | ||
| 217 | 228 | return true; | |
@@ -228,28 +239,30 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { | |||
| 228 | 239 | hostname = '' + hostname; | |
| 229 | 240 | ||
| 230 | 241 | if (altNames) { | |
| 231 | - for (const name of altNames.split(', ')) { | ||
| 232 | - if (name.startsWith('DNS:')) { | ||
| 233 | - dnsNames.push(name.slice(4)); | ||
| 234 | - } else if (name.startsWith('URI:')) { | ||
| 242 | + for (const name of StringPrototypeSplit(altNames, ', ')) { | ||
| 243 | + if (StringPrototypeStartsWith(name, 'DNS:')) { | ||
| 244 | + ArrayPrototypePush(dnsNames, StringPrototypeSlice(name, 4)); | ||
| 245 | + } else if (StringPrototypeStartsWith(name, 'URI:')) { | ||
| 235 | 246 | let uri; | |
| 236 | 247 | try { | |
| 237 | - uri = new URL(name.slice(4)); | ||
| 248 | + uri = new URL(StringPrototypeSlice(name, 4)); | ||
| 238 | 249 | } catch { | |
| 239 | - uri = url.parse(name.slice(4)); | ||
| 250 | + const slicedName = StringPrototypeSlice(name, 4); | ||
| 251 | + uri = url.parse(slicedName); | ||
| 240 | 252 | if (!urlWarningEmitted && !process.noDeprecation) { | |
| 241 | 253 | urlWarningEmitted = true; | |
| 242 | 254 | process.emitWarning( | |
| 243 | - `The URI ${name.slice(4)} found in cert.subjectaltname ` + | ||
| 255 | + `The URI ${slicedName} found in cert.subjectaltname ` + | ||
| 244 | 256 | 'is not a valid URI, and is supported in the tls module ' + | |
| 245 | 257 | 'solely for compatibility.', | |
| 246 | 258 | 'DeprecationWarning', 'DEP0109'); | |
| 247 | 259 | } | |
| 248 | 260 | } | |
| 249 | 261 | ||
| 250 | - uriNames.push(uri.hostname); // TODO(bnoordhuis) Also use scheme. | ||
| 251 | - } else if (name.startsWith('IP Address:')) { | ||
| 252 | - ips.push(canonicalizeIP(name.slice(11))); | ||
| 262 | + // TODO(bnoordhuis) Also use scheme. | ||
| 263 | + ArrayPrototypePush(uriNames, uri.hostname); | ||
| 264 | + } else if (StringPrototypeStartsWith(name, 'IP Address:')) { | ||
| 265 | + ArrayPrototypePush(ips, canonicalizeIP(StringPrototypeSlice(name, 11))); | ||
| 253 | 266 | } | |
| 254 | 267 | } | |
| 255 | 268 | } | |
@@ -263,17 +276,19 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { | |||
| 263 | 276 | hostname = unfqdn(hostname); // Remove trailing dot for error messages. | |
| 264 | 277 | ||
| 265 | 278 | if (net.isIP(hostname)) { | |
| 266 | - valid = ips.includes(canonicalizeIP(hostname)); | ||
| 279 | + valid = ArrayPrototypeIncludes(ips, canonicalizeIP(hostname)); | ||
| 267 | 280 | if (!valid) | |
| 268 | - reason = `IP: ${hostname} is not in the cert's list: ${ips.join(', ')}`; | ||
| 281 | + reason = `IP: ${hostname} is not in the cert's list: ` + | ||
| 282 | + ArrayPrototypeJoin(ips, ', '); | ||
| 269 | 283 | // TODO(bnoordhuis) Also check URI SANs that are IP addresses. | |
| 270 | 284 | } else if (hasAltNames || subject) { | |
| 271 | 285 | const hostParts = splitHost(hostname); | |
| 272 | 286 | const wildcard = (pattern) => check(hostParts, pattern, true); | |
| 273 | 287 | ||
| 274 | 288 | if (hasAltNames) { | |
| 275 | 289 | const noWildcard = (pattern) => check(hostParts, pattern, false); | |
| 276 | - valid = dnsNames.some(wildcard) || uriNames.some(noWildcard); | ||
| 290 | + valid = ArrayPrototypeSome(dnsNames, wildcard) || | ||
| 291 | + ArrayPrototypeSome(uriNames, noWildcard); | ||
| 277 | 292 | if (!valid) | |
| 278 | 293 | reason = | |
| 279 | 294 | `Host: ${hostname}. is not in the cert's altnames: ${altNames}`; | |
@@ -282,7 +297,7 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) { | |||
| 282 | 297 | const cn = subject.CN; | |
| 283 | 298 | ||
| 284 | 299 | if (ArrayIsArray(cn)) | |
| 285 | - valid = cn.some(wildcard); | ||
| 300 | + valid = ArrayPrototypeSome(cn, wildcard); | ||
| 286 | 301 | else if (cn) | |
| 287 | 302 | valid = wildcard(cn); | |
| 288 | 303 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments