Skip to content
Browse files

Share SSL context between server connections

Fixes #1073.
  • Loading branch information...
1 parent 6461af1 commit 21724ecaec63aad529a1ce2f0eebd82e52d399e3 @indutny indutny committed with ry
Showing with 30 additions and 17 deletions.
  1. +15 −9 lib/crypto.js
  2. +15 −8 lib/tls.js
View
24 lib/crypto.js
@@ -36,7 +36,7 @@ try {
}
-function Credentials(secureProtocol) {
+function Credentials(secureProtocol, context) {
if (!(this instanceof Credentials)) {
return new Credentials(secureProtocol);
}
@@ -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);
View
23 lib/tls.js
@@ -713,16 +713,23 @@ function Server(/* [options], listener */) {
var self = this;
+ // Handle option defaults:
+ this.setOptions(options);
@bnoordhuis Node.js Foundation member

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

@indutny Node.js Foundation member
indutny added a note

Yeah, looks like last one should be removed

@bnoordhuis Node.js Foundation member

Okay, removed in 243c218.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ 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,

0 comments on commit 21724ec

Please sign in to comment.
Something went wrong with that request. Please try again.