Skip to content
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

crypto: add ticketKeys option in createSecureContext #20916

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function SecureContext(secureProtocol, secureOptions, context) {
if (secureOptions) this.context.setOptions(secureOptions);
}

SecureContext.prototype.getTicketKeys = function getTicketKeys() {
return this.context.getTicketKeys();
};


SecureContext.prototype.setTicketKeys = function setTicketKeys(keys) {
this.context.setTicketKeys(keys);
};

function validateKeyCert(name, value) {
if (typeof value !== 'string' && !isArrayBufferView(value)) {
throw new ERR_INVALID_ARG_TYPE(
Expand Down Expand Up @@ -223,6 +232,14 @@ exports.createSecureContext = function createSecureContext(options, context) {
options.clientCertEngine);
}

if (options.ticketKeys) {
c.context.setTicketKeys(options.ticketKeys);
}

if (options.sessionTimeout) {
c.context.setSessionTimeout(options.sessionTimeout);
}

return c;
};

Expand Down
12 changes: 3 additions & 9 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,9 @@ function Server(options, listener) {
secureOptions: this.secureOptions,
honorCipherOrder: this.honorCipherOrder,
crl: this.crl,
sessionIdContext: this.sessionIdContext
sessionIdContext: this.sessionIdContext,
ticketKeys: this.ticketKeys,
sessionTimeout: this.sessionTimeout,
});

this[kHandshakeTimeout] = options.handshakeTimeout || (120 * 1000);
Expand All @@ -896,14 +898,6 @@ function Server(options, listener) {
'options.handshakeTimeout', 'number', options.handshakeTimeout);
}

if (this.sessionTimeout) {
this._sharedCreds.context.setSessionTimeout(this.sessionTimeout);
}

if (this.ticketKeys) {
this._sharedCreds.context.setTicketKeys(this.ticketKeys);
}

// constructor call
net.Server.call(this, tlsConnectionListener);

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

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

const keys = crypto.randomBytes(48);
const otherKeys = crypto.randomBytes(48);

const context = tls.createSecureContext({
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem'),
ticketKeys: keys
});

assert.strictEqual(context.getTicketKeys(), keys);
context.setTicketKeys(otherKeys);
assert.strictEqual(context.getTicketKeys(), otherKeys);