-
Notifications
You must be signed in to change notification settings - Fork 31.3k
lib: deprecate _tls_common and _tls_wrap #57643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dario-piotrowicz
wants to merge
2
commits into
nodejs:main
Choose a base branch
from
dario-piotrowicz:dario/deprecate_tls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,156 +1,10 @@ | ||
// Copyright Joyent, Inc. and other Node contributors. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to permit | ||
// persons to whom the Software is furnished to do so, subject to the | ||
// following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN | ||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
// USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
'use strict'; | ||
|
||
const { | ||
JSONParse, | ||
} = primordials; | ||
|
||
const tls = require('tls'); | ||
|
||
const { | ||
codes: { | ||
ERR_TLS_INVALID_PROTOCOL_VERSION, | ||
ERR_TLS_PROTOCOL_VERSION_CONFLICT, | ||
}, | ||
} = require('internal/errors'); | ||
|
||
const { | ||
crypto: { | ||
SSL_OP_CIPHER_SERVER_PREFERENCE, | ||
TLS1_VERSION, | ||
TLS1_1_VERSION, | ||
TLS1_2_VERSION, | ||
TLS1_3_VERSION, | ||
}, | ||
} = internalBinding('constants'); | ||
|
||
const { | ||
kEmptyObject, | ||
} = require('internal/util'); | ||
|
||
const { | ||
validateInteger, | ||
} = require('internal/validators'); | ||
|
||
const { | ||
configSecureContext, | ||
} = require('internal/tls/secure-context'); | ||
|
||
function toV(which, v, def) { | ||
v ??= def; | ||
if (v === 'TLSv1') return TLS1_VERSION; | ||
if (v === 'TLSv1.1') return TLS1_1_VERSION; | ||
if (v === 'TLSv1.2') return TLS1_2_VERSION; | ||
if (v === 'TLSv1.3') return TLS1_3_VERSION; | ||
throw new ERR_TLS_INVALID_PROTOCOL_VERSION(v, which); | ||
} | ||
|
||
const { | ||
SecureContext: NativeSecureContext, | ||
} = internalBinding('crypto'); | ||
|
||
function SecureContext(secureProtocol, secureOptions, minVersion, maxVersion) { | ||
if (!(this instanceof SecureContext)) { | ||
return new SecureContext(secureProtocol, secureOptions, minVersion, | ||
maxVersion); | ||
} | ||
|
||
if (secureProtocol) { | ||
if (minVersion != null) | ||
throw new ERR_TLS_PROTOCOL_VERSION_CONFLICT(minVersion, secureProtocol); | ||
if (maxVersion != null) | ||
throw new ERR_TLS_PROTOCOL_VERSION_CONFLICT(maxVersion, secureProtocol); | ||
} | ||
|
||
this.context = new NativeSecureContext(); | ||
this.context.init(secureProtocol, | ||
toV('minimum', minVersion, tls.DEFAULT_MIN_VERSION), | ||
toV('maximum', maxVersion, tls.DEFAULT_MAX_VERSION)); | ||
|
||
if (secureOptions) { | ||
validateInteger(secureOptions, 'secureOptions'); | ||
this.context.setOptions(secureOptions); | ||
} | ||
} | ||
|
||
function createSecureContext(options) { | ||
options ||= kEmptyObject; | ||
const { | ||
honorCipherOrder, | ||
minVersion, | ||
maxVersion, | ||
secureProtocol, | ||
} = options; | ||
|
||
let { secureOptions } = options; | ||
|
||
if (honorCipherOrder) | ||
secureOptions |= SSL_OP_CIPHER_SERVER_PREFERENCE; | ||
|
||
const c = new SecureContext(secureProtocol, secureOptions, | ||
minVersion, maxVersion); | ||
|
||
configSecureContext(c.context, options); | ||
|
||
return c; | ||
} | ||
|
||
// Translate some fields from the handle's C-friendly format into more idiomatic | ||
// javascript object representations before passing them back to the user. Can | ||
// be used on any cert object, but changing the name would be semver-major. | ||
function translatePeerCertificate(c) { | ||
if (!c) | ||
return null; | ||
|
||
if (c.issuerCertificate != null && c.issuerCertificate !== c) { | ||
c.issuerCertificate = translatePeerCertificate(c.issuerCertificate); | ||
} | ||
if (c.infoAccess != null) { | ||
const info = c.infoAccess; | ||
c.infoAccess = { __proto__: null }; | ||
|
||
// XXX: More key validation? | ||
info.replace(/([^\n:]*):([^\n]*)(?:\n|$)/g, | ||
(all, key, val) => { | ||
if (val.charCodeAt(0) === 0x22) { | ||
// The translatePeerCertificate function is only | ||
// used on internally created legacy certificate | ||
// objects, and any value that contains a quote | ||
// will always be a valid JSON string literal, | ||
// so this should never throw. | ||
val = JSONParse(val); | ||
} | ||
if (key in c.infoAccess) | ||
c.infoAccess[key].push(val); | ||
else | ||
c.infoAccess[key] = [val]; | ||
}); | ||
} | ||
return c; | ||
} | ||
|
||
const { SecureContext, createSecureContext, translatePeerCertificate } = require('internal/tls/common'); | ||
module.exports = { | ||
SecureContext, | ||
createSecureContext, | ||
translatePeerCertificate, | ||
}; | ||
process.emitWarning('The _tls_common module is deprecated.', | ||
'DeprecationWarning', 'DEP0192'); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting... it's an unfortunate truth that while these are deprecated we likely will never be able to actually remove them. See
require('sys')
....There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see.. that's pretty disappointing 🥲 (although I understand the security implications...)
I like your suggestion of throwing an error though, it'd be pretty nice if we could do that at some point 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mh... or maybe the _ modules could be removed at some point since npm doesn't support such modules anyways? 🤔
#26292 (comment)
https://github.com/npm/validate-npm-package-name?tab=readme-ov-file#naming-rules
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm may not but an attacker could still locally inject a module which would still be problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see what you mean... like with a postinstall script or something that drops an _ module in the node_modules right? 🤔
oh too bad then 😓 (but I am still hoping for the throwing idea! 😀)