# rcgil30/proyecto-cripto architecture

> Architecture diagram of the GitHub repository rcgil30/proyecto-cripto, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rcgil30/proyecto-cripto
- Repository: https://github.com/rcgil30/proyecto-cripto

## Overview

##### Main Components
a. Client Application (src/client/ssh_client.py)
b. Server Application (src/server/ssh_server.py)
c. Cryptography Layer (src/crypto/)
- classic_crypto (ECDH-P256, RSA-SHA256, AES-192-CBC, HMAC-SHA256)
- pq_crypto (Kyber512, Dilithium2, AES-192-CBC, HMAC-SHA256)
- crypto_factory (selects between classical and PQC implementations)
d. Configuration Loader (parses .env variables: HOST, PORT, USE_PQC, MAX_CONNECTIONS)
e. Network Transport (TCP sockets over configured HOST:PORT)

##### Relationships & Data Flows
- Client starts → reads config → initializes Crypto via crypto_factory → opens TCP socket → begins SSH handshake
- Handshake on both sides uses the same Crypto implementation (classical vs. PQC)
- Key exchange → session keys → secure channel established
- Application data encrypted/decrypted via AES-192-CBC + HMAC-SHA256
- Client ↔ Network Transport ↔ Server
- Server listens for one connection (MAX_CONNECTIONS=1), then repeats handshake & data flow

##### Architectural Patterns & Principles
- Factory Pattern: crypto_factory instantiates either ClassicCrypto or PQCrypto based on USE_PQC flag
- Strategy Pattern: interchangeable crypto algorithms implementing a common interface
- Layered Architecture:
- Configuration Layer
- Application Layer (client/server logic)
- Cryptography Layer (algorithm implementations)
- Transport Layer (socket I/O)
- Single-Responsibility: each module has a distinct role (e.g., SSH logic vs. crypto vs. config)

##### Technologies & Libraries
- Python 3.9+
- socket (built-in) for TCP transport
- python-dotenv (via requirements.txt) for .env loading
- liboqs-python for post-quantum primitives
- Standard Python crypto libraries (e.g., Cryptography.io) or OpenSSL bindings for ECDH, RSA, AES, HMAC

## Diagram (Mermaid)

```mermaid
flowchart TB
    config["Configuration Loader\n.env"]:::config

    subgraph "Application Layer"
        app_pkg1["App Layer (Client)\nsrc/client/"]:::app
        client["Client Application\nssh_client.py"]:::app
        app_pkg2["App Layer (Server)\nsrc/server/"]:::app
        server["Server Application\nssh_server.py"]:::app
    end

    config -->|"HOST,PORT,USE_PQC,MAX_CONNECTIONS"| app_pkg1
    app_pkg1 -->|"initialize"| client
    config -->|"HOST,PORT,USE_PQC,MAX_CONNECTIONS"| app_pkg2
    app_pkg2 -->|"initialize"| server

    subgraph "Cryptography Layer"
        crypto_pkg["Cryptography Layer\nsrc/crypto/"]:::factory
        factory["Crypto Factory"]:::factory
        classic["ClassicCrypto\n(ECDH-P256, RSA-SHA256, AES-192-CBC, HMAC-SHA256)"]:::cryptoImpl
        pq["PQCrypto\n(Kyber512, Dilithium2, AES-192-CBC, HMAC-SHA256)"]:::cryptoImpl
    end

    crypto_pkg --> factory
    client -->|"init Crypto"| factory
    server -->|"init Crypto"| factory
    factory -->|"USE_PQC=false"| classic
    factory -->|"USE_PQC=true"| pq

    transport["TCP Socket\nHOST:PORT"]:::transport
    client -->|"Handshake:KeyExchange,SignatureDisabled"| transport
    transport -->|"Handshake:KeyExchange,SignatureDisabled"| server
    client -->|"EncryptedData:AES-192-CBC+HMAC-SHA256"| transport
    transport -->|"EncryptedData:AES-192-CBC+HMAC-SHA256"| server
    server -->|"listens (MAX_CONNECTIONS=1)"| transport

    classDef app fill:#ADD8E6,stroke:#000;
    classDef cryptoImpl fill:#90EE90,stroke:#000;
    classDef factory fill:#FFD700,stroke:#000;
    classDef config fill:#D3D3D3,stroke:#000;
    classDef transport fill:#F0E68C,stroke:#000;

    click client "https://github.com/rcgil30/proyecto-cripto/blob/main/src/client/ssh_client.py"
    click server "https://github.com/rcgil30/proyecto-cripto/blob/main/src/server/ssh_server.py"
    click app_pkg1 "https://github.com/rcgil30/proyecto-cripto/tree/main/src/client/"
    click app_pkg2 "https://github.com/rcgil30/proyecto-cripto/tree/main/src/server/"
    click crypto_pkg "https://github.com/rcgil30/proyecto-cripto/tree/main/src/crypto/"
    click factory "https://github.com/rcgil30/proyecto-cripto/blob/main/src/crypto/crypto_factory.py"
    click classic "https://github.com/rcgil30/proyecto-cripto/blob/main/src/crypto/classic_crypto.py"
    click pq "https://github.com/rcgil30/proyecto-cripto/blob/main/src/crypto/pq_crypto.py"
    click requirements "https://github.com/rcgil30/proyecto-cripto/blob/main/requirements.txt"
```
