Skip to content

HushNet/HushNet-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” HushNet Backend

Rust License: MIT PostgreSQL

HushNet Backend is a secure backend server for an end-to-end encrypted (E2EE) instant messaging application, built with Rust and Axum. It implements the Signal Protocol (X3DH + Double Ratchet) to provide cryptographically secure communication between users and devices.


πŸ“‹ Table of Contents


✨ Features

  • πŸ”’ End-to-End Encryption (E2EE): Signal Protocol implementation (X3DH + Double Ratchet)
  • πŸ” Ed25519 Authentication: Cryptographic signature-based authentication (no JWT)
  • πŸ‘₯ Multi-Device Support: Full support for multiple devices per user
  • πŸ’¬ Instant Messaging: Direct messages and group chats
  • πŸ”‘ Cryptographic Key Management: Identity keys, prekeys, signed prekeys, one-time prekeys
  • ⚑ Real-time Communication: WebSockets for instant notifications
  • πŸ“‘ PostgreSQL LISTEN/NOTIFY: Real-time event notifications
  • πŸš€ High Performance: Asynchronous backend powered by Tokio
  • 🐳 Docker Ready: Docker configuration for PostgreSQL
  • πŸ›‘οΈ Anti-Replay Protection: Timestamp-based request validation

πŸš€ Quick Start

# Clone the repository
git clone https://github.com/HushNet/HushNet-Backend.git
cd HushNet-Backend

# Start PostgreSQL with Docker
docker build -t hushnet-postgres .
docker run -d -p 5432:5432 --name hushnet-db hushnet-postgres

# Configure environment
echo "DATABASE_URL=postgres://postgres:dev@localhost:5432/e2ee" > .env

# Build and run
cargo build --release
cargo run

Server will start at http://127.0.0.1:8080 πŸŽ‰


πŸ“š Documentation

Comprehensive documentation is organized into the following sections:

Core Documentation

Setup & Deployment

Additional Resources


πŸ—οΈ Architecture

HushNet Backend follows a clean, modular architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Client Applications                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚ HTTP/WebSocket
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Axum Web Framework                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚   Routes    β”‚  β”‚ Middlewares β”‚  β”‚ Controllers β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚         β”‚                 β”‚                 β”‚            β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚                  β”‚                 β”‚                     β”‚
β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚
β”‚         β”‚    Services      β”‚  β”‚ Repositories β”‚          β”‚
β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚       PostgreSQL Database            β”‚
                    β”‚  (LISTEN/NOTIFY for real-time)       β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Communication Flow

  1. Authentication: Ed25519 signature verification on each request
  2. Key Exchange: X3DH handshake to establish secure sessions
  3. Messaging: Double Ratchet encryption for each message
  4. Real-time: PostgreSQL NOTIFY β†’ WebSocket β†’ Clients

πŸ› οΈ Technology Stack

Core Framework

  • Rust (Edition 2021) - Programming language
  • Axum 0.7 - Async web framework
  • Tokio - Async runtime
  • SQLx 0.8 - PostgreSQL async client

Cryptography

Database

  • PostgreSQL 14+ - Relational database
  • LISTEN/NOTIFY - Real-time notification mechanism

Utilities

  • Serde - JSON serialization/deserialization
  • Tracing - Structured logging
  • Dotenvy - Environment variable management
  • Anyhow - Error handling
  • UUID - Unique identifier generation
  • Chrono - Date and time handling

πŸ“‹ Prerequisites

  • Rust 1.70+ (Install)
  • PostgreSQL 14+ (Install)
  • Docker (optional, for database)
  • Cargo (included with Rust)

βš™οΈ Installation

For detailed installation instructions, see the Installation Guide.

Quick Install

# 1. Clone repository
git clone https://github.com/HushNet/HushNet-Backend.git
cd HushNet-Backend

# 2. Install dependencies
cargo build

# 3. Setup database (with Docker)
docker build -t hushnet-postgres .
docker run -d -p 5432:5432 --name hushnet-db hushnet-postgres

# 4. Configure environment
cp .env.example .env
# Edit .env with your configuration

# 5. Run server
cargo run

πŸ”§ Configuration

Environment Variables

Create a .env file in the project root:

# Database
DATABASE_URL=postgres://postgres:dev@localhost:5432/e2ee

# Logging
RUST_LOG=info

For complete configuration options, see the Configuration Guide.


🀝 Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Quick Start for Contributors

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (cargo test)
  5. Format code (cargo fmt)
  6. Check lints (cargo clippy)
  7. Commit changes (git commit -m 'Add amazing feature')
  8. Push to branch (git push origin feature/amazing-feature)
  9. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.


πŸ™ Acknowledgments

  • Signal Protocol for cryptographic inspiration
  • Axum for the excellent web framework
  • The Rust community πŸ¦€

πŸ“ž Contact


Built with ❀️ and πŸ¦€ Rust

⭐ If you like this project, please give it a star!

Documentation β€’ API Reference β€’ Contributing

About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •