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., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301,
34 echo "$0: [--verbose] [--fresh]"
40 CERTSCONF=/etc/ca-certificates.conf
41 CERTSDIR=/usr/share/ca-certificates
42 LOCALCERTSDIR=/usr/local/share/ca-certificates
43 CERTBUNDLE=ca-certificates.crt
44 ETCCERTSDIR=/etc/ssl/certs
53 # Helper files. (Some of them are not simple arrays because we spawn
54 # subshells later on.)
55 TEMPBUNDLE="$(mktemp -t "${CERTBUNDLE}.tmp.XXXXXX")"
56 ADDED="$(mktemp -t "ca-certificates.tmp.XXXXXX")"
57 REMOVED="$(mktemp -t "ca-certificates.tmp.XXXXXX")"
59 # Adds a certificate to the list of trusted ones. This includes a symlink
60 # in /etc/ssl/certs to the certificate file and its inclusion into the
64 PEM="$ETCCERTSDIR/$(basename "$CERT" .crt | sed -e 's/ /_/g' \
67 if ! test -e "$PEM" || [ "$(readlink "$PEM")" != "$CERT" ]
70 echo +$PEM >> "$ADDED"
72 cat "$CERT" >> "$TEMPBUNDLE"
77 PEM="$ETCCERTSDIR/$(basename "$CERT" .crt).pem"
81 echo -$PEM >> "$REMOVED"
86 if [ "$fresh" = 1 ]; then
87 echo -n "Clearing symlinks in $ETCCERTSDIR..."
88 find . -type l -print | while read symlink
90 case $(readlink $symlink) in
91 $CERTSDIR*) rm -f $symlink;;
94 find . -type l -print | while read symlink
96 test -f $symlink || rm -f $symlink
101 echo -n "Updating certificates in $ETCCERTSDIR... "
103 # Handle certificates that should be removed. This is an explicit act
104 # by prefixing lines in the configuration files with exclamation marks (!).
105 sed -n -e '/^$/d' -e 's/^!//p' $CERTSCONF | while read crt
107 remove "$CERTSDIR/$crt"
110 sed -e '/^$/d' -e '/^#/d' -e '/^!/d' $CERTSCONF | while read crt
112 if ! test -f "$CERTSDIR/$crt"
114 echo "W: $CERTSDIR/$crt not found, but listed in $CERTSCONF." >&2
120 # Now process certificate authorities installed by the local system
122 if [ -d "$LOCALCERTSDIR" ]
124 find -L "$LOCALCERTSDIR" -type f -name '*.crt' | while read crt
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
146 chmod 0644 "$TEMPBUNDLE"
147 mv -f "$TEMPBUNDLE" "$CERTBUNDLE"
149 echo "$ADDED_CNT added, $REMOVED_CNT removed; done."
151 HOOKSDIR=/etc/ca-certificates/update.d
152 echo -n "Running hooks in $HOOKSDIR...."
154 [ "$verbose" = 0 ] || VERBOSE_ARG=--verbose
155 eval run-parts $VERBOSE_ARG --test -- $HOOKSDIR | while read hook
158 cat $REMOVED ) | $hook || echo E: $hook exited with code $?.