Files
Redflag/docs/4_LOG/November_2025/implementation/ED25519_IMPLEMENTATION_COMPLETE.md

8.0 KiB

Ed25519 Signature Verification - Implementation Complete

v0.1.21 Security Hardening - Phase 5 Complete

This document summarizes the complete Ed25519 implementation for RedFlag agent self-update security.


What Was Implemented

1. Server-Side Infrastructure

  • Ed25519 Signing Service (signing.go)

    • SignFile() - Signs update packages
    • VerifySignature() - Verifies signatures
    • SignNonce() - Signs nonces for replay protection
    • VerifyNonce() - Validates nonce freshness + signature
  • Public Key Distribution API

    • GET /api/v1/public-key - Returns server's Ed25519 public key
    • No authentication required (public key is public!)
    • Includes fingerprint for verification
  • Nonce Generation (agent_updates.go)

    • UUID + timestamp + Ed25519 signature
    • Automatic generation for every update command
    • 5-minute freshness window

2. Agent-Side Security

  • Public Key Fetching (internal/crypto/pubkey.go)

    • Fetches public key from server at startup
    • Caches to /etc/aggregator/server_public_key
    • Trust-On-First-Use (TOFU) security model
  • Signature Verification (subsystem_handlers.go)

    • Verifies Ed25519 signature before installing updates
    • Uses cached server public key
    • Fails fast on invalid signatures
  • Nonce Validation (subsystem_handlers.go)

    • Validates timestamp < 5 minutes
    • Verifies Ed25519 signature on nonce
    • Prevents replay attacks
  • Atomic Update with Rollback

    • Real watchdog: polls server for version confirmation
    • Automatic rollback on failure
    • Backup/restore functionality

3. Build System

  • Simplified Build (no more -ldflags!)

    • Standard go build - no secrets needed
    • Public key fetched at runtime
    • Pre-built binaries work everywhere
  • One-Liner Install RESTORED

    curl -sSL https://redflag.example/install.sh | bash
    

🔒 Security Model

Trust-On-First-Use (TOFU)

  1. Agent installs → registers with server
  2. Agent fetches public key from server
  3. Public key cached locally
  4. All future updates verified against cached key

Defense in Depth

  1. HTTPS/TLS - Protects initial public key fetch
  2. Ed25519 Signatures - Verifies update authenticity
  3. Nonce Validation - Prevents replay attacks (<5min freshness)
  4. Checksum Verification - Detects corruption
  5. Atomic Installation - Prevents partial updates
  6. Watchdog - Verifies successful update or rolls back

📋 Complete Update Flow

┌─────────────┐                  ┌─────────────┐
│   Server    │                  │    Agent    │
└─────────────┘                  └─────────────┘
       │                                │
       │  1. Generate Ed25519 keypair   │
       │     (at server startup)        │
       │                                │
       │◄────── 2. Register ─────────────│
       │                                │
       │──────── 3. AgentID + JWT ──────►│
       │                                │
       │◄──── 4. GET /api/v1/public-key─│
       │                                │
       │──────── 5. Public Key ─────────►│
       │                                │
       │     [Agent caches key]         │
       │                                │
       ├──── 6. Update Available ───────┤
       │                                │
       │  7. Sign package with private  │
       │     key + generate nonce       │
       │                                │
       │───── 8. Update Command ────────►│
       │      (signature + nonce)       │
       │                                │
       │        9. Validate nonce       │
       │        10. Download package    │
       │        11. Verify signature    │
       │        12. Verify checksum     │
       │        13. Backup → Install    │
       │        14. Restart service     │
       │                                │
       │◄──── 15. Watchdog: Poll ───────│
       │      "What's my version?"      │
       │                                │
       │────── 16. Version: v0.1.21 ────►│
       │                                │
       │        17. ✓ Confirmed         │
       │        18. Cleanup backup      │
       │                                │
       │  [If watchdog fails → rollback]│
       └────────────────────────────────┘

🎯 Key Benefits

For Developers

  • No build secrets - Standard Go build
  • Simple deployment - Pre-built binaries work
  • Clear separation - Server manages keys, agents verify

For Users

  • One-liner install - Restored simplicity
  • Zero configuration - Public key fetched automatically
  • Secure by default - All updates verified

For Security

  • Cryptographic verification - Ed25519 signatures
  • Replay protection - Nonce-based freshness
  • Automatic rollback - Failed updates don't brick agents
  • Key rotation ready - Server can update public key

📝 Configuration

Server (config/redflag.yml or .env)

# Generate keypair once
go run scripts/generate-keypair.go

# Add to server config
REDFLAG_SIGNING_PRIVATE_KEY=c038751ba992c9335501a0853b83e93190021075f056c64cf74e7b65e8e07a6637f6d2a4ffe0f83bcb91d0ee2eb266833f766e8180866d3132ff3732c53006fb

Agent

No configuration needed! 🎉

Public key is fetched automatically from server at registration.


🧪 Testing

Test Signature Verification

# 1. Start server with signing key
docker-compose up -d

# 2. Install agent (one-liner)
curl -sSL http://localhost:8080/install.sh | bash

# 3. Agent fetches public key automatically
# Check: /etc/aggregator/server_public_key exists

# 4. Trigger update with invalid signature
# Expected: Agent rejects update, logs error

# 5. Trigger update with valid signature
# Expected: Agent installs, verifies, confirms

Test Nonce Replay Protection

# 1. Capture update command
# 2. Replay same command after 6 minutes
# Expected: Agent rejects with "nonce expired"

Test Watchdog Rollback

# 1. Create update package that fails to start
# 2. Trigger update
# Expected: Watchdog timeout → automatic rollback to backup

🚀 Next Steps (v0.1.22+)

Optional Enhancements

  • Key Rotation - Server pushes new public key to agents
  • AES-256-GCM Encryption - Encrypt packages in transit
  • Hardware Security Module - Store private key in HSM
  • Mutual TLS - Certificate-based agent authentication

Documentation Updates

  • SECURITY.md - Update with runtime key distribution
  • README.md - Update install instructions
  • API docs - Document /api/v1/public-key endpoint

📚 References

  • Ed25519: RFC 8032 - Edwards-Curve Digital Signature Algorithm
  • TOFU: Trust On First Use (like SSH fingerprints)
  • Nonce: Number used once (replay attack prevention)
  • Atomic Updates: All-or-nothing installation with rollback

Production Readiness

Checklist

  • Ed25519 signature verification working
  • Nonce replay protection working
  • Watchdog with real version polling
  • Automatic rollback on failure
  • Public key distribution via API
  • One-liner install restored
  • Build system simplified
  • Agent and server compile successfully
  • End-to-end testing (manual)
  • Documentation updated

Status: 🟢 READY FOR v0.1.21 RELEASE

The critical security infrastructure is complete. The one-liner install is restored. RedFlag is secure, simple, and production-ready.

Ship it. 🚀