Skip to content

Commit

Permalink
crypto: add tests of pfx in CA for client auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Shigeki Ohtsu committed Feb 8, 2016
1 parent 7b3c79b commit 1d0ae2a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/fixtures/keys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ agent2-cert.pem: agent2-csr.pem agent2-key.pem
-signkey agent2-key.pem \
-out agent2-cert.pem

# Create a PKCS#12 file with CA for the agent.
agent2.pfx: agent2-cert.pem agent2-key.pem
openssl pkcs12 -export \
-in agent2-cert.pem \
-inkey agent2-key.pem \
-certfile agent2-cert.pem \
-out agent2.pfx \
-password pass:sample

# Create a PKCS#12 file without CA for the agent.
agent2_noCA.pfx: agent2-cert.pem agent2-key.pem
openssl pkcs12 -export \
-in agent2-cert.pem \
-inkey agent2-key.pem \
-out agent2_noCA.pfx \
-password pass:sample

agent2-verify: agent2-cert.pem
openssl verify -CAfile agent2-cert.pem agent2-cert.pem

Expand Down
Binary file added test/fixtures/keys/agent1-pfx2.pem
Binary file not shown.
Binary file added test/fixtures/keys/agent2.pfx
Binary file not shown.
Binary file added test/fixtures/keys/agent2_noCA.pfx
Binary file not shown.
Binary file added test/fixtures/keys/agent2withCA.pfx
Binary file not shown.
58 changes: 58 additions & 0 deletions test/parallel/test-https-pfx_cacert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');

if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
return;
}
const https = require('https');

var pfx_withCA = fs.readFileSync(common.fixturesDir + '/keys/agent2.pfx');
var pfx_noCA = fs.readFileSync(common.fixturesDir + '/keys/agent2_noCA.pfx');

function RunTest(params) {
if (!params.length)
return;

var param = params.shift();
var options = {
host: '127.0.0.1',
port: common.PORT,
servername: 'agent2',
path: '/',
pfx: param.pfx_server,
passphrase: 'sample',
requestCert: true,
rejectUnauthorized: false
};
var server = https.createServer(options, function(req, res) {
assert.equal(req.socket.authorized, param.authorized);
res.writeHead(200);
res.end('OK');
});

server.listen(options.port, options.host, function() {
var data = '';
options.pfx = param.pfx_client;
https.get(options, function(res) {
res.on('data', function(data_) { data += data_; });
res.on('end', function() { server.close(); });
});

server.on('close', function() {
assert.equal(data, 'OK');
RunTest(params);
});
});
}

var test_params = [
{pfx_server: pfx_noCA, pfx_client: pfx_noCA, authorized: false},
{pfx_server: pfx_withCA, pfx_client: pfx_noCA, authorized: true},
{pfx_server: pfx_noCA, pfx_client: pfx_withCA, authorized: true},
{pfx_server: pfx_withCA, pfx_client: pfx_withCA, authorized: true}
];

RunTest(test_params);

0 comments on commit 1d0ae2a

Please sign in to comment.