From f450323c44e7bd6c68e14d137510265445230888 Mon Sep 17 00:00:00 2001 From: sembrestels <931684+sembrestels@users.noreply.github.com> Date: Fri, 30 Oct 2026 13:45:24 +0100 Subject: [PATCH] fix: complete Web3Signer runtime and certificate mitigations --- .github/workflows/security.yml | 21 ++ services/flyway/Dockerfile | 38 +++- services/flyway/RemoveDistrustedRoots.java | 62 ++++++ services/tracker/Dockerfile | 27 ++- services/web3signer/Dockerfile | 17 ++ .../web3signer/RemoveDistrustedRoots.java | 62 ++++++ tests/.gitignore | 1 + tests/README.md | 47 +++++ tests/security.py | 187 ++++++++++++++++++ tests/test-root-cleanup.sh | 37 ++++ 10 files changed, 496 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/security.yml create mode 100644 services/flyway/RemoveDistrustedRoots.java create mode 100644 services/web3signer/RemoveDistrustedRoots.java create mode 100644 tests/.gitignore create mode 100644 tests/README.md create mode 100644 tests/security.py create mode 100644 tests/test-root-cleanup.sh diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 0000000..99eea9e --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,21 @@ +name: Runtime security checks + +on: + pull_request: + workflow_dispatch: + +permissions: + contents: read + +jobs: + security: + strategy: + fail-fast: false + matrix: + runner: [ubuntu-latest, ubuntu-24.04-arm] + runs-on: ${{ matrix.runner }} + timeout-minutes: 35 + steps: + - uses: actions/checkout@v4 + - name: Build and check runtimes, trust stores, tracker, signer and migrations + run: python3 tests/security.py diff --git a/services/flyway/Dockerfile b/services/flyway/Dockerfile index 337924d..94aadfc 100644 --- a/services/flyway/Dockerfile +++ b/services/flyway/Dockerfile @@ -1,4 +1,12 @@ -FROM alpine:3.15.10 as migrations-download +FROM alpine:3.24 AS ca-trust +RUN apk add --no-cache 'ca-certificates>=20261020' 'ca-certificates-bundle>=20261020' + +FROM ca-trust AS java-ca-helper +RUN apk add --no-cache openjdk21-jdk +COPY RemoveDistrustedRoots.java /tmp/ +RUN mkdir -p /opt/ca-trust && javac --release 11 -d /opt/ca-trust /tmp/RemoveDistrustedRoots.java + +FROM ca-trust AS migrations-download ARG WEB3SIGNER_VERSION WORKDIR /usr/src/app @@ -6,7 +14,26 @@ WORKDIR /usr/src/app RUN apk --no-cache add git && \ git clone --depth 1 --branch ${WEB3SIGNER_VERSION} https://github.com/ConsenSys/web3signer.git +FROM ca-trust AS patched-java +ARG TARGETARCH +RUN apk add --no-cache curl +RUN case "${TARGETARCH}" in \ + amd64) url="https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.13%2B9/OpenJDK21U-jre_x64_alpine-linux_hotspot_21.0.13_9.tar.gz"; sha="9138eab0f7d230e17163953f015ec9ae2431dbc49069c658b7f991e45b54fb9b" ;; \ + arm64) url="https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.13%2B9/OpenJDK21U-jre_aarch64_alpine-linux_hotspot_21.0.13_9.tar.gz"; sha="382633eb2ba28cc5b97be1446eb1dd8d2a60a3795be0166a030e4cda338c490e" ;; \ + *) echo "Unsupported Java architecture: ${TARGETARCH}" >&2; exit 1 ;; \ + esac && \ + curl --fail --location --retry 3 "$url" -o /tmp/jre.tar.gz && \ + echo "$sha /tmp/jre.tar.gz" | sha256sum -c - && \ + mkdir /jre && tar -xzf /tmp/jre.tar.gz --strip-components=1 -C /jre && \ + rm /tmp/jre.tar.gz + FROM flyway/flyway:11.10-alpine +USER root +RUN rm -rf /opt/java/openjdk +COPY --from=patched-java /jre/ /opt/java/openjdk/ +ENV JAVA_HOME=/opt/java/openjdk JAVA_VERSION=jre-21.0.13+9 +ENV PATH="${JAVA_HOME}/bin:${PATH}" + ARG NETWORK ARG PGPASSWORD @@ -29,3 +56,12 @@ COPY --from=migrations-download /usr/src/app/web3signer/slashing-protection/src/ RUN apk update && apk --no-cache add postgresql-client ENTRYPOINT ["entrypoint.sh"] + +# Refresh all OS trust files, then clean Java's independent default keystore. +RUN rm -rf /etc/ssl/certs /usr/share/ca-certificates +COPY --from=ca-trust /etc/ssl/certs/ /etc/ssl/certs/ +COPY --from=ca-trust /usr/share/ca-certificates/ /usr/share/ca-certificates/ +COPY --from=ca-trust /etc/ca-certificates.conf /etc/ca-certificates.conf +RUN ln -sf certs/ca-certificates.crt /etc/ssl/cert.pem +COPY --from=java-ca-helper /opt/ca-trust/ /tmp/ca-trust/ +RUN java -cp /tmp/ca-trust RemoveDistrustedRoots && rm -rf /tmp/ca-trust diff --git a/services/flyway/RemoveDistrustedRoots.java b/services/flyway/RemoveDistrustedRoots.java new file mode 100644 index 0000000..424da2a --- /dev/null +++ b/services/flyway/RemoveDistrustedRoots.java @@ -0,0 +1,62 @@ +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyStore; +import java.security.MessageDigest; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; +import javax.naming.ldap.LdapName; +import javax.naming.ldap.Rdn; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; + +/** Remove compromised CA trust paths by public key, independently of alias names. */ +public final class RemoveDistrustedRoots { + private static final Set BLOCKED = Set.of( + "bd153ed7b0434f6886b17bce8bbe84ed340c7132d702a8f4fa318f756ecbd6f3", + "c619e4780ed8e0abeda24ad732567de4383a7ea941338f6d1a7d1b49ac792fe9", + "8d417db2dd8bf5e3084d1e3f196d583849d81bdd4c00c70b9d39369e96b8c782"); + + // Oracle's current mitigation includes all four roots, including G1/G2. + private static final Set BLOCKED_COMMON_NAMES = Set.of( + "emSign ECC Root CA - G3", "AAA Certificate Services", + "emSign Root CA - G1", "emSign Root CA - G2"); + + public static void main(String[] args) throws Exception { + Path path = args.length == 0 + ? Path.of(System.getProperty("java.home"), "lib", "security", "cacerts") + : Path.of(args[0]); + char[] password = "changeit".toCharArray(); + KeyStore store = KeyStore.getInstance(path.toFile(), password); + MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); + ArrayList removed = new ArrayList<>(); + for (String alias : Collections.list(store.aliases())) { + Certificate certificate = store.getCertificate(alias); + if (certificate == null) continue; + byte[] digest = sha256.digest(certificate.getPublicKey().getEncoded()); + StringBuilder hex = new StringBuilder(); + for (byte b : digest) hex.append(String.format("%02x", b & 0xff)); + boolean blockedName = false; + if (certificate instanceof X509Certificate) { + X509Certificate x509 = (X509Certificate) certificate; + for (Rdn rdn : new LdapName(x509.getSubjectX500Principal().getName()).getRdns()) { + if ("CN".equalsIgnoreCase(rdn.getType()) && BLOCKED_COMMON_NAMES.contains(rdn.getValue().toString())) { + blockedName = true; + } + } + } + if (BLOCKED.contains(hex.toString()) || blockedName) { + store.deleteEntry(alias); + removed.add(alias); + } + } + if (store.size() < 80) throw new IllegalStateException("Unexpectedly small trust store"); + if (!removed.isEmpty()) { + try (OutputStream output = Files.newOutputStream(path)) { + store.store(output, password); + } + } + System.out.println("Removed distrusted Java roots: " + removed.size()); + } +} diff --git a/services/tracker/Dockerfile b/services/tracker/Dockerfile index 2597476..2229a42 100644 --- a/services/tracker/Dockerfile +++ b/services/tracker/Dockerfile @@ -1,6 +1,29 @@ ARG TRACKER_VERSION + +FROM golang:1.27.3-alpine3.24 AS patched-go +ARG TRACKER_VERSION +# Update this pin together with TRACKER_VERSION. +ARG TRACKER_COMMIT=1c2c8076710bfc59e4958d226130ecc191a4222c +ENV GOTOOLCHAIN=local GOMAXPROCS=2 GOFLAGS=-p=2 GOMEMLIMIT=1500MiB +RUN apk add --no-cache git 'ca-certificates>=20261020' +WORKDIR /src +RUN git clone --depth 1 --branch "${TRACKER_VERSION}" https://github.com/dappnode/validator-tracker.git . && \ + test "$(git rev-parse HEAD)" = "${TRACKER_COMMIT}" +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + CGO_ENABLED=0 go build -trimpath -o /out/validator-tracker ./cmd/main.go + +FROM alpine:3.24 AS ca-trust +RUN apk add --no-cache 'ca-certificates>=20261020' 'ca-certificates-bundle>=20261020' + FROM ghcr.io/dappnode/validator-tracker:${TRACKER_VERSION} +COPY --from=patched-go /out/validator-tracker /app/validator-tracker +RUN rm -rf /etc/ssl/certs /usr/share/ca-certificates +COPY --from=ca-trust /etc/ssl/certs/ /etc/ssl/certs/ +COPY --from=ca-trust /usr/share/ca-certificates/ /usr/share/ca-certificates/ +COPY --from=ca-trust /etc/ca-certificates.conf /etc/ca-certificates.conf +RUN ln -sf certs/ca-certificates.crt /etc/ssl/cert.pem ARG NETWORK - -ENV NETWORK=${NETWORK} \ No newline at end of file +# Ordinary TCP remains available; the host still needs its kernel security update. +ENV NETWORK=${NETWORK} GODEBUG=multipathtcp=0 diff --git a/services/web3signer/Dockerfile b/services/web3signer/Dockerfile index 814fbcf..9e2370e 100644 --- a/services/web3signer/Dockerfile +++ b/services/web3signer/Dockerfile @@ -1,5 +1,13 @@ ARG WEB3SIGNER_VERSION +FROM alpine:3.24 AS ca-trust +RUN apk add --no-cache 'ca-certificates>=20261020' 'ca-certificates-bundle>=20261020' + +FROM ca-trust AS java-ca-helper +RUN apk add --no-cache openjdk21-jdk +COPY RemoveDistrustedRoots.java /tmp/ +RUN mkdir -p /opt/ca-trust && javac --release 11 -d /opt/ca-trust /tmp/RemoveDistrustedRoots.java + FROM consensys/web3signer:$WEB3SIGNER_VERSION ARG NETWORK @@ -28,3 +36,12 @@ ENV NETWORK=${NETWORK} \ POSTGRES_USER=${POSTGRES_USER} ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +# Refresh all OS trust files, then clean Java's independent default keystore. +RUN rm -rf /etc/ssl/certs /usr/share/ca-certificates +COPY --from=ca-trust /etc/ssl/certs/ /etc/ssl/certs/ +COPY --from=ca-trust /usr/share/ca-certificates/ /usr/share/ca-certificates/ +COPY --from=ca-trust /etc/ca-certificates.conf /etc/ca-certificates.conf +RUN ln -sf certs/ca-certificates.crt /etc/ssl/cert.pem +COPY --from=java-ca-helper /opt/ca-trust/ /tmp/ca-trust/ +RUN java -cp /tmp/ca-trust RemoveDistrustedRoots && rm -rf /tmp/ca-trust diff --git a/services/web3signer/RemoveDistrustedRoots.java b/services/web3signer/RemoveDistrustedRoots.java new file mode 100644 index 0000000..424da2a --- /dev/null +++ b/services/web3signer/RemoveDistrustedRoots.java @@ -0,0 +1,62 @@ +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.KeyStore; +import java.security.MessageDigest; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; +import javax.naming.ldap.LdapName; +import javax.naming.ldap.Rdn; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Set; + +/** Remove compromised CA trust paths by public key, independently of alias names. */ +public final class RemoveDistrustedRoots { + private static final Set BLOCKED = Set.of( + "bd153ed7b0434f6886b17bce8bbe84ed340c7132d702a8f4fa318f756ecbd6f3", + "c619e4780ed8e0abeda24ad732567de4383a7ea941338f6d1a7d1b49ac792fe9", + "8d417db2dd8bf5e3084d1e3f196d583849d81bdd4c00c70b9d39369e96b8c782"); + + // Oracle's current mitigation includes all four roots, including G1/G2. + private static final Set BLOCKED_COMMON_NAMES = Set.of( + "emSign ECC Root CA - G3", "AAA Certificate Services", + "emSign Root CA - G1", "emSign Root CA - G2"); + + public static void main(String[] args) throws Exception { + Path path = args.length == 0 + ? Path.of(System.getProperty("java.home"), "lib", "security", "cacerts") + : Path.of(args[0]); + char[] password = "changeit".toCharArray(); + KeyStore store = KeyStore.getInstance(path.toFile(), password); + MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); + ArrayList removed = new ArrayList<>(); + for (String alias : Collections.list(store.aliases())) { + Certificate certificate = store.getCertificate(alias); + if (certificate == null) continue; + byte[] digest = sha256.digest(certificate.getPublicKey().getEncoded()); + StringBuilder hex = new StringBuilder(); + for (byte b : digest) hex.append(String.format("%02x", b & 0xff)); + boolean blockedName = false; + if (certificate instanceof X509Certificate) { + X509Certificate x509 = (X509Certificate) certificate; + for (Rdn rdn : new LdapName(x509.getSubjectX500Principal().getName()).getRdns()) { + if ("CN".equalsIgnoreCase(rdn.getType()) && BLOCKED_COMMON_NAMES.contains(rdn.getValue().toString())) { + blockedName = true; + } + } + } + if (BLOCKED.contains(hex.toString()) || blockedName) { + store.deleteEntry(alias); + removed.add(alias); + } + } + if (store.size() < 80) throw new IllegalStateException("Unexpectedly small trust store"); + if (!removed.isEmpty()) { + try (OutputStream output = Files.newOutputStream(path)) { + store.store(output, password); + } + } + System.out.println("Removed distrusted Java roots: " + removed.size()); + } +} diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..6f69bd4 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,47 @@ +# Runtime security validation + +The security update retains Web3Signer 26.10.2 and Brain 0.1.33. It rebuilds +Validator Tracker 0.1.5 from commit `1c2c8076710bfc59e4958d226130ecc191a4222c` +with Go 1.27.3, upgrades Flyway's Java runtime to Temurin 21.0.13+9, refreshes +the three affected services' OS trust files, and removes the four roots listed +in [Oracle's current mitigation](https://ops.java/emudhra) from both Java stores. +The main signer's existing Java 25.0.5+8 runtime is retained. + +Run from the repository root with Docker Compose v2, Python 3 and OpenSSL: + +```sh +python3 tests/security.py +``` + +This builds the three changed services for the mainnet variant and checks: + +- All four variants' Compose configuration. +- The compiled Tracker Go version and its default `GODEBUG=multipathtcp=0`. +- OS certificate bundles against the incident's three blocked public-key hashes. +- Java runtime versions and all four distrusted root names in the actual default stores. +- JKS and PKCS12 cleanup with unrelated aliases, preservation of an unrelated root, + idempotency, and rejection of an implausibly small trust store. +- Tracker initialization against a mock beacon and successful initialization after restart. +- The real signer health/public-key APIs with an empty key directory, before and after restart. +- Fresh slashing-protection migrations on PostgreSQL 14 and a repeated no-op migration. + +Application fixtures run on a disposable internal Docker network without published +ports, production volumes, validator keys or external notification endpoints. Test +containers and their anonymous volumes are removed on exit. Builds download public +dependencies. The signer smoke test disables slashing protection only for its empty-key +API fixture; it is separate from the Flyway/database migration test and does not prove +full production signer/database integration or an existing database upgrade. + +CI runs these checks on native amd64 and ARM64 runners. To reuse images already built +with a specific Compose project name: + +```sh +python3 tests/security.py --project web3signer-security --skip-build +``` + +Update `TRACKER_COMMIT` alongside `TRACKER_VERSION` for future upstream bumps. The Go +setting changes the default for new sockets and can be overridden by application code +or operator-supplied environment. It reduces MPTCP exposure; **CVE-2026-98432 still needs +a patched host kernel**. Docker's daemon-owned DNS sockets require separate host/daemon +mitigation. No host sysctl, Docker daemon, PostgreSQL data format or package version is +changed by this PR. diff --git a/tests/security.py b/tests/security.py new file mode 100644 index 0000000..bdf03d5 --- /dev/null +++ b/tests/security.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python3 +"""Build and smoke-test security images with disposable, isolated fixtures.""" +import argparse +import hashlib +import io +import json +from pathlib import Path +import re +import subprocess +import tarfile +import time +import uuid + +ROOT = Path(__file__).resolve().parents[1] +parser = argparse.ArgumentParser() +parser.add_argument('--project', default='web3signer-security') +parser.add_argument('--skip-build', action='store_true') +args = parser.parse_args() +project = args.project +prefix = 'web3signer-security-test-' + uuid.uuid4().hex[:8] +network = prefix + '-net' +containers = [] +node = 'node:24.22.1-alpine3.24' +results = {} + + +def docker(*cmd, check=True, timeout=120, binary=False): + p = subprocess.run(['docker', *cmd], capture_output=True, text=not binary, timeout=timeout, cwd=ROOT) + if check and p.returncode: + message = p.stderr.decode(errors='replace') if binary else p.stderr + raise RuntimeError('docker ' + cmd[0] + ': ' + message[-3000:]) + return p.stdout if binary else p.stdout.strip() + + +def start(suffix, image, command=(), options=()): + name = prefix + '-' + suffix + containers.append(name) + docker('run', '-d', '--name', name, '--network', network, '--network-alias', suffix, + '--cpus', '1', '--memory', '1g', *options, image, *command) + return name + + +def wait(fn): + deadline = time.monotonic() + 90 + while True: + try: + return fn() + except (AssertionError, RuntimeError): + if time.monotonic() >= deadline: + raise + time.sleep(.5) + + +def http(url): + script = ('fetch(' + json.dumps(url) + ',{signal:AbortSignal.timeout(3000)})' + '.then(async r=>{if(!r.ok)throw Error(r.status);console.log(await r.text())})' + '.catch(e=>{console.error(e.message);process.exit(1)})') + return docker('run', '--rm', '--network', network, '--cpus', '.5', '--memory', '128m', + '--entrypoint', 'node', node, '-e', script) + + +try: + for variant in ('mainnet', 'gnosis', 'hoodi', 'lukso'): + docker('compose', '-f', 'docker-compose.yml', '-f', f'package_variants/{variant}/docker-compose.yml', + '-p', project, 'config', '--quiet') + if not args.skip_build: + docker('compose', '-f', 'docker-compose.yml', '-f', 'package_variants/mainnet/docker-compose.yml', + '-p', project, 'build', 'tracker', 'web3signer', 'flyway', timeout=1800) + images = {service: project + '-' + service for service in ('tracker', 'web3signer', 'flyway')} + blocked_keys = { + 'bd153ed7b0434f6886b17bce8bbe84ed340c7132d702a8f4fa318f756ecbd6f3', + 'c619e4780ed8e0abeda24ad732567de4383a7ea941338f6d1a7d1b49ac792fe9', + '8d417db2dd8bf5e3084d1e3f196d583849d81bdd4c00c70b9d39369e96b8c782', + } + results['osTrust'] = {} + for service, image in images.items(): + bundle = docker('run', '--rm', '--network', 'none', '--entrypoint', 'cat', image, + '/etc/ssl/certs/ca-certificates.crt') + certs = re.findall(r'-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----', bundle, re.S) + assert len(certs) >= 80 + for cert in certs: + key = subprocess.run(['openssl', 'x509', '-pubkey', '-noout'], input=cert.encode(), + capture_output=True, check=True).stdout + der = subprocess.run(['openssl', 'pkey', '-pubin', '-outform', 'DER'], input=key, + capture_output=True, check=True).stdout + assert hashlib.sha256(der).hexdigest() not in blocked_keys, service + results['osTrust'][service] = {'certificates': len(certs), 'incidentKeysAbsent': True} + for service, minimum in [('web3signer', (25, 0, 5)), ('flyway', (21, 0, 13))]: + image = images[service] + release = docker('run', '--rm', '--network', 'none', '--entrypoint', 'cat', image, + '/opt/java/openjdk/release') + found = re.search(r'^JAVA_VERSION="(\d+)\.(\d+)\.(\d+)', release, re.M) + assert found and tuple(map(int, found.groups())) >= minimum, release + trust = docker('run', '--rm', '--network', 'none', '--entrypoint', 'keytool', image, + '-J-Duser.language=en', '-J-Duser.country=US', '-list', '-v', + '-cacerts', '-storepass', 'changeit') + owners = [line for line in trust.splitlines() if line.startswith('Owner:')] + assert len(owners) >= 80, 'Unexpectedly empty Java trust store' + for root in ('emSign ECC Root CA - G3', 'AAA Certificate Services', + 'emSign Root CA - G1', 'emSign Root CA - G2'): + assert not any('CN=' + root in owner for owner in owners), root + results[service] = {'java': '.'.join(found.groups()), 'javaTrustRoots': len(owners), + 'fourDistrustedRootsAbsent': True} + + # Compile the cleanup helper as in production and exercise real JKS/PKCS12 stores. + helper = project + '-java-ca-helper' + compose_config = json.loads(docker('compose', '-f', 'docker-compose.yml', '-f', + 'package_variants/mainnet/docker-compose.yml', + '-p', project, 'config', '--format', 'json')) + signer_version = compose_config['services']['web3signer']['build']['args']['WEB3SIGNER_VERSION'] + docker('build', '--target', 'java-ca-helper', '--build-arg', 'WEB3SIGNER_VERSION=' + signer_version, + '-t', helper, 'services/web3signer', timeout=600) + docker('run', '--rm', '--network', 'none', '--cpus', '1', '--memory', '512m', '--tmpfs', '/tmp', + '-v', str(ROOT / 'tests') + ':/tests:ro', helper, 'sh', '/tests/test-root-cleanup.sh') + assert (ROOT / 'services/web3signer/RemoveDistrustedRoots.java').read_bytes() == \ + (ROOT / 'services/flyway/RemoveDistrustedRoots.java').read_bytes() + results['rootCleanupFixtures'] = {'JKS': True, 'PKCS12': True, 'idempotent': True, + 'unrelatedRootPreserved': True, 'smallStoreRejected': True} + + holder = prefix + '-binary' + containers.append(holder) + docker('create', '--name', holder, '--network', 'none', images['tracker']) + with tarfile.open(fileobj=io.BytesIO(docker('cp', holder + ':/app/validator-tracker', '-', binary=True))) as archive: + binary = archive.extractfile(next(m for m in archive if m.isfile())).read() + offset = binary.index(b'\xff Go buildinf:') + assert binary[offset + 15] & 2 + assert binary[offset + 33:offset + 41] == b'go1.27.3', 'Wrong tracker toolchain' + config = json.loads(docker('image', 'inspect', images['tracker']))[0]['Config'] + assert 'GODEBUG=multipathtcp=0' in config['Env'] + results['trackerBuild'] = {'go': '1.27.3', 'mptcpDefaultDisabled': True} + + docker('network', 'create', '--internal', network) + mock_script = """const http=require('http');let hits={};const root='0x'+'11'.repeat(32); +http.createServer((q,r)=>{if(q.url==='/fixture-stats'){r.end(JSON.stringify(hits));return} +hits[q.url]=(hits[q.url]||0)+1;let data={}; +if(q.url.includes('genesis'))data={genesis_time:'1606824023',genesis_validators_root:root,genesis_fork_version:'0x00000000'}; +else if(q.url.includes('/config/spec'))data={CONFIG_NAME:'mainnet',SECONDS_PER_SLOT:'12',SLOTS_PER_EPOCH:'32',DEPOSIT_CHAIN_ID:'1',DEPOSIT_NETWORK_ID:'1',GENESIS_FORK_VERSION:'0x00000000',ALTAIR_FORK_VERSION:'0x01000000',BELLATRIX_FORK_VERSION:'0x02000000',CAPELLA_FORK_VERSION:'0x03000000',DENEB_FORK_VERSION:'0x04000000',ELECTRA_FORK_VERSION:'0x05000000',FULU_FORK_VERSION:'0x06000000',MIN_GENESIS_TIME:'1606824000',GENESIS_DELAY:'172800',DEPOSIT_CONTRACT_ADDRESS:'0x'+'00'.repeat(20)}; +else if(q.url.includes('/node/version'))data={version:'security-fixture'}; +else if(q.url.includes('finality_checkpoints'))data={previous_justified:{epoch:'1',root},current_justified:{epoch:'1',root},finalized:{epoch:'1',root}}; +else if(q.url.includes('syncing'))data={head_slot:'32',sync_distance:'0',is_syncing:false,is_optimistic:false,el_offline:false}; +r.setHeader('Content-Type','application/json');r.end(JSON.stringify(q.url.includes('/brain/validators')?{}:{data}));}).listen(5052)""" + start('mock', node, ['-e', mock_script], ['--entrypoint', 'node']) + env = ['NETWORK=mainnet', 'BEACON_ENDPOINT=http://mock:5052', 'BRAIN_URL=http://mock:5052', + 'DAPPMANAGER_ENDPOINT=http://mock:5052', 'NOTIFIER_URL=http://mock:5052', + 'DUTIES_CHECKER_POLL_INTERVAL_SECONDS=1'] + tracker = start('tracker', images['tracker'], options=[x for e in env for x in ('-e', e)]) + def tracker_ready(): + assert docker('inspect', '--format', '{{.State.Running}}', tracker) == 'true' + hits = json.loads(http('http://mock:5052/fixture-stats')) + assert '/eth/v1/node/version' in hits and any('finality_checkpoints' in key for key in hits) + return hits + before_restart = wait(tracker_ready) + docker('restart', tracker) + def tracker_restarted(): + hits = tracker_ready() + assert hits['/eth/v1/node/version'] > before_restart['/eth/v1/node/version'] + wait(tracker_restarted) + results['trackerSmoke'] = {'mockBeaconInitialization': True, 'restart': True} + + signer = start('signer', images['web3signer'], ['-c', 'mkdir -p /tmp/empty-keys; exec /opt/web3signer/bin/web3signer --key-store-path=/tmp/empty-keys --http-listen-host=0.0.0.0 --http-listen-port=9000 --http-host-allowlist="*" eth2 --slashing-protection-enabled=false --network=mainnet'], + ['--entrypoint', 'sh', '-e', 'JAVA_OPTS=-Xmx512m']) + def signer_ready(): + assert json.loads(http('http://signer:9000/api/v1/eth2/publicKeys')) == [] + http('http://signer:9000/healthcheck') + wait(signer_ready) + docker('restart', signer) + wait(signer_ready) + results['signerSmoke'] = {'emptyKeyApi': True, 'healthcheck': True, 'restart': True} + + db = start('db', 'postgres:14-alpine', options=['-e', 'POSTGRES_PASSWORD=security-test', + '-e', 'POSTGRES_DB=web3signer']) + wait(lambda: docker('exec', db, 'pg_isready', '-U', 'postgres')) + migration = ['run', '--rm', '--network', network, '--cpus', '1', '--memory', '768m', + '--entrypoint', '/flyway/flyway', images['flyway'], + '-url=jdbc:postgresql://db:5432/web3signer', '-user=postgres', + '-password=security-test', 'migrate'] + docker(*migration) + assert 'up to date' in docker(*migration).lower() + count = int(docker('exec', db, 'psql', '-U', 'postgres', '-d', 'web3signer', '-Atc', + "SELECT count(*) FROM information_schema.tables WHERE table_schema='public'")) + assert count >= 7, count + results['flywaySmoke'] = {'freshMigration': True, 'repeatMigrationNoChanges': True, 'publicTables': count} + print(json.dumps(results, indent=2)) +finally: + for name in reversed(containers): + docker('rm', '-f', '-v', name, check=False) + docker('network', 'rm', network, check=False) diff --git a/tests/test-root-cleanup.sh b/tests/test-root-cleanup.sh new file mode 100644 index 0000000..6def229 --- /dev/null +++ b/tests/test-root-cleanup.sh @@ -0,0 +1,37 @@ +#!/bin/sh +set -eu +JAVA_HOME=${JAVA_HOME:-$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")} + +# Exercise both supported keystore formats with synthetic roots and unrelated aliases. +for format in JKS PKCS12; do + store="/tmp/roots-${format}" + keytool -importkeystore -srckeystore "$JAVA_HOME/lib/security/cacerts" \ + -srcstorepass changeit -destkeystore "$store" -deststorepass changeit \ + -deststoretype "$format" -noprompt >/dev/null 2>&1 + i=0 + for cn in 'emSign ECC Root CA - G3' 'AAA Certificate Services' \ + 'emSign Root CA - G1' 'emSign Root CA - G2' 'Security test retained root'; do + keytool -genkeypair -alias "fixture-$i" -dname "CN=$cn" -keyalg RSA -keysize 2048 \ + -validity 1 -keystore "$store" -storepass changeit -keypass changeit \ + -noprompt >/dev/null 2>&1 + i=$((i + 1)) + done + java -cp /opt/ca-trust RemoveDistrustedRoots "$store" + for i in 0 1 2 3; do + if keytool -list -alias "fixture-$i" -keystore "$store" -storepass changeit >/dev/null 2>&1; then + echo "Distrusted fixture-$i survived in $format" >&2 + exit 1 + fi + done + keytool -list -alias fixture-4 -keystore "$store" -storepass changeit >/dev/null + java -cp /opt/ca-trust RemoveDistrustedRoots "$store" | grep -Fx 'Removed distrusted Java roots: 0' +done + +# An implausibly small keystore must fail instead of silently accepting a broken bundle. +keytool -genkeypair -alias retained -dname 'CN=Security test retained root' -keyalg RSA \ + -keysize 2048 -validity 1 -keystore /tmp/small-store -storepass changeit \ + -keypass changeit -noprompt >/dev/null 2>&1 +if java -cp /opt/ca-trust RemoveDistrustedRoots /tmp/small-store; then + echo 'Unexpectedly small trust store was accepted' >&2 + exit 1 +fi