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 tls = require('tls');
|
2015-03-04 12:11:21 +11:00
|
|
|
|
2016-12-30 18:38:06 -05:00
|
|
|
const fs = require('fs');
|
|
|
|
const util = require('util');
|
|
|
|
const join = require('path').join;
|
2014-09-14 00:37:34 +02:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const options = {
|
2014-09-14 00:37:34 +02:00
|
|
|
key: fs.readFileSync(join(common.fixturesDir, 'keys', 'agent5-key.pem')),
|
|
|
|
cert: fs.readFileSync(join(common.fixturesDir, 'keys', 'agent5-cert.pem')),
|
|
|
|
ca: [ fs.readFileSync(join(common.fixturesDir, 'keys', 'ca2-cert.pem')) ]
|
|
|
|
};
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = tls.createServer(options, function(cleartext) {
|
2014-09-14 00:37:34 +02:00
|
|
|
cleartext.end('World');
|
|
|
|
});
|
2016-07-15 15:43:24 -04:00
|
|
|
server.listen(0, common.mustCall(function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const socket = tls.connect({
|
2016-05-29 03:06:56 -04:00
|
|
|
port: this.address().port,
|
2014-09-14 00:37:34 +02:00
|
|
|
rejectUnauthorized: false
|
2016-07-15 15:43:24 -04:00
|
|
|
}, common.mustCall(function() {
|
2017-01-08 13:19:00 +00:00
|
|
|
const peerCert = socket.getPeerCertificate();
|
2014-09-14 00:37:34 +02:00
|
|
|
|
2015-09-26 15:49:04 -07:00
|
|
|
console.error(util.inspect(peerCert));
|
2014-09-14 00:37:34 +02:00
|
|
|
assert.equal(peerCert.subject.CN, 'Ádám Lippai');
|
|
|
|
server.close();
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|
2014-09-14 00:37:34 +02:00
|
|
|
socket.end('Hello');
|
2016-07-15 15:43:24 -04:00
|
|
|
}));
|