Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit f47d295

Browse files
authored
Modification: Opera CRX Creation (#19708)
* Modification: Opera CRX Creation - MIME Type restriction requires default.rulesets to be declared - This is a better route than changing all downstream channels - Process will entail signing the hash of the Opera CRX for assurance * Create directory for special case browser distributions - Opera - Edge - Documentation
1 parent 461c95a commit f47d295

File tree

4 files changed

+207
-12
lines changed

4 files changed

+207
-12
lines changed

browser-dist/browser-dist.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Browser Distribution Special Cases
2+
3+
## Edge
4+
5+
Case:
6+
Edge does not accept CRX files for direct upload to store.
7+
8+
Work around: `edge.sh`
9+
10+
## Opera
11+
12+
Case:
13+
Opera does not accept `default.rulesets` due to strict MIME type restriction
14+
15+
In order to not disrupt many downstream channels, we are building a separate CRX file for Opera for now.
16+
17+
Work around: `opera.sh`
18+
19+
## Build process
20+
21+
These scripts are normally ran after main build and deployment is finished. The reason being we want a confirmed CRX file upload to Chrome to build the Edge zip and Opera crx distributions on.
22+
23+
## CRX Verification of Files before Upload
24+
25+
Install Node Package for CRX Verification via NPM
26+
`[sudo] npm -g i crx3-utils`
27+
28+
### Verify CRX file
29+
30+
1. `crx3-info rsa 0 < $crx > public.pem`
31+
2. `crx3-verify rsa 0 public.pem < $crx`
32+
3. `echo "CRX verified"`

edge.sh renamed to browser-dist/edge.sh

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
#!/bin/bash
22
# Written for transparency and reproducibility on Edge upload
3+
# See browser-dist.md for more info
34

4-
# Install Node Package for CRX Verification via NPM
5-
# [sudo] npm -g i crx3-utils
6-
7-
# Verify CRX file
8-
# crx3-info rsa 0 < $crx_cws > public.pem
9-
# crx3-verify rsa 0 public.pem < $crx_cws
10-
# echo "CRX verified"
11-
12-
VERSION=`python3.6 -c "import json ; print(json.loads(open('chromium/manifest.json').read())['version'])"`
13-
crx_cws="pkg/https-everywhere-$VERSION-cws.crx"
14-
crx_eff="pkg/https-everywhere-$VERSION-eff.crx"
5+
VERSION=`python3.6 -c "import json ; print(json.loads(open('../chromium/manifest.json').read())['version'])"`
6+
crx_cws="../pkg/https-everywhere-$VERSION-cws.crx"
7+
crx_eff="../pkg/https-everywhere-$VERSION-eff.crx"
158

169
crx3-info rsa 0 < $crx_cws > public.pem
1710
crx3-verify rsa 0 public.pem < $crx_cws
@@ -24,7 +17,7 @@ crx3-info < $crx_eff | awk '/^header/ {print $2}' \
2417

2518
echo >&2 "Edge zip package has sha256sum: `openssl dgst -sha256 -binary "https-everywhere-$VERSION-edge.zip" | xxd -p`"
2619

27-
mv https-everywhere-$VERSION-edge.zip pkg/https-everywhere-$VERSION-edge.zip
20+
mv https-everywhere-$VERSION-edge.zip ../pkg/https-everywhere-$VERSION-edge.zip
2821

2922
echo "Created pkg/https-everywhere-$VERSION-edge.zip"
3023

browser-dist/opera.sh

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/usr/bin/env bash
2+
3+
# Build an HTTPS Everywhere Opera CRX Distribution
4+
# Written for transparency and reproducibility on Opera upload
5+
# See browser-dist.md for more info
6+
7+
# To build the current state of the tree:
8+
#
9+
# ./browser-dist-opera.sh
10+
#
11+
# To build a particular tagged release:
12+
#
13+
# ./browser-dist-opera.sh <version number>
14+
#
15+
# eg:
16+
#
17+
# ./browser-dist-opera.sh 2017.8.15
18+
#
19+
# Note that .crx files must be signed; this script makes you a
20+
# "dummy-chromium.pem" private key for you to sign your own local releases,
21+
# but these .crx files won't detect and upgrade to official HTTPS Everywhere
22+
# releases signed by EFF :/. We should find a more elegant arrangement.
23+
24+
! getopt --test > /dev/null
25+
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
26+
echo 'I’m sorry, `getopt --test` failed in this environment.'
27+
exit 1
28+
fi
29+
30+
OPTIONS=eck:
31+
LONGOPTS=remove-extension-update,remove-update-channels,key:
32+
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
33+
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
34+
# e.g. return value is 1
35+
# then getopt has complained about wrong arguments to stdout
36+
exit 2
37+
fi
38+
39+
# read getopt’s output this way to handle the quoting right:
40+
eval set -- "$PARSED"
41+
42+
REMOVE_EXTENSION_UPDATE=false
43+
REMOVE_UPDATE_CHANNELS=false
44+
KEY=$(pwd)/dummy-chromium.pem
45+
while true; do
46+
case "$1" in
47+
-e|--remove-extension-update)
48+
REMOVE_EXTENSION_UPDATE=true
49+
shift
50+
;;
51+
-c|--remove-update-channels)
52+
REMOVE_UPDATE_CHANNELS=true
53+
shift
54+
;;
55+
-k|--key)
56+
KEY="$2"
57+
shift 2
58+
;;
59+
--)
60+
shift
61+
break
62+
;;
63+
*)
64+
echo "Programming error"
65+
exit 3
66+
;;
67+
esac
68+
done
69+
70+
if [ "${KEY:0:1}" != "/" ]; then
71+
echo "Key must be specified as an absolute path."
72+
exit 4
73+
fi
74+
75+
cd $(dirname $0)
76+
77+
if [ -n "$1" ]; then
78+
BRANCH=`git branch | head -n 1 | cut -d \ -f 2-`
79+
SUBDIR=checkout
80+
[ -d $SUBDIR ] || mkdir $SUBDIR
81+
cp -r -f -a .git $SUBDIR
82+
cd $SUBDIR
83+
git reset --hard "$1"
84+
git submodule update --recursive -f
85+
fi
86+
87+
VERSION=`python3.6 -c "import json ; print(json.loads(open('../chromium/manifest.json').read())['version'])"`
88+
89+
echo "Building version" $VERSION
90+
91+
[ -d pkg ] || mkdir -p ../pkg
92+
[ -e pkg/crx-opera ] && rm -rf ../pkg/crx-opera
93+
94+
# Clean up obsolete ruleset databases, just in case they still exist.
95+
rm -f src/chrome/content/rules/default.rulesets src/defaults/rulesets.sqlite
96+
97+
mkdir -p ../pkg/crx-opera/rules
98+
cd ../pkg/crx-opera
99+
cp -a ../../chromium/* ./
100+
# Turn the Firefox translations into the appropriate Chrome format:
101+
rm -rf _locales/
102+
mkdir _locales/
103+
python3.6 ../../utils/chromium-translations.py ../../translations/ _locales/
104+
python3.6 ../../utils/chromium-translations.py ../../src/chrome/locale/ _locales/
105+
do_not_ship="*.py *.xml"
106+
rm -f $do_not_ship
107+
108+
mkdir wasm
109+
cp ../../lib-wasm/pkg/*.wasm wasm
110+
cp ../../lib-wasm/pkg/*.js wasm
111+
112+
cd ../..
113+
114+
python3.6 ./utils/merge-rulesets.py || exit 5
115+
116+
cp src/chrome/content/rules/default.rulesets.json pkg/crx-opera/rules/default.rulesets.json
117+
118+
sed -i -e "s/VERSION/$VERSION/g" pkg/crx-opera/manifest.json
119+
120+
for x in `cat .build_exclusions`; do
121+
rm -rf pkg/crx-opera/$x
122+
done
123+
124+
#Create Opera CRX caveat
125+
cd pkg/crx-opera
126+
sed -i 's/rules\/default.rulesets/rules\/default.rulesets.json/g' background-scripts/update.js
127+
cd ../..
128+
129+
# Remove the 'applications' manifest key from the crx version of the extension, change the 'author' string to a hash, and add the "update_url" manifest key
130+
# "update_url" needs to be present to avoid problems reported in https://bugs.chromium.org/p/chromium/issues/detail?id=805755
131+
python3.6 -c "import json; m=json.loads(open('pkg/crx-opera/manifest.json').read()); m['author']={'email': '[email protected]'}; del m['applications']; open('pkg/crx-opera/manifest.json','w').write(json.dumps(m,indent=4,sort_keys=True))"
132+
133+
# If the --remove-update-channels flag is set, remove all out-of-band update channels
134+
if $REMOVE_UPDATE_CHANNELS; then
135+
echo "Flag --remove-update-channels specified. Removing all out-of-band update channels."
136+
echo "require.scopes.update_channels.update_channels = [];" >> pkg/crx-opera/background-scripts/update_channels.js
137+
fi
138+
139+
if [ -n "$BRANCH" ] ; then
140+
crx_opera="pkg/https-everywhere-$VERSION-opera.crx"
141+
else
142+
crx_opera="pkg/https-everywhere-$VERSION-pre-opera.crx"
143+
fi
144+
if ! [ -f "$KEY" ] ; then
145+
echo "Making a dummy signing key for local build purposes"
146+
openssl genrsa -out /tmp/dummy-chromium.pem 768
147+
openssl pkcs8 -topk8 -nocrypt -in /tmp/dummy-chromium.pem -out $KEY
148+
fi
149+
150+
# now pack the crx'es
151+
BROWSER="chromium-browser"
152+
which $BROWSER || BROWSER="chromium"
153+
154+
$BROWSER --no-message-box --pack-extension="pkg/crx-opera" --pack-extension-key="$KEY" 2> /dev/null
155+
156+
mv pkg/crx-opera.crx $crx_opera
157+
158+
echo >&2 "Opera crx package has sha256sum: `openssl dgst -sha256 -binary "$crx_opera" | xxd -p`"
159+
echo >&2 "Total included rules: `find src/chrome/content/rules -name "*.xml" | wc -l`"
160+
echo >&2 "Rules disabled by default: `find src/chrome/content/rules -name "*.xml" | xargs grep -F default_off | wc -l`"
161+
162+
echo "Created $crx_opera"
163+
164+
if [ -n "$BRANCH" ]; then
165+
cd ..
166+
cp $SUBDIR/$crx_opera pkg
167+
rm -rf $SUBDIR
168+
fi

make.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ cp -a pkg/crx-cws pkg/xpi-eff
131131
cp -a src/META-INF pkg/xpi-amo
132132
cp -a src/META-INF pkg/xpi-eff
133133

134+
134135
# Remove the 'applications' manifest key from the crx version of the extension, change the 'author' string to a hash, and add the "update_url" manifest key
135136
# "update_url" needs to be present to avoid problems reported in https://bugs.chromium.org/p/chromium/issues/detail?id=805755
136137
python3.6 -c "import json; m=json.loads(open('pkg/crx-cws/manifest.json').read()); m['author']={'email': '[email protected]'}; del m['applications']; m['update_url'] = 'https://clients2.google.com/service/update2/crx'; open('pkg/crx-cws/manifest.json','w').write(json.dumps(m,indent=4,sort_keys=True))"
@@ -179,6 +180,7 @@ which $BROWSER || BROWSER="chromium"
179180

180181
$BROWSER --no-message-box --pack-extension="pkg/crx-cws" --pack-extension-key="$KEY" 2> /dev/null
181182
$BROWSER --no-message-box --pack-extension="pkg/crx-eff" --pack-extension-key="$KEY" 2> /dev/null
183+
182184
mv pkg/crx-cws.crx $crx_cws
183185
mv pkg/crx-eff.crx $crx_eff
184186

0 commit comments

Comments
 (0)