How unight0/ssrpi works
Purpose and Executables
SSRPI is a Go client-server secure chatroom implementation. The server accepts TLS connections, authenticates users, maintains chatroom/admin state, and persists user data in SQLite. The client is an interactive terminal application for login, chat, administration, and file operations.
Entry points:
• Server process: serv/main.go
• Terminal client process: client/main.go
• Protocol contract: PROTOCOL.md
Protocol and Trust Boundary
PROTOCOL.md defines the application wire protocol shared by both independently built binaries. TLS protects transport confidentiality and integrity; protocol-level authentication then establishes user identity and authorization.
The public network boundary is the server listener in serv/main.go. Client input and remote server messages cross separate trust boundaries in client/main.go; server-side command handling must enforce authorization rather than trusting client UI behavior.
Server Runtime and State
serv/main.go is the authoritative service runtime. It is responsible for:
• Loading the TLS certificate/key and listening on the configured TCP port.
• Managing concurrent client sessions and message distribution.
• Registration, login, password changes, admin promotion/revocation, kicks, and shutdown.
• Enforcing the shared server password and per-user privileges.
• Loading and presenting an optional MOTD.
Persistent account state is backed by SQLite, configured through the server’s database-path flag. This requires CGO, as declared by the repository build requirements. TLS material is generated or provisioned outside the binary; serv/makecert.sh is the local certificate-generation entry point.
Client Interaction Layer
client/main.go owns connection setup and the Bubble Tea terminal UI. It obtains connection credentials from flags or interactive prompts, opens the TLS session, performs protocol authentication, and renders incoming chat/system events.
The client maps slash commands into protocol requests, including broadcast/direct chat, user listing, file upload/download, self-service password changes, and privileged administration. It should treat authorization failures and server-originated state as authoritative.
Messaging, Presence, and Administration Flow
The primary control flow is:
1. Client connects over TLS and provides server/user credentials.
2. Server validates the server password and user account state, registering users when applicable.
3. Server tracks the authenticated session and broadcasts presence/chat events to relevant connected clients.
4. Client submits user or admin commands; server validates identity and admin status before mutating shared state.
5. Session disconnect, kick, or shutdown removes/terminates active connections.
The first registered user becomes an administrator, making initial registration a bootstrap boundary. Administrative operations—including server-password changes and remote shutdown—are server-owned actions in serv/main.go, not client-enforced permissions.
File Transfer Boundary
The command surface includes upload and download operations, with recipient targeting for uploads. These operations are protocol-defined in PROTOCOL.md, initiated from client/main.go, and mediated by serv/main.go. The server is the coordination and authorization point for file identifiers, aliases, recipient selection, and retrieval; clients should not assume peer-to-peer transfer.
Build and Deployment Shape
The repository contains two separate Go modules:
• serv/go.mod
• client/go.mod
They are built and deployed as separate executables, enabling the server to run as the long-lived TLS/SQLite service while clients remain disposable terminal sessions. Required operational dependencies are Go 1.21+, CGO/SQLite support, a server certificate/key pair, and optionally an MOTD text file.
Main entry points: client/main.go Terminal client · serv/main.go Authentication & admin · PROTOCOL.md Wire protocol · makecert.sh Certificate & key
Components 15
Server runtime
Long-lived authoritative chat service.
- Server process · TLS listener, session manager, and authorization authority.
serv/main.go - TLS listener · Accepts protected client TCP connections.
serv/main.go - Sessions & distribution · Tracks authenticated clients and broadcasts events.
serv/main.go - Authentication & admin · Validates credentials, privileges, kicks, and shutdown.
serv/main.go - File mediation · Authorizes uploads, recipients, aliases, and retrieval.
serv/main.go - Account database · Persistent user and account state.
serv/main.go - Certificate & key · Provisioned outside the server binary.
serv/makecert.sh - Optional MOTD · Loaded and presented by the server.
serv/main.go - Server module · Requires CGO-backed SQLite support.
serv/go.mod
Terminal client
Interactive disposable client session.
- Terminal client · Connects, authenticates, and renders chat/system events.
client/main.go - Prompts & slash commands · Maps user actions to protocol requests.
client/main.go - Bubble Tea UI · Displays incoming chat, presence, and server state.
client/main.go - TLS connection · Establishes the protected server session.
client/main.go - Client module
client/go.mod
Other components
- Wire protocol · Shared contract for authentication, chat, administration, and files.
PROTOCOL.md
Connections 18
- Client module → Terminal client: builds
- Server module → Server process: builds
- Prompts & slash commands → Terminal client: credentials and commands
- Terminal client → TLS connection: opens
- TLS connection → TLS listener: TLS session
- Wire protocol → Terminal client: implements
- Wire protocol → Server process: implements
- Certificate & key → TLS listener: secures
- Server process → TLS listener: hosts
- TLS listener → Authentication & admin: authentication requests
- Authentication & admin → Account database: loads and mutates accounts
- Authentication & admin → Sessions & distribution: admits or terminates sessions
- Sessions & distribution → Bubble Tea UI: chat, presence, system events
- Terminal client → Bubble Tea UI: renders through
- Terminal client → Authentication & admin: user and admin requests
- Authentication & admin → File mediation: authorizes transfers
- Terminal client → File mediation: upload and download requests
- Server process → Optional MOTD: loads