summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2021-01-04 15:01:52 +0100
committertv <tv@krebsco.de>2021-01-04 15:04:15 +0100
commit0737e1f9208f26d073d49118b3aec8ebad420cd4 (patch)
tree3b7e9c9612194784ddb43e42a144f8a9b47cc6a7
parent9feb2a8b377205ff8ab0f947ee511ec1fde5b9e7 (diff)
crxid: get ID from CRX3 fileHEADv1.1.0master
-rwxr-xr-xcrxid46
1 files changed, 35 insertions, 11 deletions
diff --git a/crxid b/crxid
index 7c0236c..e3f7c1b 100755
--- a/crxid
+++ b/crxid
@@ -1,23 +1,47 @@
#! /bin/sh
-# Get CRX id from RSA key
-# usage: crxid PEM_FILE
+# Get CRX id from RSA key or CRX3 file
+# usage: crxid FILE
set -efu
-pem_path=$1
+path=$1
+type=$(file -b "$path")
-digest=$(
- openssl rsa -in "$pem_path" -pubout -outform der 2>/dev/null |
- openssl dgst -sha256 -hex |
- sed 's/^(stdin)= //;s/.*/\U&/'
-)
+case $type in
+ 'Google Chrome extension, version 3')
+ # For details about CRX3 format see
+ # https://chromium.googlesource.com/chromium/src/+/HEAD/components/crx_file/crx3.proto
+ header_length=$(od -An -j8 -N4 -tu4 "$path")
+ binary_crx_id_length=16
+ binary_crx_id_offset=$(expr 12 + $header_length - $binary_crx_id_length)
+ crx_id_hexstring=$(
+ od -An -j"$binary_crx_id_offset" -N"$binary_crx_id_length" -tx1 "$path" |
+ tr a-f A-F |
+ tr -d ' '
+ )
+ ;;
+ 'PEM RSA private key')
+ digest=$(
+ openssl rsa -in "$path" -pubout -outform der 2>/dev/null |
+ openssl dgst -sha256 -hex |
+ sed 's/^(stdin)= //;s/.*/\U&/'
+ )
+ crx_id_hexstring=$(
+ echo "$digest" | cut -b-32
+ )
+ ;;
+ *)
+ echo "crxid: error: $path has unsupported type: $type" >&2
+ exit 1
+esac
script="
obase=16;
ibase=16;
ascii_a=61;
- $(echo $digest | cut -b-32 | sed 's/./ascii_a + &;/g')
+ $(echo $crx_id_hexstring | sed 's/./ascii_a + &;/g')
"
-echo "$script" | bc | xxd -r -p
-echo
+crx_id=$(echo "$script" | bc | xxd -r -p)
+
+echo "$crx_id"