Skip to content

Commit 23196fe

Browse files
committed
crypto: add pfx certs as CA certs too
According to documentation all certificates specified in `pfx` option should be treated as a CA certificates too. While it doesn't seem to be logically correct to me, we can't afford to break API stability at this point. Fix: nodejs#5100 PR-URL: nodejs#5109 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Shigeki Ohtsu <[email protected]>
1 parent 1e146e7 commit 23196fe

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/node_crypto.cc

+11
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,17 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
982982
&sc->cert_,
983983
&sc->issuer_) &&
984984
SSL_CTX_use_PrivateKey(sc->ctx_, pkey)) {
985+
// Add CA certs too
986+
for (int i = 0; i < sk_X509_num(extra_certs); i++) {
987+
X509* ca = sk_X509_value(extra_certs, i);
988+
989+
if (!sc->ca_store_) {
990+
sc->ca_store_ = X509_STORE_new();
991+
SSL_CTX_set_cert_store(sc->ctx_, sc->ca_store_);
992+
}
993+
X509_STORE_add_cert(sc->ca_store_, ca);
994+
SSL_CTX_add_client_CA(sc->ctx_, ca);
995+
}
985996
ret = true;
986997
}
987998

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: node compiled without crypto.');
7+
return;
8+
}
9+
10+
const assert = require('assert');
11+
const tls = require('tls');
12+
const fs = require('fs');
13+
const path = require('path');
14+
15+
const pfx = fs.readFileSync(
16+
path.join(common.fixturesDir, 'keys', 'agent1-pfx.pem'));
17+
18+
const server = tls.createServer({
19+
pfx: pfx,
20+
passphrase: 'sample',
21+
requestCert: true,
22+
rejectUnauthorized: false
23+
}, common.mustCall(function(c) {
24+
assert(c.authorizationError === null, 'authorizationError must be null');
25+
c.end();
26+
})).listen(common.PORT, function() {
27+
var client = tls.connect({
28+
port: common.PORT,
29+
pfx: pfx,
30+
passphrase: 'sample',
31+
rejectUnauthorized: false
32+
}, function() {
33+
client.end();
34+
server.close();
35+
});
36+
});

0 commit comments

Comments
 (0)