Skip to content

ahmeddelattarr/matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matrix: Secure Asyncio Server/Client

matrix logo

A simple, SSL-enabled server/client application written in Python using asyncio and ssl.

Table of Contents

Features

  • Asynchronous server and client communication
  • SSL encryption for secure data transfer
  • JWT-based authentication
  • PostgreSQL database integration
  • Automatic SSL certificate generation

Project Structure

src/
│
├── ssl/
│   ├── cert.pem
│   ├── key.pem
├── client.py
├── testing.py
├── openssl.cnf
├── requirements.txt
├── dbConnection.py
└── server.py
  • ssl/: Contains SSL certificate (cert.pem) and key (key.pem)
  • client.py: Asyncio-based client implementation
  • openssl.cnf: OpenSSL configuration for certificate generation
  • requirements.txt: Project dependencies
  • dbConnection.py: Database connection and table initialization
  • server.py: Main server code handling connections, JWT, and verification
  • testing.py: Main testing, runs with pytest

Requirements

  • Python 3.8+
  • Dependencies (installed via requirements.txt):
    • asyncio
    • ssl
    • os
    • subprocess
    • pyjwt
    • python-dotenv
    • asyncpg

Setup

  1. Clone the repository:

    git clone https://github.com/yourusername/matrix.git
    cd matrix
  2. Install dependencies:

    bin/install
  3. Set up environment variables: Create a .env file in the project root and add:

    DATABASE_URL=<your-postgresql-connection-string>
    

Usage

Starting the Server

bin/start

Running the Client

python client.py

The client will establish an SSL connection with the server, receive a JWT token, and can then send authenticated messages.

Key Components

SSL Certificate

The server automatically generates SSL certificates if not present in the ssl/ directory, using the openssl.cnf configuration.

JWT Authentication

  • Clients receive a JWT token upon connection, valid for 1 hour
  • The server verifies the JWT token with each communication
  • Clients are notified upon token expiration

Database Integration

  • Utilizes Neon DB (PostgreSQL)
  • Initializes connection and creates Users and Messages tables on server start

Security

  • SSL encryption ensures secure data transfer
  • JWT tokens provide stateless authentication
  • Automatic certificate generation enhances ease of deployment

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. Run ruff check and pytest before pushing.

License

This project is licensed under the MIT License.

About

A simple, SSL-enabled server/client application written in Python using asyncio and ssl

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •