Skip to content

Commit 1d0ae2a

Browse files
author
Shigeki Ohtsu
committed
crypto: add tests of pfx in CA for client auth
1 parent 7b3c79b commit 1d0ae2a

6 files changed

Lines changed: 75 additions & 0 deletions

File tree

test/fixtures/keys/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ agent2-cert.pem: agent2-csr.pem agent2-key.pem
110110
-signkey agent2-key.pem \
111111
-out agent2-cert.pem
112112

113+
# Create a PKCS#12 file with CA for the agent.
114+
agent2.pfx: agent2-cert.pem agent2-key.pem
115+
openssl pkcs12 -export \
116+
-in agent2-cert.pem \
117+
-inkey agent2-key.pem \
118+
-certfile agent2-cert.pem \
119+
-out agent2.pfx \
120+
-password pass:sample
121+
122+
# Create a PKCS#12 file without CA for the agent.
123+
agent2_noCA.pfx: agent2-cert.pem agent2-key.pem
124+
openssl pkcs12 -export \
125+
-in agent2-cert.pem \
126+
-inkey agent2-key.pem \
127+
-out agent2_noCA.pfx \
128+
-password pass:sample
129+
113130
agent2-verify: agent2-cert.pem
114131
openssl verify -CAfile agent2-cert.pem agent2-cert.pem
115132

test/fixtures/keys/agent1-pfx2.pem

1.71 KB
Binary file not shown.

test/fixtures/keys/agent2.pfx

2.26 KB
Binary file not shown.

test/fixtures/keys/agent2_noCA.pfx

1.61 KB
Binary file not shown.
2.26 KB
Binary file not shown.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const fs = require('fs');
5+
6+
if (!common.hasCrypto) {
7+
console.log('1..0 # Skipped: missing crypto');
8+
return;
9+
}
10+
const https = require('https');
11+
12+
var pfx_withCA = fs.readFileSync(common.fixturesDir + '/keys/agent2.pfx');
13+
var pfx_noCA = fs.readFileSync(common.fixturesDir + '/keys/agent2_noCA.pfx');
14+
15+
function RunTest(params) {
16+
if (!params.length)
17+
return;
18+
19+
var param = params.shift();
20+
var options = {
21+
host: '127.0.0.1',
22+
port: common.PORT,
23+
servername: 'agent2',
24+
path: '/',
25+
pfx: param.pfx_server,
26+
passphrase: 'sample',
27+
requestCert: true,
28+
rejectUnauthorized: false
29+
};
30+
var server = https.createServer(options, function(req, res) {
31+
assert.equal(req.socket.authorized, param.authorized);
32+
res.writeHead(200);
33+
res.end('OK');
34+
});
35+
36+
server.listen(options.port, options.host, function() {
37+
var data = '';
38+
options.pfx = param.pfx_client;
39+
https.get(options, function(res) {
40+
res.on('data', function(data_) { data += data_; });
41+
res.on('end', function() { server.close(); });
42+
});
43+
44+
server.on('close', function() {
45+
assert.equal(data, 'OK');
46+
RunTest(params);
47+
});
48+
});
49+
}
50+
51+
var test_params = [
52+
{pfx_server: pfx_noCA, pfx_client: pfx_noCA, authorized: false},
53+
{pfx_server: pfx_withCA, pfx_client: pfx_noCA, authorized: true},
54+
{pfx_server: pfx_noCA, pfx_client: pfx_withCA, authorized: true},
55+
{pfx_server: pfx_withCA, pfx_client: pfx_withCA, authorized: true}
56+
];
57+
58+
RunTest(test_params);

0 commit comments

Comments
 (0)