| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f68ab39 commit 468110b
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -664,7 +664,7 @@ Type: Runtime | |||
| 664 | 664 | <a id="DEP00XX"></a> | |
| 665 | 665 | ### DEP00XX: tls.parseCertString() | |
| 666 | 666 | ||
| 667 | - Type: Documentation-only | ||
| 667 | + Type: Runtime | ||
| 668 | 668 | ||
| 669 | 669 | `tls.parseCertString()` is a trivial parsing helper that was made public by | |
| 670 | 670 | mistake. This function can usually be replaced with: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | ||
| 24 | + const { parseCertString } = require('internal/tls'); | ||
| 24 | 25 | const tls = require('tls'); | |
| 25 | 26 | const errors = require('internal/errors'); | |
| 26 | 27 | ||
@@ -202,11 +203,11 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) { | |||
| 202 | 203 | if (!c) | |
| 203 | 204 | return null; | |
| 204 | 205 | ||
| 205 | - if (c.issuer != null) c.issuer = tls.parseCertString(c.issuer); | ||
| 206 | + if (c.issuer != null) c.issuer = parseCertString(c.issuer); | ||
| 206 | 207 | if (c.issuerCertificate != null && c.issuerCertificate !== c) { | |
| 207 | 208 | c.issuerCertificate = translatePeerCertificate(c.issuerCertificate); | |
| 208 | 209 | } | |
| 209 | - if (c.subject != null) c.subject = tls.parseCertString(c.subject); | ||
| 210 | + if (c.subject != null) c.subject = parseCertString(c.subject); | ||
| 210 | 211 | if (c.infoAccess != null) { | |
| 211 | 212 | var info = c.infoAccess; | |
| 212 | 213 | c.infoAccess = Object.create(null); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,28 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Example: | ||
| 4 | + // C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org | ||
| 5 | + function parseCertString(s) { | ||
| 6 | + var out = Object.create(null); | ||
| 7 | + var parts = s.split('\n'); | ||
| 8 | + for (var i = 0, len = parts.length; i < len; i++) { | ||
| 9 | + var sepIndex = parts[i].indexOf('='); | ||
| 10 | + if (sepIndex > 0) { | ||
| 11 | + var key = parts[i].slice(0, sepIndex); | ||
| 12 | + var value = parts[i].slice(sepIndex + 1); | ||
| 13 | + if (key in out) { | ||
| 14 | + if (!Array.isArray(out[key])) { | ||
| 15 | + out[key] = [out[key]]; | ||
| 16 | + } | ||
| 17 | + out[key].push(value); | ||
| 18 | + } else { | ||
| 19 | + out[key] = value; | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + return out; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + module.exports = { | ||
| 27 | + parseCertString | ||
| 28 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | ||
| 24 | 24 | const errors = require('internal/errors'); | |
| 25 | 25 | const internalUtil = require('internal/util'); | |
| 26 | + const internalTLS = require('internal/tls'); | ||
| 26 | 27 | internalUtil.assertCrypto(); | |
| 27 | 28 | ||
| 28 | 29 | const net = require('net'); | |
@@ -228,28 +229,11 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { | |||
| 228 | 229 | } | |
| 229 | 230 | }; | |
| 230 | 231 | ||
| 231 | - // Example: | ||
| 232 | - // C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org | ||
| 233 | - exports.parseCertString = function parseCertString(s) { | ||
| 234 | - var out = Object.create(null); | ||
| 235 | - var parts = s.split('\n'); | ||
| 236 | - for (var i = 0, len = parts.length; i < len; i++) { | ||
| 237 | - var sepIndex = parts[i].indexOf('='); | ||
| 238 | - if (sepIndex > 0) { | ||
| 239 | - var key = parts[i].slice(0, sepIndex); | ||
| 240 | - var value = parts[i].slice(sepIndex + 1); | ||
| 241 | - if (key in out) { | ||
| 242 | - if (!Array.isArray(out[key])) { | ||
| 243 | - out[key] = [out[key]]; | ||
| 244 | - } | ||
| 245 | - out[key].push(value); | ||
| 246 | - } else { | ||
| 247 | - out[key] = value; | ||
| 248 | - } | ||
| 249 | - } | ||
| 250 | - } | ||
| 251 | - return out; | ||
| 252 | - }; | ||
| 232 | + exports.parseCertString = internalUtil.deprecate( | ||
| 233 | + internalTLS.parseCertString, | ||
| 234 | + 'tls.parseCertString() is deprecated. ' + | ||
| 235 | + 'Please use querystring.parse() instead.', | ||
| 236 | + 'DEP00XX'); | ||
| 253 | 237 | ||
| 254 | 238 | // Public API | |
| 255 | 239 | exports.createSecureContext = require('_tls_common').createSecureContext; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -112,6 +112,7 @@ | |||
| 112 | 112 | 'lib/internal/repl.js', | |
| 113 | 113 | 'lib/internal/socket_list.js', | |
| 114 | 114 | 'lib/internal/test/unicode.js', | |
| 115 | + 'lib/internal/tls.js', | ||
| 115 | 116 | 'lib/internal/url.js', | |
| 116 | 117 | 'lib/internal/util.js', | |
| 117 | 118 | 'lib/internal/http2/core.js', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,16 +1,22 @@ | |||
| 1 | 1 | /* eslint-disable no-proto */ | |
| 2 | 2 | 'use strict'; | |
| 3 | + | ||
| 3 | 4 | const common = require('../common'); | |
| 4 | 5 | if (!common.hasCrypto) | |
| 5 | 6 | common.skip('missing crypto'); | |
| 6 | 7 | ||
| 7 | 8 | const assert = require('assert'); | |
| 9 | + // Flags: --expose_internals | ||
| 10 | + const internalTLS = require('internal/tls'); | ||
| 8 | 11 | const tls = require('tls'); | |
| 9 | 12 | ||
| 13 | + const noOutput = common.mustNotCall(); | ||
| 14 | + common.hijackStderr(noOutput); | ||
| 15 | + | ||
| 10 | 16 | { | |
| 11 | 17 | const singles = 'C=US\nST=CA\nL=SF\nO=Node.js Foundation\nOU=Node.js\n' + | |
| 12 | 18 | 'CN=ca1\nemailAddress=ry@clouds.org'; | |
| 13 | - const singlesOut = tls.parseCertString(singles); | ||
| 19 | + const singlesOut = internalTLS.parseCertString(singles); | ||
| 14 | 20 | assert.deepStrictEqual(singlesOut, { | |
| 15 | 21 | __proto__: null, | |
| 16 | 22 | C: 'US', | |
@@ -26,7 +32,7 @@ const tls = require('tls'); | |||
| 26 | 32 | { | |
| 27 | 33 | const doubles = 'OU=Domain Control Validated\nOU=PositiveSSL Wildcard\n' + | |
| 28 | 34 | 'CN=*.nodejs.org'; | |
| 29 | - const doublesOut = tls.parseCertString(doubles); | ||
| 35 | + const doublesOut = internalTLS.parseCertString(doubles); | ||
| 30 | 36 | assert.deepStrictEqual(doublesOut, { | |
| 31 | 37 | __proto__: null, | |
| 32 | 38 | OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ], | |
@@ -36,7 +42,7 @@ const tls = require('tls'); | |||
| 36 | 42 | ||
| 37 | 43 | { | |
| 38 | 44 | const invalid = 'fhqwhgads'; | |
| 39 | - const invalidOut = tls.parseCertString(invalid); | ||
| 45 | + const invalidOut = internalTLS.parseCertString(invalid); | ||
| 40 | 46 | assert.deepStrictEqual(invalidOut, { __proto__: null }); | |
| 41 | 47 | } | |
| 42 | 48 | ||
@@ -45,5 +51,16 @@ const tls = require('tls'); | |||
| 45 | 51 | const expected = Object.create(null); | |
| 46 | 52 | expected.__proto__ = 'mostly harmless'; | |
| 47 | 53 | expected.hasOwnProperty = 'not a function'; | |
| 48 | - assert.deepStrictEqual(tls.parseCertString(input), expected); | ||
| 54 | + assert.deepStrictEqual(internalTLS.parseCertString(input), expected); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + common.restoreStderr(); | ||
| 58 | + | ||
| 59 | + { | ||
| 60 | + common.expectWarning('DeprecationWarning', | ||
| 61 | + 'tls.parseCertString() is deprecated. ' + | ||
| 62 | + 'Please use querystring.parse() instead.'); | ||
| 63 | + | ||
| 64 | + const ret = tls.parseCertString('foo=bar'); | ||
| 65 | + assert.deepStrictEqual(ret, { __proto__: null, foo: 'bar' }); | ||
| 49 | 66 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments