-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrekey-extension
executable file
·34 lines (25 loc) · 1023 Bytes
/
rekey-extension
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
OPENSSL_KEY_ARGS="-in extension-key.pem"
if [ -f extension-pubkey.pem ]; then
echo "Using existing public key in extension-pubkey.pem"
OPENSSL_KEY_ARGS="-in extension-pubkey.pem -pubin"
elif [ -f extension-key.pem ]; then
echo "Using existing private key in extension-key.pem"
else
echo "Generating new key..."
openssl genrsa 2048 | openssl pkcs8 -topk8 -nocrypt -out extension-key.pem
fi
BASE64_KEY=$(openssl rsa $OPENSSL_KEY_ARGS -pubout -outform DER | openssl base64 -A)
EXTENSION_ID=$(openssl rsa $OPENSSL_KEY_ARGS -pubout -outform DER | shasum -a 256 | head -c32 | tr 0-9a-f a-p)
echo "Extension ID is $EXTENSION_ID"
FILES_TO_PATCH=( \
build/native-host-manifest/com.github.misterfifths.cloudtabs_host.json \
build/extension/manifest.json \
)
for f in ${FILES_TO_PATCH[@]}; do
echo "Patching ${f}..."
sed -i '' "s|__EXTENSION_ID__|${EXTENSION_ID}|g" "$f"
sed -i '' "s|__BASE64_KEY__|${BASE64_KEY}|g" "$f"
done