#1153565 ca-certificates: remove() in update-ca-certificates misses sed filename sanitization, leaving symlinks in /etc/ssl/certs and entries in java cacerts when deselecting certs with spaces/parentheses/commas

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

In /usr/sbin/update-ca-certificates, `add()` and `remove()` compute the
target
symlink path `$PEM` inside `/etc/ssl/certs` (`$ETCCERTSDIR`) differently:

Lines 90-94 (`add()`):
  add() {
    CERT="$1"
    PEM="$ETCCERTSDIR/$(basename "$CERT" .crt | sed -e 's/ /_/g' \
                                                    -e 's/[()]/=/g' \
                                                    -e 's/,/_/g').pem"

Lines 104-114 (`remove()`):
  remove() {
    CERT="$1"
    PEM="$ETCCERTSDIR/$(basename "$CERT" .crt).pem"
    if test -L "$PEM"
    then
      rm -f "$PEM"
      echo "-$PEM" >> "$REMOVED"
    fi
  }

Because `remove()` omits the `sed` sanitization pipeline (`s/ /_/g`,
`s/[()]/=/g`, `s/,/_/g`) added to `add()` in commit 778b0a8b2cd6 (2009), any
certificate under `/usr/share/ca-certificates/` whose `.crt` filename on
disk
contains spaces, parentheses `()`, or commas `,` cannot be removed via `!`
deselection in `/etc/ca-certificates.conf` (without `--fresh`).

Note: For the built-in Mozilla bundle (`mozilla/*`),
`mozilla/certdata2pem.py`
already replaces spaces, parentheses, and commas with `_` and `=` at package
build time when writing the `.crt` filenames. However, for any custom or
third-party package certificate installed under
`/usr/share/ca-certificates/`
whose `.crt` filename contains a space, parenthesis, or comma (common for
Windows/AD CS or CN-derived filenames like `Corp Root CA (G1), Inc.crt`):

1. When first enabled in `/etc/ca-certificates.conf`, `add()` creates the
   sanitized symlink `/etc/ssl/certs/Corp_Root_CA_=G1=__Inc.pem` and
`openssl rehash`
   creates `/etc/ssl/certs/<hash>.0`.
2. When later deselected via `!` in `/etc/ca-certificates.conf` (or via
   `dpkg-reconfigure ca-certificates`) and `update-ca-certificates` runs:
   - `/etc/ssl/certs/ca-certificates.crt` (the single-file bundle) is
rebuilt
     without the deselected certificate.
   - However, `remove()` checks `test -L "/etc/ssl/certs/Corp Root CA (G1),
Inc.pem"`,
     which evaluates false because the symlink on disk is
     `Corp_Root_CA_=G1=__Inc.pem`.
   - As a result, `/etc/ssl/certs/Corp_Root_CA_=G1=__Inc.pem` and its
`<hash>.0`
     hash link remain in `/etc/ssl/certs/`, and nothing is written to
`$REMOVED`.

Security impact (silent trust split-brain across TLS clients):

Because the certificate is gone from `/etc/ssl/certs/ca-certificates.crt`
(`CAfile`) but still linked in `/etc/ssl/certs/` (`CApath` / OpenSSL 3
default
`CAstore`) and in `/etc/ssl/certs/java/cacerts`:
- `grep` on `/etc/ssl/certs/ca-certificates.crt`, `python3-requests` (which
  loads `CAfile` only), and Python's
`ssl.create_default_context().get_ca_certs()`
  all indicate that the CA is no longer trusted.
- Meanwhile, `curl`, `openssl verify`, Python's `urllib.request.urlopen()`,
  Go's `crypto/tls` (which reads `/etc/ssl/certs/` directory entries), and
  OpenJDK (`/etc/ssl/certs/java/cacerts`) ALL continue to trust certificates
  signed by the deselected CA!

Steps to reproduce:

  mkdir -p /usr/share/ca-certificates/localtest
  openssl req -x509 -newkey rsa:2048 -nodes -days 1 \
      -subj "/CN=Special-Char-Test-CA" \
      -keyout /tmp/spec.key \
      -out "/usr/share/ca-certificates/localtest/Corp Special CA (G1),
Inc.crt"

  echo "localtest/Corp Special CA (G1), Inc.crt" >>
/etc/ca-certificates.conf
  update-ca-certificates
  # -> 1 added, 0 removed; done.
  # Symlink created: /etc/ssl/certs/Corp_Special_CA_=G1=__Inc.pem

  # Now deselect it with '!' in /etc/ca-certificates.conf:
  sed -i 's|^localtest/Corp Special CA (G1), Inc.crt|!localtest/Corp
Special CA (G1), Inc.crt|' /etc/ca-certificates.conf
  update-ca-certificates
  # -> 0 added, 0 removed; done.

  ls -l /etc/ssl/certs/Corp_Special_CA_=G1=__Inc.pem
  # -> STILL PRESENT in /etc/ssl/certs/!
  keytool -list -cacerts -storepass changeit | grep -i corp_special
  # -> debian:corp_special_ca_=g1=__inc.pem STILL PRESENT in java cacerts!

Proposed patch:

Factor out a shared `cert_to_pem()` helper function so `add()` and
`remove()`
always compute the exact same sanitized path:
--- a/sbin/update-ca-certificates
+++ b/sbin/update-ca-certificates
@@ -87,12 +87,16 @@
 TEMPBUNDLE="${ETCCERTSDIR}/${CERTBUNDLE}.new"
 ADDED=$(mktemp -t "ca-certificates.tmp.XXXXXX")
 REMOVED=$(mktemp -t "ca-certificates.rem.XXXXXX")

+cert_to_pem() {
+  echo "$ETCCERTSDIR/$(basename "$1" .crt | sed -e 's/ /_/g' \
+                                                -e 's/[()]/=/g' \
+                                                -e 's/,/_/g').pem"
+}
+
 # Adds a certificate to the list of trusted ones.  This includes a symlink
 # in /etc/ssl/certs to the certificate file and its inclusion into the
 # bundle.
 add() {
   CERT="$1"
-  PEM="$ETCCERTSDIR/$(basename "$CERT" .crt | sed -e 's/ /_/g' \
-                                                  -e 's/[()]/=/g' \
-                                                  -e 's/,/_/g').pem"
+  PEM=$(cert_to_pem "$CERT")
   if ! test -e "$PEM" || [ "$(readlink "$PEM")" != "$CERT" ]
   then
     ln -sf "$CERT" "$PEM"
@@ -103,7 +107,7 @@

 remove() {
   CERT="$1"
-  PEM="$ETCCERTSDIR/$(basename "$CERT" .crt).pem"
+  PEM=$(cert_to_pem "$CERT")
   if test -L "$PEM"
   then
     rm -f "$PEM"