This project simulates a webhook event handling system. The application consists of a server that manages user registration, key generation, and secure event handling. Events are encrypted using RSA public key encryption on the client side, sent to the server, decrypted with the corresponding private key, and securely stored.
A webhook is a user-defined HTTP callback. It is a mechanism that allows one system to send real-time data to another whenever a particular event occurs. Unlike traditional polling mechanisms, where a client repeatedly requests information from a server, webhooks push data to the client when an event occurs, providing a more efficient and real-time update mechanism.
In this simulation:
- User Registration: A new user can register with a username and password.
- Key Generation: After registration, a unique RSA key pair (public and private keys) is generated for the user.
- Client Event Trigger: The client simulates an event (e.g., "Transaction Done") and encrypts the event data using the server's public key.
- Server Decryption and Storage: The encrypted data is sent to the server, which decrypts it using the corresponding private key and stores the decrypted event data.
.
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── venv/ # Virtual environment directory
└── README.md # Project documentation
-
User Registration:
- Endpoint: `/register`
- Method: `POST`
- Payload: `{ "username": "test_user", "password": "test_pass" }`
- Registers a new user with hashed password storage.
-
Key Generation:
- Endpoint: `/generate_keys`
- Method: `GET`
- Requires Basic Auth.
- Generates and stores RSA public/private key pair.
-
Event Handling (Webhook Simulation):
- Endpoint: `/webhook_event`
- Method: `POST`
- Requires Basic Auth.
- The client encrypts event data using the public key and sends it to this endpoint.
- The server decrypts the data and stores it securely.
- Python 3.x
- Virtual environment (optional but recommended)
-
Clone the repository:
git clone https://github.com/your-username/webhook-simulation.git cd webhook-simulation
-
Set up a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows use \`venv\Scripts\activate\`
-
Install dependencies:
pip install -r requirements.txt
-
Initialize the Database:
The database will be automatically initialized on the first run.
-
Start the Flask Server:
python app.py
-
Simulate Webhook Events:
Run the client-side script to simulate event handling:
python client.py
You can interact with the system by entering commands such as "Transaction Done" and providing a transaction ID.
Yet to be decided , Open for suggestions : )
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (`git checkout -b feature-branch`).
- Make your changes.
- Commit and push (`git push origin feature-branch`).
- Create a Pull Request.
This project is licensed under the MIT License
- Flask framework for providing an easy way to create web servers ⚡.
- The cryptography library for secure key handling and encryption #️⃣.
- Sqlite3 for lightweight database management 🙇♂️.