firefox-db2pem.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/sh
  2. # ***************************************************************************
  3. # * _ _ ____ _
  4. # * Project ___| | | | _ \| |
  5. # * / __| | | | |_) | |
  6. # * | (__| |_| | _ <| |___
  7. # * \___|\___/|_| \_\_____|
  8. # *
  9. # * Copyright (C) 1998 - 2020, 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. # ***************************************************************************
  23. # This shell script creates a fresh ca-bundle.crt file for use with libcurl.
  24. # It extracts all ca certs it finds in the local Firefox database and converts
  25. # them all into PEM format.
  26. #
  27. db=`ls -1d $HOME/.mozilla/firefox/*default*`
  28. out=$1
  29. if test -z "$out"; then
  30. out="ca-bundle.crt" # use a sensible default
  31. fi
  32. currentdate=`date`
  33. cat >$out <<EOF
  34. ##
  35. ## Bundle of CA Root Certificates
  36. ##
  37. ## Converted at: ${currentdate}
  38. ## These were converted from the local Firefox directory by the db2pem script.
  39. ##
  40. EOF
  41. certutil -L -h 'Builtin Object Token' -d $db | \
  42. grep ' *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$' | \
  43. sed -e 's/ *[CcGTPpu]*,[CcGTPpu]*,[CcGTPpu]* *$//' -e 's/\(.*\)/"\1"/' | \
  44. sort | \
  45. while read nickname; \
  46. do echo $nickname | sed -e "s/Builtin Object Token://g"; \
  47. eval certutil -d $db -L -n "$nickname" -a ; \
  48. done >> $out