Secure peer-to-peer communication protocol with proof-of-work, encryption, and error correction
Project description
ExProtocol
ExProtocol provides a comprehensive framework for establishing secure connections and exchanging data between nodes. It includes mechanisms for performing proof-of-work (PoW) challenges, establishing encrypted connections, and transmitting data with integrity checks. The protocol is designed to be extensible and adaptable to different use cases, making it suitable for a wide range of applications.
Features
- Secure Handshake: Establishes a secure connection using Elliptic-curve Diffie–Hellman (ECDH) and proof-of-work challenges.
- Encrypted Communication: Ensures data confidentiality and integrity using AES-GCM encryption.
- Flexible Packet Structure: Supports various packet types with customizable headers and payloads.
- Replay Attack Prevention: Implements mechanisms to detect and prevent replay attacks.
- Error Correction: Utilizes Hamming code for error detection and correction in packet transmission.
Getting Started
Prerequisites
- Python 3.8 or higher
- Required Python packages:
cryptography
Installation
- Clone the repository:
git clone https://github.com/Silenttttttt/ExProtocol.git - Navigate to the project directory:
cd ExProtocol - Install the required packages:
pip install cryptography
Usage
- Import the
ExProtocolclass and use it to establish secure connections and exchange data between nodes. - Refer to the example usage in the
main()function for the proper handshake flow and a demonstration of the protocol's capabilities.
1. Initiator PoW Request (HPW)
| Field | Description | Length (Bytes) | Notes |
|---|---|---|---|
| Public Key | Node A's public key | 91 | Fixed length |
| Type | Packet type identifier | 1 | Fixed length, replaces HPW_FLAG |
| Packet Size Limit | Maximum packet size allowed | Variable | Last field, no length prefix |
2. Responder PoW Challenge (HPR)
| Field | Description | Length (Bytes) | Notes |
|---|---|---|---|
| Public Key | Node A's public key | 91 | Fixed length |
| Nonce | Random nonce for PoW | 16 | Fixed length |
| Type | Packet type identifier | 1 | Fixed length, HPW_RESPONSE_FLAG |
| Difficulty | PoW difficulty level | 1 | Fixed length |
3. Handshake Request (HSK)
| Field | Description | Length (Bytes) | Notes |
|---|---|---|---|
| Public Key | Node A's public key | 91 | Fixed length |
| Type | Packet type identifier | 1 | Fixed length, HANDSHAKE_FLAG |
| Proof of Work Solution | Solution to PoW challenge | Variable | Last field, no length prefix |
4. Handshake Response (HSR)
| Field | Description | Length (Bytes) | Notes |
|---|---|---|---|
| Public Key | Node B's public key | 91 | Fixed length |
| Type | Packet type identifier | 1 | Fixed length, HANDSHAKE_RESPONSE_FLAG |
| Nonce | Random nonce for connection | 12 | Fixed length |
| Packet Size Limit Length | Length of packet size limit | 4 | Length prefix |
| Packet Size Limit | Maximum packet size allowed | Variable | Length-prefixed |
| Encrypted Handshake Data Length | Length of encrypted data | 4 | Length prefix |
| Encrypted Handshake Data | Encrypted connection information | Variable | Length-prefixed |
| Encrypted Handshake Data Fields | |||
| Field | Description | ||
| ---------------- | -------------------------------------------------- | ||
| Connection ID | Unique identifier for the connection | ||
| Valid Until | Timestamp indicating connection expiration | ||
| Max Packet Size | Maximum packet size agreed upon |
5. General data packet structure
| Field | Description | Length (Bytes) | Encrypted |
|---|---|---|---|
| Version | Protocol version number | 1 | No |
| Connection ID | Unique identifier for the connection | 16 | No |
| Nonce | Random value for encryption | 12 | No |
| Encrypted Header Length | Length of the encrypted header | 4 | No |
| Encrypted Header | Contains metadata and control information | Variable | Yes |
| Payload Length | Length of the encrypted payload | 8 | No |
| Payload | The main data being transmitted | Variable | Yes |
Encrypted Header Fields
| Field | Description |
|---|---|
| Timestamp | The time at which the packet was created, used for freshness validation |
| Encoding | Character encoding used for the payload, typically 'utf-8' |
| Type | Indicates the nature of the packet (e.g., data, response) |
| Data Type | Specifies the type of data being transmitted (e.g., text, binary) |
Data Packet Structure
- Type: Set to indicate a data packet
- Data Type: Specifies the type of data (e.g., text, binary)
Response Packet Structure
- Type: Set to indicate a response packet
- Data Type: Specifies the type of data (e.g., text, binary)
- Status Code: Required field indicating the status of the response (e.g., HTTP-like status codes)
- Packet UUID: The hash of the packet it is responding to, used for tracking and validation, derived by both parties independently.
Encrypted Header Fields for Response Packet
| Field | Description |
|---|---|
| Timestamp | The time at which the packet was created, used for freshness validation |
| Encoding | Character encoding used for the payload, e.g. 'utf-8' |
| Type | Indicates the nature of the packet (response) |
| Data Type | Specifies the type of data being transmitted (e.g., text, binary) |
| Status Code | Indicates the status of the response (e.g., 200, 500) |
| Packet UUID | The hash of the packet it is responding to, used for tracking and validation |
Contributing
Contributions are welcome! Please fork the repository and submit a pull request with your changes. Or just message me directly.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file exprotocol-0.1.2.tar.gz.
File metadata
- Download URL: exprotocol-0.1.2.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d216fd6c3a96eb9a3e2103b576adeec899a21fda0d6ce6782088c24f5887336f
|
|
| MD5 |
cd8d7a15d03a7d89ef42f23d3f8b7d91
|
|
| BLAKE2b-256 |
4d288bd358f47855045de674f48be49d7c3e282480ebca10c72a697e6e7403fc
|
File details
Details for the file exprotocol-0.1.2-py3-none-any.whl.
File metadata
- Download URL: exprotocol-0.1.2-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f62fdb793eab95b239aa4266e81226960a8c85d7ff3b9c7b1759fe6a41b4db7a
|
|
| MD5 |
4360293da5149f5f18a06b9d585d9e4e
|
|
| BLAKE2b-256 |
77a058e8384b19599daab7a090b13de8f87f1031c0053418944d34562047e943
|