Skip to content

Commit a822a1c

Browse files
lib: deprecate _tls_common and _tls_wrap
runtime deprecate the _tls_common and _tls_wrap modules, users should use nust node:tls insteal and internally internal/tls/commond and internal/tls/wrap should be used instead PR-URL: #57643 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 6710c00 commit a822a1c

11 files changed

+2000
-1941
lines changed

doc/api/deprecations.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3904,6 +3904,20 @@ of built-in modules. This was incomplete and matched the already deprecated
39043904
`repl._builtinLibs` ([DEP0142][]) instead it's better to rely
39053905
upon `require('node:module').builtinModules`.
39063906

3907+
### DEP0192: `require('node:_tls_common')` and `require('node:_tls_wrap')`
3908+
3909+
<!-- YAML
3910+
changes:
3911+
- version: REPLACEME
3912+
pr-url: https://github.com/nodejs/node/pull/57643
3913+
description: Runtime deprecation.
3914+
-->
3915+
3916+
Type: Runtime
3917+
3918+
The `node:_tls_common` and `node:_tls_wrap` modules are deprecated as they should be considered
3919+
an internal nodejs implementation rather than a public facing API, use `node:tls` instead.
3920+
39073921
[DEP0142]: #dep0142-repl_builtinlibs
39083922
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
39093923
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3

lib/_tls_common.js

Lines changed: 3 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,10 @@
1-
// Copyright Joyent, Inc. and other Node contributors.
2-
//
3-
// Permission is hereby granted, free of charge, to any person obtaining a
4-
// copy of this software and associated documentation files (the
5-
// "Software"), to deal in the Software without restriction, including
6-
// without limitation the rights to use, copy, modify, merge, publish,
7-
// distribute, sublicense, and/or sell copies of the Software, and to permit
8-
// persons to whom the Software is furnished to do so, subject to the
9-
// following conditions:
10-
//
11-
// The above copyright notice and this permission notice shall be included
12-
// in all copies or substantial portions of the Software.
13-
//
14-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
221
'use strict';
232

24-
const {
25-
JSONParse,
26-
} = primordials;
27-
28-
const tls = require('tls');
29-
30-
const {
31-
codes: {
32-
ERR_TLS_INVALID_PROTOCOL_VERSION,
33-
ERR_TLS_PROTOCOL_VERSION_CONFLICT,
34-
},
35-
} = require('internal/errors');
36-
37-
const {
38-
crypto: {
39-
SSL_OP_CIPHER_SERVER_PREFERENCE,
40-
TLS1_VERSION,
41-
TLS1_1_VERSION,
42-
TLS1_2_VERSION,
43-
TLS1_3_VERSION,
44-
},
45-
} = internalBinding('constants');
46-
47-
const {
48-
kEmptyObject,
49-
} = require('internal/util');
50-
51-
const {
52-
validateInteger,
53-
} = require('internal/validators');
54-
55-
const {
56-
configSecureContext,
57-
} = require('internal/tls/secure-context');
58-
59-
function toV(which, v, def) {
60-
v ??= def;
61-
if (v === 'TLSv1') return TLS1_VERSION;
62-
if (v === 'TLSv1.1') return TLS1_1_VERSION;
63-
if (v === 'TLSv1.2') return TLS1_2_VERSION;
64-
if (v === 'TLSv1.3') return TLS1_3_VERSION;
65-
throw new ERR_TLS_INVALID_PROTOCOL_VERSION(v, which);
66-
}
67-
68-
const {
69-
SecureContext: NativeSecureContext,
70-
} = internalBinding('crypto');
71-
72-
function SecureContext(secureProtocol, secureOptions, minVersion, maxVersion) {
73-
if (!(this instanceof SecureContext)) {
74-
return new SecureContext(secureProtocol, secureOptions, minVersion,
75-
maxVersion);
76-
}
77-
78-
if (secureProtocol) {
79-
if (minVersion != null)
80-
throw new ERR_TLS_PROTOCOL_VERSION_CONFLICT(minVersion, secureProtocol);
81-
if (maxVersion != null)
82-
throw new ERR_TLS_PROTOCOL_VERSION_CONFLICT(maxVersion, secureProtocol);
83-
}
84-
85-
this.context = new NativeSecureContext();
86-
this.context.init(secureProtocol,
87-
toV('minimum', minVersion, tls.DEFAULT_MIN_VERSION),
88-
toV('maximum', maxVersion, tls.DEFAULT_MAX_VERSION));
89-
90-
if (secureOptions) {
91-
validateInteger(secureOptions, 'secureOptions');
92-
this.context.setOptions(secureOptions);
93-
}
94-
}
95-
96-
function createSecureContext(options) {
97-
options ||= kEmptyObject;
98-
const {
99-
honorCipherOrder,
100-
minVersion,
101-
maxVersion,
102-
secureProtocol,
103-
} = options;
104-
105-
let { secureOptions } = options;
106-
107-
if (honorCipherOrder)
108-
secureOptions |= SSL_OP_CIPHER_SERVER_PREFERENCE;
109-
110-
const c = new SecureContext(secureProtocol, secureOptions,
111-
minVersion, maxVersion);
112-
113-
configSecureContext(c.context, options);
114-
115-
return c;
116-
}
117-
118-
// Translate some fields from the handle's C-friendly format into more idiomatic
119-
// javascript object representations before passing them back to the user. Can
120-
// be used on any cert object, but changing the name would be semver-major.
121-
function translatePeerCertificate(c) {
122-
if (!c)
123-
return null;
124-
125-
if (c.issuerCertificate != null && c.issuerCertificate !== c) {
126-
c.issuerCertificate = translatePeerCertificate(c.issuerCertificate);
127-
}
128-
if (c.infoAccess != null) {
129-
const info = c.infoAccess;
130-
c.infoAccess = { __proto__: null };
131-
132-
// XXX: More key validation?
133-
info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g,
134-
(all, key, val) => {
135-
if (val.charCodeAt(0) === 0x22) {
136-
// The translatePeerCertificate function is only
137-
// used on internally created legacy certificate
138-
// objects, and any value that contains a quote
139-
// will always be a valid JSON string literal,
140-
// so this should never throw.
141-
val = JSONParse(val);
142-
}
143-
if (key in c.infoAccess)
144-
c.infoAccess[key].push(val);
145-
else
146-
c.infoAccess[key] = [val];
147-
});
148-
}
149-
return c;
150-
}
151-
3+
const { SecureContext, createSecureContext, translatePeerCertificate } = require('internal/tls/common');
1524
module.exports = {
1535
SecureContext,
1546
createSecureContext,
1557
translatePeerCertificate,
1568
};
9+
process.emitWarning('The _tls_common module is deprecated.',
10+
'DeprecationWarning', 'DEP0192');

0 commit comments

Comments
 (0)