Skip to content

Commit 685a874

Browse files
committed
Merge pull request #12 from DullReferenceException/forward-compatible-https
Forward-compatible HTTPS options
2 parents d8c2ca4 + d8ee4d5 commit 685a874

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed

index.js

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ var fs = require('fs'),
1212
https = require('https'),
1313
path = require('path'),
1414
connected = require('connected'),
15-
errs = require('errs');
15+
errs = require('errs'),
16+
assign = require('object-assign');
1617

1718
var CIPHERS = [
1819
'ECDHE-RSA-AES256-SHA384',
@@ -122,54 +123,51 @@ module.exports = function createServers(options, listening) {
122123
return onListen('https');
123124
}
124125

125-
var port = +options.https.port || 443,
126-
ssl = options.https,
126+
var ssl = options.https,
127+
port = +ssl.port || 443,
128+
ciphers = ssl.ciphers || CIPHERS,
129+
ca = ssl.ca,
127130
server,
128-
args,
129-
ip;
130-
131-
ssl.ciphers = ssl.ciphers || CIPHERS;
131+
args;
132132

133133
//
134134
// Remark: If an array is passed in lets join it like we do the defaults
135135
//
136-
if (Array.isArray(ssl.ciphers)) {
137-
ssl.ciphers = ssl.ciphers.join(':');
136+
if (Array.isArray(ciphers)) {
137+
ciphers = ciphers.join(':');
138138
}
139139

140-
if (ssl.ca && !Array.isArray(ssl.ca)) {
141-
ssl.ca = [ssl.ca];
140+
if (ca && !Array.isArray(ca)) {
141+
ca = [ca];
142142
}
143143

144-
log('https | listening on %d', port);
145-
server = https.createServer({
144+
var finalHttpsOptions = assign({}, ssl, {
146145
//
147146
// Load default SSL key, cert and ca(s).
148147
//
149-
key: fs.readFileSync(path.resolve(ssl.root, ssl.key)),
148+
key: fs.readFileSync(path.resolve(ssl.root, ssl.key)),
150149
cert: fs.readFileSync(path.resolve(ssl.root, ssl.cert)),
151-
ca: ssl.ca && ssl.ca.map(
152-
function (file) {
153-
return fs.readFileSync(path.resolve(ssl.root, file));
154-
}
150+
ca: ca && ca.map(
151+
function (file) {
152+
return fs.readFileSync(path.resolve(ssl.root, file));
153+
}
155154
),
156155
//
157156
// Properly expose ciphers for an A+ SSL rating:
158157
// https://certsimple.com/blog/a-plus-node-js-ssl
159158
//
160-
ciphers: ssl.ciphers,
159+
ciphers: ciphers,
161160
honorCipherOrder: !!ssl.honorCipherOrder,
162161
//
163-
// Optionally support SNI-based SSL.
164-
//
165-
SNICallback: ssl.SNICallback,
166-
//
167162
// Protect against the POODLE attack by disabling SSLv3
168163
// @see http://googleonlinesecurity.blogspot.nl/2014/10/this-poodle-bites-exploiting-ssl-30.html
169164
//
170165
secureProtocol: 'SSLv23_method',
171166
secureOptions: require('constants').SSL_OP_NO_SSLv3
172-
}, ssl.handler || handler);
167+
});
168+
169+
log('https | listening on %d', port);
170+
server = https.createServer(finalHttpsOptions, ssl.handler || handler);
173171

174172
args = [server, port];
175173
if (options.https.host) {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
"homepage": "https://github.com/indexzero/create-servers",
2424
"dependencies": {
2525
"connected": "~0.0.2",
26-
"errs": "~0.3.0"
26+
"errs": "~0.3.0",
27+
"object-assign": "^4.1.0"
2728
},
2829
"devDependencies": {
30+
"sinon": "^1.17.4",
2931
"tape": "~2.14.0"
3032
}
3133
}

test/create-servers-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
var path = require('path'),
99
http = require('http'),
10+
https = require('https'),
1011
test = require('tape'),
12+
sinon = require('sinon'),
1113
createServers = require('../');
1214

1315
//
@@ -173,3 +175,24 @@ test('http && https with different handlers', function (t) {
173175
});
174176
});
175177
});
178+
179+
test('supports requestCert https option', function (t) {
180+
t.plan(2);
181+
var spy = sinon.spy(https, 'createServer');
182+
createServers({
183+
log: console.log,
184+
https: {
185+
port: 3456,
186+
root: path.join(__dirname, 'fixtures'),
187+
cert: 'agent2-cert.pem',
188+
key: 'agent2-key.pem',
189+
requestCert: true
190+
},
191+
handler: fend
192+
}, function (err, servers) {
193+
t.error(err);
194+
t.equals(spy.lastCall.args[0].requestCert, true, 'should preserve the requestCert option');
195+
servers.https.close();
196+
spy.restore();
197+
});
198+
});

0 commit comments

Comments
 (0)