Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[tls] share SSL context between server's connections

  • Loading branch information...
commit 77c0907dc2fedbd62eeb94b90dbb9dc852149261 1 parent c9b40da
@indutny authored
Showing with 33 additions and 23 deletions.
  1. +17 −10 lib/crypto.js
  2. +16 −13 lib/tls.js
View
27 lib/crypto.js
@@ -36,7 +36,7 @@ try {
}
-function Credentials(secureProtocol, flags) {
+function Credentials(secureProtocol, flags, context) {
if (!(this instanceof Credentials)) {
return new Credentials(secureProtocol);
}
@@ -45,24 +45,31 @@ function Credentials(secureProtocol, flags) {
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(flags) this.context.setOptions(flags);
+ if (secureProtocol) {
+ this.context.init(secureProtocol);
+ } else {
+ this.context.init();
+ }
+ if(flags) this.context.setOptions(flags);
+ }
}
exports.Credentials = Credentials;
-exports.createCredentials = function(options) {
+exports.createCredentials = function(options, context) {
if (!options) options = {};
- var c = new Credentials(options.secureProtocol, options.secureOptions);
+ var c = new Credentials(options.secureProtocol, options.secureOptions,
+ context);
+
+ if (context) return c;
if (options.key) c.context.setKey(options.key);
View
29 lib/tls.js
@@ -767,18 +767,24 @@ function Server(/* [options], listener */) {
var self = this;
+ // Handle option defaults:
+ this.setOptions(options);
+
+ var sharedCreds = crypto.createCredentials({
+ key: self.key,
+ cert: self.cert,
+ ca: self.ca,
+ ciphers: self.ciphers,
+ secureProtocol: self.secureProtocol,
+ secureOptions: self.secureOptions,
+ 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,
- ciphers: self.ciphers,
- secureProtocol: self.secureProtocol,
- secureOptions: self.secureOptions,
- 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,
@@ -819,9 +825,6 @@ function Server(/* [options], listener */) {
if (listener) {
this.on('secureConnection', listener);
}
-
- // Handle option defaults:
- this.setOptions(options);
}
util.inherits(Server, net.Server);
Please sign in to comment.
Something went wrong with that request. Please try again.