2
0

firefox-db2pem.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. # ***************************************************************************
  3. # * _ _ ____ _
  4. # * Project ___| | | | _ \| |
  5. # * / __| | | | |_) | |
  6. # * | (__| |_| | _ <| |___
  7. # * \___|\___/|_| \_\_____|
  8. # *
  9. # * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  10. # *
  11. # * This software is licensed as described in the file COPYING, which
  12. # * you should have received as part of this distribution. The terms
  13. # * are also available at https://curl.se/docs/copyright.html.
  14. # *
  15. # * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. # * copies of the Software, and permit persons to whom the Software is
  17. # * furnished to do so, under the terms of the COPYING file.
  18. # *
  19. # * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. # * KIND, either express or implied.
  21. # *
  22. # * SPDX-License-Identifier: curl
  23. # *
  24. # ***************************************************************************
  25. # This shell script creates a fresh ca-bundle.crt file for use with libcurl.
  26. # It extracts all ca certs it finds in the local Firefox database and converts
  27. # them all into PEM format.
  28. #
  29. # It uses the "certutil" command line tool from the NSS project to perform the
  30. # conversion. On Debian it comes in the "libnss3-tools" package.
  31. #
  32. set -eu
  33. db=$(ls -1d "$HOME"/.mozilla/firefox/*default*)
  34. out="${1:-}"
  35. if test -z "$out"; then
  36. out="ca-bundle.crt" # use a sensible default
  37. fi
  38. currentdate=$(date)
  39. cat > "$out" <<EOF
  40. ##
  41. ## Bundle of CA Root Certificates
  42. ##
  43. ## Converted at: ${currentdate}
  44. ## These were converted from the local Firefox directory by the db2pem script.
  45. ##
  46. EOF
  47. certutil -L -h 'Builtin Object Token' -d "$db" | \
  48. grep ' *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$' | \
  49. sed -e 's/ *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$//' -e 's/\(.*\)/"\1"/' | \
  50. sort | \
  51. while read -r nickname; \
  52. do echo "$nickname" | sed -e "s/Builtin Object Token://g"; \
  53. eval certutil -d "$db" -L -n "$nickname" -a ; \
  54. done >> "$out"