# ignacio-hernani/vault-cmpv2-demo architecture

> Architecture diagram of the GitHub repository ignacio-hernani/vault-cmpv2-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ignacio-hernani/vault-cmpv2-demo
- Repository: https://github.com/ignacio-hernani/vault-cmpv2-demo

## Overview

##### Main Components
- PKI secrets engines set up (mock root CA, intermediate CA, hardware root CA simulation).
- CMPv2 endpoint enabled and configured.
- Authentication configuration using certificates.
- Script/Automation Layer: Represent the three main Bash scripts as distinct steps:
- Setup Script (01-test-cmpv2.sh): Launches Vault, sets up the PKI secrets paths, and configures the endpoints.
- Key and CSR Generation (02-new-rsa-2048-key-csr.sh): Uses OpenSSL to generate a new RSA key and a CSR.
- Initialization Request (03-initialization-request.sh): Uses OpenSSL CMP commands to send the CSR to the Vault CMP endpoint and obtain a new certificate.
- Client Tools:
- OpenSSL: Not just as the tool used via the scripts, but a key component that interfaces with Vault (both for CSR generation and for sending the CMP request).
- Bash Shell/Environment: Where environment variables get set to mediate interaction between scripts and Vault.

##### Interactions and Data Flow
- Environment Variables: Optionally include a note or a separate “Configuration/Environment” component that represents the export of various environment variables (like VAULT_ADDR, VAULT_TOKEN, paths for certificates, keys, etc.) that tie the flows together.

##### Architectural Patterns and Principles
- Separation of Concerns: Each script is responsible for a specific part of the demo operation (setup, key generation, CMP request).
- Secure Communication: Use of TLS (explicit in the Vault configuration) should be highlighted.
- PKI/CMP Design: Emphasize that Vault is acting as both a Certificate Authority (via PKI secrets engine) and a CMP server.
- External Dependency Use: The reliance on standard utilities (Bash, OpenSSL, curl, jq, nc) to interact with Vault and perform cryptographic operations.

- Data flows: environment setup, CSR/key files creation, CMP IR submission, and certificate retrieval.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Environment
    UA("User/Bash Environment"):::env

    %% Automation Scripts
    subgraph "Automation Scripts"
        S1("01-test-cmpv2.sh – Vault Setup"):::script
        S2("02-new-rsa-2048-key-csr.sh – Key & CSR Generation"):::script
        S3("03-initialization-request.sh – CMP Request"):::script
    end

    %% Vault Server Component
    subgraph "Vault Server"
        VS("Vault Server (Dev Mode, TLS, PKI & CMP Endpoint)"):::vault
    end

    %% Data Flows
    UA -->|"Triggers_Vault_Setup"| S1
    S1 -->|"Configures_Vault_with_TLS,_PKI,_and_CMP"| VS
    UA -->|"Starts_Key_CSR_Generation"| S2
    S2 -->|"Generates_RSA_Key_and_CSR_using_OpenSSL"| S3
    S3 -->|"Sends_CMP_Request_via_TLS"| VS
    VS -->|"Returns_Certificate_to_Script"| S3

    %% Click Events
    click S1 "https://github.com/ignacio-hernani/vault-cmpv2-demo/blob/main/01-test-cmpv2.sh"
    click S2 "https://github.com/ignacio-hernani/vault-cmpv2-demo/blob/main/02-new-rsa-2048-key-csr.sh"
    click S3 "https://github.com/ignacio-hernani/vault-cmpv2-demo/blob/main/03-initialization-request.sh"
    click VS "https://github.com/ignacio-hernani/vault-cmpv2-demo/blob/main/01-test-cmpv2.sh"

    %% Class Definitions for Colors and Styles
    classDef env fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef script fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef vault fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
```
