2019-01-02 07:30:04 +05:30
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Get configuration
|
|
|
|
if [ -f /etc/make-ca.conf ]; then
|
|
|
|
. /etc/make-ca.conf
|
|
|
|
else
|
|
|
|
#Use defaults if make-ca.conf does not exist
|
|
|
|
ANCHORDIR="/etc/pki/anchors"
|
|
|
|
ANCHORLIST="/etc/pki/anchors.md5sums"
|
|
|
|
LOCALDIR="/etc/ssl/local"
|
|
|
|
MD5SUM="/usr/bin/md5sum"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Dump to a temporary directory
|
|
|
|
TEMPDIR=`mktemp -d`
|
|
|
|
/usr/bin/trust extract --filter=certificates \
|
|
|
|
--format=openssl-directory \
|
|
|
|
--overwrite \
|
|
|
|
"${TEMPDIR}"
|
|
|
|
|
2019-01-02 07:39:21 +05:30
|
|
|
# Create a list of anchors that were not present or have been modified
|
2021-08-05 08:47:50 +05:30
|
|
|
"${MD5SUM}" "${ANCHORDIR}"/* \
|
2019-04-13 09:41:01 +05:30
|
|
|
2> /dev/null > "${TEMPDIR}/anchors.md5sums"
|
|
|
|
diff -au "${ANCHORLIST}" "${TEMPDIR}/anchors.md5sums" \
|
|
|
|
2> /dev/null > "${TEMPDIR}/diff"
|
2021-08-05 08:47:50 +05:30
|
|
|
grep "^+[a-z,0-9]" "${TEMPDIR}/diff" | cut -d " " -f 3 | \
|
|
|
|
sed '/x-certificate-extension/d' 2> /dev/null > "${TEMPDIR}/certlist"
|
2019-01-02 07:30:04 +05:30
|
|
|
|
|
|
|
echo -e "\nThe following certificates have local modifications:\n"
|
2019-01-02 07:39:21 +05:30
|
|
|
|
2019-01-02 07:30:04 +05:30
|
|
|
# Copy new certificates to LOCALDIR
|
|
|
|
for certificate in `cat "${TEMPDIR}/certlist"` ; do
|
2021-08-06 08:57:20 +05:30
|
|
|
LABEL=`grep -m 1 "^label:" "${certificate}" | sed 's@^label: @@'`
|
|
|
|
LABELNEW=`echo "${LABEL}" | /bin/sed -e 's@"@@g' -e 's@ @_@g'`
|
|
|
|
|
|
|
|
# Determine default usage (this can be changed later)
|
|
|
|
usage=$(openssl x509 -in ${certificate} -noout -text | \
|
|
|
|
grep -A1 "X509v3 Key Usage:")
|
|
|
|
trust=""
|
|
|
|
echo ${usage} | grep -q "Certificate Sign" &&
|
|
|
|
trust="${trust} -addtrust serverAuth"
|
|
|
|
echo ${usage} | grep -q "Digital Signature" &&
|
|
|
|
trust="${trust} -addtrust emailProtection"
|
|
|
|
|
|
|
|
# Place into LOCALDIR
|
|
|
|
openssl x509 -in ${certificate} -text -fingerprint -setalias "${LABEL}" \
|
|
|
|
${trust} -out "${LOCALDIR}/${LABELNEW}.pem"
|
2019-01-02 07:30:04 +05:30
|
|
|
echo -e "${LABELNEW}"
|
2021-08-06 08:57:20 +05:30
|
|
|
unset LABEL LABELNEW usage trust
|
2019-01-02 07:30:04 +05:30
|
|
|
done
|
2021-08-06 08:57:20 +05:30
|
|
|
echo ""
|
2019-01-02 07:30:04 +05:30
|
|
|
|
|
|
|
# Clean up
|
|
|
|
rm -rf "${TEMPDIR}"
|
|
|
|
unset ANCHORDIR ANCHORLIST LOCALDIR CERTLIST TEMPDIR
|
|
|
|
|