-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: add TLSSocket.getEphemeralKeyInfo()
Returns an object representing a type, name and size of an ephemeral key exchange in a client connection. Currently only DHE and ECHE are supported. This api only works on on a client connection. When it is called on a server connection, null is returned. When its key exchange is not ephemeral, an empty object is returned. PR-URL: #1831 Reviewed-By: indutny - Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
Shigeki Ohtsu
committed
Oct 16, 2015
1 parent
503f279
commit 6d92eba
Showing
5 changed files
with
166 additions
and
0 deletions.
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
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); | ||
}); |