Skip to content

Commit 0bd3cea

Browse files
committed
Secrets.json encrypted at rest
1 parent 1d0b590 commit 0bd3cea

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

sh/common.sh

+6
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ if [[ $api_secrets_permissions != '-rw-------' ]] ; then
4040
exit 1
4141
fi
4242

43+
if [ -z ${1+x} ] ; then
44+
echo 'chain_name argument is missing' >&2
45+
exit 1
46+
fi
4347
declare -r chain_name="$1"
4448
shift
4549

50+
51+
4652
if [[ $(jq -Mr ."$chain_name" < api_secrets.json) == 'null' ]] ; then
4753
echo "$chain_name"' is missing from api_secrets.json' >&2
4854
exit 1

sh/common_secrets.sh

+31-8
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,49 @@ if ! hash sha256sum &>/dev/null ; then
33
exit 1
44
fi
55

6-
if [ ! -f "$project_root"/secrets.json ] ; then
7-
echo 'secrets.json is missing' >&2
6+
if [ ! -f "$project_root"/secrets.json.scrypt ] ; then
7+
echo 'secrets.json.scrypt is missing' >&2
88
exit 1
99
fi
1010

1111
declare secrets_permissions
12-
secrets_permissions="$(ls -l "$project_root"/secrets.json)"
12+
secrets_permissions="$(ls -l "$project_root"/secrets.json.scrypt)"
1313
secrets_permissions="${secrets_permissions::10}"
1414
declare -r secrets_permissions
1515
if [[ $secrets_permissions != '-rw-------' ]] ; then
16-
echo 'secrets.json permissions too lax' >&2
17-
echo 'run: chmod 600 secrets.json' >&2
16+
echo 'secrets.json.scrypt permissions too lax' >&2
17+
echo 'run: chmod 600 secrets.json.scrypt' >&2
1818
exit 1
1919
fi
2020

21-
if ! sha256sum -c <<<'bb82de121880f1182dbae410b341749e5ac1355954ae6c03151a1826e7bba745 secrets.json' >/dev/null ; then
22-
echo 'Secrets are wrong' >&2
21+
if [ -f "$project_root"/secrets.json ] ; then
22+
echo 'secrets.json exists, remove it - will use secrets.json.scrypt only' >&2
2323
exit 1
2424
fi
2525

26+
declare secrets_storage
27+
28+
function decrypt_secrets {
29+
local password
30+
echo 'Enter passphrase for secrets.json.scrypt'
31+
local decrypted
32+
decrypted="$(scrypt dec "$project_root"/secrets.json.scrypt)"
33+
if [ $? -ne 0 ]; then
34+
echo "Failed to decrypt secrets.json.scrypt" >&2
35+
exit 1
36+
fi
37+
38+
# 24290900be9575d1fb6349098b1c11615a2eac8091bc486bec6cf67239b7846a previous version prior to allowanceHolderLondon
39+
if ! echo "$decrypted" | sha256sum | grep -q "^bb82de121880f1182dbae410b341749e5ac1355954ae6c03151a1826e7bba745"; then
40+
echo "Decrypted secrets.json hash verification failed" >&2
41+
exit 1
42+
fi
43+
secrets_storage="$decrypted"
44+
}
45+
2646
function get_secret {
27-
jq -Mr ."$1"."$2" < "$project_root"/secrets.json
47+
if [ -z "$secrets_storage" ]; then
48+
decrypt_secrets
49+
fi
50+
jq -Mr ."$1"."$2" <<< "$secrets_storage"
2851
}

0 commit comments

Comments
 (0)