Skip to content

xARSENICx/CPeer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPeer: A Secure P2P Communication Platform

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:

  1. p2p: The main client application for peer-to-peer interaction.
  2. server: A lightweight rendezvous server to facilitate the initial connection between peers.
  3. 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.


Table of Contents

  1. Technical Overview
  2. Operating Modes
  3. System Requirements
  4. Building from Source
  5. Author

Technical Overview

CPeer is a command-line tool that relies on a central rendezvous server to orchestrate P2P connections.

Rendezvous Server

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.

P2P Client

The client application implements a two-stage authentication process to ensure secure communication:

  1. 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.
  2. Peer Authentication: A similar challenge-response handshake occurs directly between the two peers before any messaging or file transfer can begin.

Operating Modes

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 beta

Peer B (user: "beta"):

p2p -e <server_host> <server_port> beta alpha

2. 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.pem

Peer B:

p2p -m <server_host> <server_port> /path/to/my/keypair.pem /path/to/peerA/public.pem

3. 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.zip

Peer B (Receiving a file):

p2p -r <server_host> <server_port> /path/to/my/keypair.pem /path/to/peerA/public.pem

System Requirements

The 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)

Building from Source

  1. Clone the repository:

    git clone https://github.com/xARSENICx/CPeer.git
    cd CPeer
  2. 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
  3. 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.


Author

Ayush Sah


TODO

  • Add images for test
  • Make it cross platform for Mac and Windows

About

A P2P file-sharing and messaging tool written in C++.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published