pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / build-support / mitm-cache / setup-hook.sh
blob219674eb9ea414df5d5fe78a2fb6cb88237f41c1
1 mitmCacheConfigureHook() {
2 if [ -d "$mitmCache" ] && [ -z "$MITM_CACHE_CERT_DIR" ]; then
3 MITM_CACHE_CERT_DIR="$(mktemp -d)"
4 pushd "$MITM_CACHE_CERT_DIR"
5 MITM_CACHE_CA="$MITM_CACHE_CERT_DIR/ca.cer"
6 @openssl@/bin/openssl genrsa -out ca.key 2048
7 @openssl@/bin/openssl req -x509 -new -nodes -key ca.key -sha256 -days 1 -out ca.cer -subj "/C=AL/ST=a/L=a/O=a/OU=a/CN=example.org"
8 MITM_CACHE_HOST="127.0.0.1"
9 MITM_CACHE_PORT="${mitmCachePort:-$(@ephemeral_port_reserve@/bin/ephemeral-port-reserve "$MITM_CACHE_HOST")}"
10 MITM_CACHE_ADDRESS="$MITM_CACHE_HOST:$MITM_CACHE_PORT"
11 export http_proxy="$MITM_CACHE_ADDRESS"
12 export https_proxy="$MITM_CACHE_ADDRESS"
13 export SSL_CERT_FILE="$MITM_CACHE_CA"
14 export NIX_SSL_CERT_FILE="$MITM_CACHE_CA"
15 mitm-cache -l"$MITM_CACHE_ADDRESS" replay "$mitmCache" >/dev/null 2>/dev/null &
16 popd
20 # prepend it so any other configure hooks can use the generated root CA
21 preConfigureHooks=(mitmCacheConfigureHook "${preConfigureHooks[@]}")