browser-self-sign-macos.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/bin/bash
  2. CERTNAME=my-codesign-cert-tor
  3. BROWSERPATH=.
  4. if [ $# -ge 1 ]
  5. then
  6. BROWSERPATH=$1
  7. fi
  8. security find-certificate -c $CERTNAME > /dev/null
  9. if [ $? -ne 0 ]
  10. then
  11. echo ""
  12. echo "ERROR: Self Signing Certificate not found, please create:"
  13. echo " 1. In the Keychain Access app on your Mac, choose Keychain Access > Certificate Assistant > Create a Certificate."
  14. echo " 2. Enter the name '$CERTNAME' for the certificate"
  15. echo " 3. Choose an identity type: Self Signed Root"
  16. echo " 4. Certificate Type > Code Signing"
  17. echo " 5. Check 'Let me override defaults' & click Continue."
  18. echo " 6. Enter a unique Serial Number. (123 is fine)"
  19. echo " 7. Enter a big Validity Period (days), like 3560 & click Continue."
  20. echo " 8. Fill in your personal information & click Continue."
  21. echo " 9. Accept defaults for the rest of the dialog boxes. (Continue several times)"
  22. echo " 10. Certificate Created! Click Done."
  23. echo ""
  24. echo "For additional help see:"
  25. echo " https://support.apple.com/en-ca/guide/keychain-access/kyca8916/mac"
  26. echo " https://stackoverflow.com/questions/58356844/what-are-the-ways-or-technologies-to-sign-an-executable-application-file-in-mac"
  27. echo ""
  28. read -n 1 -r -s -p $'Press enter to launch "Keychain Access"...\n'
  29. open /System/Applications/Utilities/Keychain\ Access.app
  30. exit -1
  31. fi
  32. echo "Found $CERTNAME, looking for browser to sign..."
  33. if [ ! -f "$BROWSERPATH/XUL" ]
  34. then
  35. TESTPATH="$BROWSERPATH/Contents/MacOS"
  36. if [ -f "$TESTPATH/XUL" ]
  37. then
  38. BROWSERPATH=$TESTPATH
  39. else
  40. echo "Error: browser files not detected in $BROWSERPATH!"
  41. echo " This script needs to be run in the 'Contents/MacOS' directory of a SomeBrowser.app directory"
  42. exit -1
  43. fi
  44. fi
  45. echo "Mozilla based browser found, signing..."
  46. echo ' Will be asked for password to certificate for all the things that need to be signed. Click "Always Allow" to automate'
  47. cd "$BROWSERPATH"
  48. codesign -s $CERTNAME *.dylib
  49. codesign -s $CERTNAME plugin-container.app
  50. if [ -d Tor ]
  51. then
  52. codesign -s $CERTNAME Tor/PluggableTransports/*
  53. codesign -s $CERTNAME Tor/libevent-2.1.7.dylib
  54. if [ -f Tor/tor.real ]
  55. then
  56. codesign -s $CERTNAME Tor/tor.real
  57. fi
  58. if [ -f Tor/tor ]
  59. then
  60. codesign -s $CERTNAME Tor/tor
  61. fi
  62. fi
  63. codesign -s $CERTNAME XUL
  64. if [ -d updater.app ]
  65. then
  66. codesign -s $CERTNAME updater.app
  67. fi
  68. # mullvadbrowser
  69. if [ -f mullvadbrowser ]
  70. then
  71. codesign -s $CERTNAME mullvadbrowser
  72. fi
  73. # BB or TB
  74. if [ -f firefox ]
  75. then
  76. codesign -s $CERTNAME firefox
  77. fi
  78. echo ""
  79. echo "Browser signing step done!"
  80. echo ""
  81. echo "App still needs one more override to be easily opened with double click in Finder"
  82. echo "Alternatively you can right click it, select 'Open' and then select 'Open' from the override popup"
  83. echo "Or to enable it to be double clicked to open perform the following"
  84. echo ""
  85. echo "Double click the app and select either 'Ok' or 'Cancel' from the warning popup depending on which you get (Do Not 'Move to Trash')"
  86. echo 'Go to Preferences -> Security & Privacy and click on padlock to allow changes. '
  87. echo ' Then in "Allow appications downloaded from" select either:'
  88. echo ' - App Store and identified developers'
  89. echo ' - Anywhere'
  90. echo ' Below that may be a notice about your specific app saying it was blocked because it was not from an identified developer. Click "Open Anyways" and "Open"'