diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2025-03-29 13:39:10 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2025-03-29 13:39:10 -0300 |
commit | d00b8c3d92471476ec1ccce9c03f8c8520b6b6e8 (patch) | |
tree | 6fca7e02cc7963e575ce7fbe1a8ccf1e72fe3925 | |
parent | c3a1bf60e9694b6ac725016a15f19f49905e541f (diff) | |
download | utils-web-main.tar.gz utils-web-main.tar.bz2 |
Feat: sri-hash: support for more hash types, defaults to sha512 and added CSS supportmain
-rwxr-xr-x | sri-hash | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -9,6 +9,7 @@ # Parameters BASENAME="`basename $0`" URI="$1" +TYPE="${2:-sha512}" # Check if [ -z "$URI" ]; then @@ -19,12 +20,12 @@ fi # Get file if echo "$URI" | grep -q '^http'; then echo "downloading $URI and generating hash..." - HASH="`curl $URI | openssl dgst -sha384 -binary | openssl base64 -A`" + HASH="`curl $URI | openssl dgst -$TYPE -binary | openssl base64 -A`" echo "" else if [ -e "$URI" ]; then # See https://www.srihash.org/ - HASH="`openssl dgst -sha384 -binary $URI | openssl base64 -A`" + HASH="`openssl dgst -$TYPE -binary $URI | openssl base64 -A`" else echo "file not found: $URI" exit 1 @@ -32,6 +33,23 @@ else fi # Generate -cat <<EOF -<script src="$URI" integrity="sha384-$HASH" crossorigin="anonymous"></script> +if echo $URL | grep -q '.js$'; then + cat <<EOF +<script + src="$URI" + integrity="$TYPE-$HASH" + crossorigin="anonymous" + referrerpolicy="no-referrer" +></script> EOF +else + cat <<EOF +<link + href="$URI" + rel="stylesheet" + integrity="$TYPE-$HASH" + crossorigin="anonymous" + referrerpolicy="no-referrer" +></script> +EOF +fi |