aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2019-02-04 18:40:53 -0200
committerSilvio Rhatto <rhatto@riseup.net>2019-02-04 18:40:53 -0200
commit173f4d72aecd8f3cda669cf8f477df918bf254e0 (patch)
treee95bfd62b3442be5fb9963e973b7a96a8dc53ae4
parent8251e511d5fea47c95af3f71c1c5f39af0b1e1f5 (diff)
downloadscripts-173f4d72aecd8f3cda669cf8f477df918bf254e0.tar.gz
scripts-173f4d72aecd8f3cda669cf8f477df918bf254e0.tar.bz2
Adds sri-hash
-rwxr-xr-xsri-hash34
1 files changed, 34 insertions, 0 deletions
diff --git a/sri-hash b/sri-hash
new file mode 100755
index 0000000..5979c39
--- /dev/null
+++ b/sri-hash
@@ -0,0 +1,34 @@
+#/bin/sh
+#
+# SRI Hash Generator
+#
+
+# Parameters
+BASENAME="`basename $0`"
+URI="$1"
+
+# Check
+if [ -z "$URI" ]; then
+ echo "usage: $BASENAME <file-or-url>"
+ exit 1
+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`"
+ echo ""
+else
+ if [ -e "$URI" ]; then
+ # See https://www.srihash.org/
+ HASH="`openssl dgst -sha384 -binary $URI | openssl base64 -A`"
+ else
+ echo "file not found: $URI"
+ exit 1
+ fi
+fi
+
+# Generate
+cat <<EOF
+<script src="$URI" integrity="sha384-$HASH" crossorigin="anonymous"></script>
+EOF