2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-30 18:38:06 -05:00
|
|
|
const common = require('../common');
|
|
|
|
|
const assert = require('assert');
|
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;
|
2015-03-04 12:11:21 +11:00
|
|
|
}
|
2016-12-30 18:38:06 -05:00
|
|
|
const https = require('https');
|
2015-03-04 12:11:21 +11:00
|
|
|
|
2016-12-30 18:38:06 -05:00
|
|
|
const fs = require('fs');
|
|
|
|
|
const path = require('path');
|
2014-09-05 09:56:55 -05:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const options = {
|
2014-09-05 09:56:55 -05:00
|
|
|
key: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent3-key.pem')),
|
|
|
|
|
cert: fs.readFileSync(path.join(common.fixturesDir, 'keys/agent3-cert.pem'))
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = https.createServer(options, common.mustCall(function(req, res) {
|
2014-09-05 09:56:55 -05:00
|
|
|
res.writeHead(200);
|
|
|
|
|
res.end();
|
|
|
|
|
req.resume();
|
2016-07-15 15:43:24 -04:00
|
|
|
})).listen(0, function() {
|
2014-09-05 09:56:55 -05:00
|
|
|
authorized();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function authorized() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const req = https.request({
|
2016-05-29 03:06:56 -04:00
|
|
|
port: server.address().port,
|
2014-09-05 09:56:55 -05:00
|
|
|
rejectUnauthorized: true,
|
|
|
|
|
ca: [fs.readFileSync(path.join(common.fixturesDir, 'keys/ca2-cert.pem'))]
|
2016-07-15 15:43:24 -04:00
|
|
|
}, common.fail);
|
2015-05-19 13:00:06 +02:00
|
|
|
req.on('error', function(err) {
|
2014-09-05 09:56:55 -05:00
|
|
|
override();
|
|
|
|
|
});
|
|
|
|
|
req.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function override() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const options = {
|
2016-05-29 03:06:56 -04:00
|
|
|
port: server.address().port,
|
2014-09-05 09:56:55 -05:00
|
|
|
rejectUnauthorized: true,
|
|
|
|
|
ca: [fs.readFileSync(path.join(common.fixturesDir, 'keys/ca2-cert.pem'))],
|
2015-05-19 13:00:06 +02:00
|
|
|
checkServerIdentity: function(host, cert) {
|
2014-09-05 09:56:55 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
options.agent = new https.Agent(options);
|
2017-01-08 13:19:00 +00:00
|
|
|
const req = https.request(options, function(res) {
|
2014-09-05 09:56:55 -05:00
|
|
|
assert(req.socket.authorized);
|
|
|
|
|
server.close();
|
|
|
|
|
});
|
2015-05-19 13:00:06 +02:00
|
|
|
req.on('error', function(err) {
|
2014-09-05 09:56:55 -05:00
|
|
|
throw err;
|
|
|
|
|
});
|
|
|
|
|
req.end();
|
|
|
|
|
}
|