Skip to content

Commit d20618d

Browse files
committed
tls: load all CRLs from a PEM bundle
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>
1 parent abb365a commit d20618d

2 files changed

Lines changed: 42 additions & 10 deletions

File tree

src/crypto/crypto_tls_certificates.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,20 @@ bool AddCRL(Environment* env,
5757
X509_STORE** cache) {
5858
if (!bio) return false;
5959

60-
DeleteFnPtr<X509_CRL, X509_CRL_free> crl(
61-
PEM_read_bio_X509_CRL(bio.get(), nullptr, NoPasswordCallback, nullptr));
62-
if (!crl) return false;
63-
64-
X509_STORE* cert_store = GetOrCreateOwnedCertStore(env, ctx, cache);
65-
CHECK_EQ(1, X509_STORE_add_crl(cert_store, crl.get()));
66-
CHECK_EQ(1,
67-
X509_STORE_set_flags(
68-
cert_store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL));
69-
return true;
60+
using CRLPointer = DeleteFnPtr<X509_CRL, X509_CRL_free>;
61+
62+
bool added = false;
63+
while (CRLPointer crl = CRLPointer(PEM_read_bio_X509_CRL(
64+
bio.get(), nullptr, NoPasswordCallback, nullptr))) {
65+
X509_STORE* cert_store = GetOrCreateOwnedCertStore(env, ctx, cache);
66+
CHECK_EQ(1, X509_STORE_add_crl(cert_store, crl.get()));
67+
CHECK_EQ(
68+
1,
69+
X509_STORE_set_flags(
70+
cert_store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL));
71+
added = true;
72+
}
73+
return added;
7074
}
7175

7276
PrivateKeyResult UsePrivateKey(SSL_CTX* ctx,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
// Verify that every CRL in a concatenated PEM bundle is loaded, not just the
5+
// first one. agent3 is revoked by ca2-crl-agent3.pem, but not by ca2-crl.pem.
6+
7+
const fixtures = require('../common/fixtures');
8+
const {
9+
assert, connect, keys
10+
} = require(fixtures.path('tls-connect'));
11+
12+
const crl = fixtures.readKey('ca2-crl.pem') +
13+
fixtures.readKey('ca2-crl-agent3.pem');
14+
15+
connect({
16+
client: {
17+
servername: 'agent3',
18+
ca: keys.agent3.ca,
19+
crl,
20+
},
21+
server: {
22+
cert: keys.agent3.cert,
23+
key: keys.agent3.key,
24+
},
25+
}, common.mustCall((err, pair, cleanup) => {
26+
assert.strictEqual(err.code, 'CERT_REVOKED');
27+
return cleanup();
28+
}));

0 commit comments

Comments
 (0)