2017-01-03 13:16:48 -08: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-30 18:38:06 -05:00
|
|
|
const common = require('../common');
|
2025-01-24 16:58:32 -08:00
|
|
|
if (!common.hasCrypto) {
|
2017-07-01 02:29:09 +03:00
|
|
|
common.skip('missing crypto');
|
2025-01-24 16:58:32 -08:00
|
|
|
}
|
2014-01-18 12:18:25 +00:00
|
|
|
|
2025-01-24 16:58:32 -08:00
|
|
|
const { opensslCli } = require('../common/crypto');
|
|
|
|
|
|
|
|
if (!opensslCli) {
|
2016-05-11 15:34:52 -04:00
|
|
|
common.skip('node compiled without OpenSSL CLI.');
|
2025-01-24 16:58:32 -08:00
|
|
|
}
|
2011-08-30 22:46:48 +02:00
|
|
|
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
2017-10-07 01:57:13 +09:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-12-30 18:38:06 -05:00
|
|
|
const https = require('https');
|
2017-10-07 01:57:13 +09:00
|
|
|
const spawn = require('child_process').spawn;
|
2011-08-30 22:46:48 +02:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const options = {
|
2019-05-29 15:47:10 -07:00
|
|
|
key: fixtures.readKey('rsa_private.pem'),
|
|
|
|
cert: fixtures.readKey('rsa_cert.crt'),
|
2016-03-27 16:09:08 +03:00
|
|
|
requestCert: true,
|
|
|
|
rejectUnauthorized: false
|
2011-08-30 22:46:48 +02:00
|
|
|
};
|
|
|
|
|
2019-05-29 15:47:10 -07:00
|
|
|
const webIdUrl = 'URI:http://example.com/#me';
|
|
|
|
const modulus = fixtures.readKey('rsa_cert_foafssl_b.modulus', 'ascii').replace(/\n/g, '');
|
|
|
|
const exponent = fixtures.readKey('rsa_cert_foafssl_b.exponent', 'ascii').replace(/\n/g, '');
|
2016-07-15 15:43:24 -04:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const CRLF = '\r\n';
|
|
|
|
const body = 'hello world\n';
|
|
|
|
let cert;
|
2011-08-30 22:46:48 +02:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = https.createServer(options, common.mustCall(function(req, res) {
|
2011-10-04 18:08:18 -04:00
|
|
|
console.log('got request');
|
2011-08-30 22:46:48 +02:00
|
|
|
|
|
|
|
cert = req.connection.getPeerCertificate();
|
|
|
|
|
2019-05-29 15:47:10 -07:00
|
|
|
assert.strictEqual(cert.subjectaltname, webIdUrl);
|
|
|
|
assert.strictEqual(cert.exponent, exponent);
|
2016-07-15 15:43:24 -04:00
|
|
|
assert.strictEqual(cert.modulus, modulus);
|
2011-08-30 22:46:48 +02:00
|
|
|
res.writeHead(200, { 'content-type': 'text/plain' });
|
2020-08-02 11:10:49 -07:00
|
|
|
res.end(body, () => { console.log('stream finished'); });
|
2020-08-02 11:10:49 -07:00
|
|
|
console.log('sent response');
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2011-08-30 22:46:48 +02:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0, function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const args = ['s_client',
|
|
|
|
'-quiet',
|
|
|
|
'-connect', `127.0.0.1:${this.address().port}`,
|
2019-05-29 15:47:10 -07:00
|
|
|
'-cert', fixtures.path('keys/rsa_cert_foafssl_b.crt'),
|
|
|
|
'-key', fixtures.path('keys/rsa_private_b.pem')];
|
2013-12-10 21:10:10 -06:00
|
|
|
|
2025-01-24 16:58:32 -08:00
|
|
|
const client = spawn(opensslCli, args);
|
2013-12-10 21:10:10 -06:00
|
|
|
|
|
|
|
client.stdout.on('data', function(data) {
|
2020-08-02 11:10:49 -07:00
|
|
|
console.log('response received');
|
2017-01-08 13:19:00 +00:00
|
|
|
const message = data.toString();
|
|
|
|
const contents = message.split(CRLF + CRLF).pop();
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(body, contents);
|
2020-08-02 11:10:49 -07:00
|
|
|
server.close((e) => {
|
|
|
|
assert.ifError(e);
|
|
|
|
console.log('server closed');
|
|
|
|
});
|
|
|
|
console.log('server.close() called');
|
2011-08-30 22:46:48 +02:00
|
|
|
});
|
|
|
|
|
2023-09-16 13:08:18 +02:00
|
|
|
client.stdin.write('GET /\r\n\r\n');
|
2013-12-10 21:10:10 -06:00
|
|
|
|
|
|
|
client.on('error', function(error) {
|
|
|
|
throw error;
|
|
|
|
});
|
2011-08-30 22:46:48 +02:00
|
|
|
});
|