commit cf4bf3da46ea3ed65b1f2355c5373232dd0d2d20 Author: Pierre-Olivier Mercier Date: Sun May 30 17:40:01 2021 +0200 Initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa04c88 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine + +RUN apk add --no-cache openssl xxd zip +COPY crxmake.sh /usr/bin/crxmake + +CMD ["crxmake.sh"] \ No newline at end of file diff --git a/crxmake.sh b/crxmake.sh new file mode 100755 index 0000000..b182b21 --- /dev/null +++ b/crxmake.sh @@ -0,0 +1,59 @@ +# Purpose: Pack a Chromium extension directory into crx format + +if test $# -ne 1; then + echo "Usage: crxmake.sh " + exit 1 +fi + +dir=$1 +name=$(basename "$dir") +crx="$name.crx" +pub="$name.pub" +sig="$name.sig" +zip="$name.zip" +tosign="$name.presig" +binary_crx_id="$name.crxid" +trap 'rm -f "$pub" "$sig" "$zip" "$tosign" "$binary_crx_id"' EXIT + + +# zip up the crx dir +cwd=$(pwd -P) +(cd "$dir" && zip -qr -9 -X "$cwd/$zip" .) + +echo "${EXTENSION_CRX_KEY}" > /tmp/extension.pem +cat /tmp/extension.pem + +#extract crx id +openssl rsa -in /tmp/extension.pem -pubout -outform der | openssl dgst -sha256 -binary -out "$binary_crx_id" +truncate -s 16 "$binary_crx_id" + +#generate file to sign +( + # echo "$crmagic_hex $version_hex $header_length $pub_len_hex $sig_len_hex" + printf "CRX3 SignedData" + echo "00 12 00 00 00 0A 10" | xxd -r -p + cat "$binary_crx_id" "$zip" +) > "$tosign" + +# signature +openssl dgst -sha256 -binary -sign /tmp/extension.pem < "$tosign" > "$sig" + +# public key +openssl rsa -pubout -outform DER < /tmp/extension.pem > "$pub" 2>/dev/null + + +crmagic_hex="43 72 32 34" # Cr24 +version_hex="03 00 00 00" # 3 +header_length="45 02 00 00" +header_chunk_1="12 AC 04 0A A6 02" +header_chunk_2="12 80 02" +header_chunk_3="82 F1 04 12 0A 10" +( + echo "$crmagic_hex $version_hex $header_length $header_chunk_1" | xxd -r -p + cat "$pub" + echo "$header_chunk_2" | xxd -r -p + cat "$sig" + echo "$header_chunk_3" | xxd -r -p + cat "$binary_crx_id" "$zip" +) > "$crx" +echo "Wrote $crx"