-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a new option to limit DH key size in tls connect #1831
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,98 @@ | ||
'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 ntests = 0; | ||
var nsuccess = 0; | ||
|
||
function loadDHParam(n) { | ||
var path = common.fixturesDir; | ||
if (n !== 'error') path += '/keys'; | ||
return fs.readFileSync(path + '/dh' + n + '.pem'); | ||
} | ||
|
||
var cipherlist = { | ||
'NOT_PFS': 'AES128-SHA256', | ||
'DH': 'DHE-RSA-AES128-GCM-SHA256', | ||
'ECDH': 'ECDHE-RSA-AES128-GCM-SHA256' | ||
}; | ||
|
||
function test(size, type, name, next) { | ||
var cipher = type ? cipherlist[type] : cipherlist['NOT_PFS']; | ||
|
||
if (name) tls.DEFAULT_ECDH_CURVE = name; | ||
|
||
var options = { | ||
key: key, | ||
cert: cert, | ||
ciphers: cipher | ||
}; | ||
|
||
if (type === 'DH') options.dhparam = loadDHParam(size); | ||
|
||
var server = tls.createServer(options, function(conn) { | ||
assert.strictEqual(conn.getEphemeralKeyInfo(), null); | ||
conn.end(); | ||
}); | ||
|
||
server.on('close', function(err) { | ||
assert(!err); | ||
if (next) next(); | ||
}); | ||
|
||
server.listen(common.PORT, '127.0.0.1', function() { | ||
var client = tls.connect({ | ||
port: common.PORT, | ||
rejectUnauthorized: false | ||
}, function() { | ||
var ekeyinfo = client.getEphemeralKeyInfo(); | ||
assert.strictEqual(ekeyinfo.type, type); | ||
assert.strictEqual(ekeyinfo.size, size); | ||
assert.strictEqual(ekeyinfo.name, name); | ||
nsuccess++; | ||
server.close(); | ||
}); | ||
}); | ||
} | ||
|
||
function testNOT_PFS() { | ||
test(undefined, undefined, undefined, testDHE1024); | ||
ntests++; | ||
} | ||
|
||
function testDHE1024() { | ||
test(1024, 'DH', undefined, testDHE2048); | ||
ntests++; | ||
} | ||
|
||
function testDHE2048() { | ||
test(2048, 'DH', undefined, testECDHE256); | ||
ntests++; | ||
} | ||
|
||
function testECDHE256() { | ||
test(256, 'ECDH', tls.DEFAULT_ECDH_CURVE, testECDHE512); | ||
ntests++; | ||
} | ||
|
||
function testECDHE512() { | ||
test(521, 'ECDH', 'secp521r1', null); | ||
ntests++; | ||
} | ||
|
||
testNOT_PFS(); | ||
|
||
process.on('exit', function() { | ||
assert.equal(ntests, nsuccess); | ||
assert.equal(ntests, 5); | ||
}); |
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,81 @@ | ||
'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(size, err, next) { | ||
var options = { | ||
key: key, | ||
cert: cert, | ||
dhparam: loadDHParam(size), | ||
ciphers: 'DHE-RSA-AES128-GCM-SHA256' | ||
}; | ||
|
||
var server = tls.createServer(options, function(conn) { | ||
conn.end(); | ||
}); | ||
|
||
server.on('close', function(isException) { | ||
assert(!isException); | ||
if (next) next(); | ||
}); | ||
|
||
server.listen(common.PORT, '127.0.0.1', function() { | ||
// client set minimum DH parameter size to 2048 bits so that | ||
// it fails when it make a connection to the tls server where | ||
// dhparams is 1024 bits | ||
var client = tls.connect({ | ||
minDHSize: 2048, | ||
port: common.PORT, | ||
rejectUnauthorized: false | ||
}, function() { | ||
nsuccess++; | ||
server.close(); | ||
}); | ||
if (err) { | ||
client.on('error', function(e) { | ||
nerror++; | ||
assert.strictEqual(e.message, 'DH parameter size 1024 is less' | ||
+ ' than 2048'); | ||
server.close(); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
// A client connection fails with an error when a client has an | ||
// 2048 bits minDHSize 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 minDHSize 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); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a newline between the title and the content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed