Skip to content

Commit ef0a391

Browse files
committed
security/ca_root_nss: only add SERVER_AUTH certs,
and support CKA_NSS_SERVER_DISTRUST_AFTER to not include certificates if the extracted bundle of certificates is generated later than the expiration date. This script no longer emits trust certificates for * EMAIL_PROTECTION * CODE_SIGNING because the default certificate bundle in FreeBSD is supposed to be used for server authentication. Reported by: Christian Heimes <christian@python.org> via: Gordon Tetlow Approved by: ports-secteam (riggs@) (maintainer)
1 parent 9d30c67 commit ef0a391

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

‎security/ca_root_nss/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PORTNAME= ca_root_nss
22
PORTVERSION= ${VERSION_NSS}
3+
PORTREVISION= 1
34
CATEGORIES= security
45
MASTER_SITES= MOZILLA/security/nss/releases/${DISTNAME:tu:C/[-.]/_/g}_RTM/src
56
DISTNAME= nss-${VERSION_NSS}${NSS_SUFFIX}

‎security/ca_root_nss/files/MAca-bundle.pl.in‎

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ print <<EOH;
4444
## Authorities (CA). These were automatically extracted from Mozilla's
4545
## root CA list (the file `certdata.txt').
4646
##
47+
## It contains certificates trusted for server authentication.
48+
##
4749
## Extracted from nss-%%VERSION_NSS%%
4850
##
4951
EOH
@@ -55,6 +57,13 @@ $debug++
5557
my %certs;
5658
my %trusts;
5759

60+
# returns a string like YYMMDDhhmmssZ of current time in GMT zone
61+
sub timenow()
62+
{
63+
my ($sec,$min,$hour,$mday,$mon,$year,undef,undef,undef) = gmtime(time);
64+
return sprintf "%02d%02d%02d%02d%02d%02dZ", $year-100, $mon+1, $mday, $hour, $min, $sec;
65+
}
66+
5867
sub printcert_plain($$)
5968
{
6069
my ($label, $certdata) = @_;
@@ -80,6 +89,8 @@ sub printcert($$) {
8089
printcert_info($a, $b);
8190
}
8291

92+
# converts a datastream that is to be \177-style octal constants
93+
# from <> to a (binary) string and returns it
8394
sub graboct()
8495
{
8596
my $data;
@@ -94,12 +105,12 @@ sub graboct()
94105
return $data;
95106
}
96107

97-
98108
sub grabcert()
99109
{
100110
my $certdata;
101-
my $cka_label;
102-
my $serial;
111+
my $cka_label = '';
112+
my $serial = 0;
113+
my $distrust = 0;
103114

104115
while (<>) {
105116
chomp;
@@ -116,6 +127,19 @@ sub grabcert()
116127
if (/^CKA_SERIAL_NUMBER MULTILINE_OCTAL/) {
117128
$serial = graboct();
118129
}
130+
131+
if (/^CKA_NSS_SERVER_DISTRUST_AFTER MULTILINE_OCTAL/)
132+
{
133+
my $distrust_after = graboct();
134+
my $time_now = timenow();
135+
if ($time_now >= $distrust_after) { $distrust = 1; }
136+
if ($debug) {
137+
printf STDERR "line $.: $cka_label ser #%d: distrust after %s, now: %s -> distrust $distrust\n", $serial, $distrust_after, timenow();
138+
}
139+
if ($distrust) {
140+
return undef;
141+
}
142+
}
119143
}
120144
return ($serial, $cka_label, $certdata);
121145
}
@@ -138,13 +162,13 @@ sub grabtrust() {
138162
$serial = graboct();
139163
}
140164

141-
if (/^CKA_TRUST_(SERVER_AUTH|EMAIL_PROTECTION|CODE_SIGNING) CK_TRUST (\S+)$/)
165+
if (/^CKA_TRUST_SERVER_AUTH CK_TRUST (\S+)$/)
142166
{
143-
if ($2 eq 'CKT_NSS_NOT_TRUSTED') {
167+
if ($1 eq 'CKT_NSS_NOT_TRUSTED') {
144168
$distrust = 1;
145-
} elsif ($2 eq 'CKT_NSS_TRUSTED_DELEGATOR') {
169+
} elsif ($1 eq 'CKT_NSS_TRUSTED_DELEGATOR') {
146170
$maytrust = 1;
147-
} elsif ($2 ne 'CKT_NSS_MUST_VERIFY_TRUST') {
171+
} elsif ($1 ne 'CKT_NSS_MUST_VERIFY_TRUST') {
148172
confess "Unknown trust setting on line $.:\n"
149173
. "$_\n"
150174
. "Script must be updated:";
@@ -160,13 +184,19 @@ sub grabtrust() {
160184
return ($serial, $cka_label, $trust);
161185
}
162186

187+
my $untrusted = 0;
188+
163189
while (<>) {
164190
if (/^CKA_CLASS CK_OBJECT_CLASS CKO_CERTIFICATE/) {
165191
my ($serial, $label, $certdata) = grabcert();
166192
if (defined $certs{$label."\0".$serial}) {
167193
warn "Certificate $label duplicated!\n";
168194
}
169-
$certs{$label."\0".$serial} = $certdata;
195+
if (defined $certdata) {
196+
$certs{$label."\0".$serial} = $certdata;
197+
} else { # $certdata undefined? distrust_after in effect
198+
$untrusted ++;
199+
}
170200
} elsif (/^CKA_CLASS CK_OBJECT_CLASS CKO_NSS_TRUST/) {
171201
my ($serial, $label, $trust) = grabtrust();
172202
if (defined $trusts{$label."\0".$serial}) {
@@ -180,12 +210,11 @@ while (<>) {
180210

181211
sub printlabel(@) {
182212
my @res = @_;
183-
map { s/\0.*//; s/[^[:print:]]/_/g; $_ = "\"$_\""; } @res;
213+
map { s/\0.*//; s/[^[:print:]]/_/g; "\"$_\""; } @res;
184214
return wantarray ? @res : $res[0];
185215
}
186216

187217
# weed out untrusted certificates
188-
my $untrusted = 0;
189218
foreach my $it (keys %trusts) {
190219
if (!$trusts{$it}) {
191220
if (!exists($certs{$it})) {

0 commit comments

Comments
 (0)