#1153564 ca-certificates: removing or rotating local certs in /usr/local/share/ca-certificates without --fresh does not notify update.d hooks (leaves stale roots in java cacerts)

Package:
ca-certificates
Source:
ca-certificates
Submitter:
Shyam Kumar Arshid
Date:
2026-11-10 04:33:02 UTC
Severity:
normal
Tags:
#1153564#5
Date:
2026-11-10 04:31:21 UTC
From:
To:
Dear Maintainer,

While testing how recent fixes for #1069251 / #866670 (Salsa MR !15 and
Ubuntu's recent 20260816ubuntu0.24.04.2 update for LP #2061817) handle CA
lifecycle changes, we noticed that removing or rotating a local CA
certificate
in /usr/local/share/ca-certificates/ and running `update-ca-certificates`
(without `--fresh`) never notifies the hooks in
/etc/ca-certificates/update.d/.

As a result, when an administrator (or an Ansible/Puppet/container role)
removes or rotates an internal CA certificate in
/usr/local/share/ca-certificates/
and runs `update-ca-certificates`, OpenSSL, curl, Python, and Go stop
trusting the old CA, but Java (/etc/ssl/certs/java/cacerts) silently keeps
trusting it indefinitely.

Why this happens in /usr/sbin/update-ca-certificates:

Certificates in /usr/local/share/ca-certificates/ ($LOCALCERTSDIR) are not
listed in /etc/ca-certificates.conf, so deleting a file from $LOCALCERTSDIR
never triggers `remove()` when parsing $CERTSCONF. Instead, deleted local
certificates leave behind broken (orphan) symlinks in /etc/ssl/certs/
($ETCCERTSDIR).

There are two separate bugs in how /usr/sbin/update-ca-certificates handles
those orphan symlinks (lines 169-184):

1. When rotating a local CA (deleting `old-ca.crt` and adding `new-ca.crt`
in
   the same `update-ca-certificates` run):
   Because `new-ca.crt` was added, `$ADDED_CNT` is 1, so the block at line
171
   runs:

     if [ "$ADDED_CNT" -gt 0 ] || [ "$REMOVED_CNT" -gt 0 ]
     then
       find "$ETCCERTSDIR" -type l ! -exec test -e {} \; -print | while
read -r orphan
       do
         rm -f "$orphan"
         if [ "$verbose" = 1 ]; then
           echo "Removed orphan symlink $orphan"
         fi
       done
       ...
     fi

   Here, the loop deletes `/etc/ssl/certs/old-ca.pem` (`rm -f "$orphan"`)
and
   rehashes `/etc/ssl/certs/`, so OpenSSL/curl/Python/Go immediately reject
   `old-ca.crt`. However, the loop never appends `-$orphan` to `$REMOVED`!
   When the hooks in `/etc/ca-certificates/update.d/` run at line 198, stdin
   contains `+/etc/ssl/certs/new-ca.pem` and zero removal lines. The Java
   keystore adds `new-ca` and retains `old-ca` forever.

2. When only deleting a local CA (`rm
/usr/local/share/ca-certificates/old-ca.crt`
   with no other additions or `/etc/ca-certificates.conf` edits):
   Both `$ADDED_CNT` and `$REMOVED_CNT` are 0. Because the orphan-cleanup
   `find` loop is gated inside `if [ "$ADDED_CNT" -gt 0 ] || [
"$REMOVED_CNT" -gt 0 ]`,
   the orphan loop does not even run. `/etc/ssl/certs/old-ca.pem` is left
   behind as a dangling symlink, `openssl rehash` is not run, `$REMOVED` is
   empty, and `/etc/ssl/certs/java/cacerts` retains `debian:old-ca.pem`.

Steps to reproduce:

  # 1. Create and install two test CA certs ("old" and "new")
  openssl req -x509 -newkey rsa:2048 -nodes -days 1 \
      -subj "/CN=Test-Old-Local-CA" -keyout /tmp/old.key -out
/usr/local/share/ca-certificates/test-old.crt
  openssl req -x509 -newkey rsa:2048 -nodes -days 1 \
      -subj "/CN=Test-New-Local-CA" -keyout /tmp/new.key -out
/tmp/test-new.crt
  update-ca-certificates

  keytool -list -cacerts -storepass changeit | grep -i test-old
  # -> debian:test-old.pem, ..., trustedCertEntry

  # 2. Rotate: remove test-old.crt, install test-new.crt, run
update-ca-certificates
  rm -f /usr/local/share/ca-certificates/test-old.crt
  cp /tmp/test-new.crt /usr/local/share/ca-certificates/test-new.crt
  update-ca-certificates
  # Output: 1 added, 0 removed; done.
  #         Adding debian:test-new.pem

  # 3. Verify trust store divergence:
  grep -c "Test-Old-Local-CA" /etc/ssl/certs/ca-certificates.crt || true
  # -> 0 (gone from system bundle and /etc/ssl/certs/test-old.pem is
unlinked)
  keytool -list -cacerts -storepass changeit | grep -i test-old
  # -> debian:test-old.pem is STILL present in /etc/ssl/certs/java/cacerts!

Proposed patch:

Scan for orphan symlinks in `$ETCCERTSDIR` before evaluating `REMOVED_CNT`,
unlink all broken symlinks (`*.pem` as well as broken `<hash>.0` hash
links),
and record each unlinked `*.pem` symlink into `$REMOVED` so that
`REMOVED_CNT`,
`openssl rehash`, and `/etc/ca-certificates/update.d/` hooks all process the
removal cleanly:
--- a/sbin/update-ca-certificates
+++ b/sbin/update-ca-certificates
@@ -166,19 +166,22 @@
   done
 fi

+# Remove orphan symlinks found in ETCCERTSDIR (e.g. when local certificates
+# were removed from LOCALCERTSDIR) and record removed *.pem links in
REMOVED (#895482).
+find "$ETCCERTSDIR" -maxdepth 1 -type l ! -exec test -e {} \; -print |
while read -r orphan
+do
+  case "$orphan" in
+    *.pem) echo "-$orphan" >> "$REMOVED" ;;
+  esac
+  rm -f "$orphan"
+  if [ "$verbose" = 1 ]; then
+    echo "Removed orphan symlink $orphan"
+  fi
+done
+
 ADDED_CNT=$(wc -l < "$ADDED")
 REMOVED_CNT=$(wc -l < "$REMOVED")

 if [ "$ADDED_CNT" -gt 0 ] || [ "$REMOVED_CNT" -gt 0 ]
 then
-  # only run if set of files has changed
-  # Remove orphan symlinks found in ETCCERTSDIR to prevent `openssl rehash`
-  # from exiting with an error. See #895482, #895473.
-  find "$ETCCERTSDIR" -type l ! -exec test -e {} \; -print | while read -r
orphan
-  do
-    rm -f "$orphan"
-    if [ "$verbose" = 1 ]; then
-      echo "Removed orphan symlink $orphan"
-    fi
-  done
   if [ "$verbose" = 0 ]
   then
     openssl rehash . > /dev/null