#!/bin/sh1# ***************************************************************************2# * _ _ ____ _3# * Project ___| | | | _ \| |4# * / __| | | | |_) | |5# * | (__| |_| | _ <| |___6# * \___|\___/|_| \_\_____|7# *8# * Copyright (C) Daniel Stenberg, <[email protected]>, et al.9# *10# * This software is licensed as described in the file COPYING, which11# * you should have received as part of this distribution. The terms12# * are also available at https://curl.se/docs/copyright.html.13# *14# * You may opt to use, copy, modify, merge, publish, distribute and/or sell15# * copies of the Software, and permit persons to whom the Software is16# * furnished to do so, under the terms of the COPYING file.17# *18# * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY19# * KIND, either express or implied.20# *21# * SPDX-License-Identifier: curl22# *23# ***************************************************************************24# This shell script creates a fresh ca-bundle.crt file for use with libcurl.25# It extracts all ca certs it finds in the local Firefox database and converts26# them all into PEM format.27#28# It uses the "certutil" command line tool from the NSS project to perform the29# conversion. On Debian it comes in the "libnss3-tools" package.30#3132set -eu3334db=$(ls -1d "$HOME"/.mozilla/firefox/*default*)35out="${1:-}"3637if test -z "$out"; then38out="ca-bundle.crt" # use a sensible default39fi4041currentdate=$(date)4243cat > "$out" <<EOF44##45## Bundle of CA Root Certificates46##47## Converted at: ${currentdate}48## These were converted from the local Firefox directory by the db2pem script.49##50EOF515253certutil -L -h 'Builtin Object Token' -d "$db" | \54grep ' *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$' | \55sed -e 's/ *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$//' -e 's/\(.*\)/"\1"/' | \56sort | \57while read -r nickname; \58do echo "$nickname" | sed -e "s/Builtin Object Token://g"; \59eval certutil -d "$db" -L -n "$nickname" -a ; \60done >> "$out"616263