本文介绍了仅使用命令行界面在服务器上打包 Chrome 扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以仅使用 CLI (Ubuntu-server) 在服务器上使用密钥 (*.pem) 打包 chrome 扩展程序?

Is it possible to pack chrome extension with key (*.pem) on server only with CLI (Ubuntu-server)?

推荐答案

更新:chrome现在使用版本3,google发布的脚本只适用于版本2

Update: chrome now uses Version 3 and the scripts released by google only worked for Version 2

https://developer.chrome.com/extensions/crx#scripts - 一个在 Bash 中,一个在 Ruby 中.Google 现在希望他们为网上商店打包应用程序.

There were official packaging scripts for Version 2 listed at https://developer.chrome.com/extensions/crx#scripts - one in Bash and one in Ruby.Google now wants apps to be packaged by them for the webstore.

但是,这里有一个修改后的脚本,可用于打包 CRX3 包:

However, here's a modified script that works for packaging CRX3 packages:

# 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"

此脚本根据源代码中的信息进行了修改:

This script was revised based on information from the source code:

创建函数标头说明

以及标头的序列化文档.

这个脚本可以很容易地在 docker 容器中使用以实现自动化:

This script can easily be used in a docker container for automation:

FROM alpine:3.9
RUN apk add --no-cache git openssl zip vim
COPY scripts/crxmake.sh /usr/local/bin/crxmake

这篇关于仅使用命令行界面在服务器上打包 Chrome 扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 02:37