Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 468110b

Browse filesBrowse files
XadillaXBridgeAR
authored andcommitted
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 <refack@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent f68ab39 commit 468110b
Copy full SHA for 468110b

File tree

Expand file treeCollapse file tree

6 files changed

+60
-29
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+60
-29
lines changed
Open diff view settings
Collapse file

‎doc/api/deprecations.md‎

Copy file name to clipboardExpand all lines: doc/api/deprecations.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ Type: Runtime
664664
<a id="DEP00XX"></a>
665665
### DEP00XX: tls.parseCertString()
666666

667-
Type: Documentation-only
667+
Type: Runtime
668668

669669
`tls.parseCertString()` is a trivial parsing helper that was made public by
670670
mistake. This function can usually be replaced with:
Collapse file

‎lib/_tls_common.js‎

Copy file name to clipboardExpand all lines: lib/_tls_common.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
'use strict';
2323

24+
const { parseCertString } = require('internal/tls');
2425
const tls = require('tls');
2526
const errors = require('internal/errors');
2627

@@ -202,11 +203,11 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) {
202203
if (!c)
203204
return null;
204205

205-
if (c.issuer != null) c.issuer = tls.parseCertString(c.issuer);
206+
if (c.issuer != null) c.issuer = parseCertString(c.issuer);
206207
if (c.issuerCertificate != null && c.issuerCertificate !== c) {
207208
c.issuerCertificate = translatePeerCertificate(c.issuerCertificate);
208209
}
209-
if (c.subject != null) c.subject = tls.parseCertString(c.subject);
210+
if (c.subject != null) c.subject = parseCertString(c.subject);
210211
if (c.infoAccess != null) {
211212
var info = c.infoAccess;
212213
c.infoAccess = Object.create(null);
Collapse file

‎lib/internal/tls.js‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
};
Collapse file

‎lib/tls.js‎

Copy file name to clipboardExpand all lines: lib/tls.js
+6-22Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const errors = require('internal/errors');
2525
const internalUtil = require('internal/util');
26+
const internalTLS = require('internal/tls');
2627
internalUtil.assertCrypto();
2728

2829
const net = require('net');
@@ -228,28 +229,11 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
228229
}
229230
};
230231

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');
253237

254238
// Public API
255239
exports.createSecureContext = require('_tls_common').createSecureContext;
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
'lib/internal/repl.js',
113113
'lib/internal/socket_list.js',
114114
'lib/internal/test/unicode.js',
115+
'lib/internal/tls.js',
115116
'lib/internal/url.js',
116117
'lib/internal/util.js',
117118
'lib/internal/http2/core.js',
Collapse file

‎test/parallel/test-tls-parse-cert-string.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-tls-parse-cert-string.js
+21-4Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
/* eslint-disable no-proto */
22
'use strict';
3+
34
const common = require('../common');
45
if (!common.hasCrypto)
56
common.skip('missing crypto');
67

78
const assert = require('assert');
9+
// Flags: --expose_internals
10+
const internalTLS = require('internal/tls');
811
const tls = require('tls');
912

13+
const noOutput = common.mustNotCall();
14+
common.hijackStderr(noOutput);
15+
1016
{
1117
const singles = 'C=US\nST=CA\nL=SF\nO=Node.js Foundation\nOU=Node.js\n' +
1218
'CN=ca1\nemailAddress=ry@clouds.org';
13-
const singlesOut = tls.parseCertString(singles);
19+
const singlesOut = internalTLS.parseCertString(singles);
1420
assert.deepStrictEqual(singlesOut, {
1521
__proto__: null,
1622
C: 'US',
@@ -26,7 +32,7 @@ const tls = require('tls');
2632
{
2733
const doubles = 'OU=Domain Control Validated\nOU=PositiveSSL Wildcard\n' +
2834
'CN=*.nodejs.org';
29-
const doublesOut = tls.parseCertString(doubles);
35+
const doublesOut = internalTLS.parseCertString(doubles);
3036
assert.deepStrictEqual(doublesOut, {
3137
__proto__: null,
3238
OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ],
@@ -36,7 +42,7 @@ const tls = require('tls');
3642

3743
{
3844
const invalid = 'fhqwhgads';
39-
const invalidOut = tls.parseCertString(invalid);
45+
const invalidOut = internalTLS.parseCertString(invalid);
4046
assert.deepStrictEqual(invalidOut, { __proto__: null });
4147
}
4248

@@ -45,5 +51,16 @@ const tls = require('tls');
4551
const expected = Object.create(null);
4652
expected.__proto__ = 'mostly harmless';
4753
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' });
4966
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.