Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

39.3. ca-certificates-3.130

Bundle of CA Root Certificates from Mozilla

Version 3.130, release 1
Shelf base — The minimal userland and system daemons that every KDOS image boots with
Phase 30_foundation (Build Foundation), 55 of 127 in build order
Licence MPL-2.0
Homepage https://firefox-source-docs.mozilla.org/security/nss/
Build time 0.1 SBU
Installed size 185.7 KiB in 5 files
Recipe ports/core/base/ca-certificates/kpkgbuild

About

This port is the system’s trust store for TLS: the root certificates of the certificate authorities Mozilla trusts to issue server certificates, as one PEM bundle. The bundle is generated at build time rather than downloaded ready-made. The port pins certdata.txt from an NSS release tag (the port’s version is that NSS release) and converts it with curl’s mk-ca-bundle.pl from a pinned curl release; the two helpers _tag and _curl in kpkgbuild hold the tag and the curl version.

It installs the Mozilla bundle as /usr/share/ca-certificates/mozilla.pem, an empty /etc/ca-certificates/trust-source/anchors/ for local roots, the update-ca-certificates command, and the links /etc/ssl/certs/ca-certificates.crt and /etc/ssl/ca-bundle.crt. The file every OpenSSL program actually reads, /etc/ssl/cert.pem, is not in the package: postinstall.sh writes it on the installed system. How OpenSSL, GnuTLS, NSS and Python each find these anchors, and how to add a root of your own, is in TLS trust anchors.

Sources

Dependencies

Depends on: perl.

Required by (5): aria2, curl, ldns, p11-kit, python3-certifi.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/30_foundation/phase.env && kpkg install ca-certificates'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/base/ca-certificates.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/base/ca-certificates
echo 'beb7e6dfe6499926e52c075c27bcfbe4c957f8609c575b3860273ae2806f63eb  certdata-3.130.txt' | sha256sum -c -
echo '8e278f4982210b37e4f9a048bd6ed23df41e4a054085bd73f8242628f03d09ca  mk-ca-bundle-8.22.0.pl' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/ca-certificates
SRC=$SRC_ROOT/ca-certificates-3.130
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
cp certdata-3.130.txt "$SRC"
cp mk-ca-bundle-8.22.0.pl "$SRC"

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _tag, _curl and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

mv certdata-$version.txt certdata.txt
perl mk-ca-bundle-$_curl.pl -n -f -q \
	-d https://raw.githubusercontent.com/nss-dev/nss/$_tag/lib/ckfw/builtins/certdata.txt \
	cert.pem.raw
grep -v '^## Certificate data from Mozilla ' cert.pem.raw > cert.pem
grep -q 'BEGIN CERTIFICATE' cert.pem

install -Dm644 cert.pem $PKG/usr/share/ca-certificates/mozilla.pem
install -d $PKG/etc/ca-certificates/trust-source/anchors

install -d $PKG/etc/ssl/certs
ln -s /etc/ssl/cert.pem $PKG/etc/ssl/certs/ca-certificates.crt
ln -s /etc/ssl/cert.pem $PKG/etc/ssl/ca-bundle.crt

install -d $PKG/usr/bin
cat > $PKG/usr/bin/update-ca-certificates <<'SH'
#!/bin/sh
# update-ca-certificates [--root DIR]
#
# Writes /etc/ssl/cert.pem: the Mozilla bundle, then every PEM certificate in
# /etc/ca-certificates/trust-source/anchors/. Run it after adding or removing
# a local root there.
set -e
usage() { echo "usage: update-ca-certificates [--root DIR]" >&2; exit 2; }
root=
case "$#:$1" in
0:) ;;
2:--root) root=${2%/} ;;
*) usage ;;
esac

bundle=$root/usr/share/ca-certificates/mozilla.pem
anchors=$root/etc/ca-certificates/trust-source/anchors
out=$root/etc/ssl/cert.pem
tmp=$out.new.$$

[ -s "$bundle" ] || { echo "update-ca-certificates: $bundle is missing" >&2; exit 1; }
mkdir -p "${out%/*}"
trap 'rm -f "$tmp"' EXIT
umask 022
n=0
{
	cat "$bundle"
	for f in "$anchors"/*; do
		[ -f "$f" ] || continue
		if grep -q -e '-----BEGIN CERTIFICATE-----' "$f"; then
			printf '\n# Local anchor: %s\n' "${f##*/}"
			sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' "$f"
			n=$((n + 1))
		else
			echo "update-ca-certificates: $f holds no PEM certificate, skipped" >&2
		fi
	done
} > "$tmp"
mv -f "$tmp" "$out"
trap - EXIT
echo "update-ca-certificates: $out: the Mozilla bundle and $n local anchor file(s)"
SH
chmod 755 $PKG/usr/bin/update-ca-certificates

install -d "$PKG/usr/share/licenses/$name"
head -n 4 certdata.txt > "$PKG/usr/share/licenses/$name/NOTICE"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

postinstall.sh runs on the installed system after the package is adopted:

# /etc/ssl/cert.pem is the Mozilla bundle plus the local roots, and is written
# here rather than shipped: a package-owned copy would be replaced by every
# upgrade and lose the local roots. The tool is the one just installed, run
# against PKG_ROOT, so an install into another root writes that root's bundle.
root="${PKG_ROOT:-/}"
root="${root%/}"
"$root/usr/bin/update-ca-certificates" --root "${root:-/}"

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/ca-certificates, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf ca-certificates-3.130-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/ca-certificates, and runs the triggers its paths call for.

Contents

Installed programs: update-ca-certificates.

Installed directories: /etc/ca-certificates, /usr/share/ca-certificates, /usr/share/licenses/ca-certificates.

Notes

mk-ca-bundle.pl heads its output with a line ## Certificate data from Mozilla as of: <date>. With -n that date is certdata.txt’s modification time on the build machine, not anything recorded in the source, so build.sh deletes the line; left in, it would make two builds of the same sources differ. grep -q 'BEGIN CERTIFICATE' then stops the build if the conversion produced no certificate at all.

The converter drops every root that has already expired when it runs, so a rebuild after a root expires ships one fewer even though the sources have not changed.

certdata.txt is under MPL-2.0 and the source carries no copy of the licence, only the notice in its first four lines, which says where the text is. build.sh installs those lines as /usr/share/licenses/ca-certificates/NOTICE.

/etc/ssl/cert.pem is written by postinstall.sh rather than shipped, because a file the package owned would be replaced on every upgrade and lose the local roots appended to it. update-ca-certificates builds it in a temporary file and renames it into place, so no reader sees half a bundle, and it skips with a warning any file in the anchors directory that holds no PEM certificate, a DER file among them. Run it again after adding or removing a local root.