Add sri-integrity

This commit is contained in:
Sami Samhuri 2019-06-25 14:31:28 -07:00
parent b3bea60a8d
commit c38ca383ef

19
sri-integrity Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env ruby -w
#
# Generates Sub-Resource Integrity hashes for external resources in HTML.
# See https://infosec.mozilla.org/guidelines/web_security#subresource-integrity
#
url = ARGV.shift.to_s
unless url =~ %r{^https?://}
$stderr.puts "usage: sri-integrity <url>"
exit 1
end
hash = `curl -s '#{url}' | openssl dgst -sha384 -binary | openssl base64 -A`
if $?.success?
puts hash
else
exit 1
end