Skip to content

Commit

Permalink
tls: validate ticket keys buffer
Browse files Browse the repository at this point in the history
Fixes: #38305

PR-URL: #38308
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 authored and targos committed Jun 11, 2021
1 parent 6b58f28 commit f6e4dbb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ existing server. Existing connections to the server are not interrupted.
added: v3.0.0
-->

* `keys` {Buffer} A 48-byte buffer containing the session ticket keys.
* `keys` {Buffer|TypedArray|DataView} A 48-byte buffer containing the session
ticket keys.

Sets the session ticket keys.

Expand Down
3 changes: 3 additions & 0 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,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');
this._sharedCreds.context.setTicketKeys(keys);
};

Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-tls-ticket-invalid-arg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
}

const assert = require('assert');
const tls = require('tls');

const server = new tls.Server();

[null, undefined, 0, 1, 1n, Symbol(), {}, [], true, false, '', () => {}]
.forEach((arg) =>
assert.throws(
() => server.setTicketKeys(arg),
{ code: 'ERR_INVALID_ARG_TYPE' }
));

[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/)
);

0 comments on commit f6e4dbb

Please sign in to comment.