-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: deprecate parseCertString & move to internal
`tls.parseCertString()` exposed by accident. Now move this function to `internal/tls` and mark the original one as deprecated. PR-URL: #14249 Refs: #14193 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
- Loading branch information
Showing
6 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
// Example: | ||
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\[email protected] | ||
function parseCertString(s) { | ||
var out = Object.create(null); | ||
var parts = s.split('\n'); | ||
for (var i = 0, len = parts.length; i < len; i++) { | ||
var sepIndex = parts[i].indexOf('='); | ||
if (sepIndex > 0) { | ||
var key = parts[i].slice(0, sepIndex); | ||
var value = parts[i].slice(sepIndex + 1); | ||
if (key in out) { | ||
if (!Array.isArray(out[key])) { | ||
out[key] = [out[key]]; | ||
} | ||
out[key].push(value); | ||
} else { | ||
out[key] = value; | ||
} | ||
} | ||
} | ||
return out; | ||
} | ||
|
||
module.exports = { | ||
parseCertString | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
|
||
const errors = require('internal/errors'); | ||
const internalUtil = require('internal/util'); | ||
const internalTLS = require('internal/tls'); | ||
internalUtil.assertCrypto(); | ||
|
||
const net = require('net'); | ||
|
@@ -228,28 +229,11 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) { | |
} | ||
}; | ||
|
||
// Example: | ||
// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\[email protected] | ||
exports.parseCertString = function parseCertString(s) { | ||
var out = Object.create(null); | ||
var parts = s.split('\n'); | ||
for (var i = 0, len = parts.length; i < len; i++) { | ||
var sepIndex = parts[i].indexOf('='); | ||
if (sepIndex > 0) { | ||
var key = parts[i].slice(0, sepIndex); | ||
var value = parts[i].slice(sepIndex + 1); | ||
if (key in out) { | ||
if (!Array.isArray(out[key])) { | ||
out[key] = [out[key]]; | ||
} | ||
out[key].push(value); | ||
} else { | ||
out[key] = value; | ||
} | ||
} | ||
} | ||
return out; | ||
}; | ||
exports.parseCertString = internalUtil.deprecate( | ||
internalTLS.parseCertString, | ||
'tls.parseCertString() is deprecated. ' + | ||
'Please use querystring.parse() instead.', | ||
'DEP00XX'); | ||
|
||
// Public API | ||
exports.createSecureContext = require('_tls_common').createSecureContext; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
/* eslint-disable no-proto */ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
// Flags: --expose_internals | ||
const internalTLS = require('internal/tls'); | ||
const tls = require('tls'); | ||
|
||
const noOutput = common.mustNotCall(); | ||
common.hijackStderr(noOutput); | ||
|
||
{ | ||
const singles = 'C=US\nST=CA\nL=SF\nO=Node.js Foundation\nOU=Node.js\n' + | ||
'CN=ca1\[email protected]'; | ||
const singlesOut = tls.parseCertString(singles); | ||
const singlesOut = internalTLS.parseCertString(singles); | ||
assert.deepStrictEqual(singlesOut, { | ||
__proto__: null, | ||
C: 'US', | ||
|
@@ -26,7 +32,7 @@ const tls = require('tls'); | |
{ | ||
const doubles = 'OU=Domain Control Validated\nOU=PositiveSSL Wildcard\n' + | ||
'CN=*.nodejs.org'; | ||
const doublesOut = tls.parseCertString(doubles); | ||
const doublesOut = internalTLS.parseCertString(doubles); | ||
assert.deepStrictEqual(doublesOut, { | ||
__proto__: null, | ||
OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ], | ||
|
@@ -36,7 +42,7 @@ const tls = require('tls'); | |
|
||
{ | ||
const invalid = 'fhqwhgads'; | ||
const invalidOut = tls.parseCertString(invalid); | ||
const invalidOut = internalTLS.parseCertString(invalid); | ||
assert.deepStrictEqual(invalidOut, { __proto__: null }); | ||
} | ||
|
||
|
@@ -45,5 +51,16 @@ const tls = require('tls'); | |
const expected = Object.create(null); | ||
expected.__proto__ = 'mostly harmless'; | ||
expected.hasOwnProperty = 'not a function'; | ||
assert.deepStrictEqual(tls.parseCertString(input), expected); | ||
assert.deepStrictEqual(internalTLS.parseCertString(input), expected); | ||
} | ||
|
||
common.restoreStderr(); | ||
|
||
{ | ||
common.expectWarning('DeprecationWarning', | ||
'tls.parseCertString() is deprecated. ' + | ||
'Please use querystring.parse() instead.'); | ||
|
||
const ret = tls.parseCertString('foo=bar'); | ||
assert.deepStrictEqual(ret, { __proto__: null, foo: 'bar' }); | ||
} |