2 # This is a copy of update-ca-certificates from the ca-certificates package in stretch
3 # It allows custom paths and setting to default certs:
4 # https://bugs.debian.org/774059
5 # https://bugs.debian.org/774201
7 # update-ca-certificates
9 # Copyright (c) 2003 Fumitoshi UKAI <ukai@debian.or.jp>
10 # Copyright (c) 2009 Philipp Kern <pkern@debian.org>
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301,
31 CERTSCONF=/etc/ca-certificates.conf
32 CERTSDIR=/usr/share/ca-certificates
33 LOCALCERTSDIR=/usr/local/share/ca-certificates
34 CERTBUNDLE=ca-certificates.crt
35 ETCCERTSDIR=/etc/ssl/certs
36 HOOKSDIR=/etc/ca-certificates/update.d
67 echo "$0: [--verbose] [--fresh]"
73 if [ ! -s "$CERTSCONF" ]
85 # Helper files. (Some of them are not simple arrays because we spawn
86 # subshells later on.)
87 TEMPBUNDLE="$(mktemp -t "${CERTBUNDLE}.tmp.XXXXXX")"
88 ADDED="$(mktemp -t "ca-certificates.tmp.XXXXXX")"
89 REMOVED="$(mktemp -t "ca-certificates.tmp.XXXXXX")"
91 # Adds a certificate to the list of trusted ones. This includes a symlink
92 # in /etc/ssl/certs to the certificate file and its inclusion into the
96 PEM="$ETCCERTSDIR/$(basename "$CERT" .crt | sed -e 's/ /_/g' \
99 if ! test -e "$PEM" || [ "$(readlink "$PEM")" != "$CERT" ]
101 ln -sf "$CERT" "$PEM"
102 echo "+$PEM" >> "$ADDED"
104 # Add trailing newline to certificate, if it is missing (#635570)
105 sed -e '$a\' "$CERT" >> "$TEMPBUNDLE"
110 PEM="$ETCCERTSDIR/$(basename "$CERT" .crt).pem"
114 echo "-$PEM" >> "$REMOVED"
119 if [ "$fresh" = 1 ]; then
120 echo "Clearing symlinks in $ETCCERTSDIR..."
121 find . -type l -print | while read symlink
123 case $(readlink "$symlink") in
124 $CERTSDIR*) rm -f "$symlink";;
127 find . -type l -print | while read symlink
129 test -f "$symlink" || rm -f "$symlink"
134 echo "Updating certificates in $ETCCERTSDIR..."
136 # Add default certificate authorities if requested
137 if [ "$default" = 1 ]; then
138 find -L "$CERTSDIR" -type f -name '*.crt' | sort | while read crt
144 # Handle certificates that should be removed. This is an explicit act
145 # by prefixing lines in the configuration files with exclamation marks (!).
146 sed -n -e '/^$/d' -e 's/^!//p' "$CERTSCONF" | while read crt
148 remove "$CERTSDIR/$crt"
151 sed -e '/^$/d' -e '/^#/d' -e '/^!/d' "$CERTSCONF" | while read crt
153 if ! test -f "$CERTSDIR/$crt"
155 echo "W: $CERTSDIR/$crt not found, but listed in $CERTSCONF." >&2
161 # Now process certificate authorities installed by the local system
163 if [ -d "$LOCALCERTSDIR" ]
165 find -L "$LOCALCERTSDIR" -type f -name '*.crt' | sort | while read crt
173 ADDED_CNT=$(wc -l < "$ADDED")
174 REMOVED_CNT=$(wc -l < "$REMOVED")
176 if [ "$ADDED_CNT" -gt 0 ] || [ "$REMOVED_CNT" -gt 0 ]
178 # only run if set of files has changed
179 if [ "$verbose" = 0 ]
181 c_rehash . > /dev/null
187 chmod 0644 "$TEMPBUNDLE"
188 mv -f "$TEMPBUNDLE" "$CERTBUNDLE"
189 # Restore proper SELinux label after moving the file
190 [ -x /sbin/restorecon ] && /sbin/restorecon "$CERTBUNDLE" >/dev/null 2>&1
192 echo "$ADDED_CNT added, $REMOVED_CNT removed; done."
194 if [ -d "$HOOKSDIR" ]
197 echo "Running hooks in $HOOKSDIR..."
199 [ "$verbose" = 0 ] || VERBOSE_ARG="--verbose"
200 eval run-parts "$VERBOSE_ARG" --test -- "$HOOKSDIR" | while read hook
203 cat "$REMOVED" ) | "$hook" || echo "E: $hook exited with code $?."