Skip to content

Commit cb51a6f

Browse files
committed
Add command to reduce security of web3signer keys
1 parent fb928a4 commit cb51a6f

3 files changed

Lines changed: 91 additions & 0 deletions

File tree

web3signer.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ x-logging: &logging
77
tag: '{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}'
88

99
services:
10+
reduce-key-security:
11+
restart: "no"
12+
build:
13+
context: ./web3signer
14+
args:
15+
- DOCKER_TAG=${W3S_DOCKER_TAG:-latest}
16+
- DOCKER_REPO=${W3S_DOCKER_REPO:-consensys/web3signer}
17+
dockerfile: Dockerfile.convert
18+
image: w3s-converter:local
19+
pull_policy: never
20+
volumes:
21+
- web3signer-keys:/var/lib/web3signer
22+
environment:
23+
- NETWORK=${NETWORK}
24+
entrypoint:
25+
- convert-keys.sh
26+
1027
w3s-init:
1128
restart: "no"
1229
build:

web3signer/Dockerfile.convert

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# hadolint global ignore=DL3008
2+
FROM eclipse-temurin:21-jdk-noble AS builder
3+
4+
ARG BUILD_TARGET=main
5+
ARG SRC_REPO=https://github.com/usmansaleem/v4keystore_converter
6+
ARG SRC_DIR=converter
7+
WORKDIR /usr/src
8+
9+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates git
10+
11+
RUN bash -eo pipefail <<'EOF'
12+
git clone "$SRC_REPO" "$SRC_DIR"
13+
cd "$SRC_DIR"
14+
git config advice.detachedHead false
15+
git fetch --all --tags
16+
CLEANED=$(echo "$BUILD_TARGET" | sed 's/\$\$(/$(/g')
17+
TARGET=$(eval echo "$CLEANED")
18+
git checkout "$TARGET"
19+
git submodule update --init --recursive --jobs $(nproc)
20+
./gradlew installDist
21+
EOF
22+
23+
FROM eclipse-temurin:25-jre-noble
24+
25+
COPY --from=builder /usr/src/converter/converter/build/install/converter/ /opt/converter/
26+
COPY ./convert-keys.sh /usr/local/bin/
27+
28+
USER 10000:10000
29+
30+
ENTRYPOINT ["/opt/converter/bin/converter"]

web3signer/convert-keys.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
base_dir=/var/lib/web3signer
5+
mkdir -p "${base_dir}"/converted-keys
6+
mkdir -p "${base_dir}"/keys-backup
7+
8+
if ! find "${base_dir}"/keys -type f -name '*.password' -print -quit | grep -q .; then
9+
echo "No key files found in ${base_dir}/keys. Aborting."
10+
exit 0
11+
fi
12+
13+
if [[ -d "${base_dir}"/converted-keys ]] && find "${base_dir}"/converted-keys -type f -name '*.json' -print -quit | grep -q .; then
14+
echo "Keys have already been converted. Aborting."
15+
exit 0
16+
fi
17+
18+
if [[ "${NETWORK}" =~ ^(mainnet|gnosis)$ ]]; then
19+
echo "Reducing key security on mainnet is not recommended. If you need to do so, please do so manually."
20+
echo "Aborting"
21+
exit 0
22+
fi
23+
24+
while true; do
25+
echo "This function will reduce the security of validator keys loaded into Web3signer."
26+
echo "Web3signer startup time for thousands of keys will reduce to seconds."
27+
read -rp "Are you sure you want to convert keystores to lower security? (No/yes) " yn
28+
case "${yn}" in
29+
[Yy][Ee][Ss]) break;;
30+
*) echo "Aborting, no changes made"; exit 0;;
31+
esac
32+
done
33+
34+
cp -p "${base_dir}"/keys/* "${base_dir}"/keys-backup/
35+
36+
for file in "${base_dir}"/keys-backup/*.password; do
37+
[ -e "$file" ] || continue
38+
cp -- "$file" "${file%.password}.txt"
39+
done
40+
41+
/opt/converter/bin/converter --src="${base_dir}"/keys-backup --password-src="${base_dir}"/keys-backup --dest="${base_dir}"/converted-keys
42+
cp "${base_dir}"/converted-keys/*.json "${base_dir}"/keys/
43+
44+
echo "Restart Web3signer to use the converted keys"

0 commit comments

Comments
 (0)