2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-01 09:54:26 -06:00
|
|
|
const common = require('../common');
|
2014-01-18 12:18:25 +00:00
|
|
|
|
2015-03-04 12:11:21 +11:00
|
|
|
if (!common.hasCrypto) {
|
2016-05-11 15:34:52 -04:00
|
|
|
common.skip('missing crypto');
|
2015-07-07 20:55:55 +05:30
|
|
|
return;
|
2014-01-18 12:18:25 +00:00
|
|
|
}
|
2017-02-01 13:52:24 +09:00
|
|
|
|
|
|
|
if (!common.opensslCli) {
|
|
|
|
common.skip('missing openssl-cli');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-01 09:54:26 -06:00
|
|
|
const assert = require('assert');
|
|
|
|
const tls = require('tls');
|
2014-01-18 12:18:25 +00:00
|
|
|
|
2016-12-01 09:54:26 -06:00
|
|
|
const exec = require('child_process').exec;
|
|
|
|
const fs = require('fs');
|
2013-10-14 16:53:59 +02:00
|
|
|
|
2016-12-01 09:54:26 -06:00
|
|
|
const options = {
|
2013-10-14 16:53:59 +02:00
|
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
|
|
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'),
|
2015-11-10 14:56:52 -05:00
|
|
|
ciphers: '-ALL:ECDHE-RSA-AES128-SHA256',
|
2013-10-14 16:53:59 +02:00
|
|
|
ecdhCurve: 'prime256v1'
|
|
|
|
};
|
|
|
|
|
2016-12-01 09:54:26 -06:00
|
|
|
const reply = 'I AM THE WALRUS'; // something recognizable
|
2013-10-14 16:53:59 +02:00
|
|
|
|
2016-12-01 09:54:26 -06:00
|
|
|
const server = tls.createServer(options, common.mustCall(function(conn) {
|
2013-10-14 16:53:59 +02:00
|
|
|
conn.end(reply);
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2013-10-14 16:53:59 +02:00
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
server.listen(0, '127.0.0.1', common.mustCall(function() {
|
2016-12-01 09:54:26 -06:00
|
|
|
let cmd = '"' + common.opensslCli + '" s_client -cipher ' + options.ciphers +
|
2016-05-29 03:06:56 -04:00
|
|
|
` -connect 127.0.0.1:${this.address().port}`;
|
2013-10-14 16:53:59 +02:00
|
|
|
|
2015-07-18 11:59:55 +09:00
|
|
|
// for the performance and stability issue in s_client on Windows
|
2015-07-29 17:18:04 +05:30
|
|
|
if (common.isWindows)
|
2015-07-18 11:59:55 +09:00
|
|
|
cmd += ' -no_rand_screen';
|
|
|
|
|
2016-07-15 15:43:24 -04:00
|
|
|
exec(cmd, common.mustCall(function(err, stdout, stderr) {
|
2016-12-30 10:54:01 -05:00
|
|
|
assert.ifError(err);
|
2016-12-01 09:54:26 -06:00
|
|
|
assert(stdout.includes(reply));
|
2013-10-14 16:53:59 +02:00
|
|
|
server.close();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
|
|
|
}));
|