mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
tls: validate ticket keys buffer
Fixes: https://github.com/nodejs/node/issues/38305 PR-URL: https://github.com/nodejs/node/pull/38308 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
6b58f28472
commit
f6e4dbb779
3 files changed
+29
-1
No files matched your search
+2
-1
@@ -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.
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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/)
|
||||
);
|
||||
Reference in new issue
Block a user