Skip to content

tls: make Server.getTicketKeys throw instead of assert #58365

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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/internal/tls/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,8 +1531,9 @@ Server.prototype.getTicketKeys = function getTicketKeys() {

Server.prototype.setTicketKeys = function setTicketKeys(keys) {
validateBuffer(keys);
assert(keys.byteLength === 48,
'Session ticket keys must be a 48-byte buffer');
if (keys.byteLength !== 48) {
throw new ERR_INVALID_ARG_VALUE('keys', keys.byteLength, 'must be exactly 48 bytes');
}
this._sharedCreds.context.setTicketKeys(keys);
};

Expand Down
18 changes: 14 additions & 4 deletions test/parallel/test-tls-ticket-invalid-arg.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@
.forEach((arg) =>
assert.throws(
() => server.setTicketKeys(arg),
{ code: 'ERR_INVALID_ARG_TYPE' }
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "buffer" argument must be an instance of Buffer, TypedArray, or DataView.'
+ common.invalidArgTypeHelper(arg),

Check failure on line 20 in test/parallel/test-tls-ticket-invalid-arg.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'+' should be placed at the end of the line
}
));

[new Uint8Array(1), Buffer.from([1]), new DataView(new ArrayBuffer(2))].forEach(
(arg) =>
assert.throws(() => {
server.setTicketKeys(arg);
}, /Session ticket keys must be a 48-byte buffer/)
assert.throws(
() => server.setTicketKeys(arg),
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_VALUE',
message: `The argument 'keys' must be exactly 48 bytes. Received ${arg.byteLength}`,
}
)
);
Loading