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

tls: add missing 'new' #27614

Closed
wants to merge 2 commits into from
Closed
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/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,14 @@ exports.createSecureContext = function createSecureContext(options) {
// cipher suites all have a standard name format beginning with TLS_, so split
// the ciphers and pass them to the appropriate API.
const ciphers = (options.ciphers || tls.DEFAULT_CIPHERS).split(':');
const cipherList = ciphers.filter((_) => !_.match(/^TLS_/)).join(':');
const cipherList = ciphers.filter((_) => !_.match(/^TLS_/) &&
_.length > 0).join(':');
const cipherSuites = ciphers.filter((_) => _.match(/^TLS_/)).join(':');

if (cipherSuites === '' && cipherList === '') {
// Specifying empty cipher suites for both TLS1.2 and TLS1.3 is invalid, its
// not possible to handshake with no suites.
throw ERR_INVALID_OPT_VALUE('ciphers', ciphers);
throw new ERR_INVALID_OPT_VALUE('ciphers', ciphers);
}

c.context.setCipherSuites(cipherSuites);
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-tls-set-ciphers.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,13 @@ test('TLS_AES_128_CCM_8_SHA256', U,

test('TLS_AES_128_CCM_8_SHA256', 'TLS_AES_128_CCM_8_SHA256',
'TLS_AES_128_CCM_8_SHA256');

// Invalid cipher values
test(9, 'AES256-SHA', U, 'ERR_INVALID_ARG_TYPE', U);
test('AES256-SHA', 9, U, U, 'ERR_INVALID_ARG_TYPE');
test(':', 'AES256-SHA', U, 'ERR_INVALID_OPT_VALUE', U);
test('AES256-SHA', ':', U, U, 'ERR_INVALID_OPT_VALUE');

// Using '' is synonymous for "use default ciphers"
test('TLS_AES_256_GCM_SHA384', '', 'TLS_AES_256_GCM_SHA384');
test('', 'TLS_AES_256_GCM_SHA384', 'TLS_AES_256_GCM_SHA384');