@ 141e6346099989c841d4af3293458485a50c86e7 | history
#!/bin/sh
# openssl-unlimited.sh builds OpenSSL with its policy tree node limit
# removed and prints the path of the openssl binary.
#
# Since CVE-2023-0464, OpenSSL refuses any policy tree over 1,000 nodes, a
# limit that can only be changed when OpenSSL is compiled. GOVERNMENT
# programs grow their tree roughly as depth times width, so a stock OpenSSL
# can only check small ones. This build is for checking programs you
# compiled yourself: without the limit, a hostile chain can make it use
# exponential time and memory again, so never use it on untrusted input.
#
# The build is cached, outside the repository, in
# ${XDG_CACHE_HOME:-~/.cache}/government/. Set OPENSSL_TAG to build
# another release.
#
# Needs git, perl, make and a C compiler (on macOS, the Xcode command line
# tools).
set -eu
tag=${OPENSSL_TAG:-openssl-4.1.0}
cache=${XDG_CACHE_HOME:-$HOME/.cache}/government
dir=$cache/$tag-unlimited
bin=$dir/apps/openssl
if [ ! -x "$bin" ]; then
echo "building $tag without its policy tree limit in $dir (a few minutes)" >&2
rm -rf "$dir"
mkdir -p "$cache"
git -c advice.detachedHead=false clone --quiet --depth 1 --branch "$tag" https://github.com/openssl/openssl "$dir" >&2
cd "$dir"
./Configure -DOPENSSL_POLICY_TREE_NODES_MAX=0 no-shared no-docs no-tests >/dev/null
make -j"$(getconf _NPROCESSORS_ONLN)" build_programs >/dev/null
fi
echo "$bin"