# douglasmakey/poc-rust-https-sniffer architecture

> Architecture diagram of the GitHub repository douglasmakey/poc-rust-https-sniffer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/douglasmakey/poc-rust-https-sniffer
- Repository: https://github.com/douglasmakey/poc-rust-https-sniffer

## Overview

##### Main Components

a) Core System Components:
- User Space Application (https-sniffer)
- Kernel Space eBPF Programs (https-sniffer-ebpf)
- Common Components (https-sniffer-common)
- Target Application (e.g., curl)
- OpenSSL Library
- Linux Kernel

b) Data Structures and Maps:
- PerCpuArray (STORAGE)
- PerfEventArray (EVENTS)
- HashMap (BUFFERS)
- Data Structure (shared between user and kernel space)

Section 1: High-Level Architecture

- Target Application   |     |  HTTPS Sniffer      |
- (e.g., curl)          |     |  User Space App      |

- v                            |

- OpenSSL Library     |<------------+
- (SSL_read/SSL_write)   |    Uprobes

- v

- Linux Kernel                        |

- eBPF Programs  |      | eBPF Maps        |   |

- SSL Operation  |     | eBPF Program  |     | User Space App |

- 1. SSL_read   |---->| 2. Uprobe     |     | 5. Process    |
- SSL_write     |     | Handler       |     | Events        |

- 4. Return     |<----| 3. Uretprobe  |---->| 6. Display    |
- Values     |     | Handler       |     | Data          |

Section 3: Map Interaction Detail

- PerCpuArray   |     |     HashMap       |     |   PerfEventArray |
- (STORAGE)     |     |    (BUFFERS)      |     |    (EVENTS)     |

- Data struct |  |     | | Thread ID   |   |     | | Event Data  |  |
- per CPU     |  |     | | Buffer Ptr  |   |     | | Queue      |  |

##### Important Elements to Highlight
- Uprobe attachment points (SSL_read and SSL_write)
- Data flow through eBPF maps
- Communication between user and kernel space
- Buffer management and size limitations
- Per-CPU processing paths

##### Additional Details
- Maximum buffer sizes (16384 bytes)
- Task communication length (16 bytes)
- CPU core handling
- Error handling paths
- Performance event processing loops

**Symbol Key:**
**→ Data Flow Direction**
**⟲ Circular Buffer (PerfEventArray)**
**⚡ Probe Points**
**□ Storage Components**
**○ Processing Components**

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef userspace fill:#a8d1f0,stroke:#000
    classDef kernelspace fill:#90EE90,stroke:#000
    classDef datastructure fill:#FFE5B4,stroke:#000
    classDef system fill:#D3D3D3,stroke:#000
    classDef critical fill:#FFB6C1,stroke:#000

    %% Main components
    Target["Target Application<br/>(e.g., curl)"]:::userspace
    UserApp["HTTPS Sniffer<br/>User Space App"]:::userspace
    OpenSSL["OpenSSL Library<br/>(SSL_read/SSL_write)"]:::system
    Kernel["Linux Kernel"]:::system

    %% Kernel space components
    subgraph KernelSpace["Kernel Space"]
        eBPF["eBPF Programs"]:::kernelspace
        Maps["eBPF Maps"]:::datastructure
        
        subgraph DataMaps["Data Maps"]
            direction TB
            Storage["PerCpuArray<br/>(STORAGE)"]:::datastructure
            Buffers["HashMap<br/>(BUFFERS)"]:::datastructure
            Events["PerfEventArray<br/>(EVENTS)"]:::datastructure
        end
    end

    %% Data flow
    Target --> OpenSSL
    OpenSSL --> |"Uprobes"| eBPF
    eBPF --> Storage
    eBPF --> Buffers
    eBPF --> Events
    Events --> UserApp
    UserApp --> |"Monitoring"| OpenSSL

    %% Legend
    subgraph Legend["Legend"]
        L1["→ Data Flow"]
        L2["⚡ Probe Points"]
        L3["□ Storage"]
        L4["○ Processing"]
    end

    %% Click events
    click UserApp "https://github.com/douglasmakey/poc-rust-https-sniffer/blob/main/https-sniffer/src/main.rs"
    click eBPF "https://github.com/douglasmakey/poc-rust-https-sniffer/blob/main/https-sniffer-ebpf/src/main.rs"
    click OpenSSL "https://github.com/douglasmakey/poc-rust-https-sniffer/blob/main/https-sniffer-ebpf/src/openssl.rs"
    click Storage "https://github.com/douglasmakey/poc-rust-https-sniffer/blob/main/https-sniffer-common/src/data.rs"
    click Events "https://github.com/douglasmakey/poc-rust-https-sniffer/blob/main/https-sniffer-common/src/lib.rs"
```
