Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lots of various improvements.. #283

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1931272
minor configuration updates
warren-bank Jan 13, 2022
a623dee
work in progress..
warren-bank Jan 14, 2022
59e01e2
work in progress..
warren-bank Jan 14, 2022
c9b0c40
work in progress..
warren-bank Jan 14, 2022
6af07f7
work in progress..
warren-bank Jan 15, 2022
4b7beb1
work in progress..
warren-bank Jan 15, 2022
70ec3f1
work in progress..
warren-bank Jan 15, 2022
06222cc
work in progress..
warren-bank Jan 16, 2022
a4e23fb
work in progress..
warren-bank Jan 16, 2022
00cba76
v3.3.0 w/ Cloudflare and hCaptcha providers
warren-bank Jan 16, 2022
6fe4c6c
update jest configs for testing and fix all tests to pass
warren-bank Jan 17, 2022
578a97b
v3.3.1 w/ minified ES5
warren-bank Jan 17, 2022
929cabd
v3.3.2 w/ minified ES5
warren-bank Jan 18, 2022
b9df538
minor configuration updates
warren-bank Jan 18, 2022
cf7144c
refactor and improve the dist/.bin build scripts
warren-bank Jan 20, 2022
2f3fad0
work in progress..
warren-bank Jan 20, 2022
e101fc7
hCaptcha sends issuing requests from 'onCompleted' hook function
warren-bank Jan 20, 2022
615f189
minor css tweak to popup window
warren-bank Jan 21, 2022
37a5271
minor updates to the 'dist/.bin' build scripts
warren-bank Jan 22, 2022
706a9e7
minor updates to the 'dist/.bin' build scripts
warren-bank Jan 26, 2022
baa5e80
add popup menu buttons to backup and restore tokens in local storage
warren-bank Jan 26, 2022
b889333
minor updates to the 'dist/.bin' build scripts
warren-bank Jan 26, 2022
8d57b84
fix hCaptcha redemption
warren-bank Jan 27, 2022
1f84b01
minor refactoring
warren-bank Jan 27, 2022
bf6d1ae
address race-condition: delay blocking async code by next-tick timer
warren-bank Jan 28, 2022
48f5e14
revert hCaptcha and refactor Cloudflare
warren-bank Jan 28, 2022
71e4b54
detect and fix incorrect requests on Cloudflare issuing domain
warren-bank Jan 29, 2022
3e39527
fix: use feature detection so browser compatability isn't reduced
warren-bank Jan 29, 2022
84ea20b
fix a conditional statement that may effect Cloudflare token issuing
warren-bank Jan 30, 2022
29febe8
minor refactoring
warren-bank Jan 30, 2022
8283f46
add static helper method: "getNormalizedFormData"
warren-bank Jan 31, 2022
0ab56ce
fix the ability to restore tokens from a JSON text file
warren-bank Feb 1, 2022
7057859
add i18n translations using IBM Watson Language Translator service
warren-bank Feb 24, 2022
6ee36f8
minor html/css tweak to popup window
warren-bank Feb 24, 2022
333f32b
accomodate for changes to Cloudflare provider backend
warren-bank Mar 20, 2022
ad517dd
CF: normalize name of querystring parameter in request to issue tokens
warren-bank Mar 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .bin/chromium/pack_crx3_with_chrome.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off

set CHROME_HOME=C:\PortableApps\Google Chrome\97.0.4692.71\App\Chrome-bin
set CHROME_HOME=C:\PortableApps\SRWare Iron\85.0.4350.0\Iron
set PATH=%CHROME_HOME%;%PATH%

cd /D "%~dp0..\.."

set ext_dir="%cd%\PrivacyPass"
set ext_key="%cd%\PrivacyPass.pem"

if exist %ext_key% (
chrome --pack-extension=%ext_dir% --pack-extension-key=%ext_key%
) else (
chrome --pack-extension=%ext_dir%
)
28 changes: 28 additions & 0 deletions .bin/chromium/pack_crx3_with_chrome.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# ------------------------------------------------------------------------------
# configuration

CHROME_HOME='/c/PortableApps/Google Chrome/97.0.4692.71/App/Chrome-bin'
CHROME_HOME='/c/PortableApps/SRWare Iron/85.0.4350.0/Iron'
PATH="${CHROME_HOME}:${PATH}"

# ------------------------------------------------------------------------------
# bootstrap

function main {
cd "${DIR}/../.."
cwd=$(realpath .)
ext_dir="${cwd}/PrivacyPass"
ext_key="${cwd}/PrivacyPass.pem"

if [ -f "$ext_key" ];then
chrome "--pack-extension=${ext_dir}" "--pack-extension-key=${ext_key}"
else
chrome "--pack-extension=${ext_dir}"
fi
}

main
105 changes: 105 additions & 0 deletions .bin/chromium/pack_crx3_with_openssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/usr/bin/env bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# ------------------------------------------------------------------------------
# configuration

OPENSSL_HOME='/c/PortableApps/OpenSSL/1.1.0'
PATH="${OPENSSL_HOME}:${PATH}"

# ------------------------------------------------------------------------------
# Source: https://stackoverflow.com/a/18709204
# Purpose: Pack a Chromium extension directory into crx format
# notes: all temporary files are created in the cwd.
# the final crx is created adjacent to the input extension directory.

function pack_crx3 {
if test $# -ne 2; then
echo "Usage: crxmake.sh <extension dir> <pem path>"
exit 1
fi

ext_dir=$1
ext_key=$2
crx="${ext_dir}.crx"
name=$(basename "$ext_dir")
pub="${name}.pub"
sig="${name}.sig"
zip="${name}.zip"
tosign="${name}.presig"
binary_crx_id="${name}.crxid"

echo "writing '${name}.crx'"

# preparation: remove previous crx
rm -f "$crx"

# preparation: remove all previous temporary files in the cwd
rm -f "$pub" "$sig" "$zip" "$tosign" "$binary_crx_id"

# cleanup: remove all temporary files in the cwd
trap 'rm -f "$pub" "$sig" "$zip" "$tosign" "$binary_crx_id"' EXIT

# zip up the crx dir
cwd=$(pwd -P)
(cd "$ext_dir" && zip -qr -9 -X "${cwd}/${zip}" .)

#extract crx id
openssl rsa -in "$ext_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 "$ext_key" < "$tosign" > "$sig"

# public key
openssl rsa -pubout -outform DER < "$ext_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 'success: crx3 Chrome extension has been packed'
}

# ------------------------------------------------------------------------------
# bootstrap

function main {
cd "${DIR}/../.."
cwd=$(pwd -P)
ext_dir="${cwd}/PrivacyPass"
ext_key="${cwd}/PrivacyPass.pem"

TMP="${DIR}/temp"
[ -d "$TMP" ] && rm -rf "$TMP"
mkdir "$TMP"

cd "$TMP"
pack_crx3 "$ext_dir" "$ext_key"

# cleanup: remove temporary directory
cd "$DIR"
rm -rf "$TMP"
}

main
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
- - - -

# Add-on signing in Firefox

### What are my options if I want to use an unsigned add-on?

Firefox [Extended Support Release (ESR)](https://www.mozilla.org/firefox/organizations/), Firefox [Developer Edition](https://www.mozilla.org/firefox/developer/) and [Nightly](https://nightly.mozilla.org/) versions of Firefox will allow you to override the setting to enforce the extension signing requirement, by changing the preference `xpinstall.signatures.required` to __false__ in the [Firefox Configuration Editor](https://support.mozilla.org/en-US/kb/about-config-editor-firefox) (`about:config` page). To override the language pack signing requirement, you would set the preference `extensions.langpacks.signatures.required` to __false__. There are also special unbranded versions of Firefox that allow this override. See the MozillaWiki article, [Add-ons/Extension Signing](https://wiki.mozilla.org/Add-ons/Extension_Signing) for more information.

> The source of this post can be found:
> * [here](https://support.mozilla.org/en-US/kb/add-on-signing-in-firefox?#w_what-are-my-options-if-i-want-to-use-an-unsigned-add-on-advanced-users) in HTML format

- - - -

# Installing unsigned extensions permanently to Firefox

<small>2020-11-26</small>

If you have worked with browser extension on Firefox, you likely go to `about:debugging` for installing the extensions temporary, while useful for development, the extension gets removed once Firefox restarts.

Sometimes you may need to test how the extension behaves when Firefox starts, or, just want to leave your extension installed without signing it with the Developer Hub.


## Summary

Gladly, there is a simple solution:
1. Update your extension manifest to include custom `browser_specific_settings`.
2. Disable signature checks while installing extensions.
3. Package your extension as a zip file.
4. Install the extension.
5. Enable signature checks while installing extensions.


### Step 1
Update your `manifest.json` to include a new key, the `id` could be any email:

```json
"browser_specific_settings": {
"gecko": {
"id": "[email protected]"
}
}
```

### Step 2
Go to `about:config`, change `xpinstall.signatures.required` to `false`.

### Step 3
Simply run `zip -r -FS ../my-extension.zip * --exclude '*.git*'`.

### Step 4
Go to `about:addons`, and choose the `Install Add-on from file` option, choose the zip file created in the previous step.

### Step 5
Go to `about:config`, change `xpinstall.signatures.required` to `true`.

That's it, you have installed an unsigned extension permanently.

> The source of this post can be found:
> * [here](https://wiringbits.net/browser-extensions/2020/11/27/installing-unsigned-extensions-permanently-to-firefox.html) in HTML format
> * [here](https://github.com/wiringbits/wiringbits.github.io/blob/4f08ae14f53df32809420675d36b21deca081401/_posts/2020-11-26-installing-unsigned-extensions-permanently-to-firefox.md) in Markdown format

- - - -
15 changes: 15 additions & 0 deletions .bin/firefox/pack_xpi_with_7zip.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@echo off

set ZIP7_HOME=C:\PortableApps\7-Zip\16.02\App\7-Zip64
set PATH=%ZIP7_HOME%;%PATH%

cd /D "%~dp0..\.."

set ext_name=PrivacyPass
set xpi_file="%cd%\%ext_name%.xpi"

cd "%ext_name%"

rem :: https://sevenzip.osdn.jp/chm/cmdline/index.htm
rem :: https://sevenzip.osdn.jp/chm/cmdline/commands/add.htm
7z a -tzip %xpi_file% -r .
20 changes: 20 additions & 0 deletions .bin/firefox/pack_xpi_with_zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# ------------------------------------------------------------------------------
# bootstrap

function main {
cd "${DIR}/../.."
cwd=$(pwd -P)
ext_name='PrivacyPass'
xpi_file="${cwd}/${ext_name}.xpi"

cd "$ext_name"

# https://extensionworkshop.com/documentation/publish/package-your-extension/#package-linux
zip -r -FS "$xpi_file" *
}

main
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto

*.cmd text eol=crlf
*.bat text eol=crlf
*.sh text eol=lf
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
*.swp
/node_modules
/dist
/lib
node_modules/
lib/
PrivacyPass/
PrivacyPass.pem
PrivacyPass.crx
PrivacyPass.xpi

.bin/**/temp/
26 changes: 26 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2017-2020, Privacy Pass Team, Cloudflare, Inc., and other contributors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $ npm ci
$ npm run build
```

After that, the `dist` folder will contain all files required by the extension.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the name to PrivacyPass? I think the name PrivacyPass doesn't indicate that the files in the directory are generated files.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because when Chrome is used to pack an extension, both the name of the .crx and the .pem are expected to be the same as the input directory (all siblings)..

.gitignore allows the .pem to be permanently homed where Chrome expects it to be.. without ever being commit to version control.. and likewise, the generated .crx and .xpi files won't either

this naming convention is associated with the scripts in the .bin directory.. if you already have tools that you use to package your extensions, then.. you:

  1. won't want/need the .bin directory
    • though I find these scripts useful
  2. won't want to rename the output directory.. as you tooling will already be configured to use the old path

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another option.. which might be preferable.. would be to:

  • move the .bin directory to dist/.bin
  • configure webpack to output to dist/PrivacyPass
  • configure .gitignore to exclude: dist/PrivacyPass and dist/PrivacyPass.[pem|crx|xpi]

so all output.. and my scripts to pack the output into extensions.. would be confined under dist

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update:
That last suggestion seemed (to me) as a much cleaner option.. so I just pushed a commit to make those changes.

After that, the `PrivacyPass` folder will contain all files required by the extension.

## Development Installation

Expand All @@ -47,7 +47,7 @@ After that, the `dist` folder will contain all files required by the extension.
- Build by following the [Build Instruction](#build-instruction).
- Open Firefox and go to `about:debugging#/runtime/this-firefox`.
- Click on 'Load Temporary Add-on' button.
- Select `manifest.json` from `dist` folder.
- Select `manifest.json` from `PrivacyPass` folder.
- Check extension logo appears in the top-right corner and 0 passes
are stored (by clicking on it).
- Go to a web page supporting Privacy Pass where internet challenges
Expand All @@ -68,7 +68,7 @@ After that, the `dist` folder will contain all files required by the extension.
- Open Chrome and go to `chrome://extensions`.
- Turn on the Developer mode on the top-right corner.
- Click on 'Load unpacked' button.
- Select the `dist` folder.
- Select the `PrivacyPass` folder.
- Check extension logo appears in the top-right corner and follow
the same instruction as in Firefox. (If you cannot see the extension logo,
it's probably just not pinned to the toolbar yest)
Expand Down
6 changes: 5 additions & 1 deletion jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Mocking crypto with Node webcrypto API.

// Requires Node v15.0+
// https://nodejs.org/api/crypto.html#cryptowebcrypto

import { webcrypto } from 'crypto';

if (typeof crypto === 'undefined') {
global.crypto = (webcrypto as unknown) as Crypto
global.crypto = (webcrypto as unknown) as Crypto;
}
25 changes: 22 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading