Skip to content
HamzaK90Public

About

Peer-to-peer desktop chat: the signalling server only introduces two people, then the conversation runs directly between them — DTLS-encrypted text and file transfer, no port forwarding, and passwords that never leave the client. C++20 · Qt 6 · libdatachannel.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Spark

Spark

Peer-to-peer chat for Windows. A server introduces two people to each other and then gets out of the way — the conversation itself runs directly between the two machines, encrypted end to end, with no port forwarding and nothing to relay.

Two Spark clients holding one conversation

What it is

Spark is a small desktop chat application built on WebRTC data channels (libdatachannel) with its own signalling server, its own wire formats and its own challenge-response authentication.

  • Text and file transfer, both over one direct channel between the two peers.
  • A roster with presence — active, busy, away, offline — pushed by the server as it changes.
  • Passwords that never leave the client. The server has never seen one and cannot log one.
  • Three binaries: the Qt desktop client, the signalling server, and a console client used by the test suite.

How it works

The server does three things: it holds accounts, it tracks who is online, and it forwards the session descriptions two peers need in order to find each other. That is all. Once ICE completes, messages and files travel machine to machine over a DTLS-encrypted SCTP channel — so the server cannot read them, and an outage there cannot interrupt a conversation that is already open.

                     ┌───────────────────────────┐
                     │     signalling server     │
                     │  accounts · roster ·      │
                     │  session-description relay│
                     └───────────┬───────────────┘
                                 │
              login, roster,     │     login, roster,
              offer / answer     │     offer / answer
                 ┌───────────────┴───────────────┐
                 │                               │
            ┌────┴────┐                     ┌────┴────┐
            │  hamza  │                     │  zahi   │
            └────┬────┘                     └────┬────┘
                 │                               │
                 └───────────────────────────────┘
                 direct, DTLS-encrypted data channel
              text · file offers · chunks · checksums
                    the server never sees this

That claim is easy to check, because the server prints what it handles. Here is its entire log for the conversation and the 48 MB file transfer shown in this README:

The signalling server's log

Two accounts register, three sign in, one signs out, one offer and one answer are relayed — and then nothing at all, while a whole conversation and a 48 MB file pass between the two clients.

This is also why the server target links neither libdatachannel nor Qt: a session description is an opaque string to it. Sockets, JSON and libsodium are its whole dependency list, which is what lets it build on a plain Linux host.

Repository layout

Path What lives there
core/net/ RAII TCP sockets over Winsock2 / BSD — the one place the platforms differ
core/proto/ Both wire formats: chat frames and the signalling control messages
core/peer/ PeerLink — the libdatachannel wrapper, ICE gathering, data streams
core/chat/ ChatSession — frames in, chat operations out; file transfer lives here
core/auth/ Argon2id key derivation, challenge proofs, constant-time compare
core/signalling/ The client half of the signalling protocol, shared by the GUI and the probe
server/ spark-server: accounts, presence, description relay
app/ The Qt 6 Widgets desktop client
tools/spark-probe/ Console client — scriptable, which is what makes the tests possible
tests/ PowerShell loopback tests

The seam that matters is ChatSession: both the GUI and the probe sit on it, and neither of them touches frame bytes or knows libdatachannel exists.

Two wire formats, deliberately different

Signalling is JSON with a 4-byte big-endian length prefix, over TCP (control.hpp). TCP is a byte stream with no message boundaries, so a receiver has to be told where each message ends.

client → server server → client
register {user, salt, verifier} registered {}
hello {user} challenge {salt, nonce}
proof {proof} logged_in {user}
status {status} roster {users:[{user, online, status}]}
sdp {to, kind, sdp} sdp {from, kind, sdp}
logout {} error {code, message}

Chat frames carry no length prefix at all (frame.hpp), because SCTP data-channel messages preserve boundaries: one send is one frame, and the message boundary supplies the length. Two transports, two answers — they are not meant to be unified.

Frame Layout (big-endian)
MSG [1][utf8 text…]
FILE_OFFER [2][xferId:4][size:8][nameLen:2][utf8 name…]
FILE_ACK [3][xferId:4][accepted:1]
FILE_CHUNK [4][xferId:4][seq:4][payload…]
FILE_END [5][xferId:4][sha256:32]
TYPING [6][on:1]

xferId multiplexes concurrent transfers, so a large file and a chat message share the one channel without either blocking the other. Chunks are 16 KiB — small enough that a chat message can slip between them while a transfer is running.

Passwords never leave the client

Signing in

At registration the client picks a random salt, derives key = Argon2id(password, salt) locally, and sends the server only {salt, key}. The server stores the key and calls it a verifier.

At login the server replies with the stored salt and a fresh random nonce. The client re-derives the key from the typed password and returns HMAC(key, nonce); the server computes the same value from the stored verifier and compares it in constant time.

  • The password is never transmitted, so neither a sniffer nor the server itself ever sees it, and it cannot leak from a server-side log.
  • The nonce is fresh per login, so a captured proof cannot be replayed.
  • Argon2id runs on the client, so a login costs the server nothing and cannot be used to exhaust its memory. The few hundred milliseconds it takes are the defence against offline guessing — which is why the sign-in dialog says it is taking a moment on purpose.

What this does not buy, stated plainly: the stored verifier is the key. Anyone who steals the server's accounts.json can log in as those users without knowing their passwords. What they still cannot cheaply do is recover the passwords themselves — that costs an Argon2id brute-force per account — which is what protects people who reuse them elsewhere. Closing the impersonation gap properly needs an augmented PAKE such as SRP or OPAQUE. See core/auth/credential.hpp.

Usernames that do not exist are handed a decoy salt derived from a per-server secret — stable across attempts, so a wrong username is indistinguishable from a wrong password and accounts cannot be enumerated (user_store.hpp).

Sending a file

Either side can send. The receiver is asked first, chooses where the file lands, and the transfer starts only after they accept.

Incoming file prompt

Every transfer ends with a SHA-256 of what was sent. If the digest of what arrived does not match, the file is discarded rather than saved, and the transcript says so instead of leaving a corrupt file behind.

A completed transfer

Files are held in memory and written once, at the end — never from inside a receive callback, which must not block. That is the reason for the 64 MiB cap in core/chat/session.hpp.

Building

Requirements:

  • Visual Studio with the C++ workload. CMake and Ninja ship inside it; spark.ps1 imports the MSVC environment itself, so no "Developer PowerShell" is needed.
  • vcpkg, with VCPKG_ROOT set. Dependencies come from vcpkg.json: libdatachannel, nlohmann-json, libsodium.
  • Qt 6.5+ — optional, and not a vcpkg dependency: vcpkg's qtbase builds Qt from source and takes hours, while the official binaries install in minutes. Set SPARK_QT_ROOT, or install to C:\Qt where it will be found automatically. Without Qt the GUI target is skipped and the server and probe still build.
.\spark.ps1 doctor    # report the environment, change nothing
.\spark.ps1 build     # configure + build -> build\
.\spark.ps1           # both of the above

There is one build directory and it is always Release. A Debug build links the debug CRT, which exists only where Visual Studio is installed, so nothing shippable could come out of it.

Running

.\spark.ps1 server                      # spark-server, default port 8000
.\spark.ps1 server -- --port 8100 --accounts my-accounts.json

.\spark.ps1 app                         # the desktop client
.\spark.ps1 app -- --server chat.example.com:8000

Sign in — tick Create this account the first time — then double-click a name in the roster to start talking.

The console client

spark-probe is the same core with no UI in the way. It has two modes:

# Through the server, which exchanges the descriptions for you.
.\spark.ps1 probe -- connect --user hamza --pass <password> --server 127.0.0.1:8000 --register
#   /call <user>   /send <path>   /status <active|busy|away>   /quit

# No server at all: copy the printed description between two terminals by hand. The offerer
# goes first. This is how the transport is tested in isolation.
.\spark.ps1 probe -- offer
.\spark.ps1 probe -- answer

Both modes take --no-stun (host candidates only — loopback and LAN) or --stun <url>.

Tests

.\spark.ps1 test
Test What it proves
test_chat_loopback.ps1 Two peers on a direct channel exchange text both ways
test_file_loopback.ps1 A multi-megabyte file arrives byte-identical — hashed independently at both ends, not taken on the app's word
test_signalling.ps1 The server introduces two peers with no description copied by hand
test_server_auth.ps1 What the server refuses, and what it does not reveal while refusing

The tests drive the probes through .NET's Process with redirected stdio, because the binaries are native MSVC and do not understand MSYS mkfifo pipes as stdin. One rule if you add a test: the output collector's event handlers run in separate runspaces, so the order lines land in the list is not guaranteed to match the order they were printed. Assert on the presence of a line, never on one line preceding another (tests/harness.ps1).

Limitations

These are real and worth knowing before you rely on any of them.

  • Symmetric NAT and CGNAT cannot be hole-punched, and there is no TURN relay. On some networks — mobile hotspots especially — a direct connection simply will not form. The client says so plainly rather than leaving you watching a spinner.
  • One conversation at a time. A second incoming offer is ignored rather than allowed to tear down the one in progress. Calling someone who is offline currently leaves the client unable to start another conversation until it is restarted.
  • Files are capped at 64 MiB and held in memory for the duration.
  • Signalling is plaintext TCP — no TLS, so a network observer sees usernames, presence and the session descriptions (though not the conversation itself).
  • History is a plain text chat_log.txt written to whatever directory the client was launched from. There is no database and no search.
  • accounts.json permits impersonation if stolen (see above). It is gitignored for that reason and must never be committed.
  • The TYPING frame is implemented but unused by the GUI — ChatSession sends and receives it and the probe prints it, but the desktop client neither sends nor displays a typing indicator.

About

Peer-to-peer desktop chat: the signalling server only introduces two people, then the conversation runs directly between them — DTLS-encrypted text and file transfer, no port forwarding, and passwords that never leave the client. C++20 · Qt 6 · libdatachannel.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages