01Overview
ZapDistribuido is a secure peer-to-peer messaging application written in Java (built with Maven), developed as university coursework with two teammates. There is no centre to fail and no one to trust: peers organize into a Chord ring — a distributed hash table where finger tables route every lookup in O(log N) hops — and every security property comes from cryptography rather than from an operator.
The codebase is event-driven under the psd.group4 packages: nodes, users and services react to events like entering nodes, finger-table broadcasts, Diffie-Hellman handshakes and truststore updates, with dedicated handlers for encryption, keys, MongoDB and the node client.
02Architecture
03Security, layer by layer
- Node links over SSL/TLS. Each user keeps reusable connections to the nodes in its finger table, and new links bootstrap from an insecure channel that exists only to exchange session keys and certificates.
- End-to-end messages with AES + RSA. Every message travels encrypted under a session key, accompanied by its hash signed with the sender's private key — confidentiality from the cipher, authenticity from the signature, integrity from the hash.
- Group chat with attribute-based encryption. Using BouncyCastle, JPBC and CloudCrypto (KP-ABEngine), groups mint master keys, access policies and per-user secret keys, so joining a group means receiving exactly the cryptographic material your attributes entitle you to.
- Long-term storage with Shamir Secret Sharing. Messages persist in MongoDB individually encrypted and split into shares; only the sender or recipient can reconstruct them — with the documented caveat that the demo runs a single database.
04Stack
| Language | Java, built with Maven (mvn clean package into a shaded fat jar) |
|---|---|
| Overlay | Chord DHT — finger tables, O(log N) lookups, join/leave rebalancing |
| Transport | SSL/TLS node links with session keys bootstrapped over a plain channel; Diffie-Hellman handshake |
| Messages | AES session encryption + RSA-signed hashes (confidentiality, authenticity, integrity) |
| Groups | Attribute-based encryption via BouncyCastle, JPBC and CloudCrypto (KP-ABEngine) |
| Storage | MongoDB (sync driver + client-side field encryption) with Shamir Secret Sharing per message |
| Runtime UX | Terminal UI with progress bars; logback logging; bootstrap via a default node |
05Under the hood
- Home-grown observer bus. Instead of a framework, the node runs on a hand-rolled event system (
psd/group4/utils/observer/): every network happening — entering nodes, finger-table broadcasts, truststore updates — becomes a typedNodeEventsubclass handled by a central dispatcher. - A 13-type protocol. The
MessageTypeenum reads like the system's biography: enter/exit nodes, finger updates, sends, Diffie-Hellman, certificate trust, shared-key removal, group messages and group membership. - Key exchange as domain events. Diffie-Hellman isn't a utility call, it's a first-class
DiffHellmanEventcarrying initializer/target DTOs and both public keys through the same pipeline as everything else. - Separation by handler. Encryption, keys, MongoDB, node client/server and the terminal interface each get their own handler class — 38 Java files with no god objects.
06Running it
Build with Maven (mvn clean package)
and run the jar. The first peer into the network becomes the default
node, and nodes two ports apart keep one secure plus one insecure
connection each. From there it is terminals all the way down: