Skip to content

Commit d51efda

Browse files
committed
tools: update mk-ca-bundle to 1.35
Adds the facility to ignore root certificates by fingerprint using mk-ca-bundle's -x parameter. Signed-off-by: Renegade334 <contact.9a5d6388@renegade334.me.uk>
1 parent 82940d6 commit d51efda

2 files changed

Lines changed: 53 additions & 16 deletions

File tree

‎tools/dep_updaters/update-root-certs.mjs‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import { pipeline } from 'node:stream/promises';
88
import { fileURLToPath } from 'node:url';
99
import { parseArgs } from 'node:util';
1010

11+
// SHA-256 fingerprints of root certificates to exclude from node-root-certs.h
12+
// Fingerprints can be found in the certificate report at
13+
// https://ccadb.my.salesforce-sites.com/mozilla/IncludedRootCertificateReport
14+
const ignoreRoots = [
15+
// /* Example Root CA */
16+
// '0000000000000000000000000000000000000000000000000000000000000000',
17+
];
18+
1119
const __filename = fileURLToPath(import.meta.url);
1220

1321
const getCertdataURL = (version) => {
@@ -145,9 +153,14 @@ if (values.verbose) {
145153
}
146154
const opts = { encoding: 'utf8' };
147155
const mkCABundleTool = join(checkoutDir, 'tools', 'mk-ca-bundle.pl');
148-
const mkCABundleOut = execFileSync(mkCABundleTool,
149-
values.verbose ? [ '-v' ] : [],
150-
opts);
156+
const mkCABundleArgs = [];
157+
if (values.verbose) {
158+
mkCABundleArgs.push('-v');
159+
}
160+
if (ignoreRoots.length) {
161+
mkCABundleArgs.push('-x', ignoreRoots.join(','));
162+
}
163+
const mkCABundleOut = execFileSync(mkCABundleTool, mkCABundleArgs, opts);
151164
if (values.verbose) {
152165
console.log(mkCABundleOut);
153166
}

‎tools/mk-ca-bundle.pl‎

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
use MIME::Base64;
3838
use strict;
3939
use warnings;
40-
use vars qw($opt_h $opt_i $opt_l $opt_m $opt_p $opt_q $opt_s $opt_t $opt_v $opt_w);
40+
use vars qw($opt_h $opt_i $opt_l $opt_m $opt_p $opt_q $opt_s $opt_t $opt_v $opt_w $opt_x);
4141
use List::Util;
4242
use Text::Wrap;
4343

4444
# If the OpenSSL commandline is not in search path you can configure it here!
4545
my $openssl = 'openssl';
4646

47-
my $version = '1.33';
47+
my $version = '1.35';
4848

4949
$opt_w = 72; # default base64 encoded lines length
5050

@@ -94,7 +94,7 @@
9494

9595
$0 =~ s@.*(/|\\)@@;
9696
$Getopt::Std::STANDARD_HELP_VERSION = 1;
97-
getopts('hilmp:qs:tvw:');
97+
getopts('hilmp:qs:tvw:x:');
9898

9999
if($opt_i) {
100100
print ("=" x 78 . "\n");
@@ -107,7 +107,7 @@
107107
}
108108

109109
sub HELP_MESSAGE() {
110-
print "Usage:\t${0} [-i] [-l] [-m] [-p<purposes:levels>] [-q] [-s<algorithms>] [-t] [-v] [-w<l>] [<outputfile>]\n";
110+
print "Usage:\t${0} [-i] [-l] [-m] [-p<purposes:levels>] [-q] [-s<algorithms>] [-t] [-v] [-w<l>] [-x<sha256>] [<outputfile>]\n";
111111
print "\t-i\tprint version info about used modules\n";
112112
print "\t-l\tprint license info about certdata.txt\n";
113113
print "\t-m\tinclude meta data in output\n";
@@ -125,6 +125,7 @@ ()
125125
print "\t-t\tinclude plain text listing of certificates\n";
126126
print "\t-v\tbe verbose and print out processed CAs\n";
127127
print "\t-w <l>\twrap base64 output lines after <l> chars (default: ${opt_w})\n";
128+
print "\t-x\texclude list of SHA-256 fingerprints. Comma separated, case-insensitive, whitespace and ':' byte delimiters are ignored.\n";
128129
exit;
129130
}
130131

@@ -202,9 +203,17 @@ (%)
202203

203204
my $stdout = $crt eq '-';
204205

206+
my @opt_x_list;
207+
if($opt_x) {
208+
$opt_x = uc $opt_x;
209+
$opt_x =~ s/[\s:]//g;
210+
@opt_x_list = split(/,/, $opt_x);
211+
}
212+
205213
if($stdout) {
206214
open(CRT, '> -') or die "Could not open STDOUT: $!\n";
207-
} else {
215+
}
216+
else {
208217
open(CRT, ">", "$crt.~") or die "Could not open $crt.~: $!\n";
209218
}
210219

@@ -280,7 +289,7 @@ (%)
280289
# The commented lines in a main block are plaintext metadata that describes
281290
# the certificate. Issuer, Subject, Fingerprint, etc.
282291
if($main_block) {
283-
push @precert, s{^#}{//}r if not /^#$/;
292+
push @precert, s{^#}{//}r unless /^#$/;
284293
if(/^# Not Valid After : (.*)/) {
285294
my $stamp = $1;
286295
use Time::Piece;
@@ -356,9 +365,11 @@ (%)
356365
if(/^CKA_TRUST_([A-Z_]+)\s+CK_TRUST\s+CKT_NSS_([A-Z_]+)\s*$/) {
357366
if(!is_in_list($1, @valid_mozilla_trust_purposes)) {
358367
report "Warning: Unrecognized trust purpose for cert: $caname. Trust purpose: $1. Trust Level: $2";
359-
} elsif(!is_in_list($2, @valid_mozilla_trust_levels)) {
368+
}
369+
elsif(!is_in_list($2, @valid_mozilla_trust_levels)) {
360370
report "Warning: Unrecognized trust level for cert: $caname. Trust purpose: $1. Trust Level: $2";
361-
} else {
371+
}
372+
else {
362373
push @{$trust_purposes_by_level{$2}}, $1;
363374
}
364375
}
@@ -380,11 +391,23 @@ (%)
380391
}
381392

382393
if(!should_output_cert(%trust_purposes_by_level)) {
383-
$skipnum ++;
394+
$skipnum++;
384395
report "Skipping: $caname lacks acceptable trust level" if($opt_v);
385-
} elsif($caname =~ /TrustCor/) {
386-
$skipnum ++;
387-
} else {
396+
}
397+
else {
398+
# Skip if explicitly excluded
399+
if($opt_x) {
400+
my ($fingerprint_sha256) = grep { m{^// Fingerprint .*SHA.*256}i } @precert;
401+
$fingerprint_sha256 =~ s/://g;
402+
$fingerprint_sha256 = uc $fingerprint_sha256;
403+
($fingerprint_sha256) = $fingerprint_sha256 =~ /([A-F0-9]{64})/;
404+
if(grep { $_ eq $fingerprint_sha256 } @opt_x_list) {
405+
report "Skipping: '$main_block_name' fingerprint explicitly excluded: $fingerprint_sha256";
406+
$skipnum++;
407+
next;
408+
}
409+
}
410+
388411
my $encoded = MIME::Base64::encode_base64($cka_value, '');
389412
$encoded =~ s/(.{1,${opt_w}})/"$1\\n"\n/g;
390413
my $pem = "\"-----BEGIN CERTIFICATE-----\\n\"\n"
@@ -402,7 +425,8 @@ (%)
402425
}
403426
if(!$opt_t) {
404427
print CRT $pem;
405-
} else {
428+
}
429+
else {
406430
my $pipe = "";
407431
foreach my $hash (@included_signature_algorithms) {
408432
$pipe = "|$openssl x509 -" . $hash . " -fingerprint -noout -inform PEM";

0 commit comments

Comments
 (0)