Share SSL context between server connections

Fixes #1073.
This commit is contained in:
Fedor Indutny 2011-05-20 02:42:13 +07:00 committed by Ryan Dahl
parent 6461af1baa
commit 21724ecaec
2 changed files with 30 additions and 17 deletions

View File

@ -36,7 +36,7 @@ try {
} }
function Credentials(secureProtocol) { function Credentials(secureProtocol, context) {
if (!(this instanceof Credentials)) { if (!(this instanceof Credentials)) {
return new Credentials(secureProtocol); return new Credentials(secureProtocol);
} }
@ -45,6 +45,10 @@ function Credentials(secureProtocol) {
throw new Error('node.js not compiled with openssl crypto support.'); throw new Error('node.js not compiled with openssl crypto support.');
} }
if (context) {
this.context = context;
this.reuseContext = true;
} else {
this.context = new SecureContext(); this.context = new SecureContext();
if (secureProtocol) { if (secureProtocol) {
@ -52,15 +56,17 @@ function Credentials(secureProtocol) {
} else { } else {
this.context.init(); this.context.init();
} }
}
} }
exports.Credentials = Credentials; exports.Credentials = Credentials;
exports.createCredentials = function(options) { exports.createCredentials = function(options, context) {
if (!options) options = {}; 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); if (options.key) c.context.setKey(options.key);

View File

@ -713,16 +713,23 @@ function Server(/* [options], listener */) {
var self = this; var self = this;
// constructor call // Handle option defaults:
net.Server.call(this, function(socket) { this.setOptions(options);
var creds = crypto.createCredentials({
var sharedCreds = crypto.createCredentials({
key: self.key, key: self.key,
cert: self.cert, cert: self.cert,
ca: self.ca, ca: self.ca,
ciphers: self.ciphers,
secureProtocol: self.secureProtocol, secureProtocol: self.secureProtocol,
crl: self.crl crl: self.crl
}); });
creds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA');
sharedCreds.context.setCiphers('RC4-SHA:AES128-SHA:AES256-SHA');
// constructor call
net.Server.call(this, function(socket) {
var creds = crypto.createCredentials(null, sharedCreds.context);
var pair = new SecurePair(creds, var pair = new SecurePair(creds,
true, true,