Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d6b555e

Browse filesBrowse files
richardlauMoLow
authored andcommitted
tools: fix updating root certificates
When searching for the latest certdata.txt, check that the file exists on the remote server. PR-URL: #47607 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 2ea6e03 commit d6b555e
Copy full SHA for d6b555e

File tree

Expand file treeCollapse file tree

1 file changed

+27
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+27
-11
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: tools/dep_updaters/update-root-certs.mjs
+27-11Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ const formatDate = (d) => {
2222
return iso.substring(0, iso.indexOf('T'));
2323
};
2424

25+
const getCertdataURL = (version) => {
26+
const tag = `NSS_${version.replaceAll('.', '_')}_RTM`;
27+
const certdataURL = `https://hg.mozilla.org/projects/nss/raw-file/${tag}/lib/ckfw/builtins/certdata.txt`;
28+
return certdataURL;
29+
};
30+
2531
const normalizeTD = (text) => {
2632
// Remove whitespace and any HTML tags.
2733
return text?.trim().replace(/<.*?>/g, '');
@@ -74,22 +80,33 @@ const getReleases = (text) => {
7480
return releases;
7581
};
7682

77-
const getLatestVersion = (releases) => {
78-
const arrayNumberSort = (x, y, i) => {
83+
const getLatestVersion = async (releases) => {
84+
const arrayNumberSortDescending = (x, y, i) => {
7985
if (x[i] === undefined && y[i] === undefined) {
8086
return 0;
8187
} else if (x[i] === y[i]) {
82-
return arrayNumberSort(x, y, i + 1);
88+
return arrayNumberSortDescending(x, y, i + 1);
8389
}
84-
return (x[i] ?? 0) - (y[i] ?? 0);
90+
return (y[i] ?? 0) - (x[i] ?? 0);
8591
};
8692
const extractVersion = (t) => {
8793
return t[kNSSVersion].split('.').map((n) => parseInt(n));
8894
};
8995
const releaseSorter = (x, y) => {
90-
return arrayNumberSort(extractVersion(x), extractVersion(y), 0);
96+
return arrayNumberSortDescending(extractVersion(x), extractVersion(y), 0);
9197
};
92-
return releases.sort(releaseSorter).filter(pastRelease).at(-1)[kNSSVersion];
98+
// Return the most recent certadata.txt that exists on the server.
99+
const sortedReleases = releases.sort(releaseSorter).filter(pastRelease);
100+
for (const candidate of sortedReleases) {
101+
const candidateURL = getCertdataURL(candidate[kNSSVersion]);
102+
if (values.verbose) {
103+
console.log(`Trying ${candidateURL}`);
104+
}
105+
const response = await fetch(candidateURL, { method: 'HEAD' });
106+
if (response.ok) {
107+
return candidate[kNSSVersion];
108+
}
109+
}
93110
};
94111

95112
const pastRelease = (r) => {
@@ -129,10 +146,10 @@ if (values.help) {
129146
process.exit(0);
130147
}
131148

149+
const scheduleURL = 'https://wiki.mozilla.org/NSS:Release_Versions';
132150
if (values.verbose) {
133-
console.log('Fetching NSS release schedule');
151+
console.log(`Fetching NSS release schedule from ${scheduleURL}`);
134152
}
135-
const scheduleURL = 'https://wiki.mozilla.org/NSS:Release_Versions';
136153
const schedule = await fetch(scheduleURL);
137154
if (!schedule.ok) {
138155
console.error(`Failed to fetch ${scheduleURL}: ${schedule.status}: ${schedule.statusText}`);
@@ -142,7 +159,7 @@ const scheduleText = await schedule.text();
142159
const nssReleases = getReleases(scheduleText);
143160

144161
// Retrieve metadata for the NSS release being updated to.
145-
const version = positionals[0] ?? getLatestVersion(nssReleases);
162+
const version = positionals[0] ?? await getLatestVersion(nssReleases);
146163
const release = nssReleases.find((r) => {
147164
return new RegExp(`^${version.replace('.', '\\.')}\\b`).test(r[kNSSVersion]);
148165
});
@@ -155,8 +172,7 @@ if (values.verbose) {
155172
}
156173

157174
// Fetch certdata.txt and overwrite the local copy.
158-
const tag = `NSS_${version.replaceAll('.', '_')}_RTM`;
159-
const certdataURL = `https://hg.mozilla.org/projects/nss/raw-file/${tag}/lib/ckfw/builtins/certdata.txt`;
175+
const certdataURL = getCertdataURL(version);
160176
if (values.verbose) {
161177
console.log(`Fetching ${certdataURL}`);
162178
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.