From 5b6394ce0d4eac1f771e3a0514294d809878cd48 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Mon, 25 Sep 2023 08:45:59 +0200 Subject: [PATCH 001/256] Cleanup debugging Cleans up some of the now unused debugging things and 'dev' Dockerfiles --- .github/workflows/go_integration_tests.yml | 1 + Dockerfiles/Dockerfile.dela.debug | 18 --- README.docker.md | 10 ++ docker-compose/docker-compose.debug.yml | 167 --------------------- docker-compose/docker-compose.dev.yml | 107 +++++++++++++ docker-compose/docker-compose.yml | 14 +- scripts/init_dela.sh | 19 ++- scripts/setup_admin.sh | 8 + scripts/setup_forms.sh | 39 +++++ scripts/setup_proxies.sh | 12 ++ web/backend/readme.md | 21 +-- web/backend/src/Server.ts | 2 +- 12 files changed, 203 insertions(+), 215 deletions(-) delete mode 100644 Dockerfiles/Dockerfile.dela.debug delete mode 100644 docker-compose/docker-compose.debug.yml create mode 100644 docker-compose/docker-compose.dev.yml create mode 100755 scripts/setup_admin.sh create mode 100755 scripts/setup_forms.sh create mode 100755 scripts/setup_proxies.sh diff --git a/.github/workflows/go_integration_tests.yml b/.github/workflows/go_integration_tests.yml index 5b0cfc9dd..5263de3cc 100644 --- a/.github/workflows/go_integration_tests.yml +++ b/.github/workflows/go_integration_tests.yml @@ -7,6 +7,7 @@ on: branches: [main] jobs: + if: false integration: name: Integration test runs-on: ubuntu-latest diff --git a/Dockerfiles/Dockerfile.dela.debug b/Dockerfiles/Dockerfile.dela.debug deleted file mode 100644 index 47cee9b89..000000000 --- a/Dockerfiles/Dockerfile.dela.debug +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.20.6-bookworm - -# https://blog.jetbrains.com/go/2020/05/06/debugging-a-go-application-inside-a-docker-container/ -RUN go install github.com/go-delve/delve/cmd/dlv@latest - -RUN apt-get update && apt-get install git -RUN git clone https://github.com/dedis/dela.git -RUN git clone https://github.com/dedis/d-voting.git -WORKDIR /go/dela/cli/crypto -RUN go install -WORKDIR /go/d-voting/cli/dvoting - -RUN go build -gcflags="all=-N -l" - -ENV PATH=/go/dela/cli/crypto:/go/d-voting/cli/dvoting:${PATH} -WORKDIR /go -ENTRYPOINT ["/bin/bash", "-c", "dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /go/d-voting/cli/dvoting/dvoting -- --config /data/node start --postinstall --proxyaddr :$PROXYPORT --proxykey $PROXYKEY --listen tcp://0.0.0.0:2000 --public http://$HOSTNAME:2000 --routing tree"] -CMD [] diff --git a/README.docker.md b/README.docker.md index 230fbc875..b14736199 100644 --- a/README.docker.md +++ b/README.docker.md @@ -31,6 +31,16 @@ PROXYPORT=8080 NODEPORT=2000 # DELA node port ``` +For the `PUBLIC_KEY` and `PRIVATE_KEY`, you need to run the following commands: + +```bash +cd web/backend +npm ci +npm run keygen +``` + +And then copy the two lines to the `.env` file. + There are two Docker Compose file you may use: * `docker-compose/docker-compose.yml` for the currently released version, or diff --git a/docker-compose/docker-compose.debug.yml b/docker-compose/docker-compose.debug.yml deleted file mode 100644 index 52078a067..000000000 --- a/docker-compose/docker-compose.debug.yml +++ /dev/null @@ -1,167 +0,0 @@ -services: - - dela-worker-0: # inital DELA leader node - image: dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela.debug - context: ../ - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - PROXY_LOG: info - LLVL: debug - NODEPORT: ${NODEPORT} - volumes: - - dela-worker-0-data:/data - hostname: dela-worker-0 - ports: - - 127.0.0.1:40000:40000 - security_opt: - - apparmor:unconfined - cap_add: - - SYS_PTRACE - networks: - d-voting: - ipv4_address: 172.19.44.254 - dela-worker-1: # DELA worker node - image: dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela.debug - context: ../ - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - PROXY_LOG: info - LLVL: debug - NODEPORT: ${NODEPORT} - volumes: - - dela-worker-1-data:/data - hostname: dela-worker-1 - ports: - - 127.0.0.1:40001:40000 - security_opt: - - apparmor:unconfined - cap_add: - - SYS_PTRACE - networks: - d-voting: - ipv4_address: 172.19.44.253 - dela-worker-2: # DELA worker node - image: dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela.debug - context: ../ - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - PROXY_LOG: info - LLVL: debug - NODEPORT: ${NODEPORT} - volumes: - - dela-worker-2-data:/data - hostname: dela-worker-2 - ports: - - 127.0.0.1:40002:40000 - security_opt: - - apparmor:unconfined - cap_add: - - SYS_PTRACE - networks: - d-voting: - ipv4_address: 172.19.44.252 - dela-worker-3: # DELA worker node - image: dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela.debug - context: ../ - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - PROXY_LOG: info - LLVL: debug - NODEPORT: ${NODEPORT} - volumes: - - dela-worker-3-data:/data - hostname: dela-worker-3 - ports: - - 127.0.0.1:40003:40000 - security_opt: - - apparmor:unconfined - cap_add: - - SYS_PTRACE - networks: - d-voting: - ipv4_address: 172.19.44.251 - - frontend: # web service frontend - image: frontend:latest - build: - dockerfile: Dockerfiles/Dockerfile.frontend - context: ../ - ports: - - 127.0.0.1:3000:3000 - volumes: - - ../web/frontend/src:/web/frontend/src - environment: - BACKEND_HOST: ${BACKEND_HOST} - BACKEND_PORT: ${BACKEND_PORT} - networks: - d-voting: - ipv4_address: 172.19.44.2 - - backend: # web service backend - image: backend:latest - build: - dockerfile: Dockerfiles/Dockerfile.backend - context: ../ - environment: - DATABASE_USERNAME: ${DATABASE_USERNAME} - DATABASE_PASSWORD: ${DATABASE_PASSWORD} - DATABASE_HOST: ${DATABASE_HOST} - DATABASE_PORT: ${DATABASE_PORT} - DB_PATH: /data/${DB_PATH} - FRONT_END_URL: ${FRONT_END_URL} - DELA_NODE_URL: ${DELA_NODE_URL} - SESSION_SECRET: ${SESSION_SECRET} - PUBLIC_KEY: ${PUBLIC_KEY} - PRIVATE_KEY: ${PRIVATE_KEY} - ports: - - 127.0.0.1:5000:5000 - - 127.0.0.1:80:80 - depends_on: - db: - condition: service_started - volumes: - - backend-data:/data - - ../web/backend/src:/web/backend/src - networks: - d-voting: - ipv4_address: 172.19.44.3 - - db: # PostgreSQL database - image: postgres:15 - environment: - POSTGRES_USER: ${DATABASE_USERNAME} - POSTGRES_PASSWORD: ${DATABASE_PASSWORD} - volumes: - - postgres-data:/var/lib/postgresql/data - - ../web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql - networks: - d-voting: - ipv4_address: 172.19.44.4 - -volumes: - postgres-data: # PostgreSQL database - dela-worker-0-data: - dela-worker-1-data: - dela-worker-2-data: - dela-worker-3-data: - dela-worker-4-data: - backend-data: - -networks: - d-voting: - ipam: - config: - - subnet: 172.19.44.0/24 - gateway: 172.19.44.1 diff --git a/docker-compose/docker-compose.dev.yml b/docker-compose/docker-compose.dev.yml new file mode 100644 index 000000000..aa3c953ff --- /dev/null +++ b/docker-compose/docker-compose.dev.yml @@ -0,0 +1,107 @@ +services: + + dela-worker-0: # initial DELA leader node + image: ghcr.io/c4dt/d-voting-dela:latest + build: + dockerfile: Dockerfiles/Dockerfile.dela.localhost + context: ../ + ports: + - "2000-2007:2000-2007" + - "3000:3000" + - "6000:6000" + environment: + PROXYKEY: ${PUBLIC_KEY} + LLVL: info + NODEPORT: 2000 + PROXYPORT: 2001 + HOSTNAME: localhost + volumes: + - dela-worker-0-data:/data + + dela-worker-1: # DELA worker node + image: ghcr.io/c4dt/d-voting-dela:latest + environment: + PROXYKEY: ${PUBLIC_KEY} + LLVL: info + NODEPORT: 2002 + PROXYPORT: 2003 + HOSTNAME: localhost + network_mode: "service:dela-worker-0" + volumes: + - dela-worker-1-data:/data + + dela-worker-2: # DELA worker node + image: ghcr.io/c4dt/d-voting-dela:latest + environment: + PROXYKEY: ${PUBLIC_KEY} + LLVL: info + NODEPORT: 2004 + PROXYPORT: 2005 + HOSTNAME: localhost + network_mode: "service:dela-worker-0" + volumes: + - dela-worker-2-data:/data + + dela-worker-3: # DELA worker node + image: ghcr.io/c4dt/d-voting-dela:latest + environment: + PROXYKEY: ${PUBLIC_KEY} + LLVL: info + NODEPORT: 2006 + PROXYPORT: 2007 + HOSTNAME: localhost + network_mode: "service:dela-worker-0" + volumes: + - dela-worker-3-data:/data + + frontend: # web service frontend + image: ghcr.io/c4dt/d-voting-frontend:latest + build: + dockerfile: Dockerfiles/Dockerfile.frontend + context: ../ + environment: + BACKEND_HOST: ${BACKEND_HOST} + BACKEND_PORT: ${BACKEND_PORT} + network_mode: "service:dela-worker-0" + + backend: # web service backend + image: ghcr.io/c4dt/d-voting-backend:latest + build: + dockerfile: Dockerfiles/Dockerfile.backend + context: ../ + environment: + DATABASE_USERNAME: ${DATABASE_USERNAME} + DATABASE_PASSWORD: ${DATABASE_PASSWORD} + DATABASE_HOST: ${DATABASE_HOST} + DATABASE_PORT: ${DATABASE_PORT} + DB_PATH: /data/${DB_PATH} + FRONT_END_URL: ${FRONT_END_URL} + DELA_NODE_URL: ${DELA_NODE_URL} + SESSION_SECRET: ${SESSION_SECRET} + PUBLIC_KEY: ${PUBLIC_KEY} + PRIVATE_KEY: ${PRIVATE_KEY} + PORT: ${BACKEND_PORT} + network_mode: "service:dela-worker-0" + depends_on: + db: + condition: service_started + volumes: + - backend-data:/data + + db: # PostgreSQL database + image: postgres:15 + environment: + POSTGRES_USER: ${DATABASE_USERNAME} + POSTGRES_PASSWORD: ${DATABASE_PASSWORD} + volumes: + - postgres-data:/var/lib/postgresql/data + - ../web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql + +volumes: + postgres-data: # PostgreSQL database + dela-worker-0-data: + dela-worker-1-data: + dela-worker-2-data: + dela-worker-3-data: + dela-worker-4-data: + backend-data: diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index ad0a468b1..304fe3e09 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -1,7 +1,10 @@ services: - dela-worker-0: # inital DELA leader node + dela-worker-0: # initial DELA leader node image: ghcr.io/c4dt/d-voting-dela:latest + build: + dockerfile: Dockerfiles/Dockerfile.dela + context: ../ environment: PROXYKEY: ${PUBLIC_KEY} PROXYPORT: ${PROXYPORT} @@ -13,6 +16,7 @@ services: networks: d-voting: ipv4_address: 172.19.44.254 + dela-worker-1: # DELA worker node image: ghcr.io/c4dt/d-voting-dela:latest environment: @@ -55,6 +59,9 @@ services: frontend: # web service frontend image: ghcr.io/c4dt/d-voting-frontend:latest + build: + dockerfile: Dockerfiles/Dockerfile.frontend + context: ../ ports: - 127.0.0.1:3000:3000 environment: @@ -66,6 +73,9 @@ services: backend: # web service backend image: ghcr.io/c4dt/d-voting-backend:latest + build: + dockerfile: Dockerfiles/Dockerfile.backend + context: ../ environment: DATABASE_USERNAME: ${DATABASE_USERNAME} DATABASE_PASSWORD: ${DATABASE_PASSWORD} @@ -95,7 +105,7 @@ services: POSTGRES_PASSWORD: ${DATABASE_PASSWORD} volumes: - postgres-data:/var/lib/postgresql/data - - ./web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql + - ../web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql networks: d-voting: ipv4_address: 172.19.44.4 diff --git a/scripts/init_dela.sh b/scripts/init_dela.sh index 542ca3059..4e3f8527c 100755 --- a/scripts/init_dela.sh +++ b/scripts/init_dela.sh @@ -1,22 +1,25 @@ -#!/bin/bash +#!/bin/bash -e MEMBERS=""; +export COMPOSE_FILE=${1:-../docker-compose/docker-compose.dev.yml} +if ! [[ -f ../docker-compose/.env ]]; then + ln -s ../.env ../docker-compose/.env +fi - -# share the certificate +echo "Share the certificate" for container in dela-worker-1 dela-worker-2 dela-worker-3; do TOKEN_ARGS=$(docker compose exec dela-worker-0 /bin/bash -c 'LLVL=error dvoting --config /data/node minogrpc token'); - docker compose exec "$container" dvoting --config /data/node minogrpc join --address //dela-worker-0:2000 $TOKEN_ARGS; + docker compose exec "$container" dvoting --config /data/node minogrpc join --address //localhost:2000 $TOKEN_ARGS; done -# create a new chain with the nodes +echo "Create a new chain with the nodes" for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do # add node to the chain MEMBERS="$MEMBERS --member $(docker compose exec $container /bin/bash -c 'LLVL=error dvoting --config /data/node ordering export')"; done docker compose exec dela-worker-0 dvoting --config /data/node ordering setup $MEMBERS; -# authorize the signer to handle the access contract on each node +echo "Authorize the signer to handle the access contract on each node" for signer in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do IDENTITY=$(docker compose exec "$signer" crypto bls signer read --path /data/node/private.key --format BASE64_PUBKEY); for node in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do @@ -24,7 +27,7 @@ for signer in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do done done -# update the access contract +echo "Update the access contract" for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do IDENTITY=$(docker compose exec "$container" crypto bls signer read --path /data/node/private.key --format BASE64_PUBKEY); docker compose exec dela-worker-0 dvoting --config /data/node pool add\ @@ -42,3 +45,5 @@ for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do --args access:command\ --args GRANT done + +echo "Successfully done" \ No newline at end of file diff --git a/scripts/setup_admin.sh b/scripts/setup_admin.sh new file mode 100755 index 000000000..e5ef6ec49 --- /dev/null +++ b/scripts/setup_admin.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +export COMPOSE_FILE=${2:-../docker-compose/docker-compose.dev.yml} + +docker compose exec backend npx cli addAdmin --sciper $1 +docker compose stop backend +docker compose rm backend +docker compose up backend diff --git a/scripts/setup_forms.sh b/scripts/setup_forms.sh new file mode 100755 index 000000000..10088ac27 --- /dev/null +++ b/scripts/setup_forms.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +if [ -z "$COOKIE" ]; then + echo "'COOKIE' variable not set"; + exit 1; +fi + +FRONTEND_URL=https://127.0.0.1:3000 + +echo "add form"; +RESP=$(curl -k "$FRONTEND_URL/api/evoting/forms" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data-raw '{"Configuration":{"MainTitle":"{\"en\":\"Colours\",\"fr\":\"\",\"de\":\"\"}","Scaffold":[{"ID":"5DRhKsY2","Title":"Colours","TitleFr":"","TitleDe":"","Order":["d0mSUfpv"],"Ranks":[],"Selects":[{"ID":"d0mSUfpv","Title":"{\"en\":\"RGB\",\"fr\":\"\",\"de\":\"\"}","TitleDe":"","TitleFr":"","MaxN":1,"MinN":1,"Choices":["{\"en\":\"Red\"}","{\"en\":\"Green\"}","{\"en\":\"Blue\"}"],"ChoicesMap":{},"Hint":"{\"en\":\"\",\"fr\":\"\",\"de\":\"\"}","HintFr":"","HintDe":""}],"Texts":[],"Subjects":[]}]}}'); +FORMID=$(echo "$RESP" | jq -r .FormID); +#TOKEN=$(echo "$RESP" | jq -r .Token); +echo "add permissions"; +curl -k "$FRONTEND_URL/api/evoting/authorizations" -X PUT -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID '$ARGS.named')" -m 1; + +echo "initialize nodes"; +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2001 '$ARGS.named')"; +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2003 '$ARGS.named')"; +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2005 '$ARGS.named')"; +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2007 '$ARGS.named')"; + +echo "set node up"; +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors/$FORMID" -X PUT -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data-raw '{"Action":"setup","Proxy":"http://localhost:2001"}'; + +echo "open election"; +sleep 8; +curl -k "$FRONTEND_URL/api/evoting/forms/$FORMID" -X PUT -H "Cookie: connect.sid=$COOKIE" -H 'Content-Type: application/json' --data-raw '{"Action":"open"}' +if [ -z $1 ]; then + echo "$FORMID has been set up"; + exit 0; +fi + +echo "cast $1 votes"; +for i in $(seq 1 $1); do + echo "cast vote #$i"; + curl -sk "$FRONTEND_URL/api/evoting/forms/$FORMID/vote" -X POST -H 'Content-Type: Application/json' -H "Origin: $FRONTEND_URL" -H "Cookie: connect.sid=$COOKIE" --data-raw '{"Ballot":[{"K":[54,152,33,11,201,233,212,157,204,176,136,138,54,213,239,198,79,55,71,26,91,244,98,215,208,239,48,253,195,53,192,94],"C":[105,121,87,164,68,242,166,194,222,179,253,231,213,63,34,66,212,41,214,175,178,83,229,156,255,38,55,234,168,222,81,185]}],"UserID":null}' > /dev/null; + sleep 1; +done diff --git a/scripts/setup_proxies.sh b/scripts/setup_proxies.sh new file mode 100755 index 000000000..2643ef20a --- /dev/null +++ b/scripts/setup_proxies.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ -z "$COOKIE" ]; then + echo "'COOKIE' variable is not set"; + exit 1; +fi + +echo "add proxies"; +curl -sk 'https://127.0.0.1:3000/api/proxies/' -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE; redirect=/" --data-raw '{"NodeAddr":"localhost:2000","Proxy":"http://localhost:2001"}'; +curl -sk 'https://127.0.0.1:3000/api/proxies/' -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE; redirect=/" --data-raw '{"NodeAddr":"localhost:2002","Proxy":"http://localhost:2003"}'; +curl -sk 'https://127.0.0.1:3000/api/proxies/' -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE; redirect=/" --data-raw '{"NodeAddr":"localhost:2004","Proxy":"http://localhost:2005"}'; +curl -sk 'https://127.0.0.1:3000/api/proxies/' -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE; redirect=/" --data-raw '{"NodeAddr":"localhost:2006","Proxy":"http://localhost:2007"}'; diff --git a/web/backend/readme.md b/web/backend/readme.md index 455e3f7eb..f7daa365e 100644 --- a/web/backend/readme.md +++ b/web/backend/readme.md @@ -10,26 +10,7 @@ Copy the database credentials from `config.env.template` to `/d-voting/bachend/s ## Generate a keypair -Here is a small piece of code in Go to generate the keypair for the backend: - -```go -package main - -import ( - "fmt" - "go.dedis.ch/kyber/v3/group/edwards25519" - "go.dedis.ch/kyber/v3/util/key" -) - -func main() { - pair := key.NewKeyPair(&edwards25519.SuiteEd25519{}) - - fmt.Println("PUBLIC_KEY:", pubK) - fmt.Println("PRIVATE_KEY:", privK) -} -``` - -You can also use the `cli` program to generate the keys: +Use the `cli` program to generate the keys: ```sh npm run keygen diff --git a/web/backend/src/Server.ts b/web/backend/src/Server.ts index 0afe993b2..d27cdeb25 100644 --- a/web/backend/src/Server.ts +++ b/web/backend/src/Server.ts @@ -44,6 +44,6 @@ app.get('*', (req, res) => { res.status(404).send(`not found ${xss(url.toString())}`); }); -const serveOnPort = process.env.PORT || 5000; +const serveOnPort = process.env.BACKEND_PORT || 5000; app.listen(serveOnPort); console.log(`🚀 App is listening on port ${serveOnPort}`); From 8b1299fdc881cc517a38c9398b27547b55cf15a2 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Mon, 25 Sep 2023 12:05:00 +0200 Subject: [PATCH 002/256] @PascalinDe's comments --- .github/workflows/go_integration_tests.yml | 1 - docker-compose/docker-compose.dev.yml | 107 --------------------- docker-compose/docker-compose.yml | 14 +-- scripts/init_dela.sh | 19 ++-- scripts/setup_admin.sh | 8 -- scripts/setup_forms.sh | 39 -------- scripts/setup_proxies.sh | 12 --- web/backend/{readme.md => README.md} | 0 8 files changed, 9 insertions(+), 191 deletions(-) delete mode 100644 docker-compose/docker-compose.dev.yml delete mode 100755 scripts/setup_admin.sh delete mode 100755 scripts/setup_forms.sh delete mode 100755 scripts/setup_proxies.sh rename web/backend/{readme.md => README.md} (100%) diff --git a/.github/workflows/go_integration_tests.yml b/.github/workflows/go_integration_tests.yml index 5263de3cc..5b0cfc9dd 100644 --- a/.github/workflows/go_integration_tests.yml +++ b/.github/workflows/go_integration_tests.yml @@ -7,7 +7,6 @@ on: branches: [main] jobs: - if: false integration: name: Integration test runs-on: ubuntu-latest diff --git a/docker-compose/docker-compose.dev.yml b/docker-compose/docker-compose.dev.yml deleted file mode 100644 index aa3c953ff..000000000 --- a/docker-compose/docker-compose.dev.yml +++ /dev/null @@ -1,107 +0,0 @@ -services: - - dela-worker-0: # initial DELA leader node - image: ghcr.io/c4dt/d-voting-dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela.localhost - context: ../ - ports: - - "2000-2007:2000-2007" - - "3000:3000" - - "6000:6000" - environment: - PROXYKEY: ${PUBLIC_KEY} - LLVL: info - NODEPORT: 2000 - PROXYPORT: 2001 - HOSTNAME: localhost - volumes: - - dela-worker-0-data:/data - - dela-worker-1: # DELA worker node - image: ghcr.io/c4dt/d-voting-dela:latest - environment: - PROXYKEY: ${PUBLIC_KEY} - LLVL: info - NODEPORT: 2002 - PROXYPORT: 2003 - HOSTNAME: localhost - network_mode: "service:dela-worker-0" - volumes: - - dela-worker-1-data:/data - - dela-worker-2: # DELA worker node - image: ghcr.io/c4dt/d-voting-dela:latest - environment: - PROXYKEY: ${PUBLIC_KEY} - LLVL: info - NODEPORT: 2004 - PROXYPORT: 2005 - HOSTNAME: localhost - network_mode: "service:dela-worker-0" - volumes: - - dela-worker-2-data:/data - - dela-worker-3: # DELA worker node - image: ghcr.io/c4dt/d-voting-dela:latest - environment: - PROXYKEY: ${PUBLIC_KEY} - LLVL: info - NODEPORT: 2006 - PROXYPORT: 2007 - HOSTNAME: localhost - network_mode: "service:dela-worker-0" - volumes: - - dela-worker-3-data:/data - - frontend: # web service frontend - image: ghcr.io/c4dt/d-voting-frontend:latest - build: - dockerfile: Dockerfiles/Dockerfile.frontend - context: ../ - environment: - BACKEND_HOST: ${BACKEND_HOST} - BACKEND_PORT: ${BACKEND_PORT} - network_mode: "service:dela-worker-0" - - backend: # web service backend - image: ghcr.io/c4dt/d-voting-backend:latest - build: - dockerfile: Dockerfiles/Dockerfile.backend - context: ../ - environment: - DATABASE_USERNAME: ${DATABASE_USERNAME} - DATABASE_PASSWORD: ${DATABASE_PASSWORD} - DATABASE_HOST: ${DATABASE_HOST} - DATABASE_PORT: ${DATABASE_PORT} - DB_PATH: /data/${DB_PATH} - FRONT_END_URL: ${FRONT_END_URL} - DELA_NODE_URL: ${DELA_NODE_URL} - SESSION_SECRET: ${SESSION_SECRET} - PUBLIC_KEY: ${PUBLIC_KEY} - PRIVATE_KEY: ${PRIVATE_KEY} - PORT: ${BACKEND_PORT} - network_mode: "service:dela-worker-0" - depends_on: - db: - condition: service_started - volumes: - - backend-data:/data - - db: # PostgreSQL database - image: postgres:15 - environment: - POSTGRES_USER: ${DATABASE_USERNAME} - POSTGRES_PASSWORD: ${DATABASE_PASSWORD} - volumes: - - postgres-data:/var/lib/postgresql/data - - ../web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql - -volumes: - postgres-data: # PostgreSQL database - dela-worker-0-data: - dela-worker-1-data: - dela-worker-2-data: - dela-worker-3-data: - dela-worker-4-data: - backend-data: diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index 304fe3e09..ad0a468b1 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -1,10 +1,7 @@ services: - dela-worker-0: # initial DELA leader node + dela-worker-0: # inital DELA leader node image: ghcr.io/c4dt/d-voting-dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela - context: ../ environment: PROXYKEY: ${PUBLIC_KEY} PROXYPORT: ${PROXYPORT} @@ -16,7 +13,6 @@ services: networks: d-voting: ipv4_address: 172.19.44.254 - dela-worker-1: # DELA worker node image: ghcr.io/c4dt/d-voting-dela:latest environment: @@ -59,9 +55,6 @@ services: frontend: # web service frontend image: ghcr.io/c4dt/d-voting-frontend:latest - build: - dockerfile: Dockerfiles/Dockerfile.frontend - context: ../ ports: - 127.0.0.1:3000:3000 environment: @@ -73,9 +66,6 @@ services: backend: # web service backend image: ghcr.io/c4dt/d-voting-backend:latest - build: - dockerfile: Dockerfiles/Dockerfile.backend - context: ../ environment: DATABASE_USERNAME: ${DATABASE_USERNAME} DATABASE_PASSWORD: ${DATABASE_PASSWORD} @@ -105,7 +95,7 @@ services: POSTGRES_PASSWORD: ${DATABASE_PASSWORD} volumes: - postgres-data:/var/lib/postgresql/data - - ../web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql + - ./web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql networks: d-voting: ipv4_address: 172.19.44.4 diff --git a/scripts/init_dela.sh b/scripts/init_dela.sh index 4e3f8527c..542ca3059 100755 --- a/scripts/init_dela.sh +++ b/scripts/init_dela.sh @@ -1,25 +1,22 @@ -#!/bin/bash -e +#!/bin/bash MEMBERS=""; -export COMPOSE_FILE=${1:-../docker-compose/docker-compose.dev.yml} -if ! [[ -f ../docker-compose/.env ]]; then - ln -s ../.env ../docker-compose/.env -fi -echo "Share the certificate" + +# share the certificate for container in dela-worker-1 dela-worker-2 dela-worker-3; do TOKEN_ARGS=$(docker compose exec dela-worker-0 /bin/bash -c 'LLVL=error dvoting --config /data/node minogrpc token'); - docker compose exec "$container" dvoting --config /data/node minogrpc join --address //localhost:2000 $TOKEN_ARGS; + docker compose exec "$container" dvoting --config /data/node minogrpc join --address //dela-worker-0:2000 $TOKEN_ARGS; done -echo "Create a new chain with the nodes" +# create a new chain with the nodes for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do # add node to the chain MEMBERS="$MEMBERS --member $(docker compose exec $container /bin/bash -c 'LLVL=error dvoting --config /data/node ordering export')"; done docker compose exec dela-worker-0 dvoting --config /data/node ordering setup $MEMBERS; -echo "Authorize the signer to handle the access contract on each node" +# authorize the signer to handle the access contract on each node for signer in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do IDENTITY=$(docker compose exec "$signer" crypto bls signer read --path /data/node/private.key --format BASE64_PUBKEY); for node in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do @@ -27,7 +24,7 @@ for signer in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do done done -echo "Update the access contract" +# update the access contract for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do IDENTITY=$(docker compose exec "$container" crypto bls signer read --path /data/node/private.key --format BASE64_PUBKEY); docker compose exec dela-worker-0 dvoting --config /data/node pool add\ @@ -45,5 +42,3 @@ for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do --args access:command\ --args GRANT done - -echo "Successfully done" \ No newline at end of file diff --git a/scripts/setup_admin.sh b/scripts/setup_admin.sh deleted file mode 100755 index e5ef6ec49..000000000 --- a/scripts/setup_admin.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -export COMPOSE_FILE=${2:-../docker-compose/docker-compose.dev.yml} - -docker compose exec backend npx cli addAdmin --sciper $1 -docker compose stop backend -docker compose rm backend -docker compose up backend diff --git a/scripts/setup_forms.sh b/scripts/setup_forms.sh deleted file mode 100755 index 10088ac27..000000000 --- a/scripts/setup_forms.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -if [ -z "$COOKIE" ]; then - echo "'COOKIE' variable not set"; - exit 1; -fi - -FRONTEND_URL=https://127.0.0.1:3000 - -echo "add form"; -RESP=$(curl -k "$FRONTEND_URL/api/evoting/forms" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data-raw '{"Configuration":{"MainTitle":"{\"en\":\"Colours\",\"fr\":\"\",\"de\":\"\"}","Scaffold":[{"ID":"5DRhKsY2","Title":"Colours","TitleFr":"","TitleDe":"","Order":["d0mSUfpv"],"Ranks":[],"Selects":[{"ID":"d0mSUfpv","Title":"{\"en\":\"RGB\",\"fr\":\"\",\"de\":\"\"}","TitleDe":"","TitleFr":"","MaxN":1,"MinN":1,"Choices":["{\"en\":\"Red\"}","{\"en\":\"Green\"}","{\"en\":\"Blue\"}"],"ChoicesMap":{},"Hint":"{\"en\":\"\",\"fr\":\"\",\"de\":\"\"}","HintFr":"","HintDe":""}],"Texts":[],"Subjects":[]}]}}'); -FORMID=$(echo "$RESP" | jq -r .FormID); -#TOKEN=$(echo "$RESP" | jq -r .Token); -echo "add permissions"; -curl -k "$FRONTEND_URL/api/evoting/authorizations" -X PUT -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID '$ARGS.named')" -m 1; - -echo "initialize nodes"; -curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2001 '$ARGS.named')"; -curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2003 '$ARGS.named')"; -curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2005 '$ARGS.named')"; -curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2007 '$ARGS.named')"; - -echo "set node up"; -curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors/$FORMID" -X PUT -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE" --data-raw '{"Action":"setup","Proxy":"http://localhost:2001"}'; - -echo "open election"; -sleep 8; -curl -k "$FRONTEND_URL/api/evoting/forms/$FORMID" -X PUT -H "Cookie: connect.sid=$COOKIE" -H 'Content-Type: application/json' --data-raw '{"Action":"open"}' -if [ -z $1 ]; then - echo "$FORMID has been set up"; - exit 0; -fi - -echo "cast $1 votes"; -for i in $(seq 1 $1); do - echo "cast vote #$i"; - curl -sk "$FRONTEND_URL/api/evoting/forms/$FORMID/vote" -X POST -H 'Content-Type: Application/json' -H "Origin: $FRONTEND_URL" -H "Cookie: connect.sid=$COOKIE" --data-raw '{"Ballot":[{"K":[54,152,33,11,201,233,212,157,204,176,136,138,54,213,239,198,79,55,71,26,91,244,98,215,208,239,48,253,195,53,192,94],"C":[105,121,87,164,68,242,166,194,222,179,253,231,213,63,34,66,212,41,214,175,178,83,229,156,255,38,55,234,168,222,81,185]}],"UserID":null}' > /dev/null; - sleep 1; -done diff --git a/scripts/setup_proxies.sh b/scripts/setup_proxies.sh deleted file mode 100755 index 2643ef20a..000000000 --- a/scripts/setup_proxies.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -if [ -z "$COOKIE" ]; then - echo "'COOKIE' variable is not set"; - exit 1; -fi - -echo "add proxies"; -curl -sk 'https://127.0.0.1:3000/api/proxies/' -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE; redirect=/" --data-raw '{"NodeAddr":"localhost:2000","Proxy":"http://localhost:2001"}'; -curl -sk 'https://127.0.0.1:3000/api/proxies/' -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE; redirect=/" --data-raw '{"NodeAddr":"localhost:2002","Proxy":"http://localhost:2003"}'; -curl -sk 'https://127.0.0.1:3000/api/proxies/' -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE; redirect=/" --data-raw '{"NodeAddr":"localhost:2004","Proxy":"http://localhost:2005"}'; -curl -sk 'https://127.0.0.1:3000/api/proxies/' -X POST -H 'Content-Type: application/json' -H "Cookie: connect.sid=$COOKIE; redirect=/" --data-raw '{"NodeAddr":"localhost:2006","Proxy":"http://localhost:2007"}'; diff --git a/web/backend/readme.md b/web/backend/README.md similarity index 100% rename from web/backend/readme.md rename to web/backend/README.md From 71b08e7a9627461f057746d8600cac2f6f35326b Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Wed, 27 Sep 2023 09:41:45 +0200 Subject: [PATCH 003/256] @Pierluca's comments --- Dockerfiles/Dockerfile.dela.debug | 18 +++ docker-compose/docker-compose.debug.yml | 167 ++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 Dockerfiles/Dockerfile.dela.debug create mode 100644 docker-compose/docker-compose.debug.yml diff --git a/Dockerfiles/Dockerfile.dela.debug b/Dockerfiles/Dockerfile.dela.debug new file mode 100644 index 000000000..47cee9b89 --- /dev/null +++ b/Dockerfiles/Dockerfile.dela.debug @@ -0,0 +1,18 @@ +FROM golang:1.20.6-bookworm + +# https://blog.jetbrains.com/go/2020/05/06/debugging-a-go-application-inside-a-docker-container/ +RUN go install github.com/go-delve/delve/cmd/dlv@latest + +RUN apt-get update && apt-get install git +RUN git clone https://github.com/dedis/dela.git +RUN git clone https://github.com/dedis/d-voting.git +WORKDIR /go/dela/cli/crypto +RUN go install +WORKDIR /go/d-voting/cli/dvoting + +RUN go build -gcflags="all=-N -l" + +ENV PATH=/go/dela/cli/crypto:/go/d-voting/cli/dvoting:${PATH} +WORKDIR /go +ENTRYPOINT ["/bin/bash", "-c", "dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /go/d-voting/cli/dvoting/dvoting -- --config /data/node start --postinstall --proxyaddr :$PROXYPORT --proxykey $PROXYKEY --listen tcp://0.0.0.0:2000 --public http://$HOSTNAME:2000 --routing tree"] +CMD [] diff --git a/docker-compose/docker-compose.debug.yml b/docker-compose/docker-compose.debug.yml new file mode 100644 index 000000000..52078a067 --- /dev/null +++ b/docker-compose/docker-compose.debug.yml @@ -0,0 +1,167 @@ +services: + + dela-worker-0: # inital DELA leader node + image: dela:latest + build: + dockerfile: Dockerfiles/Dockerfile.dela.debug + context: ../ + environment: + PROXYKEY: ${PUBLIC_KEY} + PROXYPORT: ${PROXYPORT} + PROXY_LOG: info + LLVL: debug + NODEPORT: ${NODEPORT} + volumes: + - dela-worker-0-data:/data + hostname: dela-worker-0 + ports: + - 127.0.0.1:40000:40000 + security_opt: + - apparmor:unconfined + cap_add: + - SYS_PTRACE + networks: + d-voting: + ipv4_address: 172.19.44.254 + dela-worker-1: # DELA worker node + image: dela:latest + build: + dockerfile: Dockerfiles/Dockerfile.dela.debug + context: ../ + environment: + PROXYKEY: ${PUBLIC_KEY} + PROXYPORT: ${PROXYPORT} + PROXY_LOG: info + LLVL: debug + NODEPORT: ${NODEPORT} + volumes: + - dela-worker-1-data:/data + hostname: dela-worker-1 + ports: + - 127.0.0.1:40001:40000 + security_opt: + - apparmor:unconfined + cap_add: + - SYS_PTRACE + networks: + d-voting: + ipv4_address: 172.19.44.253 + dela-worker-2: # DELA worker node + image: dela:latest + build: + dockerfile: Dockerfiles/Dockerfile.dela.debug + context: ../ + environment: + PROXYKEY: ${PUBLIC_KEY} + PROXYPORT: ${PROXYPORT} + PROXY_LOG: info + LLVL: debug + NODEPORT: ${NODEPORT} + volumes: + - dela-worker-2-data:/data + hostname: dela-worker-2 + ports: + - 127.0.0.1:40002:40000 + security_opt: + - apparmor:unconfined + cap_add: + - SYS_PTRACE + networks: + d-voting: + ipv4_address: 172.19.44.252 + dela-worker-3: # DELA worker node + image: dela:latest + build: + dockerfile: Dockerfiles/Dockerfile.dela.debug + context: ../ + environment: + PROXYKEY: ${PUBLIC_KEY} + PROXYPORT: ${PROXYPORT} + PROXY_LOG: info + LLVL: debug + NODEPORT: ${NODEPORT} + volumes: + - dela-worker-3-data:/data + hostname: dela-worker-3 + ports: + - 127.0.0.1:40003:40000 + security_opt: + - apparmor:unconfined + cap_add: + - SYS_PTRACE + networks: + d-voting: + ipv4_address: 172.19.44.251 + + frontend: # web service frontend + image: frontend:latest + build: + dockerfile: Dockerfiles/Dockerfile.frontend + context: ../ + ports: + - 127.0.0.1:3000:3000 + volumes: + - ../web/frontend/src:/web/frontend/src + environment: + BACKEND_HOST: ${BACKEND_HOST} + BACKEND_PORT: ${BACKEND_PORT} + networks: + d-voting: + ipv4_address: 172.19.44.2 + + backend: # web service backend + image: backend:latest + build: + dockerfile: Dockerfiles/Dockerfile.backend + context: ../ + environment: + DATABASE_USERNAME: ${DATABASE_USERNAME} + DATABASE_PASSWORD: ${DATABASE_PASSWORD} + DATABASE_HOST: ${DATABASE_HOST} + DATABASE_PORT: ${DATABASE_PORT} + DB_PATH: /data/${DB_PATH} + FRONT_END_URL: ${FRONT_END_URL} + DELA_NODE_URL: ${DELA_NODE_URL} + SESSION_SECRET: ${SESSION_SECRET} + PUBLIC_KEY: ${PUBLIC_KEY} + PRIVATE_KEY: ${PRIVATE_KEY} + ports: + - 127.0.0.1:5000:5000 + - 127.0.0.1:80:80 + depends_on: + db: + condition: service_started + volumes: + - backend-data:/data + - ../web/backend/src:/web/backend/src + networks: + d-voting: + ipv4_address: 172.19.44.3 + + db: # PostgreSQL database + image: postgres:15 + environment: + POSTGRES_USER: ${DATABASE_USERNAME} + POSTGRES_PASSWORD: ${DATABASE_PASSWORD} + volumes: + - postgres-data:/var/lib/postgresql/data + - ../web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql + networks: + d-voting: + ipv4_address: 172.19.44.4 + +volumes: + postgres-data: # PostgreSQL database + dela-worker-0-data: + dela-worker-1-data: + dela-worker-2-data: + dela-worker-3-data: + dela-worker-4-data: + backend-data: + +networks: + d-voting: + ipam: + config: + - subnet: 172.19.44.0/24 + gateway: 172.19.44.1 From 7bfd8b5cba8f9e759f7bca27bcddc79f92fbb56a Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Fri, 22 Sep 2023 15:32:38 +0200 Subject: [PATCH 004/256] feat: improve on debug/production deployments --- Dockerfiles/Dockerfile.dela | 18 ++++- Dockerfiles/Dockerfile.dela.debug | 18 ----- README.docker.md | 16 ++-- docker-compose/docker-compose.debug.yml | 100 ++++++++++-------------- docker-compose/docker-compose.yml | 50 ++++++------ scripts/init_dela.sh | 15 ++++ 6 files changed, 103 insertions(+), 114 deletions(-) delete mode 100644 Dockerfiles/Dockerfile.dela.debug diff --git a/Dockerfiles/Dockerfile.dela b/Dockerfiles/Dockerfile.dela index 27f4fc909..15312deab 100644 --- a/Dockerfiles/Dockerfile.dela +++ b/Dockerfiles/Dockerfile.dela @@ -1,5 +1,4 @@ -FROM golang:1.20.6-bookworm - +FROM golang:1.20.6-bookworm AS base RUN apt-get update && apt-get install git # make sure we're using the same head as d-voting RUN git clone -b fix-bbolt https://github.com/dedis/dela.git @@ -7,9 +6,22 @@ WORKDIR /go/dela/cli/crypto RUN go install WORKDIR /go/d-voting COPY . . + +FROM base AS production +COPY --from=base /go/dela . +COPY --from=base /go/d-voting . WORKDIR /go/d-voting/cli/dvoting RUN go build ENV PATH=/go/dela/cli/crypto:/go/d-voting/cli/dvoting:${PATH} -WORKDIR /go ENTRYPOINT ["/bin/bash", "-c", "dvoting --config /data/node start --postinstall --proxyaddr :$PROXYPORT --proxykey $PROXYKEY --listen tcp://0.0.0.0:2000 --public http://$HOSTNAME:$NODEPORT --routing tree"] CMD [] + +FROM base AS debug +COPY --from=base /go/dela . +COPY --from=base /go/d-voting . +RUN go install github.com/go-delve/delve/cmd/dlv@latest +WORKDIR /go/d-voting/cli/dvoting +RUN go build -gcflags="all=-N -l" +ENV PATH=/go/dela/cli/crypto:/go/d-voting/cli/dvoting:${PATH} +ENTRYPOINT ["/bin/bash", "-c", "dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /go/d-voting/cli/dvoting/dvoting -- --config /data/node start --postinstall --proxyaddr :$PROXYPORT --proxykey $PROXYKEY --listen tcp://0.0.0.0:2000 --public http://$HOSTNAME:2000 --routing tree"] +CMD [] diff --git a/Dockerfiles/Dockerfile.dela.debug b/Dockerfiles/Dockerfile.dela.debug deleted file mode 100644 index 47cee9b89..000000000 --- a/Dockerfiles/Dockerfile.dela.debug +++ /dev/null @@ -1,18 +0,0 @@ -FROM golang:1.20.6-bookworm - -# https://blog.jetbrains.com/go/2020/05/06/debugging-a-go-application-inside-a-docker-container/ -RUN go install github.com/go-delve/delve/cmd/dlv@latest - -RUN apt-get update && apt-get install git -RUN git clone https://github.com/dedis/dela.git -RUN git clone https://github.com/dedis/d-voting.git -WORKDIR /go/dela/cli/crypto -RUN go install -WORKDIR /go/d-voting/cli/dvoting - -RUN go build -gcflags="all=-N -l" - -ENV PATH=/go/dela/cli/crypto:/go/d-voting/cli/dvoting:${PATH} -WORKDIR /go -ENTRYPOINT ["/bin/bash", "-c", "dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec /go/d-voting/cli/dvoting/dvoting -- --config /data/node start --postinstall --proxyaddr :$PROXYPORT --proxykey $PROXYKEY --listen tcp://0.0.0.0:2000 --public http://$HOSTNAME:2000 --routing tree"] -CMD [] diff --git a/README.docker.md b/README.docker.md index 230fbc875..cb2d44a19 100644 --- a/README.docker.md +++ b/README.docker.md @@ -33,29 +33,27 @@ NODEPORT=2000 # DELA node port There are two Docker Compose file you may use: -* `docker-compose/docker-compose.yml` for the currently released version, or +* `docker-compose/docker-compose.yml` for the preprod version, or * `docker-compose/docker-compose.debug.yml` for the development/debugging version -You can either run +You run ``` export COMPOSE_FILE= ``` -or pass the `-f/--file ` argument to choose between -the files. - -Using the currently released version will pull the images from the GitHub container registry. - -If you instead use the development/debugging version the images will be build locally and you can debug your developments. +The preprod version will create an environment without any debugging tools that's as close as possible to a real environment. +It is meant to be used to test the `main` branch before deploying it to production. Use the development/debugging version +for setting up your local development environment. Run ``` +docker compose build docker compose up ``` -(possibly with the `-f/--file` argument) to set up the environment. +to set up the environment. /!\ Any subsequent `docker compose` commands must be run with `COMPOSE_FILE` being set to the Docker Compose file that defines the current environment. diff --git a/docker-compose/docker-compose.debug.yml b/docker-compose/docker-compose.debug.yml index 52078a067..d34da1149 100644 --- a/docker-compose/docker-compose.debug.yml +++ b/docker-compose/docker-compose.debug.yml @@ -1,107 +1,73 @@ +version: "3.8" +x-dela: &dela + image: ghcr.io/c4dt/d-voting-dela:latest + environment: + PROXYKEY: ${PUBLIC_KEY} + PROXYPORT: ${PROXYPORT} + PROXY_LOG: info + LLVL: debug + NODEPORT: ${NODEPORT} + security_opt: + - apparmor:unconfined + cap_add: + - SYS_PTRACE + services: dela-worker-0: # inital DELA leader node - image: dela:latest + <<: *dela build: - dockerfile: Dockerfiles/Dockerfile.dela.debug + dockerfile: Dockerfiles/Dockerfile.dela context: ../ - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - PROXY_LOG: info - LLVL: debug - NODEPORT: ${NODEPORT} + target: debug volumes: - dela-worker-0-data:/data hostname: dela-worker-0 ports: - 127.0.0.1:40000:40000 - security_opt: - - apparmor:unconfined - cap_add: - - SYS_PTRACE networks: d-voting: ipv4_address: 172.19.44.254 dela-worker-1: # DELA worker node - image: dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela.debug - context: ../ - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - PROXY_LOG: info - LLVL: debug - NODEPORT: ${NODEPORT} + <<: *dela volumes: - dela-worker-1-data:/data hostname: dela-worker-1 ports: - 127.0.0.1:40001:40000 - security_opt: - - apparmor:unconfined - cap_add: - - SYS_PTRACE networks: d-voting: ipv4_address: 172.19.44.253 dela-worker-2: # DELA worker node - image: dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela.debug - context: ../ - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - PROXY_LOG: info - LLVL: debug - NODEPORT: ${NODEPORT} + <<: *dela volumes: - dela-worker-2-data:/data hostname: dela-worker-2 ports: - 127.0.0.1:40002:40000 - security_opt: - - apparmor:unconfined - cap_add: - - SYS_PTRACE networks: d-voting: ipv4_address: 172.19.44.252 dela-worker-3: # DELA worker node - image: dela:latest - build: - dockerfile: Dockerfiles/Dockerfile.dela.debug - context: ../ - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - PROXY_LOG: info - LLVL: debug - NODEPORT: ${NODEPORT} + <<: *dela volumes: - dela-worker-3-data:/data hostname: dela-worker-3 ports: - 127.0.0.1:40003:40000 - security_opt: - - apparmor:unconfined - cap_add: - - SYS_PTRACE networks: d-voting: ipv4_address: 172.19.44.251 frontend: # web service frontend - image: frontend:latest + image: ghcr.io/c4dt/d-voting-frontend:latest build: dockerfile: Dockerfiles/Dockerfile.frontend context: ../ ports: - 127.0.0.1:3000:3000 volumes: - - ../web/frontend/src:/web/frontend/src + - ../web/frontend/src:/web/frontend/src # mount codebase for development environment: BACKEND_HOST: ${BACKEND_HOST} BACKEND_PORT: ${BACKEND_PORT} @@ -110,7 +76,7 @@ services: ipv4_address: 172.19.44.2 backend: # web service backend - image: backend:latest + image: ghcr.io/c4dt/d-voting-backend:latest build: dockerfile: Dockerfiles/Dockerfile.backend context: ../ @@ -127,13 +93,12 @@ services: PRIVATE_KEY: ${PRIVATE_KEY} ports: - 127.0.0.1:5000:5000 - - 127.0.0.1:80:80 depends_on: db: condition: service_started volumes: - backend-data:/data - - ../web/backend/src:/web/backend/src + - ../web/backend/src:/web/backend/src # mount codebase for development networks: d-voting: ipv4_address: 172.19.44.3 @@ -150,6 +115,23 @@ services: d-voting: ipv4_address: 172.19.44.4 + shell: # helper container to execute scripts from within Docker network (macOS/Windows setup) + image: ubuntu:mantic + command: ["tail", "-f", "/dev/null"] + networks: + d-voting: + ipv4_address: 172.19.44.5 + volumes: + - ../scripts:/scripts + + firefox: # helper container to execute Firefox within Docker network (macOS/Windows setup) + image: jlesage/firefox + ports: + - 127.0.0.1:5800:5800 + networks: + d-voting: + ipv4_address: 172.19.44.6 + volumes: postgres-data: # PostgreSQL database dela-worker-0-data: diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index ad0a468b1..1f1d6fa98 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -1,12 +1,21 @@ +version: "3.8" +x-dela: &dela + image: ghcr.io/c4dt/d-voting-dela:latest + environment: + PROXYKEY: ${PUBLIC_KEY} + PROXYPORT: ${PROXYPORT} + PROXY_LOG: info + LLVL: info + NODEPORT: ${NODEPORT} + services: dela-worker-0: # inital DELA leader node - image: ghcr.io/c4dt/d-voting-dela:latest - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - LLVL: info - NODEPORT: ${NODEPORT} + <<: *dela + build: + dockerfile: Dockerfiles/Dockerfile.dela + context: ../ + target: production volumes: - dela-worker-0-data:/data hostname: dela-worker-0 @@ -14,12 +23,7 @@ services: d-voting: ipv4_address: 172.19.44.254 dela-worker-1: # DELA worker node - image: ghcr.io/c4dt/d-voting-dela:latest - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - LLVL: info - NODEPORT: ${NODEPORT} + <<: *dela volumes: - dela-worker-1-data:/data hostname: dela-worker-1 @@ -27,12 +31,7 @@ services: d-voting: ipv4_address: 172.19.44.253 dela-worker-2: # DELA worker node - image: ghcr.io/c4dt/d-voting-dela:latest - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - LLVL: info - NODEPORT: ${NODEPORT} + <<: *dela volumes: - dela-worker-2-data:/data hostname: dela-worker-2 @@ -40,12 +39,7 @@ services: d-voting: ipv4_address: 172.19.44.252 dela-worker-3: # DELA worker node - image: ghcr.io/c4dt/d-voting-dela:latest - environment: - PROXYKEY: ${PUBLIC_KEY} - PROXYPORT: ${PROXYPORT} - LLVL: info - NODEPORT: ${NODEPORT} + <<: *dela volumes: - dela-worker-3-data:/data hostname: dela-worker-3 @@ -55,6 +49,9 @@ services: frontend: # web service frontend image: ghcr.io/c4dt/d-voting-frontend:latest + build: + dockerfile: Dockerfiles/Dockerfile.frontend + context: ../ ports: - 127.0.0.1:3000:3000 environment: @@ -66,6 +63,9 @@ services: backend: # web service backend image: ghcr.io/c4dt/d-voting-backend:latest + build: + dockerfile: Dockerfiles/Dockerfile.backend + context: ../ environment: DATABASE_USERNAME: ${DATABASE_USERNAME} DATABASE_PASSWORD: ${DATABASE_PASSWORD} @@ -95,7 +95,7 @@ services: POSTGRES_PASSWORD: ${DATABASE_PASSWORD} volumes: - postgres-data:/var/lib/postgresql/data - - ./web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql + - ../web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql networks: d-voting: ipv4_address: 172.19.44.4 diff --git a/scripts/init_dela.sh b/scripts/init_dela.sh index 542ca3059..b5ba25879 100755 --- a/scripts/init_dela.sh +++ b/scripts/init_dela.sh @@ -2,29 +2,43 @@ MEMBERS=""; +if [ -z "$COMPOSE_FILE" ]; then + echo "'COMPOSE_FILE' variable not set"; + exit 1; +fi + + # share the certificate +echo "[1/4] add nodes to network"; for container in dela-worker-1 dela-worker-2 dela-worker-3; do TOKEN_ARGS=$(docker compose exec dela-worker-0 /bin/bash -c 'LLVL=error dvoting --config /data/node minogrpc token'); + echo "generated token for $container"; docker compose exec "$container" dvoting --config /data/node minogrpc join --address //dela-worker-0:2000 $TOKEN_ARGS; + echo "$container joined network"; done # create a new chain with the nodes +echo "[2/4] create a new chain"; for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do # add node to the chain MEMBERS="$MEMBERS --member $(docker compose exec $container /bin/bash -c 'LLVL=error dvoting --config /data/node ordering export')"; done docker compose exec dela-worker-0 dvoting --config /data/node ordering setup $MEMBERS; +echo "created new chain"; # authorize the signer to handle the access contract on each node +echo "[3/4] allow nodes to access contracts on each other"; for signer in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do IDENTITY=$(docker compose exec "$signer" crypto bls signer read --path /data/node/private.key --format BASE64_PUBKEY); for node in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do docker compose exec "$node" dvoting --config /data/node access add --identity "$IDENTITY"; + echo "$node allowed $signer to access contract on it"; done done # update the access contract +echo "[4/4] grant permissions to update contract"; for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do IDENTITY=$(docker compose exec "$container" crypto bls signer read --path /data/node/private.key --format BASE64_PUBKEY); docker compose exec dela-worker-0 dvoting --config /data/node pool add\ @@ -41,4 +55,5 @@ for container in dela-worker-0 dela-worker-1 dela-worker-2 dela-worker-3; do --args $IDENTITY\ --args access:command\ --args GRANT + echo "$container has been granted permission to update contract"; done From 3cb508b51bee6d5c56a4a37162e513dc95c9fe0d Mon Sep 17 00:00:00 2001 From: Carine Dengler Date: Wed, 27 Sep 2023 17:16:17 +0200 Subject: [PATCH 005/256] chore: add Docker image building to CI --- .github/workflows/build-docker.yml | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/build-docker.yml diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 000000000..bc17921bd --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,48 @@ +name: Build docker + +on: + push: + branches: + - main + +jobs: + build-docker: + name: Build D-Voting Docker images + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + - name: Login to GHCR + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build Frontend + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfiles/Dockerfile.frontend + platforms: linux/amd64 + push: true + tags: ghcr.io/c4dt/d-voting-frontend:latest + - name: Build Backend + uses: docker/build-push-action@v2 + with: + context: . + file: Dockerfiles/Dockerfile.backend + platforms: linux/amd64 + push: true + tags: ghcr.io/c4dt/d-voting-backend:latest + - name: Build D-Voting + uses: docker/build-push-action@v2 + with: + context: . + target: production + file: Dockerfiles/Dockerfile.dela + platforms: linux/amd64 + push: true + tags: ghcr.io/c4dt/d-voting-dela:latest From 40742e9471c6c87b94022685a2b2b0cb0c4c9d4f Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Thu, 28 Sep 2023 11:06:01 +0200 Subject: [PATCH 006/256] Fixing voting Using the endpoint 'forms/:formID/vote' doesn't work with the sendToDela method --- web/backend/src/controllers/dela.ts | 49 ++++++++++++++--------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/web/backend/src/controllers/dela.ts b/web/backend/src/controllers/dela.ts index 7253e4932..5129ccadf 100644 --- a/web/backend/src/controllers/dela.ts +++ b/web/backend/src/controllers/dela.ts @@ -177,31 +177,6 @@ delaRouter.use('/services/shuffle/:formID', (req, res, next) => { next(); }); -delaRouter.post('/forms/:formID/vote', (req, res) => { - if (!req.session.userId) { - res.status(401).send('Authentication required!'); - return; - } - if (!isAuthorized(req.session.userId, req.params.formID, PERMISSIONS.ACTIONS.VOTE)) { - res.status(400).send('Unauthorized'); - return; - } - - // We must set the UserID to know who this ballot is associated to. This is - // only needed to allow users to cast multiple ballots, where only the last - // ballot is taken into account. To preserve anonymity, the web-backend could - // translate UserIDs to another random ID. - // bodyData.UserID = req.session.userId.toString(); - - // DEBUG: this is only for debugging and needs to be replaced before production - const bodyData = req.body; - console.warn('DEV CODE - randomizing the SCIPER ID to allow for unlimited votes'); - bodyData.UserID = makeid(10); - - const dataStr = JSON.stringify(bodyData); - sendToDela(dataStr, req, res); -}); - delaRouter.delete('/forms/:formID', (req, res) => { if (!req.session.userId) { res.status(401).send('Unauthenticated'); @@ -263,6 +238,30 @@ delaRouter.use('/*', (req, res) => { } const bodyData = req.body; + + // special case for voting + const match = req.baseUrl.match('/api/evoting/forms/(.*)/vote'); + if (match) { + if (!req.session.userId) { + res.status(401).send('Authentication required!'); + return; + } + if (!isAuthorized(req.session.userId, match[1], PERMISSIONS.ACTIONS.VOTE)) { + res.status(400).send('Unauthorized'); + return; + } + + // We must set the UserID to know who this ballot is associated to. This is + // only needed to allow users to cast multiple ballots, where only the last + // ballot is taken into account. To preserve anonymity, the web-backend could + // translate UserIDs to another random ID. + // bodyData.UserID = req.session.userId.toString(); + + // DEBUG: this is only for debugging and needs to be replaced before production + console.warn('DEV CODE - randomizing the SCIPER ID to allow for unlimited votes'); + bodyData.UserID = makeid(10); + } + const dataStr = JSON.stringify(bodyData); sendToDela(dataStr, req, res); From e84aa4b4cbddfb899b02546f298ac114caff6db5 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Mon, 25 Sep 2023 08:56:00 +0200 Subject: [PATCH 007/256] Adds local login and script for testing - Allow for easier development with bypassing the Gaspar login - Adds a script which does all the initialisations for a first D-voting experience --- .gitignore | 5 + scripts/run_local.sh | 190 ++++++++++++++++++ web/backend/package.json | 1 + web/backend/src/controllers/authentication.ts | 31 +++ web/backend/yarn.lock | 125 +++++++++++- web/frontend/package.json | 1 + .../src/components/utils/Endpoints.tsx | 1 + .../src/pages/session/HandleLogin.tsx | 11 +- 8 files changed, 353 insertions(+), 12 deletions(-) create mode 100755 scripts/run_local.sh diff --git a/.gitignore b/.gitignore index a6b66c431..752b0635c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,8 @@ nodedata/ deb-package/dist/** +.env + +dela/ +bin/ +nodes/ diff --git a/scripts/run_local.sh b/scripts/run_local.sh new file mode 100755 index 000000000..3b9f63be2 --- /dev/null +++ b/scripts/run_local.sh @@ -0,0 +1,190 @@ +#!/bin/bash -e +# This puts all the different steps of initializing a Dela d-voting network into one shell script. +# This can be used for development by calling the script and then testing the result locally. +# The script must be called from the root of the github tree, else it returns an error. +# If the script is called with `./scripts/run_local.sh clean`, it stops all services. +# For development, the calls to the different parts can be adjusted, e.g., comment all but +# `start_backend` to only restart the backend. + +if [[ $(git rev-parse --show-toplevel) != $(pwd) ]]; then + echo "ERROR: This script must be started from the root of the git repo" + exit 1 +fi + +asdf_shell() { + if ! asdf list "$1" | grep -wq "$2"; then + asdf install "$1" "$2" + fi + asdf local "$1" "$2" +} +asdf_shell nodejs 16.20.2 +asdf_shell golang 1.21.0 +mkdir -p nodes + +function build_dela() { + echo "Building dela-node" + if ! [[ -d dela/ ]]; then + git clone -b fix-bbolt https://github.com/dedis/dela.git + fi + export GOBIN=$(pwd)/bin + PATH="$PATH":"$GOBIN" + if ! [[ -f $GOBIN/crypto ]]; then + (cd dela/cli/crypto && go install) + fi + if ! [[ -f $GOBIN/dvoting ]]; then + go install ./cli/dvoting + fi + + echo "Installing node directories" + for d in backend frontend; do + DIR=web/$d + if ! [[ -d $DIR/node_modules ]]; then + (cd $DIR && npm ci) + fi + done +} + +function keypair() { + if ! [[ "$PUBLIC_KEY" ]]; then + if ! [[ -f nodes/keypair ]]; then + echo "Getting keypair" + (cd web/backend && npm run keygen) | tail -n 2 >nodes/keypair + fi + . nodes/keypair + export PUBLIC_KEY PRIVATE_KEY + fi +} + +function kill_nodes() { + pkill dvoting || true + rm -rf nodes/node* +} + +function init_nodes() { + kill_nodes + keypair + + echo "Starting nodes" + for n in $(seq 4); do + NODEPORT=$((2000 + n * 2)) + PROXYPORT=$((2001 + n * 2)) + NODEDIR=./nodes/node-$n + mkdir -p $NODEDIR + rm -f $NODEDIR/node.log + dvoting --config $NODEDIR start --postinstall --proxyaddr :$PROXYPORT --proxykey $PUBLIC_KEY \ + --listen tcp://0.0.0.0:$NODEPORT --public http://localhost:$NODEPORT --routing tree --noTLS | + ts "Node-$n: " | tee $NODEDIR/node.log & + done + + echo "Waiting for nodes to start up" + for n in $(seq 4); do + NODEDIR=./nodes/node-$n + while ! [[ -S $NODEDIR/daemon.sock && -f $NODEDIR/node.log && $(cat $NODEDIR/node.log | wc -l) -ge 2 ]]; do + sleep .2 + done + done +} + +function init_dela() { + echo "Initializing dela" + echo " Share the certificate" + for n in $(seq 2 4); do + TOKEN_ARGS=$(dvoting --config ./nodes/node-1 minogrpc token) + NODEDIR=./nodes/node-$n + dvoting --config $NODEDIR minogrpc join --address //localhost:2002 $TOKEN_ARGS + done + + echo " Create a new chain with the nodes" + for n in $(seq 4); do + NODEDIR=./nodes/node-$n + # add node to the chain + MEMBERS="$MEMBERS --member $(dvoting --config $NODEDIR ordering export)" + done + dvoting --config ./nodes/node-1 ordering setup $MEMBERS + + echo " Authorize the signer to handle the access contract on each node" + for s in $(seq 4); do + NODEDIR=./nodes/node-$s + IDENTITY=$(crypto bls signer read --path $NODEDIR/private.key --format BASE64_PUBKEY) + for n in $(seq 4); do + NODEDIR=./nodes/node-$n + dvoting --config $NODEDIR access add --identity "$IDENTITY" + done + done + + echo " Update the access contract" + for n in $(seq 4); do + NODEDIR=./nodes/node-$n + IDENTITY=$(crypto bls signer read --path $NODEDIR/private.key --format BASE64_PUBKEY) + dvoting --config ./nodes/node-1 pool add --key ./nodes/node-1/private.key --args go.dedis.ch/dela.ContractArg \ + --args go.dedis.ch/dela.Access --args access:grant_id \ + --args 0300000000000000000000000000000000000000000000000000000000000000 --args access:grant_contract \ + --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $IDENTITY \ + --args access:command --args GRANT + done +} + +function kill_db() { + docker rm -f postgres_dvoting || true +} + +function init_db() { + kill_db + + echo "Starting postgres database" + docker run -d -v "$(pwd)/web/backend/src/migration.sql:/docker-entrypoint-initdb.d/init.sql" \ + -e POSTGRES_PASSWORD=$DATABASE_PASSWORD -e POSTGRES_USER=$DATABASE_USERNAME \ + --name postgres_dvoting -p 5432:5432 postgres:15 >/dev/null + + echo "Adding SCIPER to admin" + (cd web/backend && npx ts-node src/cli.ts addAdmin --sciper $SCIPER_ADMIN | grep -v Executing) +} + +function kill_backend() { + pkill -f "web/backend" || true +} + +function start_backend() { + kill_backend + keypair + + echo "Running backend" + (cd web/backend && npm run start-dev | ts "Backend: " &) +} + +function kill_frontend() { + pkill -f "web/frontend" || true +} + +function start_frontend() { + kill_frontend + keypair + + echo "Running frontend" + (cd web/frontend && npm run start-dev | ts "Frontend: " &) +} + +export SCIPER_ADMIN=100100 +export DATABASE_USERNAME=dvoting +export DATABASE_PASSWORD=postgres +export FRONT_END_URL="http://localhost:3000" +export DELA_NODE_URL="http://localhost:2003" +export BACKEND_HOST="localhost" +export BACKEND_PORT="6000" +export SESSION_SECRET="session secret" +export REACT_APP_NOMOCK=on + +if [[ "$1" == "clean" ]]; then + kill_frontend + kill_nodes + kill_backend + kill_db + exit +fi + +build_dela +init_nodes +init_dela +init_db +start_backend +start_frontend diff --git a/web/backend/package.json b/web/backend/package.json index abafc84ed..861cb4aa0 100644 --- a/web/backend/package.json +++ b/web/backend/package.json @@ -6,6 +6,7 @@ "type": "commonjs", "scripts": { "start": "ts-node -r dotenv/config src/Server.ts dotenv_config_path=config.env", + "start-dev": "NODE_ENV=development ts-node -r dotenv/config src/Server.ts dotenv_config_path=config.env", "dev": "./node_modules/.bin/nodemon", "eslint": "./node_modules/.bin/eslint .", "eslint-fix": "./node_modules/.bin/eslint . --fix", diff --git a/web/backend/src/controllers/authentication.ts b/web/backend/src/controllers/authentication.ts index fa224605d..8c1648cf5 100644 --- a/web/backend/src/controllers/authentication.ts +++ b/web/backend/src/controllers/authentication.ts @@ -5,6 +5,37 @@ import { getUserPermissions, setMapAuthorization } from '../authManager'; export const authenticationRouter = express.Router(); +authenticationRouter.get('/get_dev_login', (req, res) => { + if (process.env.NODE_ENV !== 'development') { + const err = `/get_dev_login can only be called in development: ${process.env.NODE_ENV}`; + console.error(err); + res.status(500).send(err); + return; + } + if (process.env.SCIPER_ADMIN === undefined) { + const err = 'Please set SCIPER_ADMIN for /get/dev/login endpoint'; + console.error(err); + res.status(500).send(err); + return; + } + const sciper = parseInt(process.env.SCIPER_ADMIN, 10); + if (sciper < 100000 || sciper > 999999) { + const err = 'SCIPER_ADMIN must be between 100000 and 999999 included'; + console.error(err); + res.status(500).send(err); + return; + } + req.session.userId = sciper; + req.session.lastName = 'develo'; + req.session.firstName = 'pment'; + + const sciperSessions = sciper2sess.get(req.session.userId) || new Set(); + sciperSessions.add(req.sessionID); + sciper2sess.set(sciper, sciperSessions); + + res.redirect('/logged'); +}); + // This is via this endpoint that the client request the tequila key, this key // will then be used for redirection on the tequila server authenticationRouter.get('/get_teq_key', (req, res) => { diff --git a/web/backend/yarn.lock b/web/backend/yarn.lock index a1b7c8d97..2c194d20e 100644 --- a/web/backend/yarn.lock +++ b/web/backend/yarn.lock @@ -69,14 +69,14 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@lmdb/lmdb-linux-x64@2.4.5": - "integrity" "sha512-p2jWhERu6Mdrm7HmPwucbvrVYNCo+NZNz9YRFGc/91zuslqCr12jzNYpXy9j+ZtxqEC/dbZUkta29FESzO3FZA==" - "resolved" "https://registry.npmjs.org/@lmdb/lmdb-linux-x64/-/lmdb-linux-x64-2.4.5.tgz" +"@lmdb/lmdb-darwin-arm64@2.4.5": + "integrity" "sha512-JlYSjhyPUQI2dyH497WkZ+AqPQZZ0v3xyAmjMpKrucgnoPGoNbSYg/LNvfVx9WE2iQunZ7vUkofunFZxuQLDcQ==" + "resolved" "https://registry.npmjs.org/@lmdb/lmdb-darwin-arm64/-/lmdb-darwin-arm64-2.4.5.tgz" "version" "2.4.5" -"@msgpackr-extract/msgpackr-extract-linux-x64@2.0.2": - "integrity" "sha512-zrBHaePwcv4cQXxzYgNj0+A8I1uVN97E7/3LmkRocYZ+rMwUsnPpp4RuTAHSRoKlTQV3nSdCQW4Qdt4MXw/iHw==" - "resolved" "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-2.0.2.tgz" +"@msgpackr-extract/msgpackr-extract-darwin-arm64@2.0.2": + "integrity" "sha512-FMX5i7a+ojIguHpWbzh5MCsCouJkwf4z4ejdUY/fsgB9Vkdak4ZnoIEskOyOUMMB4lctiZFGszFQJXUeFL8tRg==" + "resolved" "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-2.0.2.tgz" "version" "2.0.2" "@nodelib/fs.scandir@2.1.5": @@ -678,6 +678,11 @@ "readable-stream" "^3.6.0" "safe-buffer" "^5.2.0" +"buffer-writer@2.0.0": + "integrity" "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" + "resolved" "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz" + "version" "2.0.0" + "buffer-xor@^1.0.3": "integrity" "sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ==" "resolved" "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz" @@ -805,6 +810,11 @@ dependencies: "delayed-stream" "~1.0.0" +"commander@^11.0.0": + "integrity" "sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==" + "resolved" "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz" + "version" "11.0.0" + "commander@^2.20.3": "integrity" "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" "resolved" "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz" @@ -1565,6 +1575,11 @@ "resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" "version" "1.0.0" +"fsevents@~2.3.2": + "integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==" + "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + "version" "2.3.2" + "function-bind@^1.1.1": "integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" "resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" @@ -2518,6 +2533,11 @@ "registry-url" "^5.0.0" "semver" "^6.2.0" +"packet-reader@1.0.0": + "integrity" "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" + "resolved" "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz" + "version" "1.0.0" + "parent-module@^1.0.0": "integrity" "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==" "resolved" "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz" @@ -2582,16 +2602,91 @@ "safe-buffer" "^5.0.1" "sha.js" "^2.4.8" -"pg-connection-string@^2.5.0": - "integrity" "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==" - "resolved" "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz" - "version" "2.5.0" +"pg-cloudflare@^1.1.1": + "integrity" "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==" + "resolved" "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz" + "version" "1.1.1" + +"pg-connection-string@^2.5.0", "pg-connection-string@^2.6.2": + "integrity" "sha512-ch6OwaeaPYcova4kKZ15sbJ2hKb/VP48ZD2gE7i1J+L4MspCtBMAx8nMgz7bksc7IojCIIWuEhHibSMFH8m8oA==" + "resolved" "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.2.tgz" + "version" "2.6.2" + +"pg-int8@1.0.1": + "integrity" "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==" + "resolved" "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz" + "version" "1.0.1" + +"pg-pool@^3.6.1": + "integrity" "sha512-jizsIzhkIitxCGfPRzJn1ZdcosIt3pz9Sh3V01fm1vZnbnCMgmGl5wvGGdNN2EL9Rmb0EcFoCkixH4Pu+sP9Og==" + "resolved" "https://registry.npmjs.org/pg-pool/-/pg-pool-3.6.1.tgz" + "version" "3.6.1" + +"pg-protocol@^1.6.0": + "integrity" "sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q==" + "resolved" "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.0.tgz" + "version" "1.6.0" + +"pg-types@^2.1.0": + "integrity" "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==" + "resolved" "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz" + "version" "2.2.0" + dependencies: + "pg-int8" "1.0.1" + "postgres-array" "~2.0.0" + "postgres-bytea" "~1.0.0" + "postgres-date" "~1.0.4" + "postgres-interval" "^1.1.0" + +"pg@^8.11.1", "pg@>=8.0": + "integrity" "sha512-l4rmVeV8qTIrrPrIR3kZQqBgSN93331s9i6wiUiLOSk0Q7PmUxZD/m1rQI622l3NfqBby9Ar5PABfS/SulfieQ==" + "resolved" "https://registry.npmjs.org/pg/-/pg-8.11.2.tgz" + "version" "8.11.2" + dependencies: + "buffer-writer" "2.0.0" + "packet-reader" "1.0.0" + "pg-connection-string" "^2.6.2" + "pg-pool" "^3.6.1" + "pg-protocol" "^1.6.0" + "pg-types" "^2.1.0" + "pgpass" "1.x" + optionalDependencies: + "pg-cloudflare" "^1.1.1" + +"pgpass@1.x": + "integrity" "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==" + "resolved" "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz" + "version" "1.0.5" + dependencies: + "split2" "^4.1.0" "picomatch@^2.0.4", "picomatch@^2.2.1", "picomatch@^2.2.3", "picomatch@^2.3.1": "integrity" "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" "resolved" "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz" "version" "2.3.1" +"postgres-array@~2.0.0": + "integrity" "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==" + "resolved" "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz" + "version" "2.0.0" + +"postgres-bytea@~1.0.0": + "integrity" "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==" + "resolved" "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz" + "version" "1.0.0" + +"postgres-date@~1.0.4": + "integrity" "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==" + "resolved" "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz" + "version" "1.0.7" + +"postgres-interval@^1.1.0": + "integrity" "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==" + "resolved" "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz" + "version" "1.2.0" + dependencies: + "xtend" "^4.0.0" + "prelude-ls@^1.2.1": "integrity" "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==" "resolved" "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz" @@ -2993,6 +3088,11 @@ "resolved" "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz" "version" "3.0.0" +"split2@^4.1.0": + "integrity" "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==" + "resolved" "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz" + "version" "4.2.0" + "statuses@2.0.1": "integrity" "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" "resolved" "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz" @@ -3362,6 +3462,11 @@ "commander" "^2.20.3" "cssfilter" "0.0.10" +"xtend@^4.0.0": + "integrity" "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" + "resolved" "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz" + "version" "4.0.2" + "yallist@^2.1.2": "integrity" "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" "resolved" "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz" diff --git a/web/frontend/package.json b/web/frontend/package.json index 9475b197b..949c866b7 100644 --- a/web/frontend/package.json +++ b/web/frontend/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "start": "HTTPS=true react-scripts start", + "start-dev": "react-scripts start", "build": "HTTPS=true react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", diff --git a/web/frontend/src/components/utils/Endpoints.tsx b/web/frontend/src/components/utils/Endpoints.tsx index 93b8b4216..070589c4b 100644 --- a/web/frontend/src/components/utils/Endpoints.tsx +++ b/web/frontend/src/components/utils/Endpoints.tsx @@ -1,5 +1,6 @@ // information accessed through the middleware export const ENDPOINT_GET_TEQ_KEY = '/api/get_teq_key'; +export const ENDPOINT_DEV_LOGIN = '/api/get_dev_login'; export const ENDPOINT_PERSONAL_INFO = '/api/personal_info'; export const ENDPOINT_LOGOUT = '/api/logout'; export const ENDPOINT_USER_RIGHTS = '/api/user_rights'; diff --git a/web/frontend/src/pages/session/HandleLogin.tsx b/web/frontend/src/pages/session/HandleLogin.tsx index a204facdf..88d5326b1 100644 --- a/web/frontend/src/pages/session/HandleLogin.tsx +++ b/web/frontend/src/pages/session/HandleLogin.tsx @@ -1,11 +1,18 @@ -import { ENDPOINT_GET_TEQ_KEY } from 'components/utils/Endpoints'; +import { ENDPOINT_DEV_LOGIN, ENDPOINT_GET_TEQ_KEY } from 'components/utils/Endpoints'; import { FlashLevel, FlashState } from 'index'; // The backend will provide the client the URL to make a Tequila authentication. // We therefore redirect to this address. const handleLogin = async (fctx: FlashState) => { try { - const res = await fetch(ENDPOINT_GET_TEQ_KEY); + let res; + if (process.env.NODE_ENV === 'development') { + await fetch(ENDPOINT_DEV_LOGIN); + window.location.reload(); + return; + } else { + res = await fetch(ENDPOINT_GET_TEQ_KEY); + } const d = new Date(); d.setTime(d.getTime() + 120000); From da31220c53e4b88e941cd4ee5efa7594e6ee53f7 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Wed, 27 Sep 2023 10:43:49 +0200 Subject: [PATCH 008/256] @pierluca's comments --- web/backend/src/authManager.ts | 11 ++ web/backend/src/cli.ts | 13 +- web/backend/src/controllers/authentication.ts | 16 +-- web/backend/src/controllers/users.ts | 10 +- web/backend/yarn.lock | 125 ++---------------- 5 files changed, 39 insertions(+), 136 deletions(-) diff --git a/web/backend/src/authManager.ts b/web/backend/src/authManager.ts index aaceb9b7b..5885d707b 100644 --- a/web/backend/src/authManager.ts +++ b/web/backend/src/authManager.ts @@ -21,6 +21,7 @@ export const PERMISSIONS = { }; let authEnforcer: Enforcer; + /* We use the postgres adapter to store the Casbin policies we initialize the adapter with the connection string and the migrate option @@ -83,3 +84,13 @@ export function setMapAuthorization(list: string[][]): Map } return userRights; } + +// Reads a SCIPER from a string and returns the number. If the SCIPER is not in +// the range between 100000 and 999999, an error is thrown. +export function readSCIPER(s: string): number { + const n = parseInt(s, 10); + if (n < 100000 || n > 999999) { + throw new Error(`SCIPER is out of range. ${n} is not between 100000 and 999999`); + } + return n; +} diff --git a/web/backend/src/cli.ts b/web/backend/src/cli.ts index 3a37593e4..e8a740174 100755 --- a/web/backend/src/cli.ts +++ b/web/backend/src/cli.ts @@ -12,7 +12,7 @@ import { SequelizeAdapter } from 'casbin-sequelize-adapter'; import { newEnforcer } from 'casbin'; import { curve } from '@dedis/kyber'; import * as fs from 'fs'; -import { PERMISSIONS } from './authManager'; +import { PERMISSIONS, readSCIPER } from './authManager'; const program = new Command(); @@ -95,16 +95,13 @@ program const scipers: Array = data.split('\n'); const policies = []; for (let i = 0; i < scipers.length; i += 1) { - const sciper: number = Number(scipers[i]); - if (Number.isNaN(sciper)) { - throw new InvalidArgumentError(`SCIPER '${sciper}' on line ${i + 1} is not a number`); - } - if (sciper > 999999 || sciper < 100000) { + try { + policies[i] = [readSCIPER(scipers[i]), electionId, PERMISSIONS.ACTIONS.VOTE]; + } catch (e) { throw new InvalidArgumentError( - `SCIPER '${sciper}' on line ${i + 1} is outside acceptable range (100000..999999)` + `SCIPER '${scipers[i]}' on line ${i + 1} is not a valid sciper: ${e}` ); } - policies[i] = [scipers[i], electionId, PERMISSIONS.ACTIONS.VOTE]; } const enforcer = await initEnforcer(); await enforcer.addPolicies(policies); diff --git a/web/backend/src/controllers/authentication.ts b/web/backend/src/controllers/authentication.ts index 8c1648cf5..2a731391c 100644 --- a/web/backend/src/controllers/authentication.ts +++ b/web/backend/src/controllers/authentication.ts @@ -1,7 +1,7 @@ import express from 'express'; import axios, { AxiosError } from 'axios'; import { sciper2sess } from '../session'; -import { getUserPermissions, setMapAuthorization } from '../authManager'; +import { getUserPermissions, readSCIPER, setMapAuthorization } from '../authManager'; export const authenticationRouter = express.Router(); @@ -18,20 +18,20 @@ authenticationRouter.get('/get_dev_login', (req, res) => { res.status(500).send(err); return; } - const sciper = parseInt(process.env.SCIPER_ADMIN, 10); - if (sciper < 100000 || sciper > 999999) { - const err = 'SCIPER_ADMIN must be between 100000 and 999999 included'; + try { + req.session.userId = readSCIPER(process.env.SCIPER_ADMIN); + req.session.lastName = 'develo'; + req.session.firstName = 'pment'; + } catch (e) { + const err = `Invalid SCIPER_ADMIN: ${e}`; console.error(err); res.status(500).send(err); return; } - req.session.userId = sciper; - req.session.lastName = 'develo'; - req.session.firstName = 'pment'; const sciperSessions = sciper2sess.get(req.session.userId) || new Set(); sciperSessions.add(req.sessionID); - sciper2sess.set(sciper, sciperSessions); + sciper2sess.set(req.session.userId, sciperSessions); res.redirect('/logged'); }); diff --git a/web/backend/src/controllers/users.ts b/web/backend/src/controllers/users.ts index 723848b58..48922afe5 100644 --- a/web/backend/src/controllers/users.ts +++ b/web/backend/src/controllers/users.ts @@ -1,6 +1,6 @@ import express from 'express'; -import { isAuthorized, PERMISSIONS } from '../authManager'; +import { isAuthorized, PERMISSIONS, readSCIPER } from '../authManager'; export const usersRouter = express.Router(); @@ -26,13 +26,13 @@ usersRouter.post('/add_role', (req, res, next) => { return; } - const { sciper } = req.body; - - // The sciper has to contain 6 numbers - if (sciper > 999999 || sciper < 100000) { + try { + readSCIPER(req.body.sciper); + } catch (e) { res.status(400).send('Sciper length is incorrect'); return; } + next(); // Call https://search-api.epfl.ch/api/ldap?q=228271, if the answer is // empty then sciper unknown, otherwise add it in userDB diff --git a/web/backend/yarn.lock b/web/backend/yarn.lock index 2c194d20e..a1b7c8d97 100644 --- a/web/backend/yarn.lock +++ b/web/backend/yarn.lock @@ -69,14 +69,14 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@lmdb/lmdb-darwin-arm64@2.4.5": - "integrity" "sha512-JlYSjhyPUQI2dyH497WkZ+AqPQZZ0v3xyAmjMpKrucgnoPGoNbSYg/LNvfVx9WE2iQunZ7vUkofunFZxuQLDcQ==" - "resolved" "https://registry.npmjs.org/@lmdb/lmdb-darwin-arm64/-/lmdb-darwin-arm64-2.4.5.tgz" +"@lmdb/lmdb-linux-x64@2.4.5": + "integrity" "sha512-p2jWhERu6Mdrm7HmPwucbvrVYNCo+NZNz9YRFGc/91zuslqCr12jzNYpXy9j+ZtxqEC/dbZUkta29FESzO3FZA==" + "resolved" "https://registry.npmjs.org/@lmdb/lmdb-linux-x64/-/lmdb-linux-x64-2.4.5.tgz" "version" "2.4.5" -"@msgpackr-extract/msgpackr-extract-darwin-arm64@2.0.2": - "integrity" "sha512-FMX5i7a+ojIguHpWbzh5MCsCouJkwf4z4ejdUY/fsgB9Vkdak4ZnoIEskOyOUMMB4lctiZFGszFQJXUeFL8tRg==" - "resolved" "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-2.0.2.tgz" +"@msgpackr-extract/msgpackr-extract-linux-x64@2.0.2": + "integrity" "sha512-zrBHaePwcv4cQXxzYgNj0+A8I1uVN97E7/3LmkRocYZ+rMwUsnPpp4RuTAHSRoKlTQV3nSdCQW4Qdt4MXw/iHw==" + "resolved" "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-2.0.2.tgz" "version" "2.0.2" "@nodelib/fs.scandir@2.1.5": @@ -678,11 +678,6 @@ "readable-stream" "^3.6.0" "safe-buffer" "^5.2.0" -"buffer-writer@2.0.0": - "integrity" "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" - "resolved" "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz" - "version" "2.0.0" - "buffer-xor@^1.0.3": "integrity" "sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ==" "resolved" "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz" @@ -810,11 +805,6 @@ dependencies: "delayed-stream" "~1.0.0" -"commander@^11.0.0": - "integrity" "sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==" - "resolved" "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz" - "version" "11.0.0" - "commander@^2.20.3": "integrity" "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" "resolved" "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz" @@ -1575,11 +1565,6 @@ "resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" "version" "1.0.0" -"fsevents@~2.3.2": - "integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==" - "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" - "version" "2.3.2" - "function-bind@^1.1.1": "integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" "resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" @@ -2533,11 +2518,6 @@ "registry-url" "^5.0.0" "semver" "^6.2.0" -"packet-reader@1.0.0": - "integrity" "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" - "resolved" "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz" - "version" "1.0.0" - "parent-module@^1.0.0": "integrity" "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==" "resolved" "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz" @@ -2602,91 +2582,16 @@ "safe-buffer" "^5.0.1" "sha.js" "^2.4.8" -"pg-cloudflare@^1.1.1": - "integrity" "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==" - "resolved" "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz" - "version" "1.1.1" - -"pg-connection-string@^2.5.0", "pg-connection-string@^2.6.2": - "integrity" "sha512-ch6OwaeaPYcova4kKZ15sbJ2hKb/VP48ZD2gE7i1J+L4MspCtBMAx8nMgz7bksc7IojCIIWuEhHibSMFH8m8oA==" - "resolved" "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.2.tgz" - "version" "2.6.2" - -"pg-int8@1.0.1": - "integrity" "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==" - "resolved" "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz" - "version" "1.0.1" - -"pg-pool@^3.6.1": - "integrity" "sha512-jizsIzhkIitxCGfPRzJn1ZdcosIt3pz9Sh3V01fm1vZnbnCMgmGl5wvGGdNN2EL9Rmb0EcFoCkixH4Pu+sP9Og==" - "resolved" "https://registry.npmjs.org/pg-pool/-/pg-pool-3.6.1.tgz" - "version" "3.6.1" - -"pg-protocol@^1.6.0": - "integrity" "sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q==" - "resolved" "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.0.tgz" - "version" "1.6.0" - -"pg-types@^2.1.0": - "integrity" "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==" - "resolved" "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz" - "version" "2.2.0" - dependencies: - "pg-int8" "1.0.1" - "postgres-array" "~2.0.0" - "postgres-bytea" "~1.0.0" - "postgres-date" "~1.0.4" - "postgres-interval" "^1.1.0" - -"pg@^8.11.1", "pg@>=8.0": - "integrity" "sha512-l4rmVeV8qTIrrPrIR3kZQqBgSN93331s9i6wiUiLOSk0Q7PmUxZD/m1rQI622l3NfqBby9Ar5PABfS/SulfieQ==" - "resolved" "https://registry.npmjs.org/pg/-/pg-8.11.2.tgz" - "version" "8.11.2" - dependencies: - "buffer-writer" "2.0.0" - "packet-reader" "1.0.0" - "pg-connection-string" "^2.6.2" - "pg-pool" "^3.6.1" - "pg-protocol" "^1.6.0" - "pg-types" "^2.1.0" - "pgpass" "1.x" - optionalDependencies: - "pg-cloudflare" "^1.1.1" - -"pgpass@1.x": - "integrity" "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==" - "resolved" "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz" - "version" "1.0.5" - dependencies: - "split2" "^4.1.0" +"pg-connection-string@^2.5.0": + "integrity" "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==" + "resolved" "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz" + "version" "2.5.0" "picomatch@^2.0.4", "picomatch@^2.2.1", "picomatch@^2.2.3", "picomatch@^2.3.1": "integrity" "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" "resolved" "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz" "version" "2.3.1" -"postgres-array@~2.0.0": - "integrity" "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==" - "resolved" "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz" - "version" "2.0.0" - -"postgres-bytea@~1.0.0": - "integrity" "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==" - "resolved" "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz" - "version" "1.0.0" - -"postgres-date@~1.0.4": - "integrity" "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==" - "resolved" "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz" - "version" "1.0.7" - -"postgres-interval@^1.1.0": - "integrity" "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==" - "resolved" "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz" - "version" "1.2.0" - dependencies: - "xtend" "^4.0.0" - "prelude-ls@^1.2.1": "integrity" "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==" "resolved" "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz" @@ -3088,11 +2993,6 @@ "resolved" "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz" "version" "3.0.0" -"split2@^4.1.0": - "integrity" "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==" - "resolved" "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz" - "version" "4.2.0" - "statuses@2.0.1": "integrity" "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" "resolved" "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz" @@ -3462,11 +3362,6 @@ "commander" "^2.20.3" "cssfilter" "0.0.10" -"xtend@^4.0.0": - "integrity" "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" - "resolved" "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz" - "version" "4.0.2" - "yallist@^2.1.2": "integrity" "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" "resolved" "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz" From ca3ce8df0087f078940cb8c8eca29e58ffc20aef Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Tue, 26 Sep 2023 16:37:27 +0200 Subject: [PATCH 009/256] Modify scripts for login, creating a form, and voting --- .gitignore | 1 + scripts/README.md | 18 ++++++++++ scripts/local_forms.sh | 44 ++++++++++++++++++++++++ scripts/local_login.sh | 6 ++++ scripts/local_proxies.sh | 15 ++++++++ scripts/local_vars.sh | 9 +++++ scripts/local_votes.sh | 20 +++++++++++ scripts/run_local.sh | 74 +++++++++++++++++++++++++++------------- 8 files changed, 163 insertions(+), 24 deletions(-) create mode 100644 scripts/README.md create mode 100755 scripts/local_forms.sh create mode 100755 scripts/local_login.sh create mode 100755 scripts/local_proxies.sh create mode 100644 scripts/local_vars.sh create mode 100755 scripts/local_votes.sh diff --git a/.gitignore b/.gitignore index 752b0635c..361116e9b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ deb-package/dist/** dela/ bin/ nodes/ +cookies.txt diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 000000000..80ef9ba27 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,18 @@ +# Scripts for running D-voting locally + +The following scripts are available to configure and run D-voting locally. They should be called in this order: + +- `run_local.sh` - sets up a complete system with 4 nodes, the db, the authentication-server, + and the frontend. + The script runs only the DB in a docker environment, all the rest is run directly on the machine. + This allows for easier debugging and faster testing of the different parts, mainly the + authentication-server, but also the frontend. + For debugging Dela, you still need to re-run everything. +- `local_proxies.sh` needs to be run once after the `run_local.sh` script +- `local_forms.sh` creates a new form and prints its ID +- `local_votes.sh` casts the given number of votes. THE ENCRYPTION IS WRONG AND WILL NOT WORK. But it allows to test + missing votes + +The following script is only called by the other scripts: + +- `local_login.sh` logs into the frontend and stores the cookie diff --git a/scripts/local_forms.sh b/scripts/local_forms.sh new file mode 100755 index 000000000..ad29d77b3 --- /dev/null +++ b/scripts/local_forms.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +. "$SCRIPT_DIR/local_login.sh" + +echo "add form" +RESP=$(curl -sk "$FRONTEND_URL/api/evoting/forms" -X POST -H 'Content-Type: application/json' -b cookies.txt --data-raw '{"Configuration":{"MainTitle":"{\"en\":\"Colours\",\"fr\":\"\",\"de\":\"\"}","Scaffold":[{"ID":"5DRhKsY2","Title":"Colours","TitleFr":"","TitleDe":"","Order":["d0mSUfpv"],"Ranks":[],"Selects":[{"ID":"d0mSUfpv","Title":"{\"en\":\"RGB\",\"fr\":\"\",\"de\":\"\"}","TitleDe":"","TitleFr":"","MaxN":1,"MinN":1,"Choices":["{\"en\":\"Red\"}","{\"en\":\"Green\"}","{\"en\":\"Blue\"}"],"ChoicesMap":{},"Hint":"{\"en\":\"\",\"fr\":\"\",\"de\":\"\"}","HintFr":"","HintDe":""}],"Texts":[],"Subjects":[]}]}}') +FORMID=$(echo "$RESP" | jq -r .FormID) +echo "add permissions - it's normal to have a timeout error after this command" +curl -k "$FRONTEND_URL/api/evoting/authorizations" -X PUT -H 'Content-Type: application/json' -b cookies.txt --data "$(jq -cn --arg FormID $FORMID '$ARGS.named')" -m 1 + +echo "initialize nodes" +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -b cookies.txt --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2001 '$ARGS.named')" +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -b cookies.txt --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2003 '$ARGS.named')" +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -b cookies.txt --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2005 '$ARGS.named')" +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors" -X POST -H 'Content-Type: application/json' -b cookies.txt --data "$(jq -cn --arg FormID $FORMID --arg Proxy http://localhost:2007 '$ARGS.named')" + +echo "set node up" +curl -k "$FRONTEND_URL/api/evoting/services/dkg/actors/$FORMID" -X PUT -H 'Content-Type: application/json' -b cookies.txt --data-raw '{"Action":"setup","Proxy":"http://localhost:2001"}' + +echo "open election" +sleep 8 +curl -k "$FRONTEND_URL/api/evoting/forms/$FORMID" -X PUT -b cookies.txt -H 'Content-Type: application/json' --data-raw '{"Action":"open"}' >/dev/null +echo "Form with ID $FORMID has been set up" + +echo "Adding $SCIPER_ADMIN to voters" +tmpfile=$(mktemp) +echo -n "$SCIPER_ADMIN" > "$tmpfile" +(cd web/backend && npx ts-node src/cli.ts addVoters --election-id $FORMID --scipers-file "$tmpfile" ) +echo "Restarting backend to take into account voters" +"$SCRIPT_DIR/run_local.sh" backend +. "$SCRIPT_DIR/local_login.sh" + +if [[ "$1" ]]; then + echo "Casting $1 votes" + for i in $(seq $1); do + echo "Casting vote #$i" + curl -sk "$FRONTEND_URL/api/evoting/forms/$FORMID/vote" -X POST -H 'Content-Type: Application/json' \ + -H "Origin: $FRONTEND_URL" -b cookies.txt \ + --data-raw '{"Ballot":[{"K":[54,152,33,11,201,233,212,157,204,176,136,138,54,213,239,198,79,55,71,26,91,244,98,215,208,239,48,253,195,53,192,94],"C":[105,121,87,164,68,242,166,194,222,179,253,231,213,63,34,66,212,41,214,175,178,83,229,156,255,38,55,234,168,222,81,185]}],"UserID":null}' \ + >/dev/null + sleep 1 + done +fi diff --git a/scripts/local_login.sh b/scripts/local_login.sh new file mode 100755 index 000000000..6ab1435a8 --- /dev/null +++ b/scripts/local_login.sh @@ -0,0 +1,6 @@ +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +. "$SCRIPT_DIR/local_vars.sh" + +if ! [[ -f cookies.txt ]]; then + curl -k "$FRONTEND_URL/api/get_dev_login" -X GET -c cookies.txt -o /dev/null -s +fi diff --git a/scripts/local_proxies.sh b/scripts/local_proxies.sh new file mode 100755 index 000000000..af64ce0b7 --- /dev/null +++ b/scripts/local_proxies.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +. "$SCRIPT_DIR/local_login.sh" + +echo "adding proxies"; + +for node in $( seq 0 3 ); do + NodeAddr="localhost:$(( 2000 + node * 2))" + ProxyAddr="localhost:$(( 2001 + node * 2))" + echo -n "Adding proxy for node $(( node + 1)): " + curl -sk "$FRONTEND_URL/api/proxies/" -X POST -H 'Content-Type: application/json' -b cookies.txt \ + --data-raw "{\"NodeAddr\":\"$LocalAddr\",\"Proxy\":\"$ProxyAddr\"}" + echo +done diff --git a/scripts/local_vars.sh b/scripts/local_vars.sh new file mode 100644 index 000000000..c466657c1 --- /dev/null +++ b/scripts/local_vars.sh @@ -0,0 +1,9 @@ +export SCIPER_ADMIN=100100 +export DATABASE_USERNAME=dvoting +export DATABASE_PASSWORD=postgres +export FRONTEND_URL="http://localhost:3000" +export DELA_NODE_URL="http://localhost:2001" +export BACKEND_HOST="localhost" +export BACKEND_PORT="6000" +export SESSION_SECRET="session secret" +export REACT_APP_NOMOCK=on diff --git a/scripts/local_votes.sh b/scripts/local_votes.sh new file mode 100755 index 000000000..c48a90d03 --- /dev/null +++ b/scripts/local_votes.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +if ! [[ "$1" && "$2" ]]; then + echo "Syntax is: $0 #votes FORMID" + exit 1 +fi + +SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) +. "$SCRIPT_DIR/local_login.sh" + +FORMID=$2 +echo "Casting $1 votes to form $FORMID" +for i in $(seq $1); do + echo "Casting vote #$i" + curl -sk "$FRONTEND_URL/api/evoting/forms/$FORMID/vote" -X POST -H 'Content-Type: Application/json' \ + -H "Origin: $FRONTEND_URL" -b cookies.txt \ + --data-raw '{"Ballot":[{"K":[54,152,33,11,201,233,212,157,204,176,136,138,54,213,239,198,79,55,71,26,91,244,98,215,208,239,48,253,195,53,192,94],"C":[105,121,87,164,68,242,166,194,222,179,253,231,213,63,34,66,212,41,214,175,178,83,229,156,255,38,55,234,168,222,81,185]}],"UserID":null}' \ + >/dev/null + sleep 1 +done diff --git a/scripts/run_local.sh b/scripts/run_local.sh index 3b9f63be2..4692b527f 100755 --- a/scripts/run_local.sh +++ b/scripts/run_local.sh @@ -11,6 +11,9 @@ if [[ $(git rev-parse --show-toplevel) != $(pwd) ]]; then exit 1 fi +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +. "$SCRIPT_DIR/local_vars.sh" + asdf_shell() { if ! asdf list "$1" | grep -wq "$2"; then asdf install "$1" "$2" @@ -66,13 +69,13 @@ function init_nodes() { echo "Starting nodes" for n in $(seq 4); do - NODEPORT=$((2000 + n * 2)) - PROXYPORT=$((2001 + n * 2)) + NODEPORT=$((2000 + n * 2 - 2)) + PROXYPORT=$((2001 + n * 2 - 2)) NODEDIR=./nodes/node-$n mkdir -p $NODEDIR rm -f $NODEDIR/node.log dvoting --config $NODEDIR start --postinstall --proxyaddr :$PROXYPORT --proxykey $PUBLIC_KEY \ - --listen tcp://0.0.0.0:$NODEPORT --public http://localhost:$NODEPORT --routing tree --noTLS | + --listen tcp://0.0.0.0:$NODEPORT --public http://localhost:$NODEPORT --routing tree | ts "Node-$n: " | tee $NODEDIR/node.log & done @@ -91,7 +94,7 @@ function init_dela() { for n in $(seq 2 4); do TOKEN_ARGS=$(dvoting --config ./nodes/node-1 minogrpc token) NODEDIR=./nodes/node-$n - dvoting --config $NODEDIR minogrpc join --address //localhost:2002 $TOKEN_ARGS + dvoting --config $NODEDIR minogrpc join --address //localhost:2000 $TOKEN_ARGS done echo " Create a new chain with the nodes" @@ -122,6 +125,8 @@ function init_dela() { --args go.dedis.ch/dela.Evoting --args access:grant_command --args all --args access:identity --args $IDENTITY \ --args access:command --args GRANT done + + rm -f cookies.txt } function kill_db() { @@ -136,12 +141,13 @@ function init_db() { -e POSTGRES_PASSWORD=$DATABASE_PASSWORD -e POSTGRES_USER=$DATABASE_USERNAME \ --name postgres_dvoting -p 5432:5432 postgres:15 >/dev/null - echo "Adding SCIPER to admin" + echo "Adding $SCIPER_ADMIN to admin" (cd web/backend && npx ts-node src/cli.ts addAdmin --sciper $SCIPER_ADMIN | grep -v Executing) } function kill_backend() { pkill -f "web/backend" || true + rm -f cookies.txt } function start_backend() { @@ -150,6 +156,8 @@ function start_backend() { echo "Running backend" (cd web/backend && npm run start-dev | ts "Backend: " &) + + while ! lsof -ln | grep -q :6000; do sleep .1; done } function kill_frontend() { @@ -164,27 +172,45 @@ function start_frontend() { (cd web/frontend && npm run start-dev | ts "Frontend: " &) } -export SCIPER_ADMIN=100100 -export DATABASE_USERNAME=dvoting -export DATABASE_PASSWORD=postgres -export FRONT_END_URL="http://localhost:3000" -export DELA_NODE_URL="http://localhost:2003" -export BACKEND_HOST="localhost" -export BACKEND_PORT="6000" -export SESSION_SECRET="session secret" -export REACT_APP_NOMOCK=on - -if [[ "$1" == "clean" ]]; then +case "$1" in +clean) kill_frontend kill_nodes kill_backend kill_db exit -fi - -build_dela -init_nodes -init_dela -init_db -start_backend -start_frontend + ;; + +build) + build_dela + ;; + +init_nodes) + init_nodes + ;; + +init_dela) + init_dela + ;; + +init_db) + init_db + ;; + +backend) + start_backend + ;; + +frontend) + start_frontend + ;; + +*) + build_dela + init_nodes + init_dela + init_db + start_backend + start_frontend + ;; +esac From 571a94fcefe40c745f74eea936ed2e4f2ad2e318 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Thu, 28 Sep 2023 15:51:20 +0200 Subject: [PATCH 010/256] Fixing scripts to correctly handle the proxy database The proxy database is not in Postgres, but another llmdb. --- scripts/local_proxies.sh | 4 ++-- scripts/local_vars.sh | 2 ++ scripts/run_local.sh | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/local_proxies.sh b/scripts/local_proxies.sh index af64ce0b7..12d78b298 100755 --- a/scripts/local_proxies.sh +++ b/scripts/local_proxies.sh @@ -7,9 +7,9 @@ echo "adding proxies"; for node in $( seq 0 3 ); do NodeAddr="localhost:$(( 2000 + node * 2))" - ProxyAddr="localhost:$(( 2001 + node * 2))" + ProxyAddr="http://localhost:$(( 2001 + node * 2))" echo -n "Adding proxy for node $(( node + 1)): " curl -sk "$FRONTEND_URL/api/proxies/" -X POST -H 'Content-Type: application/json' -b cookies.txt \ - --data-raw "{\"NodeAddr\":\"$LocalAddr\",\"Proxy\":\"$ProxyAddr\"}" + --data-raw "{\"NodeAddr\":\"$NodeAddr\",\"Proxy\":\"$ProxyAddr\"}" echo done diff --git a/scripts/local_vars.sh b/scripts/local_vars.sh index c466657c1..bb3723c0c 100644 --- a/scripts/local_vars.sh +++ b/scripts/local_vars.sh @@ -7,3 +7,5 @@ export BACKEND_HOST="localhost" export BACKEND_PORT="6000" export SESSION_SECRET="session secret" export REACT_APP_NOMOCK=on +# shellcheck disable=SC2155 +export DB_PATH="$(pwd)/nodes/llmdb" diff --git a/scripts/run_local.sh b/scripts/run_local.sh index 4692b527f..0f1c08292 100755 --- a/scripts/run_local.sh +++ b/scripts/run_local.sh @@ -131,6 +131,7 @@ function init_dela() { function kill_db() { docker rm -f postgres_dvoting || true + rm -rf nodes/llmdb* } function init_db() { From ad74a7df851d8a85794e85dae6d015a07a9e59d1 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Thu, 28 Sep 2023 15:55:27 +0200 Subject: [PATCH 011/256] Yarn lockfile update for Mac MacOSX with arm needs some more entrires in the yarn lockfile. --- web/backend/yarn.lock | 125 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 115 insertions(+), 10 deletions(-) diff --git a/web/backend/yarn.lock b/web/backend/yarn.lock index a1b7c8d97..2c194d20e 100644 --- a/web/backend/yarn.lock +++ b/web/backend/yarn.lock @@ -69,14 +69,14 @@ "@jridgewell/resolve-uri" "^3.0.3" "@jridgewell/sourcemap-codec" "^1.4.10" -"@lmdb/lmdb-linux-x64@2.4.5": - "integrity" "sha512-p2jWhERu6Mdrm7HmPwucbvrVYNCo+NZNz9YRFGc/91zuslqCr12jzNYpXy9j+ZtxqEC/dbZUkta29FESzO3FZA==" - "resolved" "https://registry.npmjs.org/@lmdb/lmdb-linux-x64/-/lmdb-linux-x64-2.4.5.tgz" +"@lmdb/lmdb-darwin-arm64@2.4.5": + "integrity" "sha512-JlYSjhyPUQI2dyH497WkZ+AqPQZZ0v3xyAmjMpKrucgnoPGoNbSYg/LNvfVx9WE2iQunZ7vUkofunFZxuQLDcQ==" + "resolved" "https://registry.npmjs.org/@lmdb/lmdb-darwin-arm64/-/lmdb-darwin-arm64-2.4.5.tgz" "version" "2.4.5" -"@msgpackr-extract/msgpackr-extract-linux-x64@2.0.2": - "integrity" "sha512-zrBHaePwcv4cQXxzYgNj0+A8I1uVN97E7/3LmkRocYZ+rMwUsnPpp4RuTAHSRoKlTQV3nSdCQW4Qdt4MXw/iHw==" - "resolved" "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-linux-x64/-/msgpackr-extract-linux-x64-2.0.2.tgz" +"@msgpackr-extract/msgpackr-extract-darwin-arm64@2.0.2": + "integrity" "sha512-FMX5i7a+ojIguHpWbzh5MCsCouJkwf4z4ejdUY/fsgB9Vkdak4ZnoIEskOyOUMMB4lctiZFGszFQJXUeFL8tRg==" + "resolved" "https://registry.npmjs.org/@msgpackr-extract/msgpackr-extract-darwin-arm64/-/msgpackr-extract-darwin-arm64-2.0.2.tgz" "version" "2.0.2" "@nodelib/fs.scandir@2.1.5": @@ -678,6 +678,11 @@ "readable-stream" "^3.6.0" "safe-buffer" "^5.2.0" +"buffer-writer@2.0.0": + "integrity" "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" + "resolved" "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz" + "version" "2.0.0" + "buffer-xor@^1.0.3": "integrity" "sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ==" "resolved" "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz" @@ -805,6 +810,11 @@ dependencies: "delayed-stream" "~1.0.0" +"commander@^11.0.0": + "integrity" "sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==" + "resolved" "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz" + "version" "11.0.0" + "commander@^2.20.3": "integrity" "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" "resolved" "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz" @@ -1565,6 +1575,11 @@ "resolved" "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" "version" "1.0.0" +"fsevents@~2.3.2": + "integrity" "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==" + "resolved" "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" + "version" "2.3.2" + "function-bind@^1.1.1": "integrity" "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" "resolved" "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" @@ -2518,6 +2533,11 @@ "registry-url" "^5.0.0" "semver" "^6.2.0" +"packet-reader@1.0.0": + "integrity" "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" + "resolved" "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz" + "version" "1.0.0" + "parent-module@^1.0.0": "integrity" "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==" "resolved" "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz" @@ -2582,16 +2602,91 @@ "safe-buffer" "^5.0.1" "sha.js" "^2.4.8" -"pg-connection-string@^2.5.0": - "integrity" "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==" - "resolved" "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz" - "version" "2.5.0" +"pg-cloudflare@^1.1.1": + "integrity" "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==" + "resolved" "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz" + "version" "1.1.1" + +"pg-connection-string@^2.5.0", "pg-connection-string@^2.6.2": + "integrity" "sha512-ch6OwaeaPYcova4kKZ15sbJ2hKb/VP48ZD2gE7i1J+L4MspCtBMAx8nMgz7bksc7IojCIIWuEhHibSMFH8m8oA==" + "resolved" "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.6.2.tgz" + "version" "2.6.2" + +"pg-int8@1.0.1": + "integrity" "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==" + "resolved" "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz" + "version" "1.0.1" + +"pg-pool@^3.6.1": + "integrity" "sha512-jizsIzhkIitxCGfPRzJn1ZdcosIt3pz9Sh3V01fm1vZnbnCMgmGl5wvGGdNN2EL9Rmb0EcFoCkixH4Pu+sP9Og==" + "resolved" "https://registry.npmjs.org/pg-pool/-/pg-pool-3.6.1.tgz" + "version" "3.6.1" + +"pg-protocol@^1.6.0": + "integrity" "sha512-M+PDm637OY5WM307051+bsDia5Xej6d9IR4GwJse1qA1DIhiKlksvrneZOYQq42OM+spubpcNYEo2FcKQrDk+Q==" + "resolved" "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.0.tgz" + "version" "1.6.0" + +"pg-types@^2.1.0": + "integrity" "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==" + "resolved" "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz" + "version" "2.2.0" + dependencies: + "pg-int8" "1.0.1" + "postgres-array" "~2.0.0" + "postgres-bytea" "~1.0.0" + "postgres-date" "~1.0.4" + "postgres-interval" "^1.1.0" + +"pg@^8.11.1", "pg@>=8.0": + "integrity" "sha512-l4rmVeV8qTIrrPrIR3kZQqBgSN93331s9i6wiUiLOSk0Q7PmUxZD/m1rQI622l3NfqBby9Ar5PABfS/SulfieQ==" + "resolved" "https://registry.npmjs.org/pg/-/pg-8.11.2.tgz" + "version" "8.11.2" + dependencies: + "buffer-writer" "2.0.0" + "packet-reader" "1.0.0" + "pg-connection-string" "^2.6.2" + "pg-pool" "^3.6.1" + "pg-protocol" "^1.6.0" + "pg-types" "^2.1.0" + "pgpass" "1.x" + optionalDependencies: + "pg-cloudflare" "^1.1.1" + +"pgpass@1.x": + "integrity" "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==" + "resolved" "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz" + "version" "1.0.5" + dependencies: + "split2" "^4.1.0" "picomatch@^2.0.4", "picomatch@^2.2.1", "picomatch@^2.2.3", "picomatch@^2.3.1": "integrity" "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" "resolved" "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz" "version" "2.3.1" +"postgres-array@~2.0.0": + "integrity" "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==" + "resolved" "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz" + "version" "2.0.0" + +"postgres-bytea@~1.0.0": + "integrity" "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==" + "resolved" "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz" + "version" "1.0.0" + +"postgres-date@~1.0.4": + "integrity" "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==" + "resolved" "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz" + "version" "1.0.7" + +"postgres-interval@^1.1.0": + "integrity" "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==" + "resolved" "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz" + "version" "1.2.0" + dependencies: + "xtend" "^4.0.0" + "prelude-ls@^1.2.1": "integrity" "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==" "resolved" "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz" @@ -2993,6 +3088,11 @@ "resolved" "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz" "version" "3.0.0" +"split2@^4.1.0": + "integrity" "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==" + "resolved" "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz" + "version" "4.2.0" + "statuses@2.0.1": "integrity" "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" "resolved" "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz" @@ -3362,6 +3462,11 @@ "commander" "^2.20.3" "cssfilter" "0.0.10" +"xtend@^4.0.0": + "integrity" "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" + "resolved" "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz" + "version" "4.0.2" + "yallist@^2.1.2": "integrity" "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" "resolved" "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz" From 5cfa5c11048addb44155e39efd3d52b85aca7f79 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Fri, 29 Sep 2023 07:30:14 +0200 Subject: [PATCH 012/256] Pointing to c4dt forks of dela, dela-apps, and d-voting - Replaces all github.com/dedis/d-voting with github.com/c4dt/d-voting - Replaces all go.dedis.ch/dela with github.com/c4dt/dela - Removes the clone from fix-bbolt - Removes Sonarcloud --- .github/workflows/go_dvoting_test.yml | 2 +- .github/workflows/go_scenario_test.yml | 2 +- .github/workflows/go_test.yml | 33 +------ Dockerfiles/Dockerfile.dela | 2 +- Makefile | 4 +- README.md | 52 +++++----- autotest.sh | 2 +- cli/cosipbftcontroller/action.go | 20 ++-- cli/cosipbftcontroller/action_test.go | 24 ++--- cli/cosipbftcontroller/mod.go | 48 +++++----- cli/cosipbftcontroller/mod_test.go | 16 ++-- cli/dvoting/mod.go | 67 +++++++------ cli/postinstall/mod.go | 18 ++-- contracts/evoting/controller/action.go | 50 +++++----- contracts/evoting/controller/mod.go | 10 +- contracts/evoting/controller/mod_test.go | 2 +- contracts/evoting/evoting.go | 20 ++-- contracts/evoting/json/ciphervote.go | 4 +- contracts/evoting/json/forms.go | 12 +-- contracts/evoting/json/mod.go | 4 +- contracts/evoting/json/transaction.go | 76 +++++++-------- contracts/evoting/mod.go | 24 ++--- contracts/evoting/mod_test.go | 30 +++--- contracts/evoting/types/ciphervote.go | 4 +- contracts/evoting/types/election.go | 8 +- contracts/evoting/types/transactions.go | 16 ++-- deb-package/README.md | 6 +- deb-package/build-deb.sh | 2 +- docs/coverpage.md | 2 +- docs/index.html | 2 +- docs/smart_contract.md | 16 ++-- docs/verifiability_doc.md | 2 +- go.mod | 34 +++---- go.sum | 95 ++++++++++++------- integration/ballot.go | 22 ++--- integration/dkg.go | 6 +- integration/dvotingdela.go | 72 +++++++------- integration/form.go | 22 ++--- integration/integration_test.go | 8 +- integration/nodes.go | 4 +- integration/performance_test.go | 12 +-- integration/scenario_test.go | 22 ++--- integration/shuffle.go | 4 +- integration/transaction.go | 17 ++-- integration/votes_test.go | 8 +- internal/testing/fake/authority.go | 6 +- internal/testing/fake/crypto.go | 4 +- internal/testing/fake/dkg.go | 4 +- internal/testing/fake/election.go | 2 +- internal/testing/fake/mino.go | 6 +- internal/testing/fake/ordering.go | 28 +++--- internal/testing/fake/serde.go | 2 +- internal/testing/fake/store.go | 4 +- internal/testing/fake/txn.go | 10 +- internal/testing/fake/validation.go | 12 +-- metrics/controller/action.go | 6 +- metrics/controller/mod.go | 4 +- mod.go | 2 +- proxy/dkg.go | 8 +- proxy/dkg_test.go | 21 ++-- proxy/election.go | 16 ++-- proxy/mod.go | 2 +- proxy/shuffle.go | 4 +- proxy/txnmanager/mod.go | 8 +- proxy/txnmanager/transaction.go | 16 ++-- proxy/types/election.go | 2 +- runSystems.sh | 8 +- scripts/init_dela.sh | 6 +- scripts/run_local.sh | 8 +- services/dkg/mod.go | 2 +- services/dkg/pedersen/controller/action.go | 26 ++--- .../dkg/pedersen/controller/action_test.go | 10 +- services/dkg/pedersen/controller/mod.go | 36 +++---- services/dkg/pedersen/controller/mod_test.go | 20 ++-- services/dkg/pedersen/handler.go | 32 +++---- services/dkg/pedersen/handler_test.go | 18 ++-- services/dkg/pedersen/json/mod.go | 6 +- services/dkg/pedersen/json/mod_test.go | 8 +- services/dkg/pedersen/mod.go | 30 +++--- services/dkg/pedersen/mod_test.go | 39 ++++---- services/dkg/pedersen/types/messages.go | 6 +- services/dkg/pedersen/types/messages_test.go | 6 +- services/shuffle/mod.go | 2 +- services/shuffle/neff/controller/action.go | 18 ++-- .../shuffle/neff/controller/action_test.go | 2 +- services/shuffle/neff/controller/mod.go | 28 +++--- services/shuffle/neff/controller/mod_test.go | 12 +-- services/shuffle/neff/handler.go | 22 ++--- services/shuffle/neff/handler_test.go | 46 ++++----- services/shuffle/neff/json/mod.go | 14 +-- services/shuffle/neff/json/mod_test.go | 8 +- services/shuffle/neff/mod.go | 68 ++++++------- services/shuffle/neff/mod_test.go | 28 +++--- services/shuffle/neff/types/messages.go | 14 +-- services/shuffle/neff/types/messages_test.go | 6 +- setup.sh | 16 ++-- web/frontend/src/layout/Footer.tsx | 8 +- web/frontend/src/pages/Home.tsx | 2 +- 98 files changed, 811 insertions(+), 817 deletions(-) diff --git a/.github/workflows/go_dvoting_test.yml b/.github/workflows/go_dvoting_test.yml index 5deea0ce2..f98569577 100644 --- a/.github/workflows/go_dvoting_test.yml +++ b/.github/workflows/go_dvoting_test.yml @@ -19,7 +19,7 @@ jobs: - name: Install crypto util from Dela run: | - git clone https://github.com/dedis/dela.git + git clone https://github.com/c4dt/dela.git cd dela go install ./cli/crypto diff --git a/.github/workflows/go_scenario_test.yml b/.github/workflows/go_scenario_test.yml index 942b161d1..c2e609697 100644 --- a/.github/workflows/go_scenario_test.yml +++ b/.github/workflows/go_scenario_test.yml @@ -18,7 +18,7 @@ jobs: - name: Install crypto util from Dela run: | - git clone https://github.com/dedis/dela.git + git clone https://github.com/c4dt/dela.git cd dela go install ./cli/crypto diff --git a/.github/workflows/go_test.yml b/.github/workflows/go_test.yml index 6392aed7f..dba5a8188 100644 --- a/.github/workflows/go_test.yml +++ b/.github/workflows/go_test.yml @@ -27,35 +27,4 @@ jobs: - name: Test all, except integration, with coverage run: | - go test -json -covermode=count -coverprofile=profile.cov $(go list ./... | grep -v /integration) 2>&1 | tee report.json - - - name: Sonarcloud scan - uses: sonarsource/sonarcloud-github-action@master - with: - args: > - -Dsonar.organization=dedis - -Dsonar.projectKey=dedis_d-voting - -Dsonar.go.tests.reportPaths=report.json - -Dsonar.go.coverage.reportPaths=profile.cov - -Dsonar.coverage.exclusions=**/*_test.go,/internal/**/* - -Dsonar.issue.ignore.multicriteria=e1 - -Dsonar.issue.ignore.multicriteria.e1.ruleKey=*Naming* - -Dsonar.issue.ignore.multicriteria.e1.resourceKey=**/*_test.go - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - - name: Send coverage - uses: shogo82148/actions-goveralls@v1 - with: - path-to-profile: profile.cov - parallel: true - - # notifies that all test jobs are finished. - finish: - needs: test - runs-on: ubuntu-latest - steps: - - uses: shogo82148/actions-goveralls@v1 - with: - parallel-finished: true + go test $(go list ./... | grep -v /integration) diff --git a/Dockerfiles/Dockerfile.dela b/Dockerfiles/Dockerfile.dela index 15312deab..853bdcce3 100644 --- a/Dockerfiles/Dockerfile.dela +++ b/Dockerfiles/Dockerfile.dela @@ -1,7 +1,7 @@ FROM golang:1.20.6-bookworm AS base RUN apt-get update && apt-get install git # make sure we're using the same head as d-voting -RUN git clone -b fix-bbolt https://github.com/dedis/dela.git +RUN git clone https://github.com/c4dt/dela.git WORKDIR /go/dela/cli/crypto RUN go install WORKDIR /go/d-voting diff --git a/Makefile b/Makefile index a774d69a0..a7eb71f25 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ version=$(shell git describe --abbrev=0 --tags || echo '0.0.0') -versionFlag="github.com/dedis/d-voting.Version=$(version)" +versionFlag="github.com/c4dt/d-voting.Version=$(version)" versionFile=$(shell echo $(version) | tr . _) -timeFlag="github.com/dedis/d-voting.BuildTime=$(shell date +'%d/%m/%y_%H:%M')" +timeFlag="github.com/c4dt/d-voting.BuildTime=$(shell date +'%d/%m/%y_%H:%M')" lint: # Coding style static check. diff --git a/README.md b/README.md index e94a54b3a..635f11808 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ - - + +
- + GitHub contributors - + GitHub release (latest SemVer) @@ -26,37 +26,37 @@ Blockchain - - + + - - + + - - + + - - + +
- - + + - - Go Reference + + Go Reference WEB - - + + - - + + @@ -67,7 +67,7 @@ # D-Voting **D-Voting** is an e-voting platform based on the -[Dela](https://github.com/dedis/dela) blockchain. It uses state-of-the-art +[Dela](https://github.com/c4dt/dela) blockchain. It uses state-of-the-art protocols that guarantee privacy of votes and a fully decentralized process. This project was born in early 2021 and has been iteratively implemented by EPFL students under the supervision of DEDIS members. @@ -147,7 +147,7 @@ sometimes refer to the blockchain node simply as a "node". The following component diagrams summarizes the interaction between those high-level components: -[minogrpc]: https://github.com/dedis/dela/tree/master/mino/minogrpc +[minogrpc]: https://github.com/c4dt/dela/tree/master/mino/minogrpc ![Global component diagram](http://www.plantuml.com/plantuml/proxy?src=https://raw.githubusercontent.com/dedis/d-voting/main/docs/assets/component-global.puml) @@ -390,7 +390,7 @@ results. 2: Install the `crypto` utility from Dela: ```sh -git clone https://github.com/dedis/dela.git +git clone https://github.com/c4dt/dela.git cd dela/cli/crypto go install ``` @@ -601,7 +601,7 @@ Afterwards use the following commands, replace 4 by the desired nb of nodes : ./runNode.sh -n 4 -a true -d true ./setupnNode.sh -n 4 -d true -NNODES=4 KILLNODE=true go test -v -run ^TestScenario$ github.com/dedis/d-voting/integration -count=1 +NNODES=4 KILLNODE=true go test -v -run ^TestScenario$ github.com/c4dt/d-voting/integration -count=1 ``` Here we set KILLNODE=true or false to decide whether kill and restart a node @@ -650,8 +650,8 @@ Build info can be added to the binary with the `ldflags`, at build time. Infos are stored on variables in the root `mod.go`. For example: ```sh -versionFlag="github.com/dedis/d-voting.Version=`git describe --tags`" -timeFlag="github.com/dedis/d-voting.BuildTime=`date +'%d/%m/%y_%H:%M'`" +versionFlag="github.com/c4dt/d-voting.Version=`git describe --tags`" +timeFlag="github.com/c4dt/d-voting.BuildTime=`date +'%d/%m/%y_%H:%M'`" go build -ldflags="-X $versionFlag -X $timeFlag" ./cli/dvoting ``` diff --git a/autotest.sh b/autotest.sh index b9872287b..67ef14ec1 100755 --- a/autotest.sh +++ b/autotest.sh @@ -52,7 +52,7 @@ do ./setupnNode.sh -n $N_NODE -d true sleep 3 # Start scenario test and keep logs - NNODES=$N_NODE go test -v -run ^TestScenario$ github.com/dedis/d-voting/integration -count=1 | tee ./log/log/gotest.log + NNODES=$N_NODE go test -v -run ^TestScenario$ github.com/c4dt/d-voting/integration -count=1 | tee ./log/log/gotest.log sleep 3 # Stop the test ./kill_test.sh diff --git a/cli/cosipbftcontroller/action.go b/cli/cosipbftcontroller/action.go index febe68f4b..f31027197 100644 --- a/cli/cosipbftcontroller/action.go +++ b/cli/cosipbftcontroller/action.go @@ -12,16 +12,16 @@ import ( "fmt" "strings" - "go.dedis.ch/dela" - "go.dedis.ch/dela/cli/node" - "go.dedis.ch/dela/core/ordering" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - "go.dedis.ch/dela/core/ordering/cosipbft/contracts/viewchange" - "go.dedis.ch/dela/core/txn" - "go.dedis.ch/dela/core/txn/pool" - "go.dedis.ch/dela/cosi" - "go.dedis.ch/dela/crypto" - "go.dedis.ch/dela/mino" + "github.com/c4dt/dela" + "github.com/c4dt/dela/cli/node" + "github.com/c4dt/dela/core/ordering" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + "github.com/c4dt/dela/core/ordering/cosipbft/contracts/viewchange" + "github.com/c4dt/dela/core/txn" + "github.com/c4dt/dela/core/txn/pool" + "github.com/c4dt/dela/cosi" + "github.com/c4dt/dela/crypto" + "github.com/c4dt/dela/mino" "golang.org/x/xerrors" ) diff --git a/cli/cosipbftcontroller/action_test.go b/cli/cosipbftcontroller/action_test.go index 322b89863..46a2cf396 100644 --- a/cli/cosipbftcontroller/action_test.go +++ b/cli/cosipbftcontroller/action_test.go @@ -7,19 +7,19 @@ import ( "testing" "time" - "github.com/dedis/d-voting/internal/testing/fake" + "github.com/c4dt/d-voting/internal/testing/fake" + "github.com/c4dt/dela/cli/node" + "github.com/c4dt/dela/core/access" + "github.com/c4dt/dela/core/ordering" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + "github.com/c4dt/dela/core/txn" + "github.com/c4dt/dela/core/txn/pool" + "github.com/c4dt/dela/core/txn/pool/mem" + "github.com/c4dt/dela/core/validation" + "github.com/c4dt/dela/cosi" + "github.com/c4dt/dela/crypto" + "github.com/c4dt/dela/mino" "github.com/stretchr/testify/require" - "go.dedis.ch/dela/cli/node" - "go.dedis.ch/dela/core/access" - "go.dedis.ch/dela/core/ordering" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - "go.dedis.ch/dela/core/txn" - "go.dedis.ch/dela/core/txn/pool" - "go.dedis.ch/dela/core/txn/pool/mem" - "go.dedis.ch/dela/core/validation" - "go.dedis.ch/dela/cosi" - "go.dedis.ch/dela/crypto" - "go.dedis.ch/dela/mino" ) func TestSetupAction_Execute(t *testing.T) { diff --git a/cli/cosipbftcontroller/mod.go b/cli/cosipbftcontroller/mod.go index 08ae6d413..036a4f1c4 100644 --- a/cli/cosipbftcontroller/mod.go +++ b/cli/cosipbftcontroller/mod.go @@ -8,30 +8,30 @@ import ( "path/filepath" "time" - "go.dedis.ch/dela/contracts/value" - "go.dedis.ch/dela/crypto" - - "go.dedis.ch/dela/cli" - "go.dedis.ch/dela/cli/node" - "go.dedis.ch/dela/core/access/darc" - "go.dedis.ch/dela/core/execution/native" - "go.dedis.ch/dela/core/ordering" - "go.dedis.ch/dela/core/ordering/cosipbft" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - "go.dedis.ch/dela/core/ordering/cosipbft/blockstore" - "go.dedis.ch/dela/core/ordering/cosipbft/types" - "go.dedis.ch/dela/core/store/hashtree/binprefix" - "go.dedis.ch/dela/core/store/kv" - "go.dedis.ch/dela/core/txn/pool" - poolimpl "go.dedis.ch/dela/core/txn/pool/gossip" - "go.dedis.ch/dela/core/txn/signed" - "go.dedis.ch/dela/core/validation/simple" - "go.dedis.ch/dela/cosi/threshold" - "go.dedis.ch/dela/crypto/bls" - "go.dedis.ch/dela/crypto/loader" - "go.dedis.ch/dela/mino" - "go.dedis.ch/dela/mino/gossip" - "go.dedis.ch/dela/serde/json" + "github.com/c4dt/dela/contracts/value" + "github.com/c4dt/dela/crypto" + + "github.com/c4dt/dela/cli" + "github.com/c4dt/dela/cli/node" + "github.com/c4dt/dela/core/access/darc" + "github.com/c4dt/dela/core/execution/native" + "github.com/c4dt/dela/core/ordering" + "github.com/c4dt/dela/core/ordering/cosipbft" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + "github.com/c4dt/dela/core/ordering/cosipbft/blockstore" + "github.com/c4dt/dela/core/ordering/cosipbft/types" + "github.com/c4dt/dela/core/store/hashtree/binprefix" + "github.com/c4dt/dela/core/store/kv" + "github.com/c4dt/dela/core/txn/pool" + poolimpl "github.com/c4dt/dela/core/txn/pool/gossip" + "github.com/c4dt/dela/core/txn/signed" + "github.com/c4dt/dela/core/validation/simple" + "github.com/c4dt/dela/cosi/threshold" + "github.com/c4dt/dela/crypto/bls" + "github.com/c4dt/dela/crypto/loader" + "github.com/c4dt/dela/mino" + "github.com/c4dt/dela/mino/gossip" + "github.com/c4dt/dela/serde/json" "golang.org/x/xerrors" ) diff --git a/cli/cosipbftcontroller/mod_test.go b/cli/cosipbftcontroller/mod_test.go index ac9e3525e..d3cf0cb6e 100644 --- a/cli/cosipbftcontroller/mod_test.go +++ b/cli/cosipbftcontroller/mod_test.go @@ -6,15 +6,15 @@ import ( "path/filepath" "testing" - "github.com/dedis/d-voting/services/dkg" - "go.dedis.ch/dela/core/ordering" - - "github.com/dedis/d-voting/internal/testing/fake" + "github.com/c4dt/d-voting/services/dkg" + "github.com/c4dt/dela/core/ordering" + + "github.com/c4dt/d-voting/internal/testing/fake" + "github.com/c4dt/dela/cli" + "github.com/c4dt/dela/cli/node" + "github.com/c4dt/dela/core/store/kv" + "github.com/c4dt/dela/core/txn/pool" "github.com/stretchr/testify/require" - "go.dedis.ch/dela/cli" - "go.dedis.ch/dela/cli/node" - "go.dedis.ch/dela/core/store/kv" - "go.dedis.ch/dela/core/txn/pool" ) func TestMinimal_SetCommands(t *testing.T) { diff --git a/cli/dvoting/mod.go b/cli/dvoting/mod.go index 79428ad64..57a96706b 100644 --- a/cli/dvoting/mod.go +++ b/cli/dvoting/mod.go @@ -2,28 +2,27 @@ // // Unix example: // -// # Expect GOPATH to be correctly set to have dvoting available. -// go install +// # Expect GOPATH to be correctly set to have dvoting available. +// go install // -// dvoting --config /tmp/node1 start --port 2001 & -// dvoting --config /tmp/node2 start --port 2002 & -// dvoting --config /tmp/node3 start --port 2003 & +// dvoting --config /tmp/node1 start --port 2001 & +// dvoting --config /tmp/node2 start --port 2002 & +// dvoting --config /tmp/node3 start --port 2003 & // -// # Share the different certificates among the participants. -// dvoting --config /tmp/node2 minogrpc join --address 127.0.0.1:2001\ -// $(dvoting --config /tmp/node1 minogrpc token) -// dvoting --config /tmp/node3 minogrpc join --address 127.0.0.1:2001\ -// $(dvoting --config /tmp/node1 minogrpc token) +// # Share the different certificates among the participants. +// dvoting --config /tmp/node2 minogrpc join --address 127.0.0.1:2001\ +// $(dvoting --config /tmp/node1 minogrpc token) +// dvoting --config /tmp/node3 minogrpc join --address 127.0.0.1:2001\ +// $(dvoting --config /tmp/node1 minogrpc token) // -// # Create a chain with two members. -// dvoting --config /tmp/node1 ordering setup\ -// --member $(dvoting --config /tmp/node1 ordering export)\ -// --member $(dvoting --config /tmp/node2 ordering export) -// -// # Add the third after the chain is set up. -// dvoting --config /tmp/node1 ordering roster add\ -// --member $(dvoting --config /tmp/node3 ordering export) +// # Create a chain with two members. +// dvoting --config /tmp/node1 ordering setup\ +// --member $(dvoting --config /tmp/node1 ordering export)\ +// --member $(dvoting --config /tmp/node2 ordering export) // +// # Add the third after the chain is set up. +// dvoting --config /tmp/node1 ordering roster add\ +// --member $(dvoting --config /tmp/node3 ordering export) package main import ( @@ -31,25 +30,25 @@ import ( "io" "os" - dkg "github.com/dedis/d-voting/services/dkg/pedersen/controller" - "github.com/dedis/d-voting/services/dkg/pedersen/json" - shuffle "github.com/dedis/d-voting/services/shuffle/neff/controller" + dkg "github.com/c4dt/d-voting/services/dkg/pedersen/controller" + "github.com/c4dt/d-voting/services/dkg/pedersen/json" + shuffle "github.com/c4dt/d-voting/services/shuffle/neff/controller" - cosipbft "github.com/dedis/d-voting/cli/cosipbftcontroller" - "github.com/dedis/d-voting/cli/postinstall" - evoting "github.com/dedis/d-voting/contracts/evoting/controller" - metrics "github.com/dedis/d-voting/metrics/controller" - "go.dedis.ch/dela/cli/node" - access "go.dedis.ch/dela/contracts/access/controller" - db "go.dedis.ch/dela/core/store/kv/controller" - pool "go.dedis.ch/dela/core/txn/pool/controller" - signed "go.dedis.ch/dela/core/txn/signed/controller" - mino "go.dedis.ch/dela/mino/minogrpc/controller" - proxy "go.dedis.ch/dela/mino/proxy/http/controller" + cosipbft "github.com/c4dt/d-voting/cli/cosipbftcontroller" + "github.com/c4dt/d-voting/cli/postinstall" + evoting "github.com/c4dt/d-voting/contracts/evoting/controller" + metrics "github.com/c4dt/d-voting/metrics/controller" + "github.com/c4dt/dela/cli/node" + access "github.com/c4dt/dela/contracts/access/controller" + db "github.com/c4dt/dela/core/store/kv/controller" + pool "github.com/c4dt/dela/core/txn/pool/controller" + signed "github.com/c4dt/dela/core/txn/signed/controller" + mino "github.com/c4dt/dela/mino/minogrpc/controller" + proxy "github.com/c4dt/dela/mino/proxy/http/controller" - _ "github.com/dedis/d-voting/services/shuffle/neff/json" + _ "github.com/c4dt/d-voting/services/shuffle/neff/json" - gapi "go.dedis.ch/dela-apps/gapi/controller" + gapi "github.com/c4dt/dela-apps/gapi/controller" ) func main() { diff --git a/cli/postinstall/mod.go b/cli/postinstall/mod.go index 560e57d40..66b6f0d12 100644 --- a/cli/postinstall/mod.go +++ b/cli/postinstall/mod.go @@ -5,15 +5,15 @@ import ( "path/filepath" "time" - evoting "github.com/dedis/d-voting/contracts/evoting/controller" - prom "github.com/dedis/d-voting/metrics/controller" - dkg "github.com/dedis/d-voting/services/dkg/pedersen/controller" - neff "github.com/dedis/d-voting/services/shuffle/neff/controller" - "go.dedis.ch/dela" - "go.dedis.ch/dela/cli" - "go.dedis.ch/dela/cli/node" - "go.dedis.ch/dela/mino/proxy" - "go.dedis.ch/dela/mino/proxy/http" + evoting "github.com/c4dt/d-voting/contracts/evoting/controller" + prom "github.com/c4dt/d-voting/metrics/controller" + dkg "github.com/c4dt/d-voting/services/dkg/pedersen/controller" + neff "github.com/c4dt/d-voting/services/shuffle/neff/controller" + "github.com/c4dt/dela" + "github.com/c4dt/dela/cli" + "github.com/c4dt/dela/cli/node" + "github.com/c4dt/dela/mino/proxy" + "github.com/c4dt/dela/mino/proxy/http" "golang.org/x/xerrors" ) diff --git a/contracts/evoting/controller/action.go b/contracts/evoting/controller/action.go index 71e15a659..19c537ca5 100644 --- a/contracts/evoting/controller/action.go +++ b/contracts/evoting/controller/action.go @@ -17,36 +17,36 @@ import ( "go.dedis.ch/kyber/v3/sign/schnorr" "go.dedis.ch/kyber/v3/suites" - "github.com/dedis/d-voting/contracts/evoting/types" - "github.com/dedis/d-voting/internal/testing/fake" - eproxy "github.com/dedis/d-voting/proxy" - "github.com/dedis/d-voting/proxy/txnmanager" - ptypes "github.com/dedis/d-voting/proxy/types" - "github.com/dedis/d-voting/services/dkg" - "github.com/dedis/d-voting/services/shuffle" + "github.com/c4dt/d-voting/contracts/evoting/types" + "github.com/c4dt/d-voting/internal/testing/fake" + eproxy "github.com/c4dt/d-voting/proxy" + "github.com/c4dt/d-voting/proxy/txnmanager" + ptypes "github.com/c4dt/d-voting/proxy/types" + "github.com/c4dt/d-voting/services/dkg" + "github.com/c4dt/d-voting/services/shuffle" + "github.com/c4dt/dela" + "github.com/c4dt/dela/cli/node" + "github.com/c4dt/dela/core/ordering" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + "github.com/c4dt/dela/core/ordering/cosipbft/blockstore" + "github.com/c4dt/dela/core/txn" + "github.com/c4dt/dela/core/txn/pool" + "github.com/c4dt/dela/core/txn/signed" + "github.com/c4dt/dela/core/validation" + "github.com/c4dt/dela/crypto" + "github.com/c4dt/dela/crypto/bls" + "github.com/c4dt/dela/crypto/loader" + "github.com/c4dt/dela/mino" + "github.com/c4dt/dela/mino/proxy" + "github.com/c4dt/dela/serde" + sjson "github.com/c4dt/dela/serde/json" "github.com/gorilla/mux" - "go.dedis.ch/dela" - "go.dedis.ch/dela/cli/node" - "go.dedis.ch/dela/core/ordering" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - "go.dedis.ch/dela/core/ordering/cosipbft/blockstore" - "go.dedis.ch/dela/core/txn" - "go.dedis.ch/dela/core/txn/pool" - "go.dedis.ch/dela/core/txn/signed" - "go.dedis.ch/dela/core/validation" - "go.dedis.ch/dela/crypto" - "go.dedis.ch/dela/crypto/bls" - "go.dedis.ch/dela/crypto/loader" - "go.dedis.ch/dela/mino" - "go.dedis.ch/dela/mino/proxy" - "go.dedis.ch/dela/serde" - sjson "go.dedis.ch/dela/serde/json" "golang.org/x/xerrors" ) const ( - contentType = "application/json" - formPath = "/evoting/forms" + contentType = "application/json" + formPath = "/evoting/forms" // FormPathSlash is the path to the form with a trailing slash FormPathSlash = formPath + "/" formIDPath = FormPathSlash + "{formID}" diff --git a/contracts/evoting/controller/mod.go b/contracts/evoting/controller/mod.go index 24d37b7a0..27526b5f3 100644 --- a/contracts/evoting/controller/mod.go +++ b/contracts/evoting/controller/mod.go @@ -1,11 +1,11 @@ package controller import ( - "go.dedis.ch/dela/cli" - "go.dedis.ch/dela/cli/node" - "go.dedis.ch/dela/core/access" - "go.dedis.ch/dela/core/ordering" - "go.dedis.ch/dela/core/validation" + "github.com/c4dt/dela/cli" + "github.com/c4dt/dela/cli/node" + "github.com/c4dt/dela/core/access" + "github.com/c4dt/dela/core/ordering" + "github.com/c4dt/dela/core/validation" ) // NewController returns a new controller initializer diff --git a/contracts/evoting/controller/mod_test.go b/contracts/evoting/controller/mod_test.go index d95da7b7d..85dc75ac7 100644 --- a/contracts/evoting/controller/mod_test.go +++ b/contracts/evoting/controller/mod_test.go @@ -3,8 +3,8 @@ package controller import ( "testing" + "github.com/c4dt/dela/cli/node" "github.com/stretchr/testify/require" - "go.dedis.ch/dela/cli/node" ) func TestController_OnStart(t *testing.T) { diff --git a/contracts/evoting/evoting.go b/contracts/evoting/evoting.go index 0832a3de0..3c6aee364 100644 --- a/contracts/evoting/evoting.go +++ b/contracts/evoting/evoting.go @@ -11,19 +11,19 @@ import ( "math/rand" "strings" - "go.dedis.ch/dela" + "github.com/c4dt/dela" "go.dedis.ch/kyber/v3/share" - "github.com/dedis/d-voting/contracts/evoting/types" - "go.dedis.ch/dela/core/execution" - "go.dedis.ch/dela/core/execution/native" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - "go.dedis.ch/dela/core/store" - "go.dedis.ch/dela/core/txn" - "go.dedis.ch/dela/cosi/threshold" - "go.dedis.ch/dela/crypto/bls" - "go.dedis.ch/dela/serde" + "github.com/c4dt/d-voting/contracts/evoting/types" + "github.com/c4dt/dela/core/execution" + "github.com/c4dt/dela/core/execution/native" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + "github.com/c4dt/dela/core/store" + "github.com/c4dt/dela/core/txn" + "github.com/c4dt/dela/cosi/threshold" + "github.com/c4dt/dela/crypto/bls" + "github.com/c4dt/dela/serde" "go.dedis.ch/kyber/v3/proof" "go.dedis.ch/kyber/v3/shuffle" "golang.org/x/xerrors" diff --git a/contracts/evoting/json/ciphervote.go b/contracts/evoting/json/ciphervote.go index b8c51b65d..bc9140655 100644 --- a/contracts/evoting/json/ciphervote.go +++ b/contracts/evoting/json/ciphervote.go @@ -1,8 +1,8 @@ package json import ( - "github.com/dedis/d-voting/contracts/evoting/types" - "go.dedis.ch/dela/serde" + "github.com/c4dt/d-voting/contracts/evoting/types" + "github.com/c4dt/dela/serde" "golang.org/x/xerrors" ) diff --git a/contracts/evoting/json/forms.go b/contracts/evoting/json/forms.go index 8497d4ab5..374bc86e5 100644 --- a/contracts/evoting/json/forms.go +++ b/contracts/evoting/json/forms.go @@ -3,10 +3,10 @@ package json import ( "encoding/json" - "github.com/dedis/d-voting/contracts/evoting/types" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - ctypes "go.dedis.ch/dela/core/ordering/cosipbft/types" - "go.dedis.ch/dela/serde" + "github.com/c4dt/d-voting/contracts/evoting/types" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + ctypes "github.com/c4dt/dela/core/ordering/cosipbft/types" + "github.com/c4dt/dela/serde" "go.dedis.ch/kyber/v3" "go.dedis.ch/kyber/v3/suites" "golang.org/x/xerrors" @@ -58,7 +58,7 @@ func (formFormat) Encode(ctx serde.Context, message serde.Message) ([]byte, erro formJSON := FormJSON{ Configuration: m.Configuration, - FormID: m.FormID, + FormID: m.FormID, Status: uint16(m.Status), Pubkey: pubkey, BallotSize: m.BallotSize, @@ -128,7 +128,7 @@ func (formFormat) Decode(ctx serde.Context, data []byte) (serde.Message, error) return types.Form{ Configuration: formJSON.Configuration, - FormID: formJSON.FormID, + FormID: formJSON.FormID, Status: types.Status(formJSON.Status), Pubkey: pubKey, BallotSize: formJSON.BallotSize, diff --git a/contracts/evoting/json/mod.go b/contracts/evoting/json/mod.go index ab07ec828..12e706781 100644 --- a/contracts/evoting/json/mod.go +++ b/contracts/evoting/json/mod.go @@ -1,8 +1,8 @@ package json import ( - "github.com/dedis/d-voting/contracts/evoting/types" - "go.dedis.ch/dela/serde" + "github.com/c4dt/d-voting/contracts/evoting/types" + "github.com/c4dt/dela/serde" ) // Register the JSON formats for the form, ciphervote, and transaction diff --git a/contracts/evoting/json/transaction.go b/contracts/evoting/json/transaction.go index 106ada9c7..08b084321 100644 --- a/contracts/evoting/json/transaction.go +++ b/contracts/evoting/json/transaction.go @@ -3,8 +3,8 @@ package json import ( "encoding/json" - "github.com/dedis/d-voting/contracts/evoting/types" - "go.dedis.ch/dela/serde" + "github.com/c4dt/d-voting/contracts/evoting/types" + "github.com/c4dt/dela/serde" "golang.org/x/xerrors" ) @@ -38,7 +38,7 @@ func (transactionFormat) Encode(ctx serde.Context, msg serde.Message) ([]byte, e } cv := CastVoteJSON{ - FormID: t.FormID, + FormID: t.FormID, UserID: t.UserID, Ciphervote: ballot, } @@ -47,7 +47,7 @@ func (transactionFormat) Encode(ctx serde.Context, msg serde.Message) ([]byte, e case types.CloseForm: ce := CloseFormJSON{ FormID: t.FormID, - UserID: t.UserID, + UserID: t.UserID, } m = TransactionJSON{CloseForm: &ce} @@ -64,7 +64,7 @@ func (transactionFormat) Encode(ctx serde.Context, msg serde.Message) ([]byte, e } sb := ShuffleBallotsJSON{ - FormID: t.FormID, + FormID: t.FormID, Round: t.Round, Ciphervotes: ciphervotes, RandomVector: t.RandomVector, @@ -90,25 +90,25 @@ func (transactionFormat) Encode(ctx serde.Context, msg serde.Message) ([]byte, e } rp := RegisterPubSharesJSON{ - FormID: t.FormID, - Index: t.Index, - PubShares: pubShares, - Signature: t.Signature, - PublicKey: t.PublicKey, + FormID: t.FormID, + Index: t.Index, + PubShares: pubShares, + Signature: t.Signature, + PublicKey: t.PublicKey, } m = TransactionJSON{RegisterPubShares: &rp} case types.CombineShares: db := CombineSharesJSON{ FormID: t.FormID, - UserID: t.UserID, + UserID: t.UserID, } m = TransactionJSON{CombineShares: &db} case types.CancelForm: ce := CancelFormJSON{ FormID: t.FormID, - UserID: t.UserID, + UserID: t.UserID, } m = TransactionJSON{CancelForm: &ce} @@ -159,7 +159,7 @@ func (transactionFormat) Decode(ctx serde.Context, data []byte) (serde.Message, case m.CloseForm != nil: return types.CloseForm{ FormID: m.CloseForm.FormID, - UserID: m.CloseForm.UserID, + UserID: m.CloseForm.UserID, }, nil case m.ShuffleBallots != nil: msg, err := decodeShuffleBallots(ctx, *m.ShuffleBallots) @@ -178,12 +178,12 @@ func (transactionFormat) Decode(ctx serde.Context, data []byte) (serde.Message, case m.CombineShares != nil: return types.CombineShares{ FormID: m.CombineShares.FormID, - UserID: m.CombineShares.UserID, + UserID: m.CombineShares.UserID, }, nil case m.CancelForm != nil: return types.CancelForm{ FormID: m.CancelForm.FormID, - UserID: m.CancelForm.UserID, + UserID: m.CancelForm.UserID, }, nil case m.DeleteForm != nil: return types.DeleteForm{ @@ -197,15 +197,15 @@ func (transactionFormat) Decode(ctx serde.Context, data []byte) (serde.Message, // TransactionJSON is the JSON message that wraps the different kinds of // transactions. type TransactionJSON struct { - CreateForm *CreateFormJSON `json:",omitempty"` - OpenForm *OpenFormJSON `json:",omitempty"` + CreateForm *CreateFormJSON `json:",omitempty"` + OpenForm *OpenFormJSON `json:",omitempty"` CastVote *CastVoteJSON `json:",omitempty"` - CloseForm *CloseFormJSON `json:",omitempty"` + CloseForm *CloseFormJSON `json:",omitempty"` ShuffleBallots *ShuffleBallotsJSON `json:",omitempty"` RegisterPubShares *RegisterPubSharesJSON `json:",omitempty"` CombineShares *CombineSharesJSON `json:",omitempty"` - CancelForm *CancelFormJSON `json:",omitempty"` - DeleteForm *DeleteFormJSON `json:",omitempty"` + CancelForm *CancelFormJSON `json:",omitempty"` + DeleteForm *DeleteFormJSON `json:",omitempty"` } // CreateFormJSON is the JSON representation of a CreateForm transaction @@ -221,7 +221,7 @@ type OpenFormJSON struct { // CastVoteJSON is the JSON representation of a CastVote transaction type CastVoteJSON struct { - FormID string + FormID string UserID string Ciphervote json.RawMessage } @@ -229,12 +229,12 @@ type CastVoteJSON struct { // CloseFormJSON is the JSON representation of a CloseForm transaction type CloseFormJSON struct { FormID string - UserID string + UserID string } // ShuffleBallotsJSON is the JSON representation of a ShuffleBallots transaction type ShuffleBallotsJSON struct { - FormID string + FormID string Round int Ciphervotes []json.RawMessage RandomVector types.RandomVector @@ -244,23 +244,23 @@ type ShuffleBallotsJSON struct { } type RegisterPubSharesJSON struct { - FormID string - Index int - PubShares PubsharesUnitJSON - Signature []byte - PublicKey []byte + FormID string + Index int + PubShares PubsharesUnitJSON + Signature []byte + PublicKey []byte } // CombineSharesJSON is the JSON representation of a CombineShares transaction type CombineSharesJSON struct { FormID string - UserID string + UserID string } // CancelFormJSON is the JSON representation of a CancelForm transaction type CancelFormJSON struct { FormID string - UserID string + UserID string } // DeleteFormJSON is the JSON representation of a DeleteForm transaction @@ -286,8 +286,8 @@ func decodeCastVote(ctx serde.Context, m CastVoteJSON) (serde.Message, error) { return types.CastVote{ FormID: m.FormID, - UserID: m.UserID, - Ballot: ciphervote, + UserID: m.UserID, + Ballot: ciphervote, }, nil } @@ -314,7 +314,7 @@ func decodeShuffleBallots(ctx serde.Context, m ShuffleBallotsJSON) (serde.Messag } return types.ShuffleBallots{ - FormID: m.FormID, + FormID: m.FormID, Round: m.Round, ShuffledBallots: ciphervotes, RandomVector: m.RandomVector, @@ -342,10 +342,10 @@ func decodeRegisterPubShares(m RegisterPubSharesJSON) (serde.Message, error) { } return types.RegisterPubShares{ - FormID: m.FormID, - Index: m.Index, - Pubshares: pubShares, - Signature: m.Signature, - PublicKey: m.PublicKey, + FormID: m.FormID, + Index: m.Index, + Pubshares: pubShares, + Signature: m.Signature, + PublicKey: m.PublicKey, }, nil } diff --git a/contracts/evoting/mod.go b/contracts/evoting/mod.go index 7f77b75f3..58957fb4f 100644 --- a/contracts/evoting/mod.go +++ b/contracts/evoting/mod.go @@ -1,24 +1,24 @@ package evoting import ( - dvoting "github.com/dedis/d-voting" - "github.com/dedis/d-voting/contracts/evoting/types" - "github.com/dedis/d-voting/services/dkg" + dvoting "github.com/c4dt/d-voting" + "github.com/c4dt/d-voting/contracts/evoting/types" + "github.com/c4dt/d-voting/services/dkg" + "github.com/c4dt/dela/core/access" + "github.com/c4dt/dela/core/execution" + "github.com/c4dt/dela/core/execution/native" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + "github.com/c4dt/dela/core/store" + "github.com/c4dt/dela/serde" + "github.com/c4dt/dela/serde/json" "github.com/prometheus/client_golang/prometheus" - "go.dedis.ch/dela/core/access" - "go.dedis.ch/dela/core/execution" - "go.dedis.ch/dela/core/execution/native" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - "go.dedis.ch/dela/core/store" - "go.dedis.ch/dela/serde" - "go.dedis.ch/dela/serde/json" "go.dedis.ch/kyber/v3/proof" "go.dedis.ch/kyber/v3/suites" "golang.org/x/xerrors" // Register the JSON format for the form - _ "github.com/dedis/d-voting/contracts/evoting/json" + _ "github.com/c4dt/d-voting/contracts/evoting/json" ) var ( @@ -68,7 +68,7 @@ var suite = suites.MustFind("Ed25519") const ( // ContractName is the name of the contract. - ContractName = "go.dedis.ch/dela.Evoting" + ContractName = "github.com/c4dt/dela.Evoting" // CmdArg is the argument's name to indicate the kind of command we want to // run on the contract. Should be one of the Command type. diff --git a/contracts/evoting/mod_test.go b/contracts/evoting/mod_test.go index 16e139fd5..6c5d078a3 100644 --- a/contracts/evoting/mod_test.go +++ b/contracts/evoting/mod_test.go @@ -7,23 +7,23 @@ import ( "strconv" "testing" - "github.com/dedis/d-voting/contracts/evoting/types" - "github.com/dedis/d-voting/internal/testing/fake" - "github.com/dedis/d-voting/services/dkg" + "github.com/c4dt/d-voting/contracts/evoting/types" + "github.com/c4dt/d-voting/internal/testing/fake" + "github.com/c4dt/d-voting/services/dkg" + "github.com/c4dt/dela/core/access" + "github.com/c4dt/dela/core/execution" + "github.com/c4dt/dela/core/execution/native" + "github.com/c4dt/dela/core/ordering" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + "github.com/c4dt/dela/core/store" + "github.com/c4dt/dela/core/txn" + "github.com/c4dt/dela/core/txn/signed" + "github.com/c4dt/dela/crypto" + "github.com/c4dt/dela/crypto/bls" + "github.com/c4dt/dela/serde" + sjson "github.com/c4dt/dela/serde/json" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/require" - "go.dedis.ch/dela/core/access" - "go.dedis.ch/dela/core/execution" - "go.dedis.ch/dela/core/execution/native" - "go.dedis.ch/dela/core/ordering" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - "go.dedis.ch/dela/core/store" - "go.dedis.ch/dela/core/txn" - "go.dedis.ch/dela/core/txn/signed" - "go.dedis.ch/dela/crypto" - "go.dedis.ch/dela/crypto/bls" - "go.dedis.ch/dela/serde" - sjson "go.dedis.ch/dela/serde/json" "go.dedis.ch/kyber/v3" "go.dedis.ch/kyber/v3/proof" "go.dedis.ch/kyber/v3/util/random" diff --git a/contracts/evoting/types/ciphervote.go b/contracts/evoting/types/ciphervote.go index f4279ea7e..4cef2ae11 100644 --- a/contracts/evoting/types/ciphervote.go +++ b/contracts/evoting/types/ciphervote.go @@ -4,8 +4,8 @@ import ( "fmt" "io" - "go.dedis.ch/dela/serde" - "go.dedis.ch/dela/serde/registry" + "github.com/c4dt/dela/serde" + "github.com/c4dt/dela/serde/registry" "go.dedis.ch/kyber/v3" "golang.org/x/xerrors" ) diff --git a/contracts/evoting/types/election.go b/contracts/evoting/types/election.go index de35d9630..9323ace18 100644 --- a/contracts/evoting/types/election.go +++ b/contracts/evoting/types/election.go @@ -3,10 +3,10 @@ package types import ( "io" - "go.dedis.ch/dela/core/ordering/cosipbft/authority" - ctypes "go.dedis.ch/dela/core/ordering/cosipbft/types" - "go.dedis.ch/dela/serde" - "go.dedis.ch/dela/serde/registry" + "github.com/c4dt/dela/core/ordering/cosipbft/authority" + ctypes "github.com/c4dt/dela/core/ordering/cosipbft/types" + "github.com/c4dt/dela/serde" + "github.com/c4dt/dela/serde/registry" "go.dedis.ch/kyber/v3" "go.dedis.ch/kyber/v3/suites" "golang.org/x/xerrors" diff --git a/contracts/evoting/types/transactions.go b/contracts/evoting/types/transactions.go index b13b03cbe..12d39738d 100644 --- a/contracts/evoting/types/transactions.go +++ b/contracts/evoting/types/transactions.go @@ -6,8 +6,8 @@ import ( "io" "strconv" - "go.dedis.ch/dela/serde" - "go.dedis.ch/dela/serde/registry" + "github.com/c4dt/dela/serde" + "github.com/c4dt/dela/serde/registry" "golang.org/x/xerrors" ) @@ -133,8 +133,8 @@ func (oe OpenForm) Serialize(ctx serde.Context) ([]byte, error) { type CastVote struct { // FormID is hex-encoded FormID string - UserID string - Ballot Ciphervote + UserID string + Ballot Ciphervote } // Serialize implements serde.Message @@ -155,7 +155,7 @@ func (cv CastVote) Serialize(ctx serde.Context) ([]byte, error) { type CloseForm struct { // FormID is hex-encoded FormID string - UserID string + UserID string } // Serialize implements serde.Message @@ -175,7 +175,7 @@ func (ce CloseForm) Serialize(ctx serde.Context) ([]byte, error) { // - implements serde.Message // - implements serde.Fingerprinter type ShuffleBallots struct { - FormID string + FormID string Round int ShuffledBallots []Ciphervote // RandomVector is the vector to be used to generate the proof of the next @@ -239,7 +239,7 @@ func (rp RegisterPubShares) Serialize(ctx serde.Context) ([]byte, error) { type CombineShares struct { // FormID is hex-encoded FormID string - UserID string + UserID string } // Serialize implements serde.Message @@ -260,7 +260,7 @@ func (db CombineShares) Serialize(ctx serde.Context) ([]byte, error) { type CancelForm struct { // FormID is hex-encoded FormID string - UserID string + UserID string } // Serialize implements serde.Message diff --git a/deb-package/README.md b/deb-package/README.md index ddcfa9144..ef6ec6462 100644 --- a/deb-package/README.md +++ b/deb-package/README.md @@ -170,9 +170,9 @@ To be done on each node. PK=<> # taken from the "ordering export", the part after ":" sudo dvoting --config /var/opt/dedis/dvoting/data/dela pool add \ --key $keypath \ - --args go.dedis.ch/dela.ContractArg --args go.dedis.ch/dela.Access \ + --args github.com/c4dt/dela.ContractArg --args github.com/c4dt/dela.Access \ --args access:grant_id --args 0300000000000000000000000000000000000000000000000000000000000000 \ - --args access:grant_contract --args go.dedis.ch/dela.Evoting \ + --args access:grant_contract --args github.com/c4dt/dela.Evoting \ --args access:grant_command --args all \ --args access:identity --args $PK \ --args access:command --args GRANT @@ -198,7 +198,7 @@ sudo apt install rubygems build-essential git ## Get the code ```sh -git clone https://github.com/dedis/d-voting.git +git clone https://github.com/c4dt/d-voting.git ``` ## Build the deb package diff --git a/deb-package/build-deb.sh b/deb-package/build-deb.sh index a374e11fa..0a61454ec 100755 --- a/deb-package/build-deb.sh +++ b/deb-package/build-deb.sh @@ -45,7 +45,7 @@ fpm \ --after-install pkg/after-install.sh \ --before-remove pkg/before-remove.sh \ --after-remove pkg/after-remove.sh \ - --url https://dedis.github.com/dedis/dvoting \ + --url https://dedis.github.com/c4dt/dvoting \ --description 'D-Voting package' \ --package dist . diff --git a/docs/coverpage.md b/docs/coverpage.md index df717a4c8..4462113e3 100644 --- a/docs/coverpage.md +++ b/docs/coverpage.md @@ -5,7 +5,7 @@

- +

- An open platform to run voting instances on a blockchain diff --git a/docs/index.html b/docs/index.html index 1fd7617bc..4a414ee1a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -13,7 +13,7 @@