forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: add getProtocol() to TLS sockets
This commit adds a new method for TLS sockets that returns the negotiated protocol version. PR-URL: nodejs#4995 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
5 changed files
with
79 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,43 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: missing crypto'); | ||
return; | ||
} | ||
|
||
const tls = require('tls'); | ||
const fs = require('fs'); | ||
|
||
const clientConfigs = [ | ||
{ secureProtocol: 'TLSv1_method', version: 'TLSv1' }, | ||
{ secureProtocol: 'TLSv1_1_method', version: 'TLSv1.1' }, | ||
{ secureProtocol: 'TLSv1_2_method', version: 'TLSv1.2' } | ||
]; | ||
|
||
const serverConfig = { | ||
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), | ||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') | ||
}; | ||
|
||
const server = tls.createServer(serverConfig, common.mustCall(function() { | ||
|
||
}, clientConfigs.length)).listen(common.PORT, common.localhostIPv4, function() { | ||
let connected = 0; | ||
clientConfigs.forEach(function(v) { | ||
tls.connect({ | ||
host: common.localhostIPv4, | ||
port: common.PORT, | ||
rejectUnauthorized: false, | ||
secureProtocol: v.secureProtocol | ||
}, common.mustCall(function() { | ||
assert.strictEqual(this.getProtocol(), v.version); | ||
this.on('end', common.mustCall(function() { | ||
assert.strictEqual(this.getProtocol(), null); | ||
})).end(); | ||
if (++connected === clientConfigs.length) | ||
server.close(); | ||
})); | ||
}); | ||
}); |