2017-01-03 22:16:48 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
2017-07-01 01:29:09 +02:00
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('missing crypto');
|
2014-01-18 13:18:25 +01:00
|
|
|
|
2017-07-01 01:29:09 +02:00
|
|
|
if (!common.opensslCli)
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('node compiled without OpenSSL CLI.');
|
2011-08-30 22:46:48 +02:00
|
|
|
|
2016-12-31 00:38:06 +01:00
|
|
|
const assert = require('assert');
|
2017-10-06 18:57:13 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-12-31 00:38:06 +01:00
|
|
|
const https = require('https');
|
2017-10-06 18:57:13 +02:00
|
|
|
const spawn = require('child_process').spawn;
|
2011-08-30 22:46:48 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const options = {
|
2017-10-06 18:57:13 +02:00
|
|
|
key: fixtures.readSync('agent.key'),
|
|
|
|
cert: fixtures.readSync('agent.crt'),
|
2016-03-27 15:09:08 +02:00
|
|
|
requestCert: true,
|
|
|
|
rejectUnauthorized: false
|
2011-08-30 22:46:48 +02:00
|
|
|
};
|
|
|
|
|
2016-07-15 21:43:24 +02:00
|
|
|
const modulus = 'A6F44A9C25791431214F5C87AF9E040177A8BB89AC803F7E09BBC3A5519F' +
|
|
|
|
'349CD9B9C40BE436D0AA823A94147E26C89248ADA2BE3DD4D34E8C289646' +
|
|
|
|
'94B2047D217B4F1299371EA93A83C89AB9440724131E65F2B0161DE9560C' +
|
|
|
|
'DE9C13455552B2F49CF0FB00D8D77532324913F6F80FF29D0A131D29DB06' +
|
|
|
|
'AFF8BE191B7920DC2DAE1C26EA82A47847A10391EF3BF6AABB3CC40FF821' +
|
|
|
|
'00B03A4F0FF1809278E4DDFDA7DE954ED56DC7AD9A47EEBC37D771A366FC' +
|
|
|
|
'60A5BCB72373BEC180649B3EFA0E9092707210B41B90032BB18BC91F2046' +
|
|
|
|
'EBDAF1191F4A4E26D71879C4C7867B62FCD508E8CE66E82D128A71E91580' +
|
|
|
|
'9FCF44E8DE774067F1DE5D70B9C03687';
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const CRLF = '\r\n';
|
|
|
|
const body = 'hello world\n';
|
|
|
|
let cert;
|
2011-08-30 22:46:48 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const server = https.createServer(options, common.mustCall(function(req, res) {
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('got request');
|
2011-08-30 22:46:48 +02:00
|
|
|
|
|
|
|
cert = req.connection.getPeerCertificate();
|
|
|
|
|
2016-07-15 21:43:24 +02:00
|
|
|
assert.strictEqual(cert.subjectaltname, 'URI:http://example.com/#me');
|
|
|
|
assert.strictEqual(cert.exponent, '0x10001');
|
|
|
|
assert.strictEqual(cert.modulus, modulus);
|
2011-08-30 22:46:48 +02:00
|
|
|
res.writeHead(200, { 'content-type': 'text/plain' });
|
|
|
|
res.end(body);
|
2016-07-15 21:43:24 +02:00
|
|
|
}));
|
2011-08-30 22:46:48 +02:00
|
|
|
|
2016-05-29 09:06:56 +02:00
|
|
|
server.listen(0, function() {
|
2017-01-08 14:19:00 +01:00
|
|
|
const args = ['s_client',
|
|
|
|
'-quiet',
|
|
|
|
'-connect', `127.0.0.1:${this.address().port}`,
|
2017-10-06 18:57:13 +02:00
|
|
|
'-cert', fixtures.path('foafssl.crt'),
|
|
|
|
'-key', fixtures.path('foafssl.key')];
|
2013-12-11 04:10:10 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const client = spawn(common.opensslCli, args);
|
2013-12-11 04:10:10 +01:00
|
|
|
|
|
|
|
client.stdout.on('data', function(data) {
|
2017-01-08 14:19:00 +01:00
|
|
|
const message = data.toString();
|
|
|
|
const contents = message.split(CRLF + CRLF).pop();
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(body, contents);
|
2011-08-30 22:46:48 +02:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
|
2013-12-11 04:10:10 +01:00
|
|
|
client.stdin.write('GET /\n\n');
|
|
|
|
|
|
|
|
client.on('error', function(error) {
|
|
|
|
throw error;
|
|
|
|
});
|
2011-08-30 22:46:48 +02:00
|
|
|
});
|