-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: add minDHkeylen option to tls.connect()
Add a new option to specifiy a minimum key length of an ephemeral DH parameter to accept a tls connection. Default is 1024 bit.
- Loading branch information
Shigeki Ohtsu
committed
May 29, 2015
1 parent
18b8e0c
commit 9c74500
Showing
3 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: missing crypto'); | ||
process.exit(); | ||
} | ||
var tls = require('tls'); | ||
|
||
var fs = require('fs'); | ||
var key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); | ||
var cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); | ||
|
||
var nsuccess = 0; | ||
var nerror = 0; | ||
|
||
function loadDHParam(n) { | ||
var path = common.fixturesDir; | ||
if (n !== 'error') path += '/keys'; | ||
return fs.readFileSync(path + '/dh' + n + '.pem'); | ||
} | ||
|
||
function test(keylen, err, cb) { | ||
var options = { | ||
key: key, | ||
cert: cert, | ||
dhparam: loadDHParam(keylen), | ||
ciphers: 'DHE-RSA-AES128-GCM-SHA256' | ||
}; | ||
|
||
var server = tls.createServer(options, function(conn) { | ||
conn.end(); | ||
}); | ||
|
||
server.on('close', function(isException) { | ||
assert(!isException); | ||
if (cb) cb(); | ||
}); | ||
|
||
server.listen(common.PORT, '127.0.0.1', function() { | ||
// client set minimum DH key length 2048 bits so that | ||
// it fails when it make a connection to the tls server where | ||
// dhparams is 1024 bits | ||
var client = tls.connect({ | ||
minDHkeylen: 2048, | ||
port: common.PORT, | ||
rejectUnauthorized: false | ||
}, function() { | ||
nsuccess++; | ||
server.close(); | ||
}); | ||
if(err) { | ||
client.on('error', function(e) { | ||
nerror++; | ||
assert.strictEqual(e.message, 'DH key length 1024 is less than 2048'); | ||
server.close(); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
// A client connection fails with an error when a client has an | ||
// 2048 bits minDHkeylen option and a server has 1024 bits dhparam | ||
function testDHE1024() { | ||
test(1024, true, testDHE2048); | ||
} | ||
|
||
// A client connection successes when a client has an | ||
// 2048 bits minDHkeylen option and a server has 2048 bits dhparam | ||
function testDHE2048() { | ||
test(2048, false, null); | ||
} | ||
|
||
testDHE1024(); | ||
|
||
process.on('exit', function() { | ||
assert.equal(nsuccess, 1); | ||
assert.equal(nerror, 1); | ||
}); |