Skip to content

Commit 641757d

Browse files
committed
Verify OpenSSL tarball checksums
It's not nice to just download whatever source code from the Internet and build a cryptography library from that. At least verify that the checksum of the file is the expected one. The checksums are retrieved via a trusted Web browser from a trusted network from the official Web site. We check that the file we download is the one we should expect, just in case openssl.org gets MITMed.
1 parent 27e6a21 commit 641757d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

build-libssl.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,35 @@ else
461461
echo "Using ${OPENSSL_ARCHIVE_FILE_NAME}"
462462
fi
463463

464+
# Check that have downloaded and using the right thing.
465+
# Checksums available at https://www.openssl.org/source/ for current releases
466+
# and at https://www.openssl.org/source/old/ for old releases.
467+
OPENSSL_CHECKSUMS="
468+
1.0.2u ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16
469+
"
470+
checksum_checked=false
471+
while read version expectedSHA256; do
472+
if [ "$VERSION" = "$version" ]; then
473+
actualSHA256="$(shasum -a 256 "${OPENSSL_ARCHIVE_FILE_NAME}" | awk '{print $1}')"
474+
if [ "$actualSHA256" = "$expectedSHA256" ]; then
475+
checksum_checked=true
476+
else
477+
echo "SHA-256 checksum mismatch for ${OPENSSL_ARCHIVE_FILE_NAME}"
478+
echo "Please verify the file contents and your network connection."
479+
echo "Official checksums available at https://www.openssl.org/source/"
480+
exit 1
481+
fi
482+
fi
483+
done << EOF
484+
$OPENSSL_CHECKSUMS
485+
EOF
486+
if [ "$checksum_checked" != "true" ]; then
487+
echo "No known checksums for ${OPENSSL_ARCHIVE_FILE_NAME} (OpenSSL $VERSION)."
488+
echo "Please lookup the checksum at https://www.openssl.org/source/"
489+
echo "and update the OPENSSL_CHECKSUMS list in the script."
490+
exit 1
491+
fi
492+
464493
# Set reference to custom configuration (OpenSSL 1.1.1)
465494
# See: https://github.com/openssl/openssl/commit/afce395cba521e395e6eecdaf9589105f61e4411
466495
export OPENSSL_LOCAL_CONFIG_DIR="${SCRIPTDIR}/config"

0 commit comments

Comments
 (0)