3 # update-ca-certificates
5 # Copyright (c) 2003 Fumitoshi UKAI <ukai@debian.or.jp>
6 # Copyright (c) 2009 Philipp Kern <pkern@debian.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 echo "$0: [--verbose] [--fresh]"
39 CERTSCONF=/etc/ca-certificates.conf
40 CERTSDIR=/usr/share/ca-certificates
41 LOCALCERTSDIR=/usr/local/share/ca-certificates
42 CERTBUNDLE=ca-certificates.crt
43 ETCCERTSDIR=/etc/ssl/certs
52 # Helper files. (Some of them are not simple arrays because we spawn
53 # subshells later on.)
54 TEMPBUNDLE="$(mktemp -t "${CERTBUNDLE}.tmp.XXXXXX")"
55 ADDED="$(mktemp -t "ca-certificates.tmp.XXXXXX")"
56 REMOVED="$(mktemp -t "ca-certificates.tmp.XXXXXX")"
58 # Adds a certificate to the list of trusted ones. This includes a symlink
59 # in /etc/ssl/certs to the certificate file and its inclusion into the
63 PEM="$ETCCERTSDIR/$(basename "$CERT" .crt | sed -e 's/ /_/g' \
66 if ! test -e "$PEM" || [ "$(readlink "$PEM")" != "$CERT" ]
69 echo +$PEM >> "$ADDED"
71 cat "$CERT" >> "$TEMPBUNDLE"
76 PEM="$ETCCERTSDIR/$(basename "$CERT" .crt).pem"
80 echo -$PEM >> "$REMOVED"
85 if [ "$fresh" = 1 ]; then
86 echo -n "Clearing symlinks in $ETCCERTSDIR..."
87 find . -type l -print | while read symlink
89 case $(readlink $symlink) in
90 $CERTSDIR*) rm -f $symlink;;
93 find . -type l -print | while read symlink
95 test -f $symlink || rm -f $symlink
100 echo -n "Updating certificates in $ETCCERTSDIR... "
102 # Handle certificates that should be removed. This is an explicit act
103 # by prefixing lines in the configuration files with exclamation marks (!).
104 sed -n -e '/^$/d' -e 's/^!//p' $CERTSCONF | while read crt
106 remove "$CERTSDIR/$crt"
109 sed -e '/^$/d' -e '/^#/d' -e '/^!/d' $CERTSCONF | while read crt
111 if ! test -f "$CERTSDIR/$crt"
113 echo "W: $CERTSDIR/$crt not found, but listed in $CERTSCONF." >&2
119 # Now process certificate authorities installed by the local system
121 if [ -d "$LOCALCERTSDIR" ]
123 find -L "$LOCALCERTSDIR" -type f -name '*.crt' | while read crt
129 chmod 0644 "$TEMPBUNDLE"
130 mv -f "$TEMPBUNDLE" "$CERTBUNDLE"
132 ADDED_CNT=$(wc -l < "$ADDED")
133 REMOVED_CNT=$(wc -l < "$REMOVED")
135 if [ "$ADDED_CNT" -gt 0 ] || [ "$REMOVED_CNT" -gt 0 ]
137 # only run if set of files has changed
138 if [ "$verbose" = 0 ]
140 c_rehash . > /dev/null 2>&1
146 echo "$ADDED_CNT added, $REMOVED_CNT removed; done."
148 HOOKSDIR=/etc/ca-certificates/update.d
149 echo -n "Running hooks in $HOOKSDIR...."
151 [ "$verbose" = 0 ] || VERBOSE_ARG=--verbose
152 eval run-parts $VERB_ARG --test -- $HOOKSDIR | while read hook
155 cat $REMOVED ) | $hook || echo E: $hook exited with code $?.