Created
October 16, 2017 23:44
-
-
Save cypnk/b37bafa923d614d4f43a7e8e55870511 to your computer and use it in GitHub Desktop.
Verify a file with a given public key (best for files signed with "sign.sh")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Verify a signed file with the specified public key | |
# Signature file | |
SRCF=$1 | |
# Public key location | |
PUBK=$2 | |
# Signature algorithm (defaults to SHA-512) | |
ALGO=${3:-sha512} | |
# Algo file | |
ALGF=$SRCF.$ALGO.sig | |
# Check for signature file | |
if [ ! -f "$ALGF" ]; then | |
echo "Signature file must be in the same directory" | |
exit | |
fi | |
if [ -f "$PUBK" ]; then | |
if [ -f "$SRCF" ]; then | |
openssl dgst -$ALGO -verify $PUBK -signature $ALGF $SRCF | |
else | |
echo "Source file not found" | |
fi | |
else | |
echo "Public key not found" | |
fi | |
exit | |
# To use this, run: | |
# sh verify.sh /path/to/file.ext /path/to/publickey.pub | |
# The signature file should be there in "file.ext.sha512.sig" format | |
# Or if a different algorithm was used, E.G. SHA-256: | |
# sh verify.sh /path/to/file.ext /path/to/publickey.pub sha256 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment