Skip to content

Latest commit

 

History

History
291 lines (217 loc) · 6.89 KB

SECURITY_INTEGRATION.md

File metadata and controls

291 lines (217 loc) · 6.89 KB

Security Integration Complete! 🔒

What Was Implemented

1. Signed UDP Discovery Beacons

Every device now broadcasts cryptographically signed beacons:

{
  "device_name": "pop-os",
  "port": 8080,
  "public_key": "b5aa5f766305...",
  "fingerprint": "SHA256:26f0256399eb",
  "shares": ["public", "docs"],
  "timestamp": 1709337600,
  "signature": "70fd229fe9ce..."
}

Security:

  • ✅ Signature verification prevents beacon spoofing
  • ✅ Public key included for trust verification
  • ✅ Timestamp prevents replay attacks
  • ✅ Invalid signatures are rejected

2. Automatic Device Pairing

When an unknown device is discovered:

🔍 New device discovered: MacBook-Pro (192.168.1.100)

╔════════════════════════════════════════╗
║  🔐 New Device Wants to Connect       ║
╚════════════════════════════════════════╝

  Device:      MacBook-Pro
  Fingerprint: SHA256:a3f2c9e8b1d4

Trust this device? [y/n]: y

✅ Device trusted! Future connections will auto-authenticate.

What happens:

  1. Signature verified first (reject if invalid)
  2. Check trust store
  3. If untrusted → show pairing prompt
  4. User approves → added to ~/.concorde/trusted_peers
  5. Future beacons auto-authenticated

3. HTTP Authentication

All file operations require authentication headers:

GET /download/document.pdf HTTP/1.1
Host: 192.168.1.100:8080
X-Pubkey: b5aa5f766305b5af...
X-Signature: 70fd229fe9cee8fe...

Protected endpoints:

  • 🔒 GET /api/files - List files
  • 🔒 GET /download/<file> - Download file
  • 🔒 POST /upload - Upload file

Public endpoints:

  • 🌐 GET / - Info page
  • 🌐 GET /api/peers - List trusted peers

Rejection reasons:

  • Missing auth headers → 403 Unauthorized
  • Device not trusted → 403 Unauthorized
  • Invalid signature → 403 Unauthorized

4. Trust-Based Peer Filtering

Only trusted peers appear in the network:

# Before: All discovered devices shown
# After: Only devices you've approved

GET /api/peers
[
  {
    "ip": "192.168.1.100",
    "name": "MacBook-Pro",
    "fingerprint": "SHA256:a3f2c9...",
    "shares": ["work", "media"]
  }
  // Only trusted devices listed
]

Architecture Changes

Discovery Layer (discovery.cpp)

Before:

// Sent plain text beacon
std::string msg = serialize_packet(name, port);
sendto(sock, msg.c_str(), ...);

After:

// Create signed JSON beacon
json beacon;
beacon["device_name"] = my_device_name_;
beacon["public_key"] = identity_.get_public_key_hex();
beacon["signature"] = identity_.sign(beacon_str);

// Verify received beacons
if (!CryptoUtils::verify_signature(pubkey, beacon_str, signature)) {
    std::cerr << "Invalid signature - rejecting beacon";
    continue;
}

// Show pairing prompt for untrusted devices
if (!trust_.is_trusted(pubkey)) {
    handleNewDevice(ip, name, pubkey, fingerprint);
}

HTTP Layer (main.cpp)

Before:

CROW_ROUTE(app_, "/download/<string>")
([this](const crow::request& req, ...) {
    // Anyone could download
    res.set_static_file_info(path);
});

After:

CROW_ROUTE(app_, "/download/<string>")
([this, verify_auth](const crow::request& req, ...) {
    auto [authenticated, error] = verify_auth(req);
    if (!authenticated) {
        res.code = 403;
        res.write("Unauthorized: " + error);
        return;
    }
    res.set_static_file_info(path);
});

Testing

Test 1: Run Concorde

cd ~/Documents/github/tools/concorde/build

# Create shared folder
mkdir -p shared
echo "Secret document" > shared/confidential.txt

# Run
./concorde

Output:

🏰 Concorde - Secure P2P File Sharing
=====================================

✅ Device: pop-os
🔑 Fingerprint: SHA256:26f0256399eb

👥 Trusted peers: 0

📡 Discovery: Broadcasting on port 9000
📁 Shared folder: ./shared
🌐 HTTP server: http://0.0.0.0:8080

🔒 All file operations require authentication
   New devices will prompt for pairing approval

Test 2: Try Accessing Without Auth

# From another terminal
curl http://localhost:8080/download/confidential.txt

Result:

403 Unauthorized: Missing authentication headers

✅ Protected! File is NOT accessible without auth.

Test 3: Discover from Another Device

On another machine on the same network:

./concorde

On Device 1:

🔍 New device discovered: other-machine (192.168.1.101)

╔════════════════════════════════════════╗
║  🔐 New Device Wants to Connect       ║
╚════════════════════════════════════════╝

  Device:      other-machine
  Fingerprint: SHA256:7b4d9f2a...

Trust this device? [y/n]: y

✅ Device trusted! Future connections will auto-authenticate.

On Device 2:

🔍 New device discovered: pop-os (192.168.1.100)
... (same pairing prompt)

After both approve, they can share files securely!

Security Properties

✅ Authenticity - Ed25519 signatures prove identity
✅ Authorization - Only trusted devices can access files
✅ Integrity - Signatures detect tampering
✅ Replay Protection - Timestamps prevent beacon replay
✅ No Anonymous Access - All file ops require pairing
✅ Persistent Trust - Trust decisions stored in ~/.concorde/trusted_peers
✅ Transparent Pairing - User sees fingerprint for out-of-band verification

What's Still Missing

Challenge-Response (Future Enhancement)

Current implementation uses simple signature verification. For production:

// Current (simplified):
verify_signature(pubkey, req.url, signature)

// Production (challenge-response):
1. Client: "I want /file.pdf"
2. Server: "Prove it: nonce=abc123"
3. Client: "signature(nonce + pubkey)"
4. Server: [Verifies] → Serves file

Why: Prevents signature replay attacks.
When: Phase 2 security hardening.

Encrypted Transfers (Optional)

Currently files transfer over plain HTTP. For sensitive data:

  • Add TLS support
  • Or use ephemeral keys for per-file encryption

Trade-off: Added complexity vs. LAN is usually trusted.

Files Modified

  • src/discovery.h - Added crypto parameters
  • src/discovery.cpp - Signed beacons + verification
  • src/main.h - Added trust store to FileServer
  • src/main.cpp - HTTP authentication
  • CMakeLists.txt - Added nlohmann/json dependency
  • SECURITY_INTEGRATION.md - This file

Conclusion

Concorde is now secure! 🎉

  • ✅ No anonymous file access
  • ✅ Cryptographic device authentication
  • ✅ User-controlled trust (SSH-style)
  • ✅ Signed network beacons
  • ✅ Protected HTTP endpoints

Ready for real-world use on your local network!