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

Remove unused context arg #24241

Closed
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
23 changes: 6 additions & 17 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,13 @@ const { SSL_OP_CIPHER_SERVER_PREFERENCE } = internalBinding('constants').crypto;
let toBuf = null;

const { SecureContext: NativeSecureContext } = internalBinding('crypto');
function SecureContext(secureProtocol, secureOptions, context) {
function SecureContext(secureProtocol, secureOptions) {
if (!(this instanceof SecureContext)) {
return new SecureContext(secureProtocol, secureOptions, context);
return new SecureContext(secureProtocol, secureOptions);
}

if (context) {
this.context = context;
} else {
this.context = new NativeSecureContext();

if (secureProtocol) {
this.context.init(secureProtocol);
} else {
this.context.init();
}
}
this.context = new NativeSecureContext();
this.context.init(secureProtocol);

if (secureOptions) this.context.setOptions(secureOptions);
}
Expand All @@ -68,19 +59,17 @@ function validateKeyCert(name, value) {
exports.SecureContext = SecureContext;


exports.createSecureContext = function createSecureContext(options, context) {
exports.createSecureContext = function createSecureContext(options) {
if (!options) options = {};

var secureOptions = options.secureOptions;
if (options.honorCipherOrder)
secureOptions |= SSL_OP_CIPHER_SERVER_PREFERENCE;

const c = new SecureContext(options.secureProtocol, secureOptions, context);
const c = new SecureContext(options.secureProtocol, secureOptions);
var i;
var val;

if (context) return c;

// NOTE: It's important to add CA before the cert to be able to load
// cert's issuer in C++ code.
const { ca } = options;
Expand Down
14 changes: 7 additions & 7 deletions test/parallel/test-crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ const tls = require('tls');
const fixtures = require('../common/fixtures');

// Test Certificates
const caPem = fixtures.readSync('test_ca.pem', 'ascii');
const certPem = fixtures.readSync('test_cert.pem', 'ascii');
const certPfx = fixtures.readSync('test_cert.pfx');
const keyPem = fixtures.readSync('test_key.pem', 'ascii');

// 'this' safety
// https://github.com/joyent/node/issues/6690
assert.throws(function() {
const options = { key: keyPem, cert: certPem, ca: caPem };
const credentials = tls.createSecureContext(options);
const credentials = tls.createSecureContext();
const context = credentials.context;
const notcontext = { setOptions: context.setOptions, setKey: context.setKey };
tls.createSecureContext({ secureOptions: 1 }, notcontext);
const notcontext = { setOptions: context.setOptions };

// Methods of native objects should not segfault when reassigned to a new
// object and called illegally. This core dumped in 0.10 and was fixed in
// 0.11.
notcontext.setOptions();
}, (err) => {
// Throws TypeError, so there is no opensslErrorStack property.
if ((err instanceof Error) &&
Expand Down