sshkey-chat

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2026 License: MIT

README

sshkey-chat

v0.1.0 — Expect breaking changes until v1.0.

Private messaging server over SSH with end-to-end encryption. No accounts, no passwords -- identity is your SSH key.

The server is a blind relay. It routes, stores, and sequences encrypted blobs. It sees metadata (who, when, where, sizes) but never message content. Same trust model as Signal.

Inspired by ssh-chat.

Features

  • E2E encrypted -- server stores opaque blobs, never sees message content
  • SSH identity -- no accounts, no passwords, your Ed25519 key is your permanent identity (no key rotation; lost or compromised keys require account retirement + a fresh account)
  • Rooms with epoch-based key rotation (forward secrecy, bounded exposure)
  • DMs and group DMs with per-message keys (Signal-level forward secrecy)
  • File sharing via encrypted upload/download channels (server can't see filenames, types, or content)
  • Sync on reconnect -- paginated catch-up with bundled epoch keys
  • Lazy scroll-back -- on-demand history, no bulk download on connect
  • Reactions, typing indicators, read receipts, presence, pins
  • Push notifications -- content-free APNs/FCM wake pushes (app syncs over SSH)
  • Config hot-reload -- add/remove users and rooms without restarting
  • Admin CLI -- manage users, devices, pending keys from the server shell
  • User self-service -- retire own account, list and revoke own devices from the client
  • Pure Go -- no cgo, no external dependencies, single binary

Architecture

Server (:2222)                           Clients
┌─────────────────────────┐
│  SSH listener            │◄──── sshkey-chat  (terminal, Go)
│  NDJSON protocol (Ch 1)  │◄──── sshkey-app   (GUI, Rust)
│  Downloads      (Ch 2)   │◄──── any other client that speaks the protocol
│  Uploads        (Ch 3)   │
│  SQLite WAL storage      │
└─────────────────────────┘

Three SSH channels per connection: Channel 1 carries NDJSON protocol messages, Channel 2 carries download file bytes (server → client), Channel 3 carries upload file bytes (client → server). Splitting uploads and downloads onto separate channels lets a large transfer in one direction run in parallel with the other. All message content is encrypted client-side before reaching the server.

Encryption
Context Model Forward secrecy
Rooms Epoch keys (AES-256-GCM, rotated every 100 msgs or 1 hour) Bounded -- max 100 messages exposed per key compromise
DMs Per-message keys (fresh AES-256 key per message, wrapped per member) Per-message -- one key = one message

Key wrapping: Ed25519 -> X25519 conversion, ephemeral ECDH, HKDF-SHA256, AES-256-GCM. Same algorithm for both epoch keys and per-message keys.

Only Ed25519 SSH keys are supported. The server rejects RSA, ECDSA, and other key types.

Binaries

Binary Description
sshkey-server Chat server -- SSH listener, protocol handler, storage
sshkey-ctl Local admin tool -- reads/writes config, manages users and devices

Quick start

# 1. Edit docker/config/users.toml — add your Ed25519 public key
#    cat ~/.ssh/id_ed25519.pub

# 2. Start the server
docker compose up -d

# 3. Connect with the terminal client
sshkey-chat --host localhost --key ~/.ssh/id_ed25519

Manage users:

# View pending key requests
docker exec sshkey-server sshkey-ctl pending

# List users
docker exec sshkey-server sshkey-ctl list-users

# Approve a user (writes to users.toml — server hot-reloads)
docker exec sshkey-server sshkey-ctl approve --key "ssh-ed25519 AAAA... Alice" --rooms general

# Revoke a device
docker exec sshkey-server sshkey-ctl revoke-device --user alice --device dev_x

# View logs
docker logs -f sshkey-server

Config files are in docker/config/ (volume-mounted). Edit them directly — the server watches for changes and reloads automatically.

Install
# Install via go install
go install github.com/brushtailmedia/sshkey-chat/cmd/sshkey-server@latest
go install github.com/brushtailmedia/sshkey-chat/cmd/sshkey-ctl@latest

Or download pre-built binaries from Releases.

Build from source
Requirements
  • Go 1.25 or later
Build
go build -o sshkey-server ./cmd/sshkey-server
go build -o sshkey-ctl ./cmd/sshkey-ctl
Configure
mkdir -p /etc/sshkey-chat /var/sshkey-chat

Create the config files:

/etc/sshkey-chat/server.toml

[server]
port = 2222
bind = "0.0.0.0"
admins = ["alice"]

[devices]
max_per_user = 10

[rate_limits]
messages_per_second = 5
uploads_per_minute = 60
history_per_minute = 50

See testdata/config/server.toml for a complete example with all options.

/etc/sshkey-chat/users.toml

[alice]
key = "ssh-ed25519 AAAA... alice@laptop"
display_name = "Alice"
rooms = ["general", "engineering"]

[bob]
key = "ssh-ed25519 AAAA... bob@desktop"
display_name = "Bob"
rooms = ["general"]

/etc/sshkey-chat/rooms.toml

[general]
topic = "General chat"

[engineering]
topic = "Core platform work"
Run
./sshkey-server -config /etc/sshkey-chat -data /var/sshkey-chat

The server generates an Ed25519 host key on first run and stores it in the config directory.

Deploy (systemd)

Install the binaries and set up a dedicated service user:

# Install binaries
sudo cp sshkey-server sshkey-ctl /usr/local/bin/

# Create service user
sudo useradd -r -s /usr/sbin/nologin sshkey

# Create directories with correct ownership
sudo mkdir -p /etc/sshkey-chat /var/sshkey-chat
sudo chown sshkey:sshkey /var/sshkey-chat
sudo chmod 750 /var/sshkey-chat

# Copy config files
sudo cp testdata/config/*.toml /etc/sshkey-chat/
# Edit users.toml and rooms.toml for your setup

# Install and enable the service
sudo cp init/sshkey-server.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now sshkey-server

The server runs as a systemd service with automatic restart on failure. Config changes are picked up automatically via fsnotify, or you can trigger a manual reload:

sudo systemctl reload sshkey-server   # sends SIGHUP, reloads config
sudo systemctl restart sshkey-server  # full restart (only needed for port/bind changes)
sudo journalctl -u sshkey-server -f   # follow logs
Admin
sshkey-ctl pending                                             # view pending key requests
sshkey-ctl approve --key "ssh-ed25519 AAAA... name" --rooms general  # approve (name from key comment)
sshkey-ctl approve --key "ssh-ed25519 AAAA..." --name NAME --rooms general  # approve (override name)
sshkey-ctl reject --fingerprint FP                             # reject a pending key
sshkey-ctl list-users                                          # list all users
sshkey-ctl remove-user usr_abc123                              # remove a user
sshkey-ctl retire-user usr_abc123 --reason key_lost            # permanently retire an account
sshkey-ctl list-retired                                        # list retired accounts
sshkey-ctl add-to-room --user usr_abc123 --room engineering    # add user to a room
sshkey-ctl remove-from-room --user usr_abc123 --room engineering  # remove user from a room
sshkey-ctl revoke-device --user usr_abc123 --device dev_x      # revoke a stolen device
sshkey-ctl restore-device --user usr_abc123 --device dev_x     # re-authorize a device
sshkey-ctl status                                              # show server overview
sshkey-ctl host-key                                            # print server host key fingerprint
sshkey-ctl purge --older-than 5y                               # delete old messages + vacuum
sshkey-ctl purge --older-than 1y --dry-run                     # preview what would be deleted

Protocol

NDJSON (newline-delimited JSON) over SSH. One JSON object per line. Capabilities are individually negotiated on connect.

Handshake
Client connects via SSH with Ed25519 key
  Server -> server_hello (capabilities)
  Client -> client_hello (device_id, requested capabilities)
  Server -> welcome (user, rooms, active capabilities)
  Server -> room_list, conversation_list, profiles, epoch_keys, unread counts, pins
  Server -> sync_batch (catch-up messages) ...
  Server -> sync_complete
  -- real-time push --
Message types
Category Client -> Server Server -> Client
Handshake client_hello server_hello, welcome
Rooms send message, room_list, room_event
DMs create_dm, send_dm, leave_conversation, rename_conversation dm, dm_created, conversation_list, conversation_event, conversation_renamed
Sync -- sync_batch, sync_complete
History history history_result
Epoch keys epoch_rotate epoch_trigger, epoch_key, epoch_confirmed
Deletion delete deleted
Typing typing typing
Read receipts read read, unread
Reactions react, unreact reaction, reaction_removed
Pins pin, unpin pinned, unpinned, pins
Profiles set_profile, set_status profile, presence
Files upload_start, download upload_ready, upload_complete, upload_error, download_start, download_complete, download_error
Push push_register push_registered
Retirement retire_me user_retired, retired_users
Device management list_devices, revoke_device device_list, device_revoke_result
Membership room_members room_members_list
Admin list_pending_keys admin_notify, pending_keys_list, device_revoked, server_shutdown
Errors -- error

Storage

Server-side

SQLite in WAL mode. The server stores encrypted blobs only -- it cannot read message content.

/var/sshkey-chat/data/
├── users.db              # devices, epoch keys, conversations, profiles, push tokens, read positions
├── room-general.db       # encrypted messages, reactions, pins for "general"
├── room-engineering.db   # encrypted messages for "engineering"
├── conv-xK9mQ2pR.db     # encrypted DM messages
└── files/                # encrypted file blobs
Schema: users.db
-- Device registry (per user, per device)
CREATE TABLE devices (
    user TEXT, device_id TEXT, last_synced TEXT, created_at TEXT,
    PRIMARY KEY (user, device_id)
);

-- Wrapped epoch keys (rooms only, per user per epoch)
CREATE TABLE epoch_keys (
    room TEXT, epoch INTEGER, user TEXT, wrapped_key TEXT,
    PRIMARY KEY (room, epoch, user)
);

-- DM conversations
CREATE TABLE conversations (id TEXT PRIMARY KEY, created_at TEXT);
CREATE TABLE conversation_members (
    conversation_id TEXT, user TEXT, joined_at TEXT DEFAULT (datetime('now')),
    PRIMARY KEY (conversation_id, user),
    FOREIGN KEY (conversation_id) REFERENCES conversations(id)
);

-- User room join tracking (first_seen / first_epoch filtering)
CREATE TABLE user_rooms (
    user TEXT, room TEXT, first_seen INTEGER, first_epoch INTEGER,
    PRIMARY KEY (user, room)
);

-- Read positions (per device, per room/conversation)
CREATE TABLE read_positions (
    user TEXT, device_id TEXT, room TEXT, conversation_id TEXT,
    last_read TEXT, ts INTEGER,
    PRIMARY KEY (user, device_id, room, conversation_id)
);

-- Push notification tokens
CREATE TABLE push_tokens (
    user TEXT, device_id TEXT, platform TEXT, token TEXT,
    updated_at TEXT DEFAULT (datetime('now')), active INTEGER DEFAULT 1,
    PRIMARY KEY (user, device_id)
);

-- Revoked devices
CREATE TABLE revoked_devices (
    user TEXT, device_id TEXT, revoked_at TEXT, reason TEXT,
    PRIMARY KEY (user, device_id)
);

-- Pending key requests (unknown SSH keys that tried to connect)
CREATE TABLE pending_keys (
    fingerprint TEXT PRIMARY KEY, remote_addr TEXT,
    attempts INTEGER, first_seen TEXT, last_seen TEXT
);

-- User profiles
CREATE TABLE profiles (
    user TEXT PRIMARY KEY, display_name TEXT, avatar_id TEXT, status_text TEXT
);

-- File content hashes (BLAKE2b-256, verified on upload/download)
CREATE TABLE file_hashes (
    file_id TEXT PRIMARY KEY, content_hash TEXT NOT NULL, size INTEGER NOT NULL
);

-- Performance indexes (per-connect query paths)
CREATE INDEX idx_epoch_keys_room_user_epoch ON epoch_keys(room, user, epoch);
CREATE INDEX idx_epoch_keys_user ON epoch_keys(user, room, epoch);
CREATE INDEX idx_conversation_members_user ON conversation_members(user, conversation_id);
CREATE INDEX idx_devices_last_synced ON devices(last_synced) WHERE last_synced IS NOT NULL AND last_synced != '';
CREATE INDEX idx_push_tokens_user_active ON push_tokens(user, active);
Schema: room/conversation DBs
-- Messages (encrypted blobs, server cannot read content)
CREATE TABLE messages (
    id TEXT PRIMARY KEY, sender TEXT, ts INTEGER, epoch INTEGER,
    payload TEXT, file_ids TEXT, signature TEXT, wrapped_keys TEXT,
    deleted INTEGER DEFAULT 0
);

-- Reactions (encrypted, server cannot read emoji)
CREATE TABLE reactions (
    reaction_id TEXT PRIMARY KEY, message_id TEXT, user TEXT, ts INTEGER,
    epoch INTEGER, payload TEXT, signature TEXT, wrapped_keys TEXT
);

-- Pinned messages (rooms only)
CREATE TABLE pins (
    message_id TEXT PRIMARY KEY, pinned_by TEXT, ts INTEGER
);

-- Performance indexes
CREATE INDEX idx_messages_ts ON messages(ts);
CREATE INDEX idx_messages_sender ON messages(sender);
CREATE INDEX idx_messages_not_deleted ON messages(deleted) WHERE deleted = 0;
CREATE INDEX idx_reactions_message ON reactions(message_id);

Config hot-reload

The server watches config files via fsnotify and reloads on SIGHUP.

Hot-reloadable (no restart): users, rooms, admins, rate limits, retention, file limits, device limits, sync settings.

Requires restart: port, bind address.

On reload, the server notifies affected connected clients (updated room lists, join/leave events) and triggers epoch rotation for rooms with membership changes.

Push notifications

Content-free wake pushes via APNs (iOS) and FCM (Android). The server never sends message content in push payloads -- it sends a silent wake signal, the app connects via SSH, syncs, and shows a local notification with real content.

Disabled by default. Enable by adding credentials to server.toml:

[push.apns]
enabled = true
key_path = "/etc/sshkey-chat/AuthKey_ABC123.p8"
key_id = "ABC123DEFG"
team_id = "TEAM123456"
bundle_id = "chat.sshkey.app"

[push.fcm]
enabled = true
credentials_path = "/etc/sshkey-chat/firebase-sa.json"
project_id = "sshkey-chat"

Project structure

sshkey-chat/
├── cmd/
│   ├── sshkey-server/     # server entry point
│   └── sshkey-ctl/        # admin CLI tool
├── init/                  # systemd service file
├── internal/
│   ├── config/            # TOML config parsing + validation
│   ├── protocol/          # wire format message types + NDJSON codec
│   ├── push/              # APNs + FCM push notification senders
│   ├── server/            # SSH server, session handling, all protocol logic
│   └── store/             # SQLite storage (messages, devices, epochs, conversations)
├── testdata/config/       # example config files for testing
├── go.mod
└── go.sum
Repo Description
sshkey-chat Server + admin tool + Go core library (this repo)
sshkey-term Terminal client (Go + Bubble Tea + rasterm)
sshkey-app Desktop + mobile GUI client (Rust + egui)

Testing

go test ./...

Tests cover the full handshake, room messaging with isolation, sync on reconnect, history scroll-back, DM conversations with wrapped_keys validation, and storage operations.

Building a client

See PROTOCOL.md for the complete protocol reference -- everything you need to build a compatible client in any language. Includes wire format, all message types with JSON examples, crypto specs, key wrapping, and a minimal client checklist.

Design

See PROJECT.md for the full design document including threat model, cryptographic primitives, key exchange protocols, epoch rotation, replay detection, and safety numbers.

License

MIT

Directories

Path Synopsis
cmd
sshkey-ctl command
sshkey-server command
internal
config
Package config handles parsing of server.toml, users.toml, and rooms.toml.
Package config handles parsing of server.toml, users.toml, and rooms.toml.
protocol
Package protocol defines the sshkey-chat wire format message types.
Package protocol defines the sshkey-chat wire format message types.
push
Package push implements APNs and FCM push notification senders.
Package push implements APNs and FCM push notification senders.
server
Package server implements the sshkey-chat SSH server.
Package server implements the sshkey-chat SSH server.
store
Package store implements SQLite-based storage for the sshkey-chat server.
Package store implements SQLite-based storage for the sshkey-chat server.
testutil
Package testutil provides shared test infrastructure for sshkey-chat.
Package testutil provides shared test infrastructure for sshkey-chat.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL