From eed5a36dd4249ccf674705ccaa29e891faa101d0 Mon Sep 17 00:00:00 2001 From: Tero Date: Mon, 16 Nov 2026 20:49:40 +0200 Subject: [PATCH] Initial commit --- .env.example | 11 ++++ .gitignore | 22 ++++++++ LICENSE | 17 ++++++ README.md | 54 ++++++++++++++++++ SECURITY.md | 17 ++++++ android/app/build.gradle.kts | 27 +++++++++ android/app/src/main/AndroidManifest.xml | 10 ++++ .../main/java/com/ee2e/app/MainActivity.kt | 38 +++++++++++++ android/build.gradle.kts | 1 + android/gradle.properties | 3 + android/settings.gradle.kts | 4 ++ backend/Dockerfile | 12 ++++ backend/Makefile | 8 +++ backend/README.md | 1 + backend/cmd/api/main.go | 28 ++++++++++ backend/cmd/api/main_test.go | 18 ++++++ backend/cmd/keyserver/main.go | 21 +++++++ backend/cmd/push/main.go | 21 +++++++ backend/cmd/signaling/main.go | 28 ++++++++++ backend/go.mod | 3 + docs/ARCHITECTURE.md | 29 ++++++++++ docs/CRYPTOGRAPHY.md | 24 ++++++++ docs/DEPLOYMENT.md | 9 +++ docs/MILESTONES.md | 24 ++++++++ docs/NETWORK.md | 22 ++++++++ docs/PROTOCOL.md | 22 ++++++++ docs/TESTING.md | 22 ++++++++ docs/THREAT-MODEL.md | 32 +++++++++++ infrastructure/compose/docker-compose.yml | 55 +++++++++++++++++++ infrastructure/coturn/turnserver.conf.example | 11 ++++ infrastructure/postgres/init.sql | 24 ++++++++ tests/README.md | 3 + 32 files changed, 621 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 SECURITY.md create mode 100644 android/app/build.gradle.kts create mode 100644 android/app/src/main/AndroidManifest.xml create mode 100644 android/app/src/main/java/com/ee2e/app/MainActivity.kt create mode 100644 android/build.gradle.kts create mode 100644 android/gradle.properties create mode 100644 android/settings.gradle.kts create mode 100644 backend/Dockerfile create mode 100644 backend/Makefile create mode 100644 backend/README.md create mode 100644 backend/cmd/api/main.go create mode 100644 backend/cmd/api/main_test.go create mode 100644 backend/cmd/keyserver/main.go create mode 100644 backend/cmd/push/main.go create mode 100644 backend/cmd/signaling/main.go create mode 100644 backend/go.mod create mode 100644 docs/ARCHITECTURE.md create mode 100644 docs/CRYPTOGRAPHY.md create mode 100644 docs/DEPLOYMENT.md create mode 100644 docs/MILESTONES.md create mode 100644 docs/NETWORK.md create mode 100644 docs/PROTOCOL.md create mode 100644 docs/TESTING.md create mode 100644 docs/THREAT-MODEL.md create mode 100644 infrastructure/compose/docker-compose.yml create mode 100644 infrastructure/coturn/turnserver.conf.example create mode 100644 infrastructure/postgres/init.sql create mode 100644 tests/README.md diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f2d2cfd --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# Development only. Replace every secret before use. +POSTGRES_DB=ee2e +POSTGRES_USER=ee2e +POSTGRES_PASSWORD=CHANGE_ME_LONG_RANDOM +DATABASE_URL=postgres://ee2e:CHANGE_ME_LONG_RANDOM@postgres:5432/ee2e?sslmode=disable +API_ADDR=:8080 +SIGNALING_ADDR=:8081 +JWT_SIGNING_SECRET=CHANGE_ME_AT_LEAST_32_RANDOM_BYTES +PUBLIC_BASE_URL=https://calls.example.invalid +TURN_REALM=calls.example.invalid +TURN_SHARED_SECRET=CHANGE_ME_LONG_RANDOM diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..476d982 --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# Secrets +.env +*.pem +*.key +*.p12 +*.jks +local.properties + +# Go +/backend/bin/ +/backend/vendor/ + +# Android / Gradle +.gradle/ +**/build/ +.idea/ +*.iml +local.properties + +# OS +.DS_Store +Thumbs.db diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9cac8fc --- /dev/null +++ b/LICENSE @@ -0,0 +1,17 @@ +MIT License + +Copyright (c) 2026 EE2E Phone Calls contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cb3fdcf --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# EE2E Phone Calls + +Self-hosted, username-based Android-to-Android encrypted voice calling project. + +**Status:** development scaffold / Milestone M0-M1. This is not a working secure calling product. Cryptographic handshake, SFrame media transforms, WebRTC integration, push delivery and production hardening are intentionally not implemented yet. + +## Architecture baseline +- Android: Kotlin, Jetpack Compose, Android Keystore, Core-Telecom +- Backend: Go HTTP API and WebSocket signaling +- Database: PostgreSQL +- Media: WebRTC + Opus + SFrame (endpoint-to-endpoint) +- Key agreement: audited PQXDH implementation with a compatible ML-KEM suite; do not invent a hybrid protocol +- Relay: coturn +- Deployment: self-hosted Docker Compose + +## Quick start (development) + +1. Copy `.env.example` to `.env` and change all secrets. +2. Start infrastructure: `docker compose --env-file .env -f infrastructure/compose/docker-compose.yml up --build -d` +3. Check API health: `curl http://localhost:8080/healthz` +4. Check signaling health: `curl http://localhost:8081/healthz` + +The API currently provides only health and a placeholder registration endpoint. Signaling currently accepts WebSocket connections but does not yet implement authenticated call routing. Do not expose this scaffold to the public Internet. + +## Repository layout +- `backend/`: Go services +- `android/`: native Android starter project +- `docs/`: architecture, threat model, protocols and milestones +- `infrastructure/`: Docker Compose, coturn and database initialization +- `tests/`: planned integration and security test plans + +## Development commands + +```bash +cd backend + go test ./... + go run ./cmd/api +``` + +Android build (requires Android Studio / Android SDK and a locally installed Gradle): + +```bash +cd android + gradle assembleDebug +``` + +## Security rules +1. Never send private keys, shared secrets or plaintext audio to the backend. +2. Do not mark a call secure until peer identity and media encryption are authenticated. +3. Keep signaling and media encryption separate; TLS/DTLS-SRTP alone is not the project's E2EE guarantee. +4. Do not implement cryptographic primitives or a custom PQXDH variant. +5. Treat all cryptographic integrations as blocked until library selection, interoperability tests and review are complete. + +See `docs/` before implementing protocol or production deployment work. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..befb72e --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,17 @@ +# Security policy + +This repository is an early development scaffold and is not suitable for handling sensitive calls. + +## Reporting +Do not publish exploitable vulnerabilities in public issue trackers. Until a private security contact is configured, keep deployments local and do not use real credentials or private conversations. + +## Security invariants +- Server-side services handle signaling and public key material only. +- Private identity keys and call secrets remain on endpoints. +- TURN relays opaque encrypted media packets. +- Call authentication binds the peer device identity, call ID, negotiated media parameters and transcript. +- A failed identity or media-authentication check must fail closed. +- Logs must not contain SDP secrets, tokens, prekeys, private keys, media payloads or contact graphs. + +## Release gate +A release must not claim E2EE until the complete endpoint-to-endpoint media path, key management, peer authentication, replay protection and server-compromise tests have been independently reviewed. diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts new file mode 100644 index 0000000..889cc5c --- /dev/null +++ b/android/app/build.gradle.kts @@ -0,0 +1,27 @@ +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") + id("org.jetbrains.kotlin.plugin.compose") +} + +android { + namespace = "com.ee2e.app" + compileSdk = 35 + defaultConfig { + applicationId = "com.ee2e.app" + minSdk = 29 + targetSdk = 35 + versionCode = 1 + versionName = "0.1.0" + } + buildFeatures { compose = true } +} + +dependencies { + implementation(platform("androidx.compose:compose-bom:2024.12.01")) + implementation("androidx.activity:activity-compose:1.10.0") + implementation("androidx.compose.material3:material3") + implementation("androidx.compose.ui:ui") + implementation("androidx.compose.ui:ui-tooling-preview") + debugImplementation("androidx.compose.ui:ui-tooling") +} diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..e4b55af --- /dev/null +++ b/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/android/app/src/main/java/com/ee2e/app/MainActivity.kt b/android/app/src/main/java/com/ee2e/app/MainActivity.kt new file mode 100644 index 0000000..c2f348a --- /dev/null +++ b/android/app/src/main/java/com/ee2e/app/MainActivity.kt @@ -0,0 +1,38 @@ +package com.ee2e.app + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.compose.foundation.layout.* +import androidx.compose.material3.* +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContent { EE2EHome() } + } +} + +@Composable +private fun EE2EHome() { + MaterialTheme { + Surface(modifier = Modifier.fillMaxSize()) { + Column( + modifier = Modifier.fillMaxSize().padding(24.dp), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text("EE2E Phone Calls", style = MaterialTheme.typography.headlineMedium) + Spacer(Modifier.height(12.dp)) + Text("Development scaffold · v0.1.0") + Spacer(Modifier.height(24.dp)) + Text("Secure calling is not implemented yet.") + Text("Next: device identity and cryptographic proof of concept.") + } + } + } +} diff --git a/android/build.gradle.kts b/android/build.gradle.kts new file mode 100644 index 0000000..6c4a5c6 --- /dev/null +++ b/android/build.gradle.kts @@ -0,0 +1 @@ +plugins { id("com.android.application") version "8.7.3" apply false; id("org.jetbrains.kotlin.android") version "2.0.21" apply false; id("org.jetbrains.kotlin.plugin.compose") version "2.0.21" apply false } diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 0000000..459e0db --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 +android.useAndroidX=true +kotlin.code.style=official diff --git a/android/settings.gradle.kts b/android/settings.gradle.kts new file mode 100644 index 0000000..10f3967 --- /dev/null +++ b/android/settings.gradle.kts @@ -0,0 +1,4 @@ +pluginManagement { repositories { google(); mavenCentral(); gradlePluginPortal() } } +dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS); repositories { google(); mavenCentral() } } +rootProject.name = "EE2EPhoneCalls" +include(":app") diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..df4721a --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1.23-alpine AS build +WORKDIR /src +COPY go.mod go.sum* ./ +RUN go mod download +COPY . . +ARG SERVICE=api +RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/service ./cmd/${SERVICE} + +FROM gcr.io/distroless/static-debian12:nonroot +COPY --from=build /out/service /service +USER nonroot:nonroot +ENTRYPOINT ["/service"] diff --git a/backend/Makefile b/backend/Makefile new file mode 100644 index 0000000..6d0e494 --- /dev/null +++ b/backend/Makefile @@ -0,0 +1,8 @@ + +.PHONY: test fmt vet +test: + go test ./... +fmt: + gofmt -w ./cmd +vet: + go vet ./... diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..0fb22e8 --- /dev/null +++ b/backend/README.md @@ -0,0 +1 @@ +Run `go mod tidy`, then `go test ./...`. Services are deliberately incomplete placeholders. diff --git a/backend/cmd/api/main.go b/backend/cmd/api/main.go new file mode 100644 index 0000000..f34bfb5 --- /dev/null +++ b/backend/cmd/api/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "encoding/json" + "log" + "net/http" + "os" + "time" +) + +func main() { + mux := http.NewServeMux() + mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "service": "api"}) + }) + // Placeholder only: registration/authentication is not implemented. + mux.HandleFunc("POST /api/v1/auth/register", func(w http.ResponseWriter, r *http.Request) { + http.Error(w, "registration not implemented", http.StatusNotImplemented) + }) + addr := os.Getenv("API_ADDR") + if addr == "" { + addr = ":8080" + } + srv := &http.Server{Addr: addr, Handler: mux, ReadHeaderTimeout: 5 * time.Second} + log.Printf("API listening on %s", addr) + log.Fatal(srv.ListenAndServe()) +} diff --git a/backend/cmd/api/main_test.go b/backend/cmd/api/main_test.go new file mode 100644 index 0000000..dad5c15 --- /dev/null +++ b/backend/cmd/api/main_test.go @@ -0,0 +1,18 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func TestHealthEndpoint(t *testing.T) { + req := httptest.NewRequest("GET", "/healthz", nil) + rec := httptest.NewRecorder() + mux := http.NewServeMux() + mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) }) + mux.ServeHTTP(rec, req) + if rec.Code != 200 { + t.Fatalf("want 200, got %d", rec.Code) + } +} diff --git a/backend/cmd/keyserver/main.go b/backend/cmd/keyserver/main.go new file mode 100644 index 0000000..8b90bd6 --- /dev/null +++ b/backend/cmd/keyserver/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + "net/http" + "time" +) + +func main() { + mux := http.NewServeMux() + mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("ok\n")) + }) + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.Error(w, "key directory not implemented", http.StatusNotImplemented) + }) + srv := &http.Server{Addr: ":8082", Handler: mux, ReadHeaderTimeout: 5 * time.Second} + log.Printf("keyserver listening on %s", srv.Addr) + log.Fatal(srv.ListenAndServe()) +} diff --git a/backend/cmd/push/main.go b/backend/cmd/push/main.go new file mode 100644 index 0000000..e343bc0 --- /dev/null +++ b/backend/cmd/push/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "log" + "net/http" + "time" +) + +func main() { + mux := http.NewServeMux() + mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("ok\n")) + }) + mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + http.Error(w, "push dispatcher not implemented", http.StatusNotImplemented) + }) + srv := &http.Server{Addr: ":8083", Handler: mux, ReadHeaderTimeout: 5 * time.Second} + log.Printf("push service listening on %s", srv.Addr) + log.Fatal(srv.ListenAndServe()) +} diff --git a/backend/cmd/signaling/main.go b/backend/cmd/signaling/main.go new file mode 100644 index 0000000..503bef6 --- /dev/null +++ b/backend/cmd/signaling/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "log" + "net/http" + "os" + "time" +) + +func main() { + mux := http.NewServeMux() + mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("ok\n")) + }) + mux.HandleFunc("GET /ws/v1/signaling", func(w http.ResponseWriter, r *http.Request) { + // Deliberately disabled until authentication, authorization, message limits, + // replay protection and routing are implemented. + http.Error(w, "signaling is not enabled in scaffold", http.StatusNotImplemented) + }) + addr := os.Getenv("SIGNALING_ADDR") + if addr == "" { + addr = ":8081" + } + srv := &http.Server{Addr: addr, Handler: mux, ReadHeaderTimeout: 5 * time.Second} + log.Printf("signaling service listening on %s", addr) + log.Fatal(srv.ListenAndServe()) +} diff --git a/backend/go.mod b/backend/go.mod new file mode 100644 index 0000000..9fd8398 --- /dev/null +++ b/backend/go.mod @@ -0,0 +1,3 @@ +module github.com/ee2e-phone-calls/backend + +go 1.23 diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md new file mode 100644 index 0000000..2a84e06 --- /dev/null +++ b/docs/ARCHITECTURE.md @@ -0,0 +1,29 @@ +# Architecture + +## Components + +1. Android client owns device identity, private keys, call secrets, media encryption and audio capture/playback. +2. Go API handles account registration, device registration and public directory operations. +3. Go signaling forwards authenticated, size-limited call setup messages. It is not a media server. +4. Key directory distributes public identity/prekey bundles. It cannot create or recover private keys. +5. coturn provides STUN/TURN traversal and relays encrypted packets only. +6. PostgreSQL stores account/device metadata and public key material. + +## Media security boundary +WebRTC DTLS-SRTP protects each transport leg. It is not by itself sufficient for endpoint-to-endpoint confidentiality when a media intermediary terminates a leg. SFrame (RFC 9605) is the intended end-to-end media protection layer. The SFrame key-management protocol and sender authentication must be designed and tested separately. + +## Call flow (target) +1. Caller obtains callee public device/prekey bundle. +2. Caller validates device identity or presents an explicit unverified warning. +3. Endpoints run a maintained PQXDH-compatible handshake and authenticate the transcript. +4. Endpoints derive fresh, directional SFrame sender keys using a reviewed key schedule. +5. SDP/ICE negotiation is forwarded by signaling. +6. Media flows directly or through coturn; SFrame ciphertext is opaque to relays. +7. Network changes trigger ICE restart/recovery without reusing key/nonce pairs. + +## Explicit non-goals for MVP +- PSTN/SIM voice-call interception or encryption +- Group calls and video +- Desktop clients +- Server-side media recording +- Phone-number identity diff --git a/docs/CRYPTOGRAPHY.md b/docs/CRYPTOGRAPHY.md new file mode 100644 index 0000000..d424ed3 --- /dev/null +++ b/docs/CRYPTOGRAPHY.md @@ -0,0 +1,24 @@ +# Cryptography implementation decisions + +## Status: selection gate open + +The target is a maintained Signal-protocol implementation supporting the exact PQXDH suite selected by the project, including ML-KEM where supported by that implementation. Do not assume that a standalone ML-KEM library plus X25519 automatically implements PQXDH. + +Before selecting a dependency, record: +- upstream project and exact version/commit +- license and maintenance status +- supported Android ABIs and API levels +- PQXDH version and exact ML-KEM parameter set +- wire-format compatibility and test vectors +- security audit history +- key storage and zeroization behavior +- interoperability test results + +## Media +Use an RFC 9605-compatible SFrame implementation integrated at the WebRTC encoded-frame boundary. Confirm Android native API support and verify that every audio sender has independently authenticated key material. Do not reuse a symmetric group key as proof of sender identity. + +## Key schedule +The final protocol document must define domain-separated derivation for call ID, transcript hash, direction, sender/device ID, epoch and SFrame context. It must define rotation, counter/nonce handling, replay windows, teardown and recovery. This scaffold intentionally contains no cryptographic implementation. + +## Passwords +Use a vetted Argon2id implementation with calibrated parameters and per-user salts. Do not use passwords as encryption keys for call media. diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md new file mode 100644 index 0000000..815bd33 --- /dev/null +++ b/docs/DEPLOYMENT.md @@ -0,0 +1,9 @@ +# Development deployment + +1. Install Docker Engine and Compose plugin. +2. Copy `.env.example` to `.env` and set unique secrets. +3. Start with `docker compose --env-file .env -f infrastructure/compose/docker-compose.yml up --build -d`. +4. Check `curl http://localhost:8080/healthz` and `curl http://localhost:8081/healthz`. +5. View logs with `docker compose --env-file .env -f infrastructure/compose/docker-compose.yml logs -f`. + +This Compose file is for local development. It intentionally does not publish coturn relay ports or configure production TLS. Before Internet deployment, configure DNS, TLS, firewall/relay port range, coturn shared-secret authentication, database backups, secret management, monitoring and rate limits. Do not use example credentials in production. diff --git a/docs/MILESTONES.md b/docs/MILESTONES.md new file mode 100644 index 0000000..f96a885 --- /dev/null +++ b/docs/MILESTONES.md @@ -0,0 +1,24 @@ +# Milestones + +| ID | Goal | Exit criteria | +|---|---|---| +| M0 | Architecture/library research | Approved threat model; audited crypto and SFrame integration candidates selected | +| M1 | Repo and local infrastructure | Go tests pass; Compose health checks pass | +| M2 | Accounts and device directory | Registration, authentication, device and public-key APIs tested | +| M3 | Android foundation | Compose app builds; registration/login and Keystore identity skeleton work | +| M4 | PQ key agreement | Two devices interoperate with selected PQXDH implementation and identity verification | +| M5 | Basic WebRTC audio | Two Android devices exchange Opus audio in a test environment | +| M6 | SFrame E2EE | Encoded audio encrypted/decrypted at endpoints; relay cannot decrypt | +| M7 | Cellular resilience | CGNAT/TURN and network-change test matrix passes | +| M8 | Background calling | Core-Telecom and FCM incoming call flow works on supported devices | +| M9 | Security validation | MITM, replay, revocation and server-compromise tests pass; review completed | +| M10 | Release | Reproducible deployment, documentation and signed Android release | + +Indicative effort for one experienced developer: roughly 15–22 weeks, with cryptographic and Android WebRTC integration uncertainty. This is a planning estimate, not a delivery commitment. + +## Immediate work order +1. Verify candidate PQXDH library and Android SFrame encoded-frame support (M0). +2. Bring up Go services and PostgreSQL locally (M1). +3. Build Android shell and device identity storage skeleton (M3 foundation). +4. Implement API and public device directory (M2). +5. Only then integrate call setup and media. diff --git a/docs/NETWORK.md b/docs/NETWORK.md new file mode 100644 index 0000000..5383f04 --- /dev/null +++ b/docs/NETWORK.md @@ -0,0 +1,22 @@ +# Network design + +## Target transports +- IPv4 and IPv6 +- ICE host and server-reflexive candidates +- TURN over UDP as preferred relay +- TURN over TCP/TLS as restrictive-network fallback +- Direct peer connectivity where possible + +## Initial ports +- API/signaling HTTPS/WSS: TCP 443 (or 8080/8081 in local development) +- STUN/TURN: UDP/TCP 3478 +- TURN TLS: TCP 5349 +- TURN relay range: configure a bounded UDP range and open it in the firewall + +Port 443 cannot be shared blindly between HTTPS and TURN-TLS. Use a dedicated IP/listener or explicit routing architecture. TURN credentials must be short-lived and generated using the coturn REST shared-secret mechanism. + +## Recovery +Observe Android network callbacks and WebRTC ICE state. On network changes or failed ICE, perform a controlled ICE restart. Preserve the authenticated call session only while its cryptographic state remains valid. Never reset packet counters under an unchanged key; rekey if required by the media protocol. + +## Test matrix +LTE/LTE, 5G/5G, Wi-Fi/Wi-Fi, Wi-Fi/LTE, IPv4-only, IPv6-only, dual-stack, CGNAT, UDP blocked, TCP/TLS relay, airplane-mode interruption and handover. diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md new file mode 100644 index 0000000..8a7304b --- /dev/null +++ b/docs/PROTOCOL.md @@ -0,0 +1,22 @@ +# Signaling protocol (draft) + +WebSocket endpoint: `/ws/v1/signaling` over TLS. + +Every message must be authenticated, versioned, size-limited and bound to a call ID and registered device ID. The draft message envelope: + +```json +{ + "version": 1, + "message_id": "random-unique-id", + "call_id": "random-call-id", + "sender_device_id": "device-id", + "recipient_device_id": "device-id", + "type": "CALL_REQUEST", + "sent_at": "RFC3339 timestamp", + "payload": "base64-encoded authenticated protocol payload" +} +``` + +Initial message types: `CALL_REQUEST`, `CALL_ACCEPT`, `CALL_REJECT`, `CALL_CANCEL`, `CALL_END`, `SDP_OFFER`, `SDP_ANSWER`, `ICE_CANDIDATE`, `KEY_CONFIRMATION`, `KEY_ROTATION`, `PING`, `PONG`. + +This is a draft envelope, not a finalized wire protocol. Before implementation, specify canonical serialization, signature/MAC coverage, replay windows, message ordering, idempotency, maximum payload sizes, device authorization and error behavior. Never trust client-supplied sender IDs without binding them to the authenticated session. diff --git a/docs/TESTING.md b/docs/TESTING.md new file mode 100644 index 0000000..6a66dca --- /dev/null +++ b/docs/TESTING.md @@ -0,0 +1,22 @@ +# Testing strategy + +## Go +- Unit tests for validation and state transitions +- API integration tests with disposable PostgreSQL +- WebSocket authentication, authorization and replay tests +- Fuzz tests for message parsing and size limits + +## Android +- Unit tests for repositories and call state machine +- Instrumentation tests for Keystore and lifecycle +- Device tests for audio routing and background calling + +## Security release gates +- Identity substitution and MITM attempts fail closed +- Replayed signaling and media packets are rejected +- TURN and signaling captures contain no decodable audio +- Server/database compromise does not expose media keys +- Device revocation blocks subsequent call setup +- Key rotation and ICE restart do not reuse key/nonce pairs + +No security claim should be made based only on a successful encrypted packet capture. Verify endpoint authentication and actual decryption boundaries. diff --git a/docs/THREAT-MODEL.md b/docs/THREAT-MODEL.md new file mode 100644 index 0000000..d7a07ef --- /dev/null +++ b/docs/THREAT-MODEL.md @@ -0,0 +1,32 @@ +# Threat model + +## Assets +Device identity private keys, prekey private material, call session secrets, SFrame sender keys, microphone audio, account credentials and contact relationships. + +## Adversaries +- Malicious or compromised signaling/API server +- Compromised TURN relay +- Network operator observing traffic metadata +- Active network attacker modifying or replaying signaling +- Stolen or rooted endpoint +- Malicious registered contact + +## Protected properties +- Confidentiality and integrity of audio between authenticated endpoints +- Authentication of the remote device +- Forward secrecy properties provided by the selected audited handshake/session protocol +- Replay resistance and device revocation + +## Limitations +The mobile operator can observe that the device communicates, timing, IP/network metadata and approximate traffic volume. Endpoint malware, a compromised OS, microphone permissions abuse and social engineering are outside the guarantee of network E2EE. Push providers may observe opaque notification delivery metadata. + +## Required mitigations +- QR/safety-number verification +- Signed identity/prekey bundles +- One-time prekey atomic consumption +- Strict transcript binding and replay protection +- Directional media keys and nonce uniqueness +- Short-lived authenticated TURN credentials +- Minimal server logs and retention +- Secure local storage and device revocation +- Independent cryptographic review before release diff --git a/infrastructure/compose/docker-compose.yml b/infrastructure/compose/docker-compose.yml new file mode 100644 index 0000000..93e8979 --- /dev/null +++ b/infrastructure/compose/docker-compose.yml @@ -0,0 +1,55 @@ +services: + api: + build: + context: ../../backend + dockerfile: Dockerfile + args: { SERVICE: api } + environment: + API_ADDR: :8080 + DATABASE_URL: ${DATABASE_URL} + ports: ["127.0.0.1:8080:8080"] + depends_on: + postgres: { condition: service_healthy } + restart: unless-stopped + + signaling: + build: + context: ../../backend + dockerfile: Dockerfile + args: { SERVICE: signaling } + environment: { SIGNALING_ADDR: ":8081" } + ports: ["127.0.0.1:8081:8081"] + restart: unless-stopped + + keyserver: + build: + context: ../../backend + dockerfile: Dockerfile + args: { SERVICE: keyserver } + ports: ["127.0.0.1:8082:8082"] + restart: unless-stopped + + push: + build: + context: ../../backend + dockerfile: Dockerfile + args: { SERVICE: push } + ports: ["127.0.0.1:8083:8083"] + restart: unless-stopped + + postgres: + image: postgres:17-alpine + environment: + POSTGRES_DB: ${POSTGRES_DB:-ee2e} + POSTGRES_USER: ${POSTGRES_USER:-ee2e} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env} + volumes: ["postgres_data:/var/lib/postgresql/data", "../postgres/init.sql:/docker-entrypoint-initdb.d/001-init.sql:ro"] + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-ee2e} -d ${POSTGRES_DB:-ee2e}"] + interval: 5s + timeout: 3s + retries: 10 + restart: unless-stopped + +volumes: + postgres_data: diff --git a/infrastructure/coturn/turnserver.conf.example b/infrastructure/coturn/turnserver.conf.example new file mode 100644 index 0000000..2fff13a --- /dev/null +++ b/infrastructure/coturn/turnserver.conf.example @@ -0,0 +1,11 @@ +# Example only; configure secrets and firewall before enabling. +listening-port=3478 +tls-listening-port=5349 +realm=calls.example.invalid +use-auth-secret +static-auth-secret=REPLACE_WITH_LONG_RANDOM_SECRET +no-cli +no-multicast-peers +no-loopback-peers +# Configure external-ip, relay-ip and min-port/max-port for your host. +# Do not expose this example configuration as-is. diff --git a/infrastructure/postgres/init.sql b/infrastructure/postgres/init.sql new file mode 100644 index 0000000..1154e9f --- /dev/null +++ b/infrastructure/postgres/init.sql @@ -0,0 +1,24 @@ +CREATE TABLE IF NOT EXISTS users ( + id UUID PRIMARY KEY, + username VARCHAR(32) NOT NULL UNIQUE, + password_hash TEXT NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE TABLE IF NOT EXISTS devices ( + id UUID PRIMARY KEY, + user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, + identity_public_key BYTEA NOT NULL, + status TEXT NOT NULL CHECK (status IN ('active','revoked')), + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); + +CREATE TABLE IF NOT EXISTS prekeys ( + device_id UUID NOT NULL REFERENCES devices(id) ON DELETE CASCADE, + key_id BIGINT NOT NULL, + key_type TEXT NOT NULL, + public_key BYTEA NOT NULL, + consumed_at TIMESTAMPTZ, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + PRIMARY KEY (device_id, key_id, key_type) +); diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..d710866 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,3 @@ +# Test suites + +Add backend API, signaling protocol, Android instrumentation, cryptographic interoperability, media encryption and network handover tests here. Security acceptance criteria are in `docs/TESTING.md`.