Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Share SSL context between server connections
Browse files Browse the repository at this point in the history
Fixes #1073.
  • Loading branch information
indutny authored and ry committed May 19, 2011
1 parent 6461af1 commit 21724ec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
24 changes: 15 additions & 9 deletions lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ try {
}


function Credentials(secureProtocol) {
function Credentials(secureProtocol, context) {
if (!(this instanceof Credentials)) {
return new Credentials(secureProtocol);
}
Expand All @@ -45,22 +45,28 @@ function Credentials(secureProtocol) {
throw new Error('node.js not compiled with openssl crypto support.');
}

this.context = new SecureContext();

if (secureProtocol) {
this.context.init(secureProtocol);
if (context) {
this.context = context;
this.reuseContext = true;
} else {
this.context.init();
}
this.context = new SecureContext();

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

exports.Credentials = Credentials;


exports.createCredentials = function(options) {
exports.createCredentials = function(options, context) {
if (!options) options = {};
var c = new Credentials(options.secureProtocol);
var c = new Credentials(options.secureProtocol, context);

if (context) return c;

if (options.key) c.context.setKey(options.key);

Expand Down
23 changes: 15 additions & 8 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,16 +713,23 @@ function Server(/* [options], listener */) {

var self = this;

// Handle option defaults:
this.setOptions(options);

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Sep 16, 2011

Member

Merge conflict? Those two lines are repeated at the end of the constructor.

This comment has been minimized.

Copy link
@indutny

indutny Sep 17, 2011

Author Member

Yeah, looks like last one should be removed

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Sep 19, 2011

Member

Okay, removed in 243c218.


var sharedCreds = crypto.createCredentials({
key: self.key,
cert: self.cert,
ca: self.ca,
ciphers: self.ciphers,
secureProtocol: self.secureProtocol,
crl: self.crl
});

sharedCreds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA');

// constructor call
net.Server.call(this, function(socket) {
var creds = crypto.createCredentials({
key: self.key,
cert: self.cert,
ca: self.ca,
secureProtocol: self.secureProtocol,
crl: self.crl
});
creds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA');
var creds = crypto.createCredentials(null, sharedCreds.context);

var pair = new SecurePair(creds,
true,
Expand Down

0 comments on commit 21724ec

Please sign in to comment.