diff options
author | XadillaX <admin@xcoder.in> | 2017-09-08 15:58:54 +0800 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2017-09-13 16:54:35 -0300 |
commit | 468110b3276007f445741b41c36beb0ef62d751c (patch) | |
tree | 20dad9aa50d6ec82a19100a12cff79bcd884d8a7 /lib | |
parent | f68ab39f8e7d21b9689ac1f9978758a4393c2072 (diff) | |
download | android-node-v8-468110b3276007f445741b41c36beb0ef62d751c.tar.gz android-node-v8-468110b3276007f445741b41c36beb0ef62d751c.tar.bz2 android-node-v8-468110b3276007f445741b41c36beb0ef62d751c.zip |
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: https://github.com/nodejs/node/pull/14249
Refs: https://github.com/nodejs/node/issues/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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_tls_common.js | 5 | ||||
-rw-r--r-- | lib/internal/tls.js | 28 | ||||
-rw-r--r-- | lib/tls.js | 28 |
3 files changed, 37 insertions, 24 deletions
diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 3c4f2e2bb9..fa31fd7de6 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -21,6 +21,7 @@ 'use strict'; +const { parseCertString } = require('internal/tls'); const tls = require('tls'); const errors = require('internal/errors'); @@ -202,11 +203,11 @@ exports.translatePeerCertificate = function translatePeerCertificate(c) { if (!c) return null; - if (c.issuer != null) c.issuer = tls.parseCertString(c.issuer); + if (c.issuer != null) c.issuer = parseCertString(c.issuer); if (c.issuerCertificate != null && c.issuerCertificate !== c) { c.issuerCertificate = translatePeerCertificate(c.issuerCertificate); } - if (c.subject != null) c.subject = tls.parseCertString(c.subject); + if (c.subject != null) c.subject = parseCertString(c.subject); if (c.infoAccess != null) { var info = c.infoAccess; c.infoAccess = Object.create(null); diff --git a/lib/internal/tls.js b/lib/internal/tls.js new file mode 100644 index 0000000000..6d367dbf28 --- /dev/null +++ b/lib/internal/tls.js @@ -0,0 +1,28 @@ +'use strict'; + +// Example: +// C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org +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 +}; diff --git a/lib/tls.js b/lib/tls.js index bbf73e6e2a..91a543cb55 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -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\nemailAddress=ry@clouds.org -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; |