ioq3quest/code/autoupdater/rsa_tools/build-rsa-tools.sh

34 lines
790 B
Bash
Raw Normal View History

Initial add of rsa_tools. This is just a simple RSA public key digital signature thing built on libtomcrypt. The gist: Some admin will generate a public/private key with rsa_make_keys, keeping the private key secret. Using the private key and rsa_sign, the admin will sign the autoupdater manifests, generating manifest.txt.sig. The public key ships with the game (adding 270 bytes to the download), the .sig is downloaded with the manifest by the autoupdater (256 bytes extra download), then the autoupdater checks the manifest against the signature with the public key. if the signature isn't valid (the manifest was tampered with or corrupt), the autoupdater refuses to continue. If the manifest is to be trusted, it lists sha256 checksums for every file to download, so there's no need to sign every file; if they can't tamper with the manifest, they can't tamper with any other file to be updated since the file's listed sha256 won't match. If the private key is compromised, we generate new keys and ship new installers, so new installations will be able to update but existing ones will need to do a new install to keep getting updates. Don't let the private key get compromised. The private key doesn't go on a public server. Maybe it doesn't even live on the admin's laptop hard drive. If the download server is compromised and serving malware, the autoupdater will reject it outright if they haven't compromised the private key, generated a new manifest, and signed it with the private key. libtomcrypt is sort of a big pile of source code, so instead of putting it in revision control, we have a script to download it. Most things don't need it. It lives on GitHub, so we _could_ do a git submodule, but most people don't need it, so why waste their disk and bandwidth? That said, when compiled you end up with a few hundred kilobytes of binary code to verify a signature and no external dependencies, so it seems like a win.
2017-06-04 00:26:07 +00:00
#!/bin/bash
export TFMDIR="tomsfastmath-0.13.1"
export LTCDIR="libtomcrypt-1.17"
OSTYPE=`uname -s`
if [ -z "$CC" ]; then
if [ "`uname -o`" = "Cygwin" ]; then
export CC=/usr/bin/i686-w64-mingw32-gcc
else
export CC=cc
fi
fi
Initial add of rsa_tools. This is just a simple RSA public key digital signature thing built on libtomcrypt. The gist: Some admin will generate a public/private key with rsa_make_keys, keeping the private key secret. Using the private key and rsa_sign, the admin will sign the autoupdater manifests, generating manifest.txt.sig. The public key ships with the game (adding 270 bytes to the download), the .sig is downloaded with the manifest by the autoupdater (256 bytes extra download), then the autoupdater checks the manifest against the signature with the public key. if the signature isn't valid (the manifest was tampered with or corrupt), the autoupdater refuses to continue. If the manifest is to be trusted, it lists sha256 checksums for every file to download, so there's no need to sign every file; if they can't tamper with the manifest, they can't tamper with any other file to be updated since the file's listed sha256 won't match. If the private key is compromised, we generate new keys and ship new installers, so new installations will be able to update but existing ones will need to do a new install to keep getting updates. Don't let the private key get compromised. The private key doesn't go on a public server. Maybe it doesn't even live on the admin's laptop hard drive. If the download server is compromised and serving malware, the autoupdater will reject it outright if they haven't compromised the private key, generated a new manifest, and signed it with the private key. libtomcrypt is sort of a big pile of source code, so instead of putting it in revision control, we have a script to download it. Most things don't need it. It lives on GitHub, so we _could_ do a git submodule, but most people don't need it, so why waste their disk and bandwidth? That said, when compiled you end up with a few hundred kilobytes of binary code to verify a signature and no external dependencies, so it seems like a win.
2017-06-04 00:26:07 +00:00
function build {
2017-06-04 05:44:39 +00:00
if [ "$OSTYPE" = "Darwin" ]; then
$CC -mmacosx-version-min=10.7 -DMAC_OS_X_VERSION_MIN_REQUIRED=1070 -I $TFMDIR/src/headers -I $LTCDIR/src/headers -o "$1" -Wall -O3 "$1.c" rsa_common.c $LTCDIR/libtomcrypt.a $TFMDIR/libtfm.a
2017-06-04 05:44:39 +00:00
else
$CC -I $TFMDIR/src/headers -I $LTCDIR/src/headers -o "$1" -Wall -O3 "$1.c" rsa_common.c $LTCDIR/libtomcrypt.a $TFMDIR/libtfm.a
2017-06-04 05:44:39 +00:00
fi
Initial add of rsa_tools. This is just a simple RSA public key digital signature thing built on libtomcrypt. The gist: Some admin will generate a public/private key with rsa_make_keys, keeping the private key secret. Using the private key and rsa_sign, the admin will sign the autoupdater manifests, generating manifest.txt.sig. The public key ships with the game (adding 270 bytes to the download), the .sig is downloaded with the manifest by the autoupdater (256 bytes extra download), then the autoupdater checks the manifest against the signature with the public key. if the signature isn't valid (the manifest was tampered with or corrupt), the autoupdater refuses to continue. If the manifest is to be trusted, it lists sha256 checksums for every file to download, so there's no need to sign every file; if they can't tamper with the manifest, they can't tamper with any other file to be updated since the file's listed sha256 won't match. If the private key is compromised, we generate new keys and ship new installers, so new installations will be able to update but existing ones will need to do a new install to keep getting updates. Don't let the private key get compromised. The private key doesn't go on a public server. Maybe it doesn't even live on the admin's laptop hard drive. If the download server is compromised and serving malware, the autoupdater will reject it outright if they haven't compromised the private key, generated a new manifest, and signed it with the private key. libtomcrypt is sort of a big pile of source code, so instead of putting it in revision control, we have a script to download it. Most things don't need it. It lives on GitHub, so we _could_ do a git submodule, but most people don't need it, so why waste their disk and bandwidth? That said, when compiled you end up with a few hundred kilobytes of binary code to verify a signature and no external dependencies, so it seems like a win.
2017-06-04 00:26:07 +00:00
}
set -e
set -x
./build-libtom-unix.sh
build rsa_make_keys
build rsa_sign
build rsa_verify
set +x
echo "rsa_tools are compiled!"