Guest User

Untitled

a guest
Jul 22nd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #!/bin/bash -e
  2. #
  3. # Purpose: Pack a Chromium extension directory into crx format
  4.  
  5. if test $# -ne 2; then
  6. echo "Usage: crxmake.sh <extension dir> <pem path>"
  7. exit 1
  8. fi
  9.  
  10. dir=$1
  11. key=$2
  12. name=$(basename "$dir")
  13. crx="$name.crx"
  14. pub="$name.pub"
  15. sig="$name.sig"
  16. zip="$name.zip"
  17. trap 'rm -f "$pub" "$sig" "$zip"' EXIT
  18.  
  19. # zip up the crx dir
  20. cwd=$(pwd -P)
  21. (cd "$dir" && zip -qr -9 -X "$cwd/$zip" .)
  22.  
  23. # signature
  24. openssl sha1 -sha1 -binary -sign "$key" < "$zip" > "$sig"
  25.  
  26. # public key
  27. openssl rsa -pubout -outform DER < "$key" > "$pub" 2>/dev/null
  28.  
  29. byte_swap () {
  30. # Take "abcdefgh" and return it as "ghefcdab"
  31. echo "${1:6:2}${1:4:2}${1:2:2}${1:0:2}"
  32. }
  33.  
  34. crmagic_hex="4372 3234" # Cr24
  35. version_hex="0200 0000" # 2
  36. pub_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$pub" | awk '{print $5}')))
  37. sig_len_hex=$(byte_swap $(printf '%08x\n' $(ls -l "$sig" | awk '{print $5}')))
  38. (
  39. echo "$crmagic_hex $version_hex $pub_len_hex $sig_len_hex" | xxd -r -p
  40. cat "$pub" "$sig" "$zip"
  41. ) > "$crx"
  42. echo "Wrote $crx"
Add Comment
Please, Sign In to add comment