This file contains a Flask server implementation for user registration, login, encrypted requests, encrypted responses, and signed request handling using RSA.
- Flask
- Flask-SQLAlchemy
- Flask-Bcrypt
- Flask-RSA
- cryptography
-
Install the required packages from
requirements.txt
:pip install -r requirements.txt
-
Run the server using the following command:
python server.py
-
The server will run on
http://127.0.0.1:5000
.
- Register a new user with a unique username, password, and public key.
- Authenticate a user with a username and password, returning an authentication token.
- Accept a signed request with a valid access token, verifying the RSA signature.
Accept a signed request with a valid access token and encrypted payload, verifying the RSA signature and decrypting the payload.
Accept a signed request with a valid access token and encrypted payload, verifying the RSA signature, decrypting the payload, and returning an encrypted response.
- RSA signatures are used for secure communication.
- Tokens are generated during login and used for subsequent signed requests.
- The server's public key is exposed at
/public-key
.
Requests can be encrypted using RSA encryption to ensure confidentiality of sensitive data.
- SQLite is used as the database backend.
- The
Users
table stores user information.
- The server will create a SQLite database file (
db.sqlite
) if it does not exist. - Run the server in debug mode with automatic database commit.
This file contains a sample client implementation that interacts with the server.
- requests
- cryptography
-
Ensure the server is running.
-
Run the client using the following command:
python client.py
-
The client will register a new user, login, and send a signed request to the server.
generate_keys
: Generates RSA private and public keys.get_server_public_key
: Retrieves the server's public key.register_user
: Registers a new user on the server.login
: Logs in a user and obtains an authentication token.create_signature_input
: Creates input for generating an RSA signature.generate_signature
: Generates an RSA signature for a given input.send_signed_request
: Sends a signed request to the server.add_signature
: Adds an RSA signature to request headers.is_signature_correct
: Checks if the server's signature is correct.encrypt
: Encrypts data using the server's public key.decrypt
: Decrypts data using the client's private key.
- The client generates a random username and password for registration and login.
- It interacts with the server to demonstrate user registration, login, signed request handling, encryption, and decryption.
This file lists the required Python packages for running the server and client.
- requests
- Flask (v3.0.0)
- Flask-SQLAlchemy (v3.1.1)
- cryptography (v42.0.2)
- flask_rsa
- Flask-Bcrypt (v1.0.1)