Skip to content
/ flyme Public

Local IPC for Rust, where "hello" requires a cryptographic handshake.

Notifications You must be signed in to change notification settings

notashes/flyme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Flyme IPC

A cross-platform Inter-Process Communication (IPC) library written in Rust with built-in anti-tampering protection against fake clients. This library provides secure, mutual TLS-authenticated communication between privileged server processes and unprivileged client applications.

Features

  • πŸ”’ Mutual TLS Authentication: Certificate-based security for both client and server
  • πŸ›‘οΈ Anti-Tampering Protection: Process credential verification and binary hash validation
  • 🌐 Cross-Platform: Unix domain sockets on Unix-like systems, named pipes on Windows
  • πŸ”§ Clean Architecture: Multi-crate workspace with clear separation of concerns
  • ⚑ High Performance: Async-first design with tokio for concurrent client handling
  • πŸ”„ Thread-Safe: Safe concurrent access with proper synchronization primitives

Architecture

This workspace is organized into three main crates:

πŸ“¦ Crates

Crate Description Purpose
common/ Shared protocols and utilities Platform-specific socket implementations, TLS streams, message definitions
client/ Client library Secure IPC client for connecting to servers
server/ Server library Secure IPC server with client validation

πŸ”§ Key Components

  • Platform Abstraction: Unified interface for Unix domain sockets and Windows named pipes
  • TLS Integration: Rustls-based mutual TLS with certificate management
  • Process Validation: Client binary hash verification and user credential checking
  • Message Protocol: Efficient binary serialization with structured message types

Quick Start

Prerequisites

  • Rust 1.70+ (2021 edition)
  • Valid TLS certificates for mutual authentication

Building

# Build the entire workspace
cargo build

# Build with optimizations
cargo build --release

# Check all crates
cargo check

Running Examples

# Client examples
cargo run --example basic                    # Basic client example
cargo run --example cli interactive         # Interactive CLI client
cargo run --example cli ping                # Quick connection test

# Server examples
cargo run --example basic -p flyme-server    # Basic server setup
cargo run --example daemon -p flyme-server   # Daemon server with signal handling
cargo run --example echo -p flyme-server     # Echo server with custom commands

Usage

Client Library

use flyme_client::{ClientConfig, SecureIpcClient};
use std::time::Duration;

// Create client with custom configuration
let config = ClientConfig::new()
    .with_timeout(Duration::from_secs(10))
    .with_verbose(true);

// Connect and send requests
let mut client = SecureIpcClient::new(config)?;
client.connect()?;

let response = client.send_request("status")?;
println!("Server response: {}", response);

client.disconnect()?;

Server Library

use flyme_server::SecureIpcServer;
use flyme_common::config::ServerCertPath;

// Initialize server with TLS certificates
let cert_path = ServerCertPath::new();
let server = SecureIpcServer::new(cert_path, "my-socket".to_string())?;

// Start accepting connections (blocking)
server.run()?;

Server Examples

The server crate includes several examples demonstrating different use cases:

  • Basic Server (examples/basic.rs): Simple server setup with certificate management
  • Daemon Server (examples/daemon.rs): Long-running server with signal handling and graceful shutdown
  • Echo Server (examples/echo.rs): Custom server implementation with command processing

Security Model

Authentication Flow

  1. Socket Connection: Client connects to platform-specific socket
  2. TLS Handshake: Mutual TLS authentication with certificate verification
  3. Process Validation: Server verifies client user credentials and process information
  4. Binary Verification: Optional client binary hash validation
  5. Secure Communication: Encrypted message exchange over established TLS channel

Certificate Management

The library expects the following certificate structure:

certificates/
β”œβ”€β”€ ca.pem              # Certificate Authority
β”œβ”€β”€ server-cert.pem     # Server certificate  
β”œβ”€β”€ server-key.pem      # Server private key
β”œβ”€β”€ client-cert.pem     # Client certificate
└── client-key.pem      # Client private key

Anti-Tampering Features

  • Process Credential Verification: Ensures client runs with expected user privileges
  • Binary Hash Validation: Verifies client executable integrity (configurable)
  • Certificate Pinning: Mutual TLS prevents man-in-the-middle attacks
  • Abstract Namespace Sockets: On Linux, uses abstract sockets to prevent filesystem-based attacks

Configuration

Environment Variables

Variable Description Default
FLYME_CLIENT_BINARY_HASH Expected SHA256 hash of client binary Empty (validation disabled)
FLYME_CLIENT_BINARY_HASHES Comma-separated list of allowed hashes Empty
FLYME_ENFORCE_CLIENT_HASH_VALIDATION Enable/disable hash validation false

Socket Configuration

  • Unix: Abstract namespace socket /tmp/flyme
  • Windows: Named pipe \\.\pipe\flyme

Development

Project Structure

flyme/
β”œβ”€β”€ Cargo.toml          # Workspace configuration
β”œβ”€β”€ common/             # Shared protocols and utilities
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config.rs       # Message and cert path definitions
β”‚   β”‚   β”œβ”€β”€ platform_socket.rs  # Cross-platform socket abstraction
β”‚   β”‚   β”œβ”€β”€ tls_stream.rs   # TLS wrapper for sockets

β”‚   β”‚   └── lib.rs          # Common library entry point
β”‚   └── Cargo.toml
β”œβ”€β”€ client/             # Client library
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ client.rs       # Main client implementation
β”‚   β”‚   └── lib.rs          # Client library entry point
β”‚   β”œβ”€β”€ examples/           # Client usage examples
β”‚   β”‚   β”œβ”€β”€ basic.rs        # Basic client example
β”‚   β”‚   └── cli.rs          # Interactive CLI client
β”‚   └── Cargo.toml
β”œβ”€β”€ server/             # Server library  
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   └── lib.rs          # Server implementation
β”‚   β”œβ”€β”€ examples/           # Server usage examples
β”‚   β”‚   β”œβ”€β”€ basic.rs        # Basic server setup
β”‚   β”‚   β”œβ”€β”€ daemon.rs       # Daemon server with signal handling
β”‚   β”‚   └── echo.rs         # Echo server with custom commands
β”‚   └── Cargo.toml
└── README.md

Testing

# Run all tests
cargo test

# Run tests with output
cargo test -- --nocapture

# Test specific crate
cargo test -p secure-ipc-client

# Run integration test (requires certificates)
./scripts/test_integration.sh

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass: cargo test
  5. Check formatting: cargo fmt
  6. Run clippy: cargo clippy
  7. Submit a pull request

Platform Support

Platform Socket Type Status
Linux Unix Domain Sockets (Abstract) βœ… Supported
macOS Unix Domain Sockets βœ… Supported
Windows Named Pipes βœ… Supported
BSD Unix Domain Sockets πŸ”„ Should work

Dependencies

Core Dependencies

  • rustls: TLS implementation
  • tokio: Async runtime
  • serde: Serialization framework
  • anyhow: Error handling
  • nix: Unix systems programming (Unix only)
  • windows: Windows API bindings (Windows only)

Platform-Specific Notes

  • Unix: Uses libc and nix for socket operations and process information
  • Windows: Uses windows crate for named pipes and process APIs
  • Cross-platform: Runtime detection of platform capabilities

Changelog

v0.1.0 (Initial Release)

  • ✨ Multi-crate workspace architecture
  • ✨ Mutual TLS authentication
  • ✨ Cross-platform socket support
  • ✨ Process credential verification
  • ✨ Binary hash validation
  • ✨ Comprehensive examples and documentation

Built with ❀️ in Rust for secure system-level communication

About

Local IPC for Rust, where "hello" requires a cryptographic handshake.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published