|
| 1 | +set -euo pipefail |
| 2 | + |
| 3 | +echo "=== mitmproxy certificates setup wizard ===" |
| 4 | +echo "Use this shell script to setup the mitmproxy certificates for the integration tests on your local machine." |
| 5 | + |
| 6 | +# we could also add openssl to the conda environment, but this should be available on most systems |
| 7 | +if ! command -v openssl &> /dev/null; then |
| 8 | + echo "error: openssl is not installed. Please install it first." |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 13 | +mitmproxy_dir="${script_dir}/.mitmproxy" |
| 14 | + |
| 15 | +# the mitmproxy_dir should already exist |
| 16 | +cd "${mitmproxy_dir}" |
| 17 | + |
| 18 | +echo "Press enter to generate the mitmproxy certificates." |
| 19 | +read -r |
| 20 | + |
| 21 | +openssl genrsa -out mitmproxy-ca.key 4096 |
| 22 | +openssl req -x509 -new -nodes -key mitmproxy-ca.key -sha256 -days 365 -out mitmproxy-ca.crt -addext keyUsage=critical,keyCertSign -subj "/C=US/ST=cf-scripts/L=cf-scripts/O=cf-scripts/OU=cf-scripts/CN=cf-scripts" |
| 23 | +cat mitmproxy-ca.key mitmproxy-ca.crt > mitmproxy-ca.pem |
| 24 | + |
| 25 | +echo "The mitmproxy certificates have been generated successfully." |
| 26 | +echo "The root certificate will be valid for 365 days." |
| 27 | +echo "You now need to trust the mitmproxy-ca.pem certificate in your system's trust store." |
| 28 | +echo "The exact process depends on your operating system." |
| 29 | +echo "On MacOS, drag and drop the mitmproxy-ca.pem file into the Keychain Access app while having the 'Login' keychain selected." |
| 30 | +echo "Then, double-click the certificate in the keychain and set ‘Always Trust‘ in the ‘Trust‘ section." |
| 31 | +echo "The certificate is located at: ${mitmproxy_dir}/mitmproxy-ca.pem" |
| 32 | +echo "After you're done, press enter to continue." |
| 33 | +read -r |
| 34 | + |
| 35 | +echo "Generating the certificate bundle mitmproxy-cert-bundle.pem to pass to Python..." |
| 36 | +cp "$(python -m certifi)" mitmproxy-cert-bundle.pem |
| 37 | +cat mitmproxy-ca.pem >> mitmproxy-cert-bundle.pem |
| 38 | + |
| 39 | +echo "The certificate bundle has been generated successfully." |
| 40 | +echo "The mitmproxy certificate setup wizard has been completed successfully." |
0 commit comments