#!/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 -eu3334if [ -d "$HOME/Library/Application Support"/Firefox/Profiles ]; then35db=$(ls -1d "$HOME/Library/Application Support"/Firefox/Profiles/*default*)36else37db=$(ls -1d "$HOME"/.mozilla/firefox/*default*)38fi39out="${1:-}"4041if test -z "$out"; then42out="ca-bundle.crt" # use a sensible default43fi4445currentdate=$(date)4647cat > "$out" <<EOF48##49## Bundle of CA Root Certificates50##51## Converted at: ${currentdate}52## These were converted from the local Firefox directory by the db2pem script.53##54EOF555657certutil -L -h 'Builtin Object Token' -d "$db" | \58grep ' *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$' | \59sed -e 's/ *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$//' -e 's/\(.*\)/"\1"/' | \60sort | \61while read -r nickname; do62echo "$nickname" | sed 's/Builtin Object Token://g'63echo "$nickname" | xargs -I{} certutil -d "$db" -L -a -n {}64done >> "$out"656667