有没有可能只用命令行(Ubuntu- server )在服务器上打包带密钥的chrome扩展(*.pem)?
发布于 2013-09-10 08:52:04
更新: chrome现在使用版本3,谷歌发布的脚本只适用于版本2
在https://developer.chrome.com/extensions/crx#scripts上列出了版本2的官方打包脚本--一个在Bash中,一个在Ruby中。谷歌现在希望应用程序由他们打包,供网络商店使用。
但是,下面是一个用于打包CRX3包的修改后的脚本:
# Purpose: Pack a Chromium extension directory into crx format
if test $# -ne 2; then
echo "Usage: crxmake.sh <extension dir> <pem path>"
exit 1
fi
dir=$1
key=$2
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" .)
#extract crx id
openssl rsa -in "$key" -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 "$key" < "$tosign" > "$sig"
# public key
openssl rsa -pubout -outform DER < "$key" > "$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"
此脚本已根据源代码中的信息进行了修改:
Create Function Header Description
以及报头的serialization documentation。
这个脚本可以很容易地在docker容器中使用以实现自动化:
FROM alpine:3.9
RUN apk add --no-cache git openssl zip vim
COPY scripts/crxmake.sh /usr/local/bin/crxmake
发布于 2013-09-10 00:13:55
您可以按照documentation中的说明使用应用程序开关--pack-extension
和--pack-extension-key
。
基本上,在Windows上,您可以在终端中运行以下命令:
chrome.exe --pack-extension=c:\myext --pack-extension-key=c:\myext.pem
它也可以在Mac上运行:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --pack-extension=./myext --pack-extension-key=./myext.pem
在Ubuntu上应该是类似的。
省略--pack-extension-key
将自动为您创建一个密钥。
https://stackoverflow.com/questions/18693962
复制相似问题