2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-01 18:13:38 +01:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2015-07-07 17:25:55 +02:00
|
|
|
return;
|
2015-03-04 02:11:21 +01:00
|
|
|
}
|
2016-12-01 18:13:38 +01:00
|
|
|
const tls = require('tls');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
2016-12-01 18:13:38 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const util = require('util');
|
|
|
|
const join = require('path').join;
|
2011-08-26 13:00:40 +02:00
|
|
|
|
2016-12-01 18:13:38 +01:00
|
|
|
const options = {
|
2014-04-17 13:57:36 +02:00
|
|
|
key: fs.readFileSync(join(common.fixturesDir, 'keys', 'agent1-key.pem')),
|
|
|
|
cert: fs.readFileSync(join(common.fixturesDir, 'keys', 'agent1-cert.pem')),
|
|
|
|
ca: [ fs.readFileSync(join(common.fixturesDir, 'keys', 'ca1-cert.pem')) ]
|
2011-08-26 13:00:40 +02:00
|
|
|
};
|
|
|
|
|
2016-12-01 18:13:38 +01:00
|
|
|
const server = tls.createServer(options, function(cleartext) {
|
2011-08-26 13:00:40 +02:00
|
|
|
cleartext.end('World');
|
|
|
|
});
|
2016-07-15 21:43:24 +02:00
|
|
|
server.listen(0, common.mustCall(function() {
|
2016-12-01 18:13:38 +01:00
|
|
|
const socket = tls.connect({
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port,
|
2012-08-30 16:43:20 +02:00
|
|
|
rejectUnauthorized: false
|
2016-07-15 21:43:24 +02:00
|
|
|
}, common.mustCall(function() {
|
2016-12-01 18:13:38 +01:00
|
|
|
let peerCert = socket.getPeerCertificate();
|
2014-04-17 13:57:36 +02:00
|
|
|
assert.ok(!peerCert.issuerCertificate);
|
|
|
|
|
|
|
|
// Verify that detailed return value has all certs
|
|
|
|
peerCert = socket.getPeerCertificate(true);
|
|
|
|
assert.ok(peerCert.issuerCertificate);
|
|
|
|
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error(util.inspect(peerCert));
|
2016-12-01 18:13:38 +01:00
|
|
|
assert.strictEqual(peerCert.subject.emailAddress, 'ry@tinyclouds.org');
|
|
|
|
assert.strictEqual(peerCert.serialNumber, '9A84ABCFB8A72AC0');
|
|
|
|
assert.strictEqual(peerCert.exponent, '0x10001');
|
|
|
|
assert.strictEqual(
|
|
|
|
peerCert.fingerprint,
|
|
|
|
'8D:06:3A:B3:E5:8B:85:29:72:4F:7D:1B:54:CD:95:19:3C:EF:6F:AA'
|
|
|
|
);
|
2016-04-20 00:37:45 +02:00
|
|
|
assert.deepStrictEqual(peerCert.infoAccess['OCSP - URI'],
|
2016-04-26 08:32:35 +02:00
|
|
|
[ 'http://ocsp.nodejs.org/' ]);
|
2014-04-17 13:57:36 +02:00
|
|
|
|
2016-12-01 18:13:38 +01:00
|
|
|
const issuer = peerCert.issuerCertificate;
|
|
|
|
assert.strictEqual(issuer.issuerCertificate, issuer);
|
|
|
|
assert.strictEqual(issuer.serialNumber, '8DF21C01468AF393');
|
2011-08-26 13:00:40 +02:00
|
|
|
server.close();
|
2016-07-15 21:43:24 +02:00
|
|
|
}));
|
2011-08-26 13:00:40 +02:00
|
|
|
socket.end('Hello');
|
2016-07-15 21:43:24 +02:00
|
|
|
}));
|