This repository contains the source code for CPeer, a C++ application enabling secure, peer-to-peer (P2P) file transfers and messaging across different networks.
The project builds three primary executables:
p2p: The main client application for peer-to-peer interaction.server: A lightweight rendezvous server to facilitate the initial connection between peers.test: A suite of unit tests to validate the application's core functionality.
Communication is brokered by the server only during the initial handshake. Once peers have established a direct connection, the server is no longer involved.
The connection flow is initiated when one peer registers with the rendezvous server, providing its own connection details and the public key hash of the intended recipient. When the second peer comes online and authenticates, the server exchanges the necessary endpoint information between them. This allows the peers to perform TCP hole punching and establish a direct communication channel.
CPeer is a command-line tool that relies on a central rendezvous server to orchestrate P2P connections.
The server's role is strictly to mediate introductions. It listens on a publicly accessible port (e.g., exposed via ngrok) and waits for peers to connect. After exchanging peer details, its job is done. Note that the current implementation is single-threaded and not designed for high-concurrency or production environments.
The client application implements a two-stage authentication process to ensure secure communication:
- Server Authentication: The client first authenticates with the rendezvous server by signing a cryptographic nonce, proving ownership of its private key. The server validates this against a stored public key.
- Peer Authentication: A similar challenge-response handshake occurs directly between the two peers before any messaging or file transfer can begin.
Once built, the p2p client can be operated in three distinct modes:
1. Unencrypted Chat (-e)
This mode allows for quick, unencrypted messaging by using simple usernames for peer identification.
Peer A (user: "alpha"):
p2p -e <server_host> <server_port> alpha betaPeer B (user: "beta"):
p2p -e <server_host> <server_port> beta alpha2. Secure Messaging (-m)
This mode establishes a fully encrypted chat session using public/private key pairs for authentication and encryption.
Peer A:
p2p -m <server_host> <server_port> /path/to/my/keypair.pem /path/to/peerB/public.pemPeer B:
p2p -m <server_host> <server_port> /path/to/my/keypair.pem /path/to/peerA/public.pem3. File Transfer (-f to send, -r to receive)
This mode allows for sending and receiving files after establishing a secure, authenticated connection.
Peer A (Sending a file):
p2p -f <server_host> <server_port> /path/to/my/keypair.pem /path/to/peerB/public.pem /path/to/your/file.zipPeer B (Receiving a file):
p2p -r <server_host> <server_port> /path/to/my/keypair.pem /path/to/peerA/public.pemThe following dependencies are required to build and run CPeer:
- Protocol Buffers: For structured data serialization. (
sudo apt install protobuf-compiler) - OpenSSL: For all cryptographic operations. (
sudo apt-get install libssl-dev) - libcurl: For external IP address discovery. (
sudo apt-get install -y libcurl-dev) - GoogleTest: For running the unit test suite. (
sudo apt-get install -y googletest) - CMake: For managing the build process. (
sudo apt-get -y install cmake)
-
Clone the repository:
git clone https://github.com/xARSENICx/CPeer.git cd CPeer -
Configure and build the project using CMake:
# Create a dedicated build directory mkdir build && cd build # Run CMake to configure the project and then build it cmake .. && make
-
Install the client shortcut (optional):
# This script creates a 'p2p' terminal command source install.sh
The build directory will contain the final executables (p2p, server, test) and a certs folder with example keys for testing.
- Add images for test
- Make it cross platform for Mac and Windows