Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 29b55bfd01 | |||
| 4092bdfb1a | |||
| 743dca2fb3 | |||
| 92bba64772 | |||
| 7d14635a72 | |||
| 58aa217428 | |||
| a05dba49f7 | |||
| 3efe86e29e | |||
| c0320c35f0 | |||
| 0f4a1b268b | |||
| 3eb4749b4d | |||
| 983ab56662 | |||
| 90bdb8c329 | |||
| d185e317df | |||
| 72cda5877a |
@@ -1,16 +1,88 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img src="docs/screenshots/logo/certctl-logo.png" alt="certctl logo" width="450">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=89db181e-76e0-45cc-b9c0-790c3dfdfc73" />
|
||||||
|
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=b9379aff-9e5c-4d01-8f2d-9e4ffa09d126" />
|
||||||
|
|
||||||
# certctl — Self-Hosted Certificate Lifecycle Platform
|
# certctl — Self-Hosted Certificate Lifecycle Platform
|
||||||
|
|
||||||
TLS certificate lifespans are shrinking. The CA/Browser Forum passed [Ballot SC-081v3](https://cabforum.org/2025/04/11/ballot-sc081v3-introduce-schedule-of-reducing-validity-and-data-reuse-periods/) unanimously in April 2025, setting a phased reduction: **200 days** by March 2026, **100 days** by March 2027, and **47 days** by March 2029. Manual certificate management is no longer viable at any scale.
|
90+ API endpoints. 21 database tables. 900+ tests. Full GUI. Ships with Docker Compose.
|
||||||
|
|
||||||
certctl is a self-hosted platform for **end-to-end certificate lifecycle automation** — from issuance through renewal to deployment — with zero human intervention. Track every certificate in your organization, automatically renew them before they expire, and deploy them to your servers without touching a terminal. Private keys never leave your infrastructure.
|
```mermaid
|
||||||
|
timeline
|
||||||
|
title TLS Certificate Maximum Lifespan (CA/Browser Forum Ballot SC-081v3)
|
||||||
|
2015 : 5 years
|
||||||
|
2018 : 825 days
|
||||||
|
2020 : 398 days
|
||||||
|
March 2026 : 200 days
|
||||||
|
March 2027 : 100 days
|
||||||
|
March 2029 : 47 days
|
||||||
|
```
|
||||||
|
|
||||||
|
TLS certificate lifespans are shrinking fast. The CA/Browser Forum passed [Ballot SC-081v3](https://cabforum.org/2025/04/11/ballot-sc081v3-introduce-schedule-of-reducing-validity-and-data-reuse-periods/) unanimously in April 2025, setting a phased reduction: **200 days** by March 2026, **100 days** by March 2027, and **47 days** by March 2029. Organizations managing dozens or hundreds of certificates can no longer rely on spreadsheets, calendar reminders, or manual renewal workflows. The math doesn't work — at 47-day lifespans, a team managing 100 certificates is processing 7+ renewals per week, every week, forever.
|
||||||
|
|
||||||
|
certctl is a self-hosted platform that automates the entire certificate lifecycle — from issuance through renewal to deployment — with zero human intervention. It works with any certificate authority, deploys to any server, and keeps private keys on your infrastructure where they belong.
|
||||||
|
|
||||||
[](LICENSE)
|
[](LICENSE)
|
||||||
[](https://goreportcard.com/report/github.com/shankar0123/certctl)
|
[](https://goreportcard.com/report/github.com/shankar0123/certctl)
|
||||||

|

|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
| Guide | Description |
|
||||||
|
|-------|-------------|
|
||||||
|
| [Concepts](docs/concepts.md) | TLS certificates explained from scratch — for beginners who know nothing about certs |
|
||||||
|
| [Quick Start](docs/quickstart.md) | Get running in 5 minutes — dashboard, API, CLI, discovery, stakeholder demo flow |
|
||||||
|
| [Advanced Demo](docs/demo-advanced.md) | Issue a certificate end-to-end with technical deep-dives |
|
||||||
|
| [Architecture](docs/architecture.md) | System design, data flow diagrams, security model |
|
||||||
|
| [Connectors](docs/connectors.md) | Build custom issuer, target, and notifier connectors |
|
||||||
|
| [Compliance Mapping](docs/compliance.md) | SOC 2 Type II, PCI-DSS 4.0, NIST SP 800-57 alignment guides |
|
||||||
|
| [Manual Testing Guide](docs/testing-guide.md) | 284 tests across 25 areas — full V2 QA runbook with exact commands and pass/fail criteria |
|
||||||
|
|
||||||
|
## Contents
|
||||||
|
|
||||||
|
- [Why certctl Exists](#why-certctl-exists)
|
||||||
|
- [What It Does](#what-it-does)
|
||||||
|
- [Screenshots](#screenshots)
|
||||||
|
- [Quick Start](#quick-start)
|
||||||
|
- [Architecture](#architecture)
|
||||||
|
- [Configuration](#configuration)
|
||||||
|
- [MCP Server (AI Integration)](#mcp-server-ai-integration)
|
||||||
|
- [CLI](#cli)
|
||||||
|
- [API Overview](#api-overview)
|
||||||
|
- [Supported Integrations](#supported-integrations)
|
||||||
|
- [Development](#development)
|
||||||
|
- [Security](#security)
|
||||||
|
- [Roadmap](#roadmap)
|
||||||
|
- [License](#license)
|
||||||
|
|
||||||
|
## Why certctl Exists
|
||||||
|
|
||||||
|
Certificate lifecycle tooling today falls into two camps: expensive enterprise platforms (Venafi, Keyfactor, Sectigo) that cost six figures and take months to deploy, or single-purpose tools (cert-manager, certbot) that handle one slice of the problem. If you run a mixed infrastructure — some NGINX, some Apache, a few HAProxy nodes, maybe an F5 — and you need to manage certificates from multiple CAs, there's nothing self-hosted that covers the full lifecycle without vendor lock-in.
|
||||||
|
|
||||||
|
certctl fills that gap. It's **CA-agnostic** — the issuer connector interface means you can plug in any certificate authority: a self-signed local CA for dev, Let's Encrypt via ACME for public certs, Smallstep step-ca for your private PKI, your enterprise ADCS via sub-CA mode, or any custom CA through a shell script adapter. You're never locked to a single CA vendor, and you can run multiple issuers simultaneously for different certificate types.
|
||||||
|
|
||||||
|
It's also **target-agnostic**. Agents deploy certificates to NGINX, Apache, and HAProxy today, with the same pluggable connector model for any server that accepts cert files. The control plane never initiates outbound connections — agents poll for work, which means certctl works behind firewalls, across network zones, and in air-gapped environments.
|
||||||
|
|
||||||
## What It Does
|
## What It Does
|
||||||
|
|
||||||
certctl gives you a single pane of glass for every TLS certificate in your organization. The **web dashboard** shows your full certificate inventory — what's healthy, what's expiring, what's already expired, and who owns each one. The **REST API** (91 endpoints under `/api/v1/`) lets you automate everything. **Agents** deployed on your infrastructure generate private keys locally, discover existing certificates on disk, and submit CSRs — private keys never leave your servers. The **network scanner** discovers certificates on TLS endpoints across your infrastructure without requiring agents. The background scheduler watches expiration dates and triggers renewals automatically — when certificate lifespans drop to 47 days, certctl handles the constant rotation without human involvement.
|
certctl gives you a single pane of glass for every TLS certificate in your organization. The **web dashboard** shows your full certificate inventory — what's healthy, what's expiring, what's already expired, and who owns each one. The **REST API** (95 endpoints under `/api/v1/` + `/.well-known/est/`) lets you automate everything. **Agents** deployed on your infrastructure generate private keys locally, discover existing certificates on disk, and submit CSRs — private keys never leave your servers. The **network scanner** discovers certificates on TLS endpoints across your infrastructure without requiring agents. The **EST server** (RFC 7030) enables device and WiFi certificate enrollment via industry-standard Enrollment over Secure Transport. The background scheduler watches expiration dates and triggers renewals automatically — when certificate lifespans drop to 47 days, certctl handles the constant rotation without human involvement.
|
||||||
|
|
||||||
|
**Core capabilities:**
|
||||||
|
|
||||||
|
- **Full lifecycle automation** — issuance, renewal, deployment, and revocation with zero human intervention. Configurable renewal policies trigger jobs automatically based on expiration thresholds.
|
||||||
|
- **CA-agnostic issuer connectors** — Local CA (self-signed + sub-CA for enterprise root chains), ACME v2 with HTTP-01 and DNS-01 challenges (Let's Encrypt, Sectigo, any ACME-compatible CA), Smallstep step-ca (native /sign API), and OpenSSL/Custom CA (delegate to any shell script). Pluggable interface — add your own CA in one file.
|
||||||
|
- **Agent-side key generation** — agents generate ECDSA P-256 keys locally, store them with 0600 permissions, and submit only the CSR. Private keys never touch the control plane. This is the default mode, not an opt-in feature.
|
||||||
|
- **Certificate discovery** — agents scan filesystems for existing PEM/DER certificates and report findings for triage. The network scanner probes TLS endpoints across CIDR ranges to find certificates you didn't know existed.
|
||||||
|
- **Revocation infrastructure** — RFC 5280 revocation with all standard reason codes, DER-encoded X.509 CRL per issuer, embedded OCSP responder, and short-lived certificate exemption (certs under 1 hour skip CRL/OCSP).
|
||||||
|
- **Policy engine** — 5 rule types with violation tracking and severity levels. Certificate profiles enforce allowed key types, maximum TTL, and crypto constraints at enrollment time.
|
||||||
|
- **Immutable audit trail** — every action recorded to an append-only log. Every API call recorded with method, path, actor, SHA-256 body hash, response status, and latency. No update or delete on audit records.
|
||||||
|
- **Operational dashboard** — Full React GUI with certificate inventory, bulk operations (multi-select renew/revoke/reassign), deployment timeline visualization, inline policy editing, agent fleet overview, expiration heatmaps, and real-time short-lived credential tracking.
|
||||||
|
- **Observability** — JSON and Prometheus metrics endpoints, 5 stats API endpoints for dashboards, structured slog logging with request ID propagation. Compatible with Prometheus, Grafana Agent, Datadog Agent, and Victoria Metrics.
|
||||||
|
- **Notifications** — threshold-based alerting with deduplication. Routes to email, webhooks, Slack, Microsoft Teams, PagerDuty, and OpsGenie.
|
||||||
|
- **EST enrollment (RFC 7030)** — built-in Enrollment over Secure Transport server for device certificate enrollment. Supports WiFi/802.1X, MDM, and IoT use cases. PKCS#7 certs-only wire format, accepts PEM or base64-encoded DER CSRs, configurable issuer and profile binding.
|
||||||
|
- **AI and CLI access** — MCP server exposes all 78 API operations as tools for Claude, Cursor, and any MCP-compatible client. CLI tool with 12 subcommands for terminal workflows and scripting.
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart LR
|
flowchart LR
|
||||||
@@ -35,16 +107,22 @@ flowchart LR
|
|||||||
|
|
||||||
| | |
|
| | |
|
||||||
|---|---|
|
|---|---|
|
||||||
|  |  |
|
|  |  |
|
||||||
| **Dashboard** — certificate stats, expiry timeline, recent jobs | **Certificates** — full inventory with status, environment, owner filters |
|
| **Dashboard** — real-time stats, expiration heatmap, renewal trends, issuance rate | **Certificates** — full inventory with status filters, environment, owner, team |
|
||||||
|  |  |
|
|  |  |
|
||||||
| **Agents** — fleet health, hostname, heartbeat tracking | **Jobs** — issuance, renewal, deployment job queue |
|
| **Agents** — fleet health, hostname, OS/arch, IP, version tracking | **Fleet Overview** — OS distribution, status breakdown, version analysis |
|
||||||
|  |  |
|
|  |  |
|
||||||
| **Notifications** — threshold alerts grouped by certificate | **Policies** — enforcement rules with enable/disable and delete |
|
| **Jobs** — issuance, renewal, deployment job queue with status filters | **Notifications** — expiration warnings, renewal results, unread/all toggle |
|
||||||
|  |  |
|
|  |  |
|
||||||
| **Issuers** — CA connectors with test connectivity | **Targets** — deployment targets (NGINX, Apache, HAProxy, F5, IIS) |
|
| **Policies** — enforcement rules for ownership, environments, lifetime, renewal | **Profiles** — enrollment templates with key types, max TTL, crypto constraints |
|
||||||
|  | |
|
|  |  |
|
||||||
| **Audit Trail** — immutable log of every action | |
|
| **Issuers** — CA connectors (Local CA, Let's Encrypt, step-ca, DigiCert) | **Targets** — deployment targets (NGINX, F5 BIG-IP, IIS, HAProxy) |
|
||||||
|
|  |  |
|
||||||
|
| **Owners** — certificate ownership with email and team assignment | **Teams** — organizational grouping for notification routing |
|
||||||
|
|  |  |
|
||||||
|
| **Agent Groups** — dynamic grouping by OS, arch, CIDR, version | **Audit Trail** — immutable log with filters, CSV/JSON export |
|
||||||
|
|  | |
|
||||||
|
| **Short-Lived Credentials** — ephemeral certs with live TTL countdown | |
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
@@ -72,7 +150,7 @@ curl -s http://localhost:8443/api/v1/certificates | jq '.total'
|
|||||||
### Manual Build
|
### Manual Build
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Prerequisites: Go 1.22+, PostgreSQL 16+
|
# Prerequisites: Go 1.25+, PostgreSQL 16+
|
||||||
go mod download
|
go mod download
|
||||||
make build
|
make build
|
||||||
|
|
||||||
@@ -92,26 +170,13 @@ export CERTCTL_AGENT_ID=agent-local-01
|
|||||||
./bin/agent --agent-id=agent-local-01
|
./bin/agent --agent-id=agent-local-01
|
||||||
```
|
```
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
| Guide | Description |
|
|
||||||
|-------|-------------|
|
|
||||||
| [Concepts](docs/concepts.md) | TLS certificates explained from scratch — for beginners who know nothing about certs |
|
|
||||||
| [Quick Start](docs/quickstart.md) | Get running in 5 minutes with accurate API examples |
|
|
||||||
| [Demo Walkthrough](docs/demo-guide.md) | 5-7 minute guided stakeholder presentation |
|
|
||||||
| [Advanced Demo](docs/demo-advanced.md) | Issue a certificate end-to-end with technical deep-dives |
|
|
||||||
| [Architecture](docs/architecture.md) | System design, data flow diagrams, security model |
|
|
||||||
| [Connectors](docs/connectors.md) | Build custom issuer, target, and notifier connectors |
|
|
||||||
| [Compliance Mapping](docs/compliance.md) | SOC 2 Type II, PCI-DSS 4.0, NIST SP 800-57 alignment guides |
|
|
||||||
| [Manual Testing Guide](docs/testing-guide.md) | 284 tests across 25 areas — full V2 QA runbook with exact commands and pass/fail criteria |
|
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart TB
|
flowchart TB
|
||||||
subgraph "Control Plane (certctl-server)"
|
subgraph "Control Plane (certctl-server)"
|
||||||
DASH["Web Dashboard\nReact SPA"]
|
DASH["Web Dashboard\nReact SPA"]
|
||||||
API["REST API\nGo 1.22 net/http"]
|
API["REST API\nGo 1.25 net/http"]
|
||||||
SVC["Service Layer"]
|
SVC["Service Layer"]
|
||||||
REPO["Repository Layer\ndatabase/sql + lib/pq"]
|
REPO["Repository Layer\ndatabase/sql + lib/pq"]
|
||||||
SCHED["Scheduler\nRenewal · Jobs · Health · Notifications · Short-Lived Expiry · Network Scan"]
|
SCHED["Scheduler\nRenewal · Jobs · Health · Notifications · Short-Lived Expiry · Network Scan"]
|
||||||
@@ -206,6 +271,9 @@ All server environment variables use the `CERTCTL_` prefix:
|
|||||||
| `CERTCTL_OPENSSL_TIMEOUT_SECONDS` | `30` | Timeout for OpenSSL script execution |
|
| `CERTCTL_OPENSSL_TIMEOUT_SECONDS` | `30` | Timeout for OpenSSL script execution |
|
||||||
| `CERTCTL_NETWORK_SCAN_ENABLED` | `false` | Enable server-side network certificate discovery (TLS scanning) |
|
| `CERTCTL_NETWORK_SCAN_ENABLED` | `false` | Enable server-side network certificate discovery (TLS scanning) |
|
||||||
| `CERTCTL_NETWORK_SCAN_INTERVAL` | `6h` | How often the scheduler runs network scans |
|
| `CERTCTL_NETWORK_SCAN_INTERVAL` | `6h` | How often the scheduler runs network scans |
|
||||||
|
| `CERTCTL_EST_ENABLED` | `false` | Enable EST (RFC 7030) enrollment endpoints under /.well-known/est/ |
|
||||||
|
| `CERTCTL_EST_ISSUER_ID` | `iss-local` | Issuer connector ID used for EST certificate enrollment |
|
||||||
|
| `CERTCTL_EST_PROFILE_ID` | — | Optional certificate profile ID to constrain EST enrollments |
|
||||||
| `CERTCTL_SLACK_WEBHOOK_URL` | — | Slack incoming webhook URL for notifications |
|
| `CERTCTL_SLACK_WEBHOOK_URL` | — | Slack incoming webhook URL for notifications |
|
||||||
| `CERTCTL_TEAMS_WEBHOOK_URL` | — | Microsoft Teams incoming webhook URL |
|
| `CERTCTL_TEAMS_WEBHOOK_URL` | — | Microsoft Teams incoming webhook URL |
|
||||||
| `CERTCTL_PAGERDUTY_ROUTING_KEY` | — | PagerDuty Events API v2 routing key |
|
| `CERTCTL_PAGERDUTY_ROUTING_KEY` | — | PagerDuty Events API v2 routing key |
|
||||||
@@ -269,19 +337,26 @@ go install github.com/shankar0123/certctl/cmd/cli@latest
|
|||||||
export CERTCTL_SERVER_URL=http://localhost:8443
|
export CERTCTL_SERVER_URL=http://localhost:8443
|
||||||
export CERTCTL_API_KEY=your-api-key
|
export CERTCTL_API_KEY=your-api-key
|
||||||
|
|
||||||
# Commands
|
# Certificate commands
|
||||||
certctl-cli list-certs # List all certificates
|
certctl-cli certs list # List all certificates
|
||||||
certctl-cli get-cert --id mc-api-prod # Get certificate details
|
certctl-cli certs get mc-api-prod # Get certificate details
|
||||||
certctl-cli renew-cert --id mc-api-prod # Trigger renewal
|
certctl-cli certs renew mc-api-prod # Trigger renewal
|
||||||
certctl-cli revoke-cert --id mc-api-prod --reason keyCompromise
|
certctl-cli certs revoke mc-api-prod --reason keyCompromise
|
||||||
certctl-cli list-agents # List registered agents
|
|
||||||
certctl-cli list-jobs # List jobs
|
# Agent and job commands
|
||||||
certctl-cli health # Server health check
|
certctl-cli agents list # List registered agents
|
||||||
certctl-cli metrics # Server metrics
|
certctl-cli agents get ag-web-prod # Get agent details
|
||||||
certctl-cli import --file certs.pem # Bulk import from PEM file
|
certctl-cli jobs list # List jobs
|
||||||
|
certctl-cli jobs get job-123 # Get job details
|
||||||
|
certctl-cli jobs cancel job-123 # Cancel a pending job
|
||||||
|
|
||||||
|
# Operations
|
||||||
|
certctl-cli status # Server health + summary stats
|
||||||
|
certctl-cli import certs.pem # Bulk import from PEM file
|
||||||
|
certctl-cli version # Show CLI version
|
||||||
|
|
||||||
# Output formats
|
# Output formats
|
||||||
certctl-cli list-certs --format json # JSON output (default: table)
|
certctl-cli certs list --format json # JSON output (default: table)
|
||||||
```
|
```
|
||||||
|
|
||||||
## API Overview
|
## API Overview
|
||||||
@@ -420,6 +495,14 @@ GET /api/v1/auth/info Auth mode info (no auth required)
|
|||||||
GET /api/v1/auth/check Validate credentials
|
GET /api/v1/auth/check Validate credentials
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### EST Enrollment (RFC 7030)
|
||||||
|
```
|
||||||
|
GET /.well-known/est/cacerts CA certificate chain (PKCS#7 certs-only)
|
||||||
|
POST /.well-known/est/simpleenroll Simple enrollment (PEM or base64-DER CSR)
|
||||||
|
POST /.well-known/est/simplereenroll Simple re-enrollment (certificate renewal)
|
||||||
|
GET /.well-known/est/csrattrs CSR attributes request
|
||||||
|
```
|
||||||
|
|
||||||
### Health
|
### Health
|
||||||
```
|
```
|
||||||
GET /health Server health check
|
GET /health Server health check
|
||||||
@@ -509,7 +592,7 @@ make docker-clean # Stop + remove volumes
|
|||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
### V1 (v1.0.0 released)
|
### V1 (v1.0.0 released)
|
||||||
All nine development milestones (M1–M9) are complete. The backend covers the full certificate lifecycle: Local CA and ACME v2 issuers, NGINX/Apache/HAProxy/F5/IIS target connectors, threshold-based expiration alerting, agent-side ECDSA P-256 key generation, API auth with rate limiting, and a React dashboard with 19 pages wired to the real API. The CI pipeline runs build, vet, test with coverage gates (service layer 30%+, handler layer 50%+), frontend type checking, Vitest test suite, and Vite production build on every push. Docker images are published to GitHub Container Registry on every version tag via the release workflow.
|
All nine development milestones (M1–M9) are complete. The backend covers the full certificate lifecycle: Local CA and ACME v2 issuers, NGINX/Apache/HAProxy/F5/IIS target connectors, threshold-based expiration alerting, agent-side ECDSA P-256 key generation, API auth with rate limiting, and a full React dashboard wired to the real API. The CI pipeline runs build, vet, test with coverage gates (service layer 30%+, handler layer 50%+), frontend type checking, Vitest test suite, and Vite production build on every push. Docker images are published to GitHub Container Registry on every version tag via the release workflow.
|
||||||
|
|
||||||
### V2: Operational Maturity
|
### V2: Operational Maturity
|
||||||
- **M10: Agent Metadata + Targets** ✅ — agents report OS, architecture, IP, hostname, version via heartbeat; Apache httpd and HAProxy target connectors
|
- **M10: Agent Metadata + Targets** ✅ — agents report OS, architecture, IP, hostname, version via heartbeat; Apache httpd and HAProxy target connectors
|
||||||
@@ -523,16 +606,20 @@ All nine development milestones (M1–M9) are complete. The backend covers the f
|
|||||||
- **M19: Immutable API Audit Log** ✅ — every API call recorded to immutable audit trail (method, path, actor, SHA-256 body hash, status, latency), async recording via goroutine, configurable path exclusions
|
- **M19: Immutable API Audit Log** ✅ — every API call recorded to immutable audit trail (method, path, actor, SHA-256 body hash, status, latency), async recording via goroutine, configurable path exclusions
|
||||||
- **M16a: Notifier Connectors** ✅ — Slack (incoming webhook), Microsoft Teams (MessageCard), PagerDuty (Events API v2), OpsGenie (Alert API v2) — config-driven enablement via env vars
|
- **M16a: Notifier Connectors** ✅ — Slack (incoming webhook), Microsoft Teams (MessageCard), PagerDuty (Events API v2), OpsGenie (Alert API v2) — config-driven enablement via env vars
|
||||||
- **M17: Additional Connectors** ✅ — OpenSSL/Custom CA issuer connector (script-based signing with configurable timeout)
|
- **M17: Additional Connectors** ✅ — OpenSSL/Custom CA issuer connector (script-based signing with configurable timeout)
|
||||||
- **M16b: CLI + Bulk Import** ✅ — `certctl-cli` with 10 subcommands (list/get/renew/revoke certs, list agents/jobs, health, metrics, PEM bulk import), stdlib-only, JSON/table output
|
- **M16b: CLI + Bulk Import** ✅ — `certctl-cli` with 12 subcommands (certs list/get/renew/revoke, agents list/get, jobs list/get/cancel, import, status, version), stdlib-only, JSON/table output
|
||||||
- **M20: Enhanced Query API** ✅ — sparse field selection (`?fields=`), sort with direction (`?sort=-notAfter`), time-range filters (`expires_before`, `created_after`, etc.), cursor-based pagination (`?cursor=&page_size=`), `GET /certificates/{id}/deployments`, additional filters (`agent_id`, `profile_id`)
|
- **M20: Enhanced Query API** ✅ — sparse field selection (`?fields=`), sort with direction (`?sort=-notAfter`), time-range filters (`expires_before`, `created_after`, etc.), cursor-based pagination (`?cursor=&page_size=`), `GET /certificates/{id}/deployments`, additional filters (`agent_id`, `profile_id`)
|
||||||
- **M18b: Filesystem Cert Discovery** ✅ — agents scan configured directories (PEM/DER), report findings to control plane, deduplication by SHA-256 fingerprint, claim/dismiss/triage workflow via API
|
- **M18b: Filesystem Cert Discovery** ✅ — agents scan configured directories (PEM/DER), report findings to control plane, deduplication by SHA-256 fingerprint, claim/dismiss/triage workflow via API
|
||||||
- **M21: Network Cert Discovery** ✅ — server-side active TLS scanning of CIDR ranges and ports, concurrent probing (50 goroutines), CIDR expansion with /20 safety cap, sentinel agent pattern for discovery pipeline reuse, CRUD API for scan targets, scheduler integration (6h default)
|
- **M21: Network Cert Discovery** ✅ — server-side active TLS scanning of CIDR ranges and ports, concurrent probing (50 goroutines), CIDR expansion with /20 safety cap, sentinel agent pattern for discovery pipeline reuse, CRUD API for scan targets, scheduler integration (6h default)
|
||||||
- **M22: Prometheus Metrics** ✅ — `GET /api/v1/metrics/prometheus` returns Prometheus exposition format (`text/plain; version=0.0.4`), 11 metrics with `certctl_` prefix, compatible with Prometheus, Grafana Agent, Datadog Agent, Victoria Metrics
|
- **M22: Prometheus Metrics** ✅ — `GET /api/v1/metrics/prometheus` returns Prometheus exposition format (`text/plain; version=0.0.4`), 11 metrics with `certctl_` prefix, compatible with Prometheus, Grafana Agent, Datadog Agent, Victoria Metrics
|
||||||
|
- **M23: EST Server (RFC 7030)** ✅ — Enrollment over Secure Transport for device/WiFi certificate enrollment, 4 endpoints under /.well-known/est/, PKCS#7 certs-only wire format, base64-encoded DER CSR input, configurable issuer + profile binding, audit trail, 28 new tests
|
||||||
- **Compliance Mapping** ✅ — SOC 2 Type II, PCI-DSS 4.0, NIST SP 800-57 capability mapping documentation
|
- **Compliance Mapping** ✅ — SOC 2 Type II, PCI-DSS 4.0, NIST SP 800-57 capability mapping documentation
|
||||||
|
|
||||||
### V3: Team & Enterprise
|
### V3: certctl Pro
|
||||||
|
|
||||||
Team access controls, identity provider integration, enterprise deployment targets, compliance and risk scoring, advanced fleet operations, event-driven architecture, advanced search, real-time operational views, and premium CA integrations.
|
Team access controls, identity provider integration, enterprise deployment targets, compliance and risk scoring, advanced fleet operations, event-driven architecture, advanced search, real-time operational views, and premium CA integrations.
|
||||||
|
|
||||||
|
> **Need SSO, RBAC, F5/IIS deployment, or real-time fleet operations?** [Join the certctl Pro waitlist](https://forms.gle/YOUR_FORM_ID) — early access shipping Q2 2026.
|
||||||
|
|
||||||
### V4+: Cloud, Scale & Passive Discovery
|
### V4+: Cloud, Scale & Passive Discovery
|
||||||
Passive network discovery (TLS listener), Kubernetes integration, cloud infrastructure targets (AWS ALB/ACM, Azure Key Vault), extended CA support, and platform-scale features.
|
Passive network discovery (TLS listener), Kubernetes integration, cloud infrastructure targets (AWS ALB/ACM, Azure Key Vault), extended CA support, and platform-scale features.
|
||||||
|
|
||||||
|
|||||||
@@ -302,6 +302,25 @@ func main() {
|
|||||||
discoveryHandler,
|
discoveryHandler,
|
||||||
networkScanHandler,
|
networkScanHandler,
|
||||||
)
|
)
|
||||||
|
// Register EST (RFC 7030) handlers if enabled
|
||||||
|
if cfg.EST.Enabled {
|
||||||
|
issuerConn, ok := issuerRegistry[cfg.EST.IssuerID]
|
||||||
|
if !ok {
|
||||||
|
logger.Error("EST issuer not found in registry", "issuer_id", cfg.EST.IssuerID)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
estService := service.NewESTService(cfg.EST.IssuerID, issuerConn, auditService, logger)
|
||||||
|
if cfg.EST.ProfileID != "" {
|
||||||
|
estService.SetProfileID(cfg.EST.ProfileID)
|
||||||
|
}
|
||||||
|
estHandler := handler.NewESTHandler(estService)
|
||||||
|
apiRouter.RegisterESTHandlers(estHandler)
|
||||||
|
logger.Info("EST server enabled",
|
||||||
|
"issuer_id", cfg.EST.IssuerID,
|
||||||
|
"profile_id", cfg.EST.ProfileID,
|
||||||
|
"endpoints", "/.well-known/est/{cacerts,simpleenroll,simplereenroll,csrattrs}")
|
||||||
|
}
|
||||||
|
|
||||||
logger.Info("registered all API handlers")
|
logger.Info("registered all API handlers")
|
||||||
|
|
||||||
// Build middleware stack
|
// Build middleware stack
|
||||||
@@ -380,9 +399,10 @@ func main() {
|
|||||||
fileServer := http.FileServer(http.Dir(webDir))
|
fileServer := http.FileServer(http.Dir(webDir))
|
||||||
finalHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
finalHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
// API and health routes go to the API handler
|
// API, health, and EST routes go to the API handler
|
||||||
if path == "/health" || path == "/ready" ||
|
if path == "/health" || path == "/ready" ||
|
||||||
(len(path) >= 8 && path[:8] == "/api/v1/") {
|
(len(path) >= 8 && path[:8] == "/api/v1/") ||
|
||||||
|
(len(path) >= 16 && path[:16] == "/.well-known/est") {
|
||||||
apiHandler.ServeHTTP(w, r)
|
apiHandler.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ The control plane is a Go HTTP server backed by PostgreSQL. It manages state (ce
|
|||||||
|
|
||||||
The server exposes a REST API under `/api/v1/` and optionally serves the web dashboard as static files from the `web/` directory.
|
The server exposes a REST API under `/api/v1/` and optionally serves the web dashboard as static files from the `web/` directory.
|
||||||
|
|
||||||
**Key internals**: The server uses Go 1.22's `net/http` stdlib routing (no external router framework), structured logging via `slog`, and a handler → service → repository layered architecture. Handlers define their own service interfaces for clean dependency inversion.
|
**Key internals**: The server uses Go 1.25's `net/http` stdlib routing (no external router framework), structured logging via `slog`, and a handler → service → repository layered architecture. Handlers define their own service interfaces for clean dependency inversion.
|
||||||
|
|
||||||
### Agents
|
### Agents
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ The agent runs two background loops: a heartbeat (every 60 seconds) to signal it
|
|||||||
|
|
||||||
The web dashboard is the primary operational interface for certctl. It is built with Vite + React + TypeScript and uses TanStack Query for server state management (caching, background refetching, optimistic updates).
|
The web dashboard is the primary operational interface for certctl. It is built with Vite + React + TypeScript and uses TanStack Query for server state management (caching, background refetching, optimistic updates).
|
||||||
|
|
||||||
**Current views (19 pages)**: certificate inventory (list with multi-select bulk operations + "New Certificate" creation modal + detail with deployment status timeline, inline policy/profile editor, version history, deploy, revoke, archive, and trigger renewal actions), agent fleet (list + detail with system info + OS/architecture grouping with charts), job queue (status, retry, cancel, approve/reject), notification inbox (threshold alert grouping, mark-as-read), audit trail (time range, actor, action filters + CSV/JSON export), policy management (rules with enable/disable toggle + delete + violations), issuers (list with test connection + delete), targets (list with 3-step configuration wizard + delete), owners (list with team resolution + delete), teams (list with delete), agent groups (list with dynamic match criteria badges + enable/disable + delete), certificate profiles (list with crypto constraints), short-lived credentials dashboard (TTL countdown, profile filtering, auto-refresh), summary dashboard with charts (expiration heatmap, renewal success rate, status distribution, issuance rate), and login page.
|
**Current views**: certificate inventory (list with multi-select bulk operations + "New Certificate" creation modal + detail with deployment status timeline, inline policy/profile editor, version history, deploy, revoke, archive, and trigger renewal actions), agent fleet (list + detail with system info + OS/architecture grouping with charts), job queue (status, retry, cancel, approve/reject), notification inbox (threshold alert grouping, mark-as-read), audit trail (time range, actor, action filters + CSV/JSON export), policy management (rules with enable/disable toggle + delete + violations), issuers (list with test connection + delete), targets (list with 3-step configuration wizard + delete), owners (list with team resolution + delete), teams (list with delete), agent groups (list with dynamic match criteria badges + enable/disable + delete), certificate profiles (list with crypto constraints), short-lived credentials dashboard (TTL countdown, profile filtering, auto-refresh), summary dashboard with charts (expiration heatmap, renewal success rate, status distribution, issuance rate), and login page.
|
||||||
|
|
||||||
The dashboard includes an **ErrorBoundary component** for graceful error recovery — if a view crashes, the boundary catches the error and displays a user-friendly message instead of breaking the entire dashboard. It also includes a **demo mode** that activates when the API is unreachable — it renders realistic mock data for screenshots and offline presentations.
|
The dashboard includes an **ErrorBoundary component** for graceful error recovery — if a view crashes, the boundary catches the error and displays a user-friendly message instead of breaking the entire dashboard. It also includes a **demo mode** that activates when the API is unreachable — it renders realistic mock data for screenshots and offline presentations.
|
||||||
|
|
||||||
@@ -122,8 +122,11 @@ erDiagram
|
|||||||
managed_certificates ||--o{ policy_violations : "violates"
|
managed_certificates ||--o{ policy_violations : "violates"
|
||||||
managed_certificates ||--o{ audit_events : "logged in"
|
managed_certificates ||--o{ audit_events : "logged in"
|
||||||
managed_certificates ||--o{ notification_events : "generates"
|
managed_certificates ||--o{ notification_events : "generates"
|
||||||
|
managed_certificates ||--o{ certificate_revocations : "revoked via"
|
||||||
agent_groups ||--o{ agent_group_members : "has members"
|
agent_groups ||--o{ agent_group_members : "has members"
|
||||||
agents ||--o{ agent_group_members : "belongs to"
|
agents ||--o{ agent_group_members : "belongs to"
|
||||||
|
agents ||--o{ discovered_certificates : "discovers"
|
||||||
|
agents ||--o{ discovery_scans : "performs"
|
||||||
|
|
||||||
teams {
|
teams {
|
||||||
text id PK
|
text id PK
|
||||||
@@ -242,6 +245,43 @@ erDiagram
|
|||||||
text agent_id FK
|
text agent_id FK
|
||||||
text membership_type
|
text membership_type
|
||||||
}
|
}
|
||||||
|
renewal_policies {
|
||||||
|
text id PK
|
||||||
|
text certificate_id FK
|
||||||
|
int renewal_days_before
|
||||||
|
jsonb alert_thresholds_days
|
||||||
|
boolean auto_renew
|
||||||
|
text agent_group_id FK
|
||||||
|
}
|
||||||
|
certificate_revocations {
|
||||||
|
text id PK
|
||||||
|
text certificate_id FK
|
||||||
|
text serial_number
|
||||||
|
text reason
|
||||||
|
timestamp revoked_at
|
||||||
|
boolean issuer_notified
|
||||||
|
}
|
||||||
|
discovered_certificates {
|
||||||
|
text id PK
|
||||||
|
text agent_id FK
|
||||||
|
text fingerprint_sha256
|
||||||
|
text common_name
|
||||||
|
text source_path
|
||||||
|
text status
|
||||||
|
}
|
||||||
|
discovery_scans {
|
||||||
|
text id PK
|
||||||
|
text agent_id FK
|
||||||
|
int certs_found
|
||||||
|
timestamp scanned_at
|
||||||
|
}
|
||||||
|
network_scan_targets {
|
||||||
|
text id PK
|
||||||
|
text name
|
||||||
|
text[] cidrs
|
||||||
|
int[] ports
|
||||||
|
boolean enabled
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Migrations are idempotent (`IF NOT EXISTS` on all CREATE statements, `ON CONFLICT (id) DO NOTHING` on all seed data) so they're safe to run multiple times — important for Docker Compose where both initdb and the server may run the same SQL.
|
Migrations are idempotent (`IF NOT EXISTS` on all CREATE statements, `ON CONFLICT (id) DO NOTHING` on all seed data) so they're safe to run multiple times — important for Docker Compose where both initdb and the server may run the same SQL.
|
||||||
@@ -481,10 +521,13 @@ type Connector interface {
|
|||||||
RenewCertificate(ctx context.Context, request RenewalRequest) (*IssuanceResult, error)
|
RenewCertificate(ctx context.Context, request RenewalRequest) (*IssuanceResult, error)
|
||||||
RevokeCertificate(ctx context.Context, request RevocationRequest) error
|
RevokeCertificate(ctx context.Context, request RevocationRequest) error
|
||||||
GetOrderStatus(ctx context.Context, orderID string) (*OrderStatus, error)
|
GetOrderStatus(ctx context.Context, orderID string) (*OrderStatus, error)
|
||||||
|
GenerateCRL(ctx context.Context, revokedCerts []RevokedCertEntry) ([]byte, error)
|
||||||
|
SignOCSPResponse(ctx context.Context, req OCSPSignRequest) ([]byte, error)
|
||||||
|
GetCACertPEM(ctx context.Context) (string, error)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Built-in issuers: **Local CA** (self-signed or sub-CA mode using `crypto/x509`), **ACME v2** (HTTP-01 and DNS-01 challenges, compatible with Let's Encrypt, Sectigo, and any ACME-compliant CA), and **step-ca** (Smallstep private CA via native /sign API with JWK provisioner auth). The ACME connector uses `golang.org/x/crypto/acme`, generates an ECDSA P-256 account key, handles account registration with ToS acceptance, order creation, challenge solving (HTTP-01 via built-in server, DNS-01 via script-based hooks), order finalization, and DER-to-PEM chain conversion.
|
Built-in issuers: **Local CA** (self-signed or sub-CA mode using `crypto/x509`), **ACME v2** (HTTP-01 and DNS-01 challenges, compatible with Let's Encrypt, Sectigo, and any ACME-compliant CA), **step-ca** (Smallstep private CA via native /sign API with JWK provisioner auth), and **OpenSSL/Custom CA** (script-based signing delegating to user-provided shell scripts). The ACME connector uses `golang.org/x/crypto/acme`, generates an ECDSA P-256 account key, handles account registration with ToS acceptance, order creation, challenge solving (HTTP-01 via built-in server, DNS-01 via script-based hooks), order finalization, and DER-to-PEM chain conversion. The interface also includes `GetCACertPEM(ctx)` for CA chain distribution (used by the EST server's `/cacerts` endpoint).
|
||||||
|
|
||||||
### Target Connector
|
### Target Connector
|
||||||
|
|
||||||
@@ -520,6 +563,45 @@ Built-in notifiers: **Email** (SMTP), **Webhook** (HTTP POST), **Slack** (incomi
|
|||||||
|
|
||||||
See the [Connector Development Guide](connectors.md) for details on building custom connectors.
|
See the [Connector Development Guide](connectors.md) for details on building custom connectors.
|
||||||
|
|
||||||
|
### EST Server (RFC 7030)
|
||||||
|
|
||||||
|
The EST (Enrollment over Secure Transport) server provides an industry-standard enrollment interface for devices that need certificates without using the REST API. It runs under `/.well-known/est/` per RFC 7030 and supports four operations: CA certificate distribution (`/cacerts`), initial enrollment (`/simpleenroll`), re-enrollment (`/simplereenroll`), and CSR attributes (`/csrattrs`).
|
||||||
|
|
||||||
|
**Architecture:** EST is a handler-level protocol that delegates certificate issuance to an existing `IssuerConnector`. This means EST is not a new issuer — it's a new *interface* to the existing issuance infrastructure. The `ESTService` bridges the `ESTHandler` to whichever issuer connector is configured via `CERTCTL_EST_ISSUER_ID`.
|
||||||
|
|
||||||
|
```
|
||||||
|
Client (WiFi AP, MDM, IoT)
|
||||||
|
│
|
||||||
|
▼
|
||||||
|
ESTHandler (handler layer)
|
||||||
|
│ CSR parsing, PKCS#7 response encoding
|
||||||
|
▼
|
||||||
|
ESTService (service layer)
|
||||||
|
│ CSR validation, CN/SAN extraction, audit recording
|
||||||
|
▼
|
||||||
|
IssuerConnector (connector layer via IssuerConnectorAdapter)
|
||||||
|
│ Certificate signing (Local CA, step-ca, etc.)
|
||||||
|
▼
|
||||||
|
Signed certificate returned as PKCS#7 certs-only
|
||||||
|
```
|
||||||
|
|
||||||
|
**Wire format:** EST uses PKCS#7 (RFC 2315) certs-only degenerate SignedData for certificate responses and base64-encoded DER for CSR requests. The handler includes a hand-rolled ASN.1 PKCS#7 builder — no external PKCS#7 dependency. The CSR reader accepts both base64-encoded DER (standard EST wire format) and PEM-encoded PKCS#10 (convenience for debugging).
|
||||||
|
|
||||||
|
**Interface:** The `ESTHandler` defines an `ESTService` interface (dependency inversion, same pattern as all other handlers):
|
||||||
|
|
||||||
|
```go
|
||||||
|
type ESTService interface {
|
||||||
|
GetCACerts(ctx context.Context) (string, error)
|
||||||
|
SimpleEnroll(ctx context.Context, csrPEM string) (*domain.ESTEnrollResult, error)
|
||||||
|
SimpleReEnroll(ctx context.Context, csrPEM string) (*domain.ESTEnrollResult, error)
|
||||||
|
GetCSRAttrs(ctx context.Context) ([]byte, error)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Issuer connector extension:** EST required adding `GetCACertPEM(ctx) (string, error)` to the issuer connector interface so the `/cacerts` endpoint can serve the CA chain. The Local CA connector returns its CA certificate PEM; ACME, step-ca, and OpenSSL connectors return errors (they don't expose a static CA chain — their chains are per-issuance).
|
||||||
|
|
||||||
|
**Audit:** Every EST enrollment is recorded in the audit trail with `protocol: "EST"`, the CN, SANs, issuer ID, serial number, and optional profile ID.
|
||||||
|
|
||||||
## Security Model
|
## Security Model
|
||||||
|
|
||||||
### Private Key Management
|
### Private Key Management
|
||||||
@@ -606,9 +688,9 @@ All endpoints are under `/api/v1/` and follow consistent patterns:
|
|||||||
- **Delete**: `DELETE /api/v1/{resources}/{id}` — returns `204` (soft delete/archive)
|
- **Delete**: `DELETE /api/v1/{resources}/{id}` — returns `204` (soft delete/archive)
|
||||||
- **Actions**: `POST /api/v1/{resources}/{id}/{action}` — returns `202` for async operations
|
- **Actions**: `POST /api/v1/{resources}/{id}/{action}` — returns `202` for async operations
|
||||||
|
|
||||||
Resources: certificates, issuers, targets, agents, jobs, policies, profiles, teams, owners, agent-groups, audit, notifications.
|
Resources: certificates, issuers, targets, agents, jobs, policies, profiles, teams, owners, agent-groups, audit, notifications, discovered-certificates, discovery-scans, network-scan-targets, stats, metrics.
|
||||||
|
|
||||||
The full API is documented in an OpenAPI 3.1 specification at `api/openapi.yaml` with 91 endpoints across 19 resource domains (including health, readiness, auth, 7 discovery endpoints from M18b, 6 network scan endpoints from M21, and Prometheus metrics from M22), all request/response schemas, and pagination conventions. See the [OpenAPI Guide](openapi.md) for usage with Swagger UI and SDK generation.
|
The full API is documented in an OpenAPI 3.1 specification at `api/openapi.yaml` with 97 endpoints across 20 resource domains (95 under `/api/v1/` + `/.well-known/est/` plus `/health` and `/ready`; includes auth, 7 discovery endpoints from M18b, 6 network scan endpoints from M21, Prometheus metrics from M22, and 4 EST enrollment endpoints from M23), all request/response schemas, and pagination conventions. See the [OpenAPI Guide](openapi.md) for usage with Swagger UI and SDK generation.
|
||||||
|
|
||||||
Jobs support additional action endpoints: `POST /api/v1/jobs/{id}/cancel`, `POST /api/v1/jobs/{id}/approve`, `POST /api/v1/jobs/{id}/reject`.
|
Jobs support additional action endpoints: `POST /api/v1/jobs/{id}/cancel`, `POST /api/v1/jobs/{id}/approve`, `POST /api/v1/jobs/{id}/reject`.
|
||||||
|
|
||||||
@@ -654,7 +736,7 @@ The 78 tools are organized across 16 resource domains with typed input structs a
|
|||||||
|
|
||||||
certctl ships with a command-line tool (`certctl-cli`, built from `cmd/cli/main.go`) that wraps the REST API for terminal workflows. The CLI uses Go's standard library only (`flag` + `text/tabwriter`) — no Cobra or other framework dependencies.
|
certctl ships with a command-line tool (`certctl-cli`, built from `cmd/cli/main.go`) that wraps the REST API for terminal workflows. The CLI uses Go's standard library only (`flag` + `text/tabwriter`) — no Cobra or other framework dependencies.
|
||||||
|
|
||||||
10 subcommands: `list-certs`, `get-cert`, `renew-cert`, `revoke-cert`, `list-agents`, `list-jobs`, `health`, `metrics`, and `import` (bulk PEM import). Output is available in table (default) or JSON format via `--format`. Connection is configured via `CERTCTL_SERVER_URL` and `CERTCTL_API_KEY` environment variables or CLI flags.
|
12 subcommands organized by resource: `certs list`, `certs get`, `certs renew`, `certs revoke`, `agents list`, `agents get`, `jobs list`, `jobs get`, `jobs cancel`, `import` (bulk PEM import), `status` (health + summary stats), and `version`. Output is available in table (default) or JSON format via `--format`. Connection is configured via `CERTCTL_SERVER_URL` and `CERTCTL_API_KEY` environment variables or CLI flags.
|
||||||
|
|
||||||
The bulk import command (`certctl-cli import <file.pem>`) parses multi-certificate PEM files and creates certificate records via the API — useful for bootstrapping certctl with existing certificate inventory.
|
The bulk import command (`certctl-cli import <file.pem>`) parses multi-certificate PEM files and creates certificate records via the API — useful for bootstrapping certctl with existing certificate inventory.
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ certctl generates certificate keys on agent infrastructure using Go's `crypto/ra
|
|||||||
|
|
||||||
**Server-Side Key Generation (Demo Only)**
|
**Server-Side Key Generation (Demo Only)**
|
||||||
- Available for development and testing via `CERTCTL_KEYGEN_MODE=server`
|
- Available for development and testing via `CERTCTL_KEYGEN_MODE=server`
|
||||||
- Explicitly logged as a warning at startup: "server-side keygen enabled (production deployments must use agent mode)"
|
- Explicitly logged as a warning at startup: "server-side key generation enabled (CERTCTL_KEYGEN_MODE=server) — private keys touch control plane, demo only"
|
||||||
- Docker Compose demo uses server mode for backward compatibility
|
- Docker Compose demo uses server mode for backward compatibility
|
||||||
- Not recommended for production; agent mode is the secure default
|
- Not recommended for production; agent mode is the secure default
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ This requirement covers key generation, storage, rotation, and destruction. Cert
|
|||||||
- **Server-Side Fallback** (demo/development only) — `CERTCTL_KEYGEN_MODE=server`:
|
- **Server-Side Fallback** (demo/development only) — `CERTCTL_KEYGEN_MODE=server`:
|
||||||
- Control plane generates RSA 2048-bit or ECDSA P-256 keys using `crypto/rand` + `crypto/rsa`.
|
- Control plane generates RSA 2048-bit or ECDSA P-256 keys using `crypto/rand` + `crypto/rsa`.
|
||||||
- Server signs CSR and stores the private key in the certificate version record for agent deployment. **Security note:** In server keygen mode, the control plane holds private keys — this is why agent keygen mode is the recommended default for production.
|
- Server signs CSR and stores the private key in the certificate version record for agent deployment. **Security note:** In server keygen mode, the control plane holds private keys — this is why agent keygen mode is the recommended default for production.
|
||||||
- **Must not be used in production.** Explicit warning logged: `Key generation mode is server; this should only be used for testing.`
|
- **Must not be used in production.** Explicit warning logged: `server-side key generation enabled (CERTCTL_KEYGEN_MODE=server) — private keys touch control plane, demo only`
|
||||||
|
|
||||||
- **Issuer-Specific Key Negotiation**:
|
- **Issuer-Specific Key Negotiation**:
|
||||||
- **ACME (Let's Encrypt, ZeroSSL)**: Let's Encrypt controls key types; certctl requests ECDSA P-256 by default.
|
- **ACME (Let's Encrypt, ZeroSSL)**: Let's Encrypt controls key types; certctl requests ECDSA P-256 by default.
|
||||||
@@ -178,7 +178,7 @@ This requirement covers key generation, storage, rotation, and destruction. Cert
|
|||||||
|
|
||||||
**Evidence You Can Provide**:
|
**Evidence You Can Provide**:
|
||||||
- Deployment configuration: `CERTCTL_KEYGEN_MODE=agent` in production (verify in `docker-compose.yml`, Kubernetes manifests, or systemd units).
|
- Deployment configuration: `CERTCTL_KEYGEN_MODE=agent` in production (verify in `docker-compose.yml`, Kubernetes manifests, or systemd units).
|
||||||
- Agent log excerpt showing key generation: `openssl genrsa...` or agent process logs with CSR submission timestamp.
|
- Agent log excerpt showing key generation: Go `crypto/ecdsa.GenerateKey(elliptic.P256())` via agent process logs with CSR submission timestamp.
|
||||||
- Certificate CSR audit: `GET /api/v1/audit?type=certificate_issued` showing CSR fingerprint (SHA-256 hash of CSR PEM).
|
- Certificate CSR audit: `GET /api/v1/audit?type=certificate_issued` showing CSR fingerprint (SHA-256 hash of CSR PEM).
|
||||||
- Renewal job logs showing agent-submitted CSR, not server-generated key.
|
- Renewal job logs showing agent-submitted CSR, not server-generated key.
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ This requirement covers key generation, storage, rotation, and destruction. Cert
|
|||||||
- **Control Plane Key Storage** — Sensitive credentials managed via environment variables or `.env` files:
|
- **Control Plane Key Storage** — Sensitive credentials managed via environment variables or `.env` files:
|
||||||
- CA private key path: `CERTCTL_CA_CERT_PATH` + `CERTCTL_CA_KEY_PATH` (for Local CA sub-CA mode).
|
- CA private key path: `CERTCTL_CA_CERT_PATH` + `CERTCTL_CA_KEY_PATH` (for Local CA sub-CA mode).
|
||||||
- ACME account key: embedded in ACME issuer config (not stored separately; ACME library handles in memory).
|
- ACME account key: embedded in ACME issuer config (not stored separately; ACME library handles in memory).
|
||||||
- step-ca provisioner key: `CERTCTL_STEPCA_PROVISIONER_KEY` env var (JWK, in memory during runtime).
|
- step-ca provisioner key: `CERTCTL_STEPCA_KEY_PATH` env var (path to JWK private key file, loaded into memory during runtime).
|
||||||
- API keys: `CERTCTL_API_KEY` (SHA-256 hashed in database, plaintext never stored).
|
- API keys: `CERTCTL_API_KEY` (SHA-256 hashed in database, plaintext never stored).
|
||||||
- Database credentials: `CERTCTL_DATABASE_URL` in `.env` file, not in source code.
|
- Database credentials: `CERTCTL_DATABASE_URL` in `.env` file, not in source code.
|
||||||
|
|
||||||
@@ -785,7 +785,7 @@ Certctl v3 (Pro) adds paid features that strengthen PCI-DSS compliance posture:
|
|||||||
For additional guidance on certctl features and PCI-DSS mapping:
|
For additional guidance on certctl features and PCI-DSS mapping:
|
||||||
- Review the [Architecture Guide](architecture.md) for system design.
|
- Review the [Architecture Guide](architecture.md) for system design.
|
||||||
- Check [Connectors Documentation](connectors.md) for issuer/target/notifier capabilities.
|
- Check [Connectors Documentation](connectors.md) for issuer/target/notifier capabilities.
|
||||||
- Run the [Demo Guide](demo-guide.md) to see features in action.
|
- Run the [Quick Start Guide](quickstart.md) to see features in action.
|
||||||
- Consult your QSA for final compliance determination.
|
- Consult your QSA for final compliance determination.
|
||||||
|
|
||||||
**Last Updated**: March 24, 2026 (certctl v1.0 with M18b discovery and M19 audit logging)
|
**Last Updated**: March 24, 2026 (certctl v1.0 with M18b discovery and M19 audit logging)
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ Each section includes:
|
|||||||
|
|
||||||
- **API Key Policy** — All API access requires an API key or explicit opt-out. Opt-out (`CERTCTL_AUTH_TYPE=none`) logs a warning: "WARNING: Auth disabled (CERTCTL_AUTH_TYPE=none) — this is insecure and only for development". Configuration choice is logged at startup.
|
- **API Key Policy** — All API access requires an API key or explicit opt-out. Opt-out (`CERTCTL_AUTH_TYPE=none`) logs a warning: "WARNING: Auth disabled (CERTCTL_AUTH_TYPE=none) — this is insecure and only for development". Configuration choice is logged at startup.
|
||||||
- **Agent Authentication** — Agents authenticate to the server via API keys (same mechanism as users). Agent credentials are separate from user API keys.
|
- **Agent Authentication** — Agents authenticate to the server via API keys (same mechanism as users). Agent credentials are separate from user API keys.
|
||||||
- **Private Key Policy** — Agent-side key generation is the default (`CERTCTL_KEYGEN_MODE=agent`). Server-side keygen (`CERTCTL_KEYGEN_MODE=server`) requires explicit configuration and logs a warning: "Server-side keygen enabled — private keys will be stored in PostgreSQL (development only)".
|
- **Private Key Policy** — Agent-side key generation is the default (`CERTCTL_KEYGEN_MODE=agent`). Server-side keygen (`CERTCTL_KEYGEN_MODE=server`) requires explicit configuration and logs a warning: "server-side key generation enabled (CERTCTL_KEYGEN_MODE=server) — private keys touch control plane, demo only".
|
||||||
- **Password Policy** — Not applicable; certctl uses API keys exclusively. Password management is delegated to your organization's IAM system if you integrate OIDC/SSO (V3).
|
- **Password Policy** — Not applicable; certctl uses API keys exclusively. Password management is delegated to your organization's IAM system if you integrate OIDC/SSO (V3).
|
||||||
|
|
||||||
**Evidence Locations**:
|
**Evidence Locations**:
|
||||||
@@ -119,7 +119,7 @@ Each section includes:
|
|||||||
|
|
||||||
**certctl Implementation** (V2):
|
**certctl Implementation** (V2):
|
||||||
|
|
||||||
- **TLS for Control Plane** — All API communication occurs over HTTPS (TLS 1.2+). Server uses `tls.Dial()` for outbound connections to issuers and targets. Configuration: `CERTCTL_SERVER_ADDR` (default `:8443`).
|
- **TLS for Control Plane** — All API communication occurs over HTTPS (TLS 1.2+). Server uses `tls.Dial()` for outbound connections to issuers and targets. Configuration: `CERTCTL_SERVER_HOST` (default `127.0.0.1`) + `CERTCTL_SERVER_PORT` (default `8080`; Docker Compose maps to `8443`).
|
||||||
- **Agent-to-Server Communication** — Agents submit CSRs and heartbeats over HTTPS to the server using the same TLS stack.
|
- **Agent-to-Server Communication** — Agents submit CSRs and heartbeats over HTTPS to the server using the same TLS stack.
|
||||||
- **Private Key Isolation** — Agents generate ECDSA P-256 private keys locally (`crypto/ecdsa` + `crypto/elliptic`). Private keys are never transmitted to the server — agents submit CSRs only. Private keys are stored on agent filesystem (`CERTCTL_KEY_DIR`, default `/var/lib/certctl/keys`) with 0600 (owner read/write only) permissions. Server-side keygen mode logs a development warning; production must use agent-side keygen.
|
- **Private Key Isolation** — Agents generate ECDSA P-256 private keys locally (`crypto/ecdsa` + `crypto/elliptic`). Private keys are never transmitted to the server — agents submit CSRs only. Private keys are stored on agent filesystem (`CERTCTL_KEY_DIR`, default `/var/lib/certctl/keys`) with 0600 (owner read/write only) permissions. Server-side keygen mode logs a development warning; production must use agent-side keygen.
|
||||||
- **Certificate Storage** — Signed certificates are stored in PostgreSQL as PEM text (along with metadata). Certificates are not secrets and may be transmitted plaintext. Private keys are never stored on the control plane in production (agent-side keygen mode).
|
- **Certificate Storage** — Signed certificates are stored in PostgreSQL as PEM text (along with metadata). Certificates are not secrets and may be transmitted plaintext. Private keys are never stored on the control plane in production (agent-side keygen mode).
|
||||||
|
|||||||
@@ -38,6 +38,14 @@ ACME (Automatic Certificate Management Environment) is the protocol Let's Encryp
|
|||||||
|
|
||||||
certctl speaks ACME natively with both HTTP-01 and DNS-01 challenges, so it can request certificates — including wildcard certificates — from Let's Encrypt or any ACME-compatible CA without manual intervention. HTTP-01 uses a built-in temporary HTTP server for domain validation; DNS-01 uses pluggable script-based hooks to create TXT records with any DNS provider (Cloudflare, Route53, Azure DNS, etc.).
|
certctl speaks ACME natively with both HTTP-01 and DNS-01 challenges, so it can request certificates — including wildcard certificates — from Let's Encrypt or any ACME-compatible CA without manual intervention. HTTP-01 uses a built-in temporary HTTP server for domain validation; DNS-01 uses pluggable script-based hooks to create TXT records with any DNS provider (Cloudflare, Route53, Azure DNS, etc.).
|
||||||
|
|
||||||
|
### EST Protocol (Enrollment over Secure Transport)
|
||||||
|
|
||||||
|
EST (RFC 7030) is a standard protocol for devices to request certificates from a CA. While ACME was designed for web servers proving domain ownership, EST was designed for devices that need certificates without domain validation — think WiFi access points, corporate laptops connecting to 802.1X networks, IoT devices, and mobile devices managed by MDM platforms.
|
||||||
|
|
||||||
|
The workflow is straightforward: a device generates a key pair and a Certificate Signing Request (CSR), sends the CSR to the EST server, and gets back a signed certificate. The EST server also distributes its CA certificate chain so devices can build a complete trust path.
|
||||||
|
|
||||||
|
certctl includes a built-in EST server at `/.well-known/est/` with four operations: distributing the CA certificate chain (`/cacerts`), enrolling new devices (`/simpleenroll`), renewing existing certificates (`/simplereenroll`), and advertising CSR requirements (`/csrattrs`). EST enrollment uses the same issuer connectors as the REST API — so a certificate issued via EST and a certificate issued via the dashboard go through the same CA, appear in the same inventory, and follow the same policies.
|
||||||
|
|
||||||
### Private Key
|
### Private Key
|
||||||
|
|
||||||
Every certificate has a corresponding private key. The certificate is public — anyone can see it. The private key is secret — it's what allows your server to decrypt traffic. If someone gets your private key, they can impersonate your server.
|
Every certificate has a corresponding private key. The certificate is public — anyone can see it. The private key is secret — it's what allows your server to decrypt traffic. If someone gets your private key, they can impersonate your server.
|
||||||
@@ -180,16 +188,22 @@ certctl can alert you when certificates are expiring, when renewals fail, when d
|
|||||||
|
|
||||||
### CLI
|
### CLI
|
||||||
|
|
||||||
certctl ships with a command-line tool (`certctl-cli`) for operators who prefer terminal workflows or need to integrate certctl into shell scripts and CI/CD pipelines. The CLI wraps the REST API with 10 subcommands: `list-certs`, `get-cert`, `renew-cert`, `revoke-cert`, `list-agents`, `list-jobs`, `health`, `metrics`, and `import` (for bulk PEM import).
|
certctl ships with a command-line tool (`certctl-cli`) for operators who prefer terminal workflows or need to integrate certctl into shell scripts and CI/CD pipelines. The CLI wraps the REST API with 12 subcommands organized by resource: `certs list`, `certs get`, `certs renew`, `certs revoke`, `agents list`, `agents get`, `jobs list`, `jobs get`, `jobs cancel`, `import` (bulk PEM import), `status` (health + summary stats), and `version`.
|
||||||
|
|
||||||
The CLI supports both table and JSON output formats (`--format table` or `--format json`), connects to the server via `CERTCTL_SERVER_URL` and authenticates with `CERTCTL_API_KEY`. It's built with Go's standard library only — no external dependencies.
|
The CLI supports both table and JSON output formats (`--format table` or `--format json`), connects to the server via `CERTCTL_SERVER_URL` and authenticates with `CERTCTL_API_KEY`. It's built with Go's standard library only — no external dependencies.
|
||||||
|
|
||||||
### MCP Server (AI Integration)
|
### MCP Server (AI Integration)
|
||||||
|
|
||||||
certctl includes an MCP (Model Context Protocol) server that exposes all 78 API endpoints as MCP tools. This enables AI assistants like Claude, Cursor, and other MCP-compatible tools to interact with your certificate infrastructure using natural language — "show me all expiring certificates," "revoke the VPN cert," or "what agents are offline?"
|
certctl includes an MCP (Model Context Protocol) server that exposes 78 MCP tools covering the REST API. This enables AI assistants like Claude, Cursor, and other MCP-compatible tools to interact with your certificate infrastructure using natural language — "show me all expiring certificates," "revoke the VPN cert," or "what agents are offline?"
|
||||||
|
|
||||||
The MCP server is a separate binary (`cmd/mcp-server/`) that communicates via stdio transport and acts as a stateless HTTP proxy to the certctl REST API. It requires no additional infrastructure — just point it at your certctl server URL and API key.
|
The MCP server is a separate binary (`cmd/mcp-server/`) that communicates via stdio transport and acts as a stateless HTTP proxy to the certctl REST API. It requires no additional infrastructure — just point it at your certctl server URL and API key.
|
||||||
|
|
||||||
|
### EST Enrollment (Device Certificates)
|
||||||
|
|
||||||
|
certctl's EST server enables device certificate enrollment for use cases that don't fit the traditional "ops team requests a cert via API" model. When a RADIUS server is configured to use certctl for 802.1X WiFi authentication, or an MDM platform enrolls corporate devices, they use the EST protocol at `/.well-known/est/`. The EST server validates the CSR, issues a certificate via the configured issuer connector, and returns it in PKCS#7 format — the standard wire format that every EST client understands. Each enrollment is recorded in the audit trail with the protocol, common name, SANs, issuer, and serial number.
|
||||||
|
|
||||||
|
Enable it with `CERTCTL_EST_ENABLED=true`. Optionally bind enrollments to a specific issuer (`CERTCTL_EST_ISSUER_ID`) or certificate profile (`CERTCTL_EST_PROFILE_ID`) to constrain what EST clients can request.
|
||||||
|
|
||||||
### Certificate Discovery
|
### Certificate Discovery
|
||||||
|
|
||||||
Certificate discovery is the process of automatically finding existing certificates in your infrastructure — certificates you didn't issue through certctl, possibly issued by other CAs or tools. This is essential for building a complete inventory before you can manage everything.
|
Certificate discovery is the process of automatically finding existing certificates in your infrastructure — certificates you didn't issue through certctl, possibly issued by other CAs or tools. This is essential for building a complete inventory before you can manage everything.
|
||||||
|
|||||||
@@ -37,6 +37,19 @@ type Connector interface {
|
|||||||
|
|
||||||
// GetOrderStatus checks the status of an async issuance order
|
// GetOrderStatus checks the status of an async issuance order
|
||||||
GetOrderStatus(ctx context.Context, orderID string) (*OrderStatus, error)
|
GetOrderStatus(ctx context.Context, orderID string) (*OrderStatus, error)
|
||||||
|
|
||||||
|
// GenerateCRL generates a DER-encoded X.509 CRL signed by this issuer.
|
||||||
|
// Returns nil if the issuer does not support CRL generation (e.g., ACME).
|
||||||
|
GenerateCRL(ctx context.Context, revokedCerts []RevokedCertEntry) ([]byte, error)
|
||||||
|
|
||||||
|
// SignOCSPResponse signs an OCSP response for the given certificate serial.
|
||||||
|
// Returns nil if the issuer does not support OCSP (e.g., ACME).
|
||||||
|
SignOCSPResponse(ctx context.Context, req OCSPSignRequest) ([]byte, error)
|
||||||
|
|
||||||
|
// GetCACertPEM returns the PEM-encoded CA certificate chain for this issuer.
|
||||||
|
// Used by the EST server's /cacerts endpoint (RFC 7030).
|
||||||
|
// Returns error if the issuer doesn't provide a static CA chain (e.g., ACME, step-ca).
|
||||||
|
GetCACertPEM(ctx context.Context) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type IssuanceRequest struct {
|
type IssuanceRequest struct {
|
||||||
@@ -198,6 +211,17 @@ Each issuer handles revocation differently:
|
|||||||
- **step-ca**: Calls step-ca's `/revoke` API endpoint. Clients should check step-ca's own CRL/OCSP for authoritative status.
|
- **step-ca**: Calls step-ca's `/revoke` API endpoint. Clients should check step-ca's own CRL/OCSP for authoritative status.
|
||||||
- **OpenSSL/Custom CA**: Invokes the configured revoke script (`CERTCTL_OPENSSL_REVOKE_SCRIPT`) with the serial number as an argument.
|
- **OpenSSL/Custom CA**: Invokes the configured revoke script (`CERTCTL_OPENSSL_REVOKE_SCRIPT`) with the serial number as an argument.
|
||||||
|
|
||||||
|
### EST Integration (GetCACertPEM)
|
||||||
|
|
||||||
|
The `GetCACertPEM()` method returns the PEM-encoded CA certificate chain, used by the EST server's `/.well-known/est/cacerts` endpoint (RFC 7030) to distribute the CA chain to enrolling devices. Each issuer handles this differently:
|
||||||
|
|
||||||
|
- **Local CA**: Returns the CA certificate PEM (self-signed or sub-CA cert). This is the primary EST issuer.
|
||||||
|
- **ACME**: Returns error — ACME CAs provide chains per-issuance, not statically.
|
||||||
|
- **step-ca**: Returns error — step-ca serves its own `/root` endpoint for CA distribution.
|
||||||
|
- **OpenSSL/Custom CA**: Returns error — custom script-based CAs have no CA cert access through certctl.
|
||||||
|
|
||||||
|
Note: EST (Enrollment over Secure Transport) is not a connector — it's a protocol handler (`internal/api/handler/est.go`) that delegates certificate issuance to whichever issuer connector is configured via `CERTCTL_EST_ISSUER_ID`. See the [Architecture Guide](architecture.md#est-server-rfc-7030) for details.
|
||||||
|
|
||||||
### Planned Issuers
|
### Planned Issuers
|
||||||
|
|
||||||
The following issuer connectors are planned for future milestones:
|
The following issuer connectors are planned for future milestones:
|
||||||
@@ -474,6 +498,8 @@ Each notifier is enabled by its configuration env var:
|
|||||||
|
|
||||||
| Notifier | Env Var | Description |
|
| Notifier | Env Var | Description |
|
||||||
|----------|---------|-------------|
|
|----------|---------|-------------|
|
||||||
|
| Email | `CERTCTL_EMAIL_SMTP_HOST`, `CERTCTL_EMAIL_SMTP_PORT`, `CERTCTL_EMAIL_FROM` | SMTP email delivery. Optional: `CERTCTL_EMAIL_SMTP_USERNAME`, `CERTCTL_EMAIL_SMTP_PASSWORD` |
|
||||||
|
| Webhook | `CERTCTL_WEBHOOK_URL` | HTTP POST to any endpoint. Optional: `CERTCTL_WEBHOOK_SECRET` for HMAC signing |
|
||||||
| Slack | `CERTCTL_SLACK_WEBHOOK_URL` | Incoming webhook URL. Optional: `CERTCTL_SLACK_CHANNEL`, `CERTCTL_SLACK_USERNAME` |
|
| Slack | `CERTCTL_SLACK_WEBHOOK_URL` | Incoming webhook URL. Optional: `CERTCTL_SLACK_CHANNEL`, `CERTCTL_SLACK_USERNAME` |
|
||||||
| Teams | `CERTCTL_TEAMS_WEBHOOK_URL` | Incoming webhook URL (MessageCard format) |
|
| Teams | `CERTCTL_TEAMS_WEBHOOK_URL` | Incoming webhook URL (MessageCard format) |
|
||||||
| PagerDuty | `CERTCTL_PAGERDUTY_ROUTING_KEY` | Events API v2 routing key. Optional: `CERTCTL_PAGERDUTY_SEVERITY` (default: "warning") |
|
| PagerDuty | `CERTCTL_PAGERDUTY_ROUTING_KEY` | Events API v2 routing key. Optional: `CERTCTL_PAGERDUTY_SEVERITY` (default: "warning") |
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ You should see:
|
|||||||
|
|
||||||
The result is a structurally valid X.509 certificate — browsers won't trust it (no root CA in their trust store), but it exercises the exact same code paths that a production ACME or Vault issuer would.
|
The result is a structurally valid X.509 certificate — browsers won't trust it (no root CA in their trust store), but it exercises the exact same code paths that a production ACME or Vault issuer would.
|
||||||
|
|
||||||
**Why pluggable issuers:** Different organizations use different CAs. Some use Let's Encrypt (ACME protocol), some use step-ca or internal PKI (Vault), some use commercial CAs (DigiCert, Entrust, GlobalSign), and some have custom OpenSSL-based workflows. For enterprises with ADCS, certctl can operate as a sub-CA — all issued certs chain to the enterprise root. The connector interface means certctl doesn't care — it calls `IssueCertificate()` and gets back a signed cert regardless of the backend. V1 ships with Local CA (self-signed or sub-CA), ACME (HTTP-01 + DNS-01 for wildcards), and step-ca (Smallstep private CA via native /sign API). OpenSSL/Custom CA is planned for V2; DigiCert, Vault PKI, Entrust, GlobalSign, Google CAS, and EJBCA are planned for V3.
|
**Why pluggable issuers:** Different organizations use different CAs. Some use Let's Encrypt (ACME protocol), some use step-ca or internal PKI (Vault), some use commercial CAs (DigiCert, Entrust, GlobalSign), and some have custom OpenSSL-based workflows. For enterprises with ADCS, certctl can operate as a sub-CA — all issued certs chain to the enterprise root. The connector interface means certctl doesn't care — it calls `IssueCertificate()` and gets back a signed cert regardless of the backend. V1 ships with Local CA (self-signed or sub-CA), ACME (HTTP-01 + DNS-01 for wildcards), and step-ca (Smallstep private CA via native /sign API). V2 adds the OpenSSL/Custom CA connector (script-based signing). DigiCert, Vault PKI, Entrust, GlobalSign, Google CAS, and EJBCA are planned for V3+.
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart TD
|
flowchart TD
|
||||||
@@ -472,14 +472,14 @@ In production, agents poll for work and report results. You can simulate this ma
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Poll for pending deployment work (as an agent)
|
# Poll for pending deployment work (as an agent)
|
||||||
curl -s "$API/api/v1/agents/agent-nginx-prod/work" | jq .
|
curl -s "$API/api/v1/agents/ag-web-prod/work" | jq .
|
||||||
```
|
```
|
||||||
|
|
||||||
This returns pending deployment jobs assigned to the agent. The agent would then fetch the certificate, deploy it, and report back:
|
This returns pending deployment jobs assigned to the agent. The agent would then fetch the certificate, deploy it, and report back:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Report job completion (replace JOB_ID with an actual job ID from the work response)
|
# Report job completion (replace JOB_ID with an actual job ID from the work response)
|
||||||
curl -s -X POST "$API/api/v1/agents/agent-nginx-prod/jobs/JOB_ID/status" \
|
curl -s -X POST "$API/api/v1/agents/ag-web-prod/jobs/JOB_ID/status" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"status": "Completed",
|
"status": "Completed",
|
||||||
@@ -875,28 +875,28 @@ export CERTCTL_SERVER_URL="http://localhost:8443"
|
|||||||
export CERTCTL_API_KEY="test-key-123"
|
export CERTCTL_API_KEY="test-key-123"
|
||||||
|
|
||||||
# List certificates (JSON or table format)
|
# List certificates (JSON or table format)
|
||||||
./certctl-cli list-certs --format table
|
./certctl-cli certs list
|
||||||
|
|
||||||
# Get certificate details
|
# Get certificate details
|
||||||
./certctl-cli get-cert mc-demo-api
|
./certctl-cli certs get mc-demo-api
|
||||||
|
|
||||||
# Trigger renewal
|
# Trigger renewal
|
||||||
./certctl-cli renew-cert mc-demo-api
|
./certctl-cli certs renew mc-demo-api
|
||||||
|
|
||||||
# Revoke a certificate with RFC 5280 reason
|
# Revoke a certificate with RFC 5280 reason
|
||||||
./certctl-cli revoke-cert mc-demo-payments --reason keyCompromise
|
./certctl-cli certs revoke mc-demo-payments --reason keyCompromise
|
||||||
|
|
||||||
# List agents
|
# List agents
|
||||||
./certctl-cli list-agents
|
./certctl-cli agents list
|
||||||
|
|
||||||
# List pending jobs
|
# List pending jobs
|
||||||
./certctl-cli list-jobs
|
./certctl-cli jobs list
|
||||||
|
|
||||||
# Check system health
|
# Check system health and stats
|
||||||
./certctl-cli health
|
./certctl-cli status
|
||||||
|
|
||||||
# Export metrics
|
# JSON output format
|
||||||
./certctl-cli metrics --format json
|
./certctl-cli --format json status
|
||||||
|
|
||||||
# Bulk import certificates from a PEM file
|
# Bulk import certificates from a PEM file
|
||||||
./certctl-cli import /path/to/certificates.pem
|
./certctl-cli import /path/to/certificates.pem
|
||||||
@@ -908,7 +908,7 @@ export CERTCTL_API_KEY="test-key-123"
|
|||||||
|
|
||||||
## Part 15: MCP Server for AI Integration (M18a)
|
## Part 15: MCP Server for AI Integration (M18a)
|
||||||
|
|
||||||
certctl exposes all 78 API endpoints as tools via the Model Context Protocol (MCP), enabling seamless integration with Claude, Cursor, and other AI assistants:
|
certctl exposes 78 MCP tools covering the REST API via the Model Context Protocol (MCP), enabling seamless integration with Claude, Cursor, and other AI assistants:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Build the MCP server
|
# Build the MCP server
|
||||||
@@ -922,7 +922,7 @@ export CERTCTL_API_KEY="test-key-123"
|
|||||||
./mcp-server
|
./mcp-server
|
||||||
```
|
```
|
||||||
|
|
||||||
**How it works:** The MCP server uses the official Model Context Protocol Go SDK to expose stateless HTTP proxies to all 78 API endpoints. Each MCP tool corresponds to one or more REST endpoints and includes:
|
**How it works:** The MCP server uses the official Model Context Protocol Go SDK to expose 78 stateless HTTP proxy tools covering the REST API. Each MCP tool corresponds to one or more REST endpoints and includes:
|
||||||
|
|
||||||
- **Input schema** — typed arguments with JSON schema hints for LLM-friendly introspection
|
- **Input schema** — typed arguments with JSON schema hints for LLM-friendly introspection
|
||||||
- **Binary support** — handles DER-encoded CRL and OCSP responses without mangling
|
- **Binary support** — handles DER-encoded CRL and OCSP responses without mangling
|
||||||
|
|||||||
@@ -1,254 +0,0 @@
|
|||||||
# certctl Demo Guide
|
|
||||||
|
|
||||||
A 5-10 minute guided walkthrough of certctl's dashboard and API. Perfect for stakeholder presentations and team demos.
|
|
||||||
|
|
||||||
New to certificates? Read the [Concepts Guide](concepts.md) first. Want a hands-on demo where you issue certificates yourself? See the [Advanced Demo](demo-advanced.md).
|
|
||||||
|
|
||||||
## Quick Start
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/shankar0123/certctl.git
|
|
||||||
cd certctl
|
|
||||||
docker compose -f deploy/docker-compose.yml up -d --build
|
|
||||||
```
|
|
||||||
|
|
||||||
Wait ~30 seconds for PostgreSQL to initialize and the server to start, then open:
|
|
||||||
|
|
||||||
**http://localhost:8443**
|
|
||||||
|
|
||||||
You'll see the dashboard pre-loaded with 15 demo certificates across multiple teams, environments, and statuses — including expiring, expired, active, failed, wildcard, and in-progress renewals.
|
|
||||||
|
|
||||||
## What You'll See
|
|
||||||
|
|
||||||
### Dashboard Overview
|
|
||||||
The main dashboard shows at a glance:
|
|
||||||
- **Total certificates** managed across your infrastructure
|
|
||||||
- **Expiring soon** — certificates within 30 days of expiration (yellow/red)
|
|
||||||
- **Expired** — certificates past their expiration date
|
|
||||||
- **Active** — healthy certificates with time remaining
|
|
||||||
- **Renewal success rate** — percentage of automated renewals that succeeded
|
|
||||||
|
|
||||||
Below the stats, interactive charts provide deeper visibility: an **expiration heatmap** (90-day weekly buckets), **renewal success rate trends** (30-day line chart), **certificate status distribution** (donut chart), and **issuance rate** (30-day bar chart).
|
|
||||||
|
|
||||||
### Certificates View
|
|
||||||
Click "Certificates" in the sidebar to see the full inventory:
|
|
||||||
- Search by name or domain
|
|
||||||
- Filter by status (Active, Expiring, Expired, Failed) or environment (Production, Staging)
|
|
||||||
- Sort by any column
|
|
||||||
- Click any row to see full details: metadata, version history, deployment targets, and audit trail
|
|
||||||
|
|
||||||
### Demo Scenarios to Walk Through
|
|
||||||
|
|
||||||
**1. "We're about to have an outage"**
|
|
||||||
Filter by status → Expiring. You'll see `auth-production` (12 days), `cdn-production` (8 days), and `mail-production` (5 days). These are real alerts the platform would catch automatically.
|
|
||||||
|
|
||||||
**2. "A renewal failed"**
|
|
||||||
Look at `vpn-production` — status: Failed. Click it to see the audit trail showing the ACME challenge failure after 3 retry attempts. The system sent a webhook notification to the ops channel.
|
|
||||||
|
|
||||||
**3. "Who owns this cert?"**
|
|
||||||
Click any certificate to see the owner, team, environment, and tags. Every cert has clear accountability.
|
|
||||||
|
|
||||||
**4. "What happened to the legacy app?"**
|
|
||||||
Filter by status → Expired. `legacy-app` expired 3 days ago, `old-api-v1` expired 15 days ago. Both have policy violations flagged.
|
|
||||||
|
|
||||||
**5. "Show me the agent fleet"**
|
|
||||||
Click "Agents" in the sidebar. Four agents are online, one (`iis-prod-agent`) went offline 3 hours ago — you'd want to investigate that.
|
|
||||||
|
|
||||||
**6. "What policies are enforced?"**
|
|
||||||
Click "Policies" to see the active rules: required owner metadata, allowed environments, max certificate lifetime, minimum renewal window. Check the violations list to see which certs are non-compliant.
|
|
||||||
|
|
||||||
**7. "Can I revoke a compromised cert?"**
|
|
||||||
Click any active certificate, then click the "Revoke" button. A modal appears with RFC 5280 reason codes (Key Compromise, Superseded, Cessation of Operation, etc.). After revocation, the cert shows a revocation banner with the reason and timestamp.
|
|
||||||
|
|
||||||
**8. "Show me short-lived credentials"**
|
|
||||||
Click "Short-Lived" in the sidebar. This view shows certificates with TTL under 1 hour — live countdown timers, auto-refresh every 10 seconds, and profile-based filtering. These are for service-to-service auth where rapid expiry replaces revocation.
|
|
||||||
|
|
||||||
**9. "What about bulk operations?"**
|
|
||||||
On the Certificates page, select multiple certificates using the checkboxes. A bulk action bar appears with options to trigger renewal, revoke (with reason codes), or reassign ownership — all with progress tracking.
|
|
||||||
|
|
||||||
**10. "How do I see the deployment history?"**
|
|
||||||
Click any certificate, then scroll to the deployment timeline. A visual 4-step timeline shows the lifecycle: Requested → Issued → Deploying → Active. Previous versions show a rollback button.
|
|
||||||
|
|
||||||
**11. "What about certificates already running in production?"**
|
|
||||||
Enable discovery on agents by setting `CERTCTL_DISCOVERY_DIRS` to directories containing certificates (e.g., `/etc/nginx/certs`). Agents scan on startup and every 6 hours, report findings to the control plane. For network-based discovery without agents, enable `CERTCTL_NETWORK_SCAN_ENABLED=true` and configure scan targets via the API — the server probes TLS endpoints on configured CIDR ranges and ports. Click "Discovered Certificates" to see what agents and network scans found — claim unmanaged certs to bring them under certctl's management, or dismiss them.
|
|
||||||
|
|
||||||
## REST API Walkthrough
|
|
||||||
|
|
||||||
The dashboard is backed by a real REST API (91 endpoints). Try these while the demo is running:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# List all certificates
|
|
||||||
curl -s http://localhost:8443/api/v1/certificates | jq .
|
|
||||||
|
|
||||||
# Get expiring certs
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?status=expiring" | jq .
|
|
||||||
|
|
||||||
# Advanced query: sort by expiration, sparse fields, cursor pagination
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?sort=-expires_at&fields=id,common_name,expires_at" | jq .
|
|
||||||
|
|
||||||
# Time-range filter: certs expiring before June 2026
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?expires_before=2026-06-01T00:00:00Z" | jq .
|
|
||||||
|
|
||||||
# Get a specific certificate
|
|
||||||
curl -s http://localhost:8443/api/v1/certificates/mc-api-prod | jq .
|
|
||||||
|
|
||||||
# Get deployment targets for a certificate
|
|
||||||
curl -s http://localhost:8443/api/v1/certificates/mc-api-prod/deployments | jq .
|
|
||||||
|
|
||||||
# List agents
|
|
||||||
curl -s http://localhost:8443/api/v1/agents | jq .
|
|
||||||
|
|
||||||
# View audit trail (immutable API audit log of all actions)
|
|
||||||
curl -s http://localhost:8443/api/v1/audit | jq .
|
|
||||||
|
|
||||||
# View policy violations (replace POLICY_ID with a real policy ID, e.g. pr-require-owner)
|
|
||||||
curl -s http://localhost:8443/api/v1/policies/pr-require-owner/violations | jq .
|
|
||||||
|
|
||||||
# Check system health
|
|
||||||
curl -s http://localhost:8443/health | jq .
|
|
||||||
|
|
||||||
# Dashboard stats and metrics
|
|
||||||
curl -s http://localhost:8443/api/v1/stats/summary | jq .
|
|
||||||
curl -s http://localhost:8443/api/v1/stats/certificates-by-status | jq .
|
|
||||||
curl -s http://localhost:8443/api/v1/stats/expiration-timeline | jq .
|
|
||||||
curl -s http://localhost:8443/api/v1/stats/job-trends | jq .
|
|
||||||
curl -s http://localhost:8443/api/v1/stats/issuance-rate | jq .
|
|
||||||
curl -s http://localhost:8443/api/v1/metrics | jq .
|
|
||||||
curl -s http://localhost:8443/api/v1/metrics/prometheus # Prometheus format
|
|
||||||
|
|
||||||
# Certificate profiles
|
|
||||||
curl -s http://localhost:8443/api/v1/profiles | jq .
|
|
||||||
|
|
||||||
# Agent groups
|
|
||||||
curl -s http://localhost:8443/api/v1/agent-groups | jq .
|
|
||||||
|
|
||||||
# Revoke a certificate
|
|
||||||
curl -s -X POST http://localhost:8443/api/v1/certificates/mc-api-prod/revoke \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"reason": "superseded"}' | jq .
|
|
||||||
|
|
||||||
# CRL and OCSP endpoints
|
|
||||||
curl -s http://localhost:8443/api/v1/crl | jq .
|
|
||||||
curl -s http://localhost:8443/api/v1/crl/iss-local -o /tmp/crl.der
|
|
||||||
|
|
||||||
# List discovered certificates
|
|
||||||
curl -s http://localhost:8443/api/v1/discovered-certificates | jq .
|
|
||||||
|
|
||||||
# Discovery summary (counts by status)
|
|
||||||
curl -s http://localhost:8443/api/v1/discovery-summary | jq .
|
|
||||||
|
|
||||||
# Network scan targets (active TLS scanning)
|
|
||||||
curl -s http://localhost:8443/api/v1/network-scan-targets | jq .
|
|
||||||
```
|
|
||||||
|
|
||||||
## CLI Tool
|
|
||||||
|
|
||||||
certctl ships with a command-line tool (`certctl-cli`) for terminal users:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Build the CLI
|
|
||||||
cd cmd/cli && go build -o certctl-cli .
|
|
||||||
|
|
||||||
# Set credentials
|
|
||||||
export CERTCTL_SERVER_URL="http://localhost:8443"
|
|
||||||
export CERTCTL_API_KEY="test-key-123"
|
|
||||||
|
|
||||||
# List certificates (JSON or table format)
|
|
||||||
./certctl-cli list-certs --format json
|
|
||||||
./certctl-cli list-certs --format table
|
|
||||||
|
|
||||||
# Get certificate details
|
|
||||||
./certctl-cli get-cert mc-api-prod
|
|
||||||
|
|
||||||
# Trigger renewal
|
|
||||||
./certctl-cli renew-cert mc-api-prod
|
|
||||||
|
|
||||||
# Revoke a certificate (with RFC 5280 reason)
|
|
||||||
./certctl-cli revoke-cert mc-api-prod --reason keyCompromise
|
|
||||||
|
|
||||||
# List agents
|
|
||||||
./certctl-cli list-agents
|
|
||||||
|
|
||||||
# List pending jobs
|
|
||||||
./certctl-cli list-jobs
|
|
||||||
|
|
||||||
# Bulk import certificates from PEM files
|
|
||||||
./certctl-cli import /path/to/certs.pem
|
|
||||||
|
|
||||||
# Check health and metrics
|
|
||||||
./certctl-cli health
|
|
||||||
./certctl-cli metrics
|
|
||||||
```
|
|
||||||
|
|
||||||
## MCP Server for AI Integration
|
|
||||||
|
|
||||||
certctl exposes its 78 API endpoints as tools via the Model Context Protocol (MCP), enabling integration with Claude, Cursor, and other AI assistants:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Build and run the MCP server
|
|
||||||
cd cmd/mcp-server && go build -o mcp-server .
|
|
||||||
|
|
||||||
export CERTCTL_SERVER_URL="http://localhost:8443"
|
|
||||||
export CERTCTL_API_KEY="test-key-123"
|
|
||||||
|
|
||||||
./mcp-server
|
|
||||||
```
|
|
||||||
|
|
||||||
The MCP server:
|
|
||||||
- Exposes all 78 API endpoints as MCP tools with typed schemas
|
|
||||||
- Handles binary responses (DER CRL, OCSP responses)
|
|
||||||
- Uses stdio transport for Claude/Cursor/OpenClaw integration
|
|
||||||
- Zero external dependencies — pure Go with official MCP SDK
|
|
||||||
|
|
||||||
You can then ask Claude questions like:
|
|
||||||
- "What certificates are expiring in the next 30 days?"
|
|
||||||
- "Revoke the payments certificate due to key compromise"
|
|
||||||
- "Show me the audit trail for the last 10 actions"
|
|
||||||
- "List all certificates with PCI compliance tags"
|
|
||||||
|
|
||||||
## Dashboard Demo Mode
|
|
||||||
|
|
||||||
The dashboard includes a **Demo Mode** that works without any backend. Build and serve the frontend with Vite:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd web
|
|
||||||
npm install
|
|
||||||
npm run dev
|
|
||||||
# Dashboard available at http://localhost:5173
|
|
||||||
```
|
|
||||||
|
|
||||||
When the API is unreachable, the dashboard automatically loads realistic mock data and shows a subtle "Demo Mode" badge. This is perfect for screenshots, presentations, or quick demos without any infrastructure.
|
|
||||||
|
|
||||||
## Teardown
|
|
||||||
|
|
||||||
```bash
|
|
||||||
docker compose -f deploy/docker-compose.yml down -v
|
|
||||||
```
|
|
||||||
|
|
||||||
The `-v` flag removes the PostgreSQL data volume so you get a clean slate next time.
|
|
||||||
|
|
||||||
## Presenting to Stakeholders
|
|
||||||
|
|
||||||
If you're demoing to a team or customer, here's a suggested flow:
|
|
||||||
|
|
||||||
1. **Start with the dashboard** — "This is your certificate inventory at a glance, with real-time charts showing expiration trends and renewal health"
|
|
||||||
2. **Show the expiring certs** — "These three would have caused outages without this platform"
|
|
||||||
3. **Click into auth-production** — "Here's the full lifecycle: who owns it, where it's deployed, deployment timeline, when it was last renewed"
|
|
||||||
4. **Show revocation** — "If a key is compromised, one click revokes the cert with an RFC 5280 reason code. CRL and OCSP are served automatically"
|
|
||||||
5. **Show the failed VPN cert** — "The system tried 3 times, then alerted the team via Slack, Teams, PagerDuty, or OpsGenie"
|
|
||||||
6. **Show agents and fleet overview** — "Agents run on your infrastructure, handle key generation locally (ECDSA P-256). Fleet view shows OS, architecture, and version distribution"
|
|
||||||
7. **Show profiles** — "Certificate profiles enforce crypto constraints — key types, max TTL, compliance requirements"
|
|
||||||
8. **Show policies** — "Guardrails prevent teams from going outside approved scope"
|
|
||||||
9. **Show bulk operations** — "Select multiple certs, trigger renewal or revoke in bulk with progress tracking"
|
|
||||||
10. **Show certificate discovery** — "We discover certificates two ways: agents scan local filesystems, and the server actively probes TLS endpoints on your network. We deduplicate by fingerprint, show you what we found, and let you claim them or dismiss them"
|
|
||||||
11. **Show the immutable audit trail** — "Every action in the system is recorded: who did it, what they did, when, what changed. Export to CSV/JSON for compliance"
|
|
||||||
12. **Show advanced query features** — "Sort by any field, filter by date range, paginate efficiently with cursor-based pagination, select just the fields you need"
|
|
||||||
13. **Show the CLI and MCP server** — "Terminal users get `certctl-cli` with 10 subcommands. AI assistants get MCP integration with 78 tools. Everything is API-first"
|
|
||||||
|
|
||||||
The whole walkthrough takes 5-10 minutes.
|
|
||||||
|
|
||||||
## Next Steps
|
|
||||||
|
|
||||||
- **[Advanced Demo](demo-advanced.md)** — Go hands-on: create a team, issue a certificate via API, trigger renewal, and watch it appear in the dashboard
|
|
||||||
- **[Concepts Guide](concepts.md)** — Understand TLS certificates, CAs, and private keys from scratch
|
|
||||||
- **[Architecture](architecture.md)** — Deep dive into the control plane, agent model, and connector architecture
|
|
||||||
@@ -7,7 +7,7 @@ Complete reference of all features shipped in the V2 release (as of March 2026).
|
|||||||
## API Surface
|
## API Surface
|
||||||
|
|
||||||
### Overview
|
### Overview
|
||||||
- **91 endpoints** across 19 resource domains under `/api/v1/`
|
- **95 endpoints** across 20 resource domains under `/api/v1/` + `/.well-known/est/`
|
||||||
- REST API with HTTP semantics (GET, POST, PUT, DELETE)
|
- REST API with HTTP semantics (GET, POST, PUT, DELETE)
|
||||||
- All endpoints require authentication by default (configurable)
|
- All endpoints require authentication by default (configurable)
|
||||||
- OpenAPI 3.1 spec with full schema documentation
|
- OpenAPI 3.1 spec with full schema documentation
|
||||||
@@ -94,6 +94,7 @@ curl -H "$AUTH" "$SERVER/api/v1/certificates?expires_before=2026-04-24T00:00:00Z
|
|||||||
| **Notifications** | 3 | List, get, mark as read |
|
| **Notifications** | 3 | List, get, mark as read |
|
||||||
| **Stats** | 5 | Dashboard summary, certificates by status, expiration timeline, job trends, issuance rate |
|
| **Stats** | 5 | Dashboard summary, certificates by status, expiration timeline, job trends, issuance rate |
|
||||||
| **Metrics** | 2 | JSON metrics (gauges, counters, uptime), Prometheus exposition format |
|
| **Metrics** | 2 | JSON metrics (gauges, counters, uptime), Prometheus exposition format |
|
||||||
|
| **EST (RFC 7030)** | 4 | CA certs (PKCS#7), simple enrollment, re-enrollment, CSR attributes |
|
||||||
| **Health** | 4 | Health check, readiness check, auth info, auth check |
|
| **Health** | 4 | Health check, readiness check, auth info, auth check |
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -296,7 +297,7 @@ curl -H "$AUTH" "$SERVER/api/v1/policies/rp-standard/violations"
|
|||||||
### step-ca
|
### step-ca
|
||||||
- **Protocol** — Native `/sign` and `/revoke` API (not ACME)
|
- **Protocol** — Native `/sign` and `/revoke` API (not ACME)
|
||||||
- **Authentication** — JWK provisioner with key file + password
|
- **Authentication** — JWK provisioner with key file + password
|
||||||
- **Configuration** — `CERTCTL_STEPCA_URL`, `CERTCTL_STEPCA_PROVISIONER_NAME`, `CERTCTL_STEPCA_PROVISIONER_KEY_PATH`, `CERTCTL_STEPCA_PROVISIONER_PASSWORD`
|
- **Configuration** — `CERTCTL_STEPCA_URL`, `CERTCTL_STEPCA_PROVISIONER`, `CERTCTL_STEPCA_KEY_PATH`, `CERTCTL_STEPCA_PASSWORD`
|
||||||
- **Operations** — Issue, renew, revoke
|
- **Operations** — Issue, renew, revoke
|
||||||
- **Use Case** — Smallstep private CA, internal PKI with strong auth
|
- **Use Case** — Smallstep private CA, internal PKI with strong auth
|
||||||
|
|
||||||
@@ -818,7 +819,7 @@ All loops have configurable intervals via environment variables (`CERTCTL_SCHEDU
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Web Dashboard (19 Pages)
|
## Web Dashboard
|
||||||
|
|
||||||
### Overview
|
### Overview
|
||||||
The web dashboard is the primary operational interface for certctl. Built with **Vite + React 18 + TypeScript + TanStack Query v5 + Tailwind CSS 3 + Recharts**.
|
The web dashboard is the primary operational interface for certctl. Built with **Vite + React 18 + TypeScript + TanStack Query v5 + Tailwind CSS 3 + Recharts**.
|
||||||
@@ -903,16 +904,18 @@ The web dashboard is the primary operational interface for certctl. Built with *
|
|||||||
|
|
||||||
| Subcommand | Usage | Output Format |
|
| Subcommand | Usage | Output Format |
|
||||||
|------------|-------|----------------|
|
|------------|-------|----------------|
|
||||||
| **list-certs** | `certctl-cli list-certs [--filter]` | Table or JSON (--format=json) |
|
| **certs list** | `certctl-cli certs list` | Table or JSON (--format=json) |
|
||||||
| **get-cert** | `certctl-cli get-cert <id>` | JSON cert details |
|
| **certs get** | `certctl-cli certs get <id>` | JSON cert details |
|
||||||
| **renew-cert** | `certctl-cli renew-cert <id>` | Job ID confirmation |
|
| **certs renew** | `certctl-cli certs renew <id>` | Job ID confirmation |
|
||||||
| **revoke-cert** | `certctl-cli revoke-cert <id> [--reason]` | Revocation confirmation |
|
| **certs revoke** | `certctl-cli certs revoke <id> [--reason]` | Revocation confirmation |
|
||||||
| **list-agents** | `certctl-cli list-agents` | Table or JSON |
|
| **agents list** | `certctl-cli agents list` | Table or JSON |
|
||||||
| **list-jobs** | `certctl-cli list-jobs [--filter]` | Table or JSON |
|
| **agents get** | `certctl-cli agents get <id>` | Agent details |
|
||||||
| **health** | `certctl-cli health` | Server status |
|
| **jobs list** | `certctl-cli jobs list` | Table or JSON |
|
||||||
| **metrics** | `certctl-cli metrics` | JSON metrics |
|
| **jobs get** | `certctl-cli jobs get <id>` | Job details |
|
||||||
|
| **jobs cancel** | `certctl-cli jobs cancel <id>` | Cancellation confirmation |
|
||||||
|
| **status** | `certctl-cli status` | Health + summary stats |
|
||||||
| **import** | `certctl-cli import <pem-file>` | Bulk import cert count |
|
| **import** | `certctl-cli import <pem-file>` | Bulk import cert count |
|
||||||
| **help** | `certctl-cli help [command]` | Command documentation |
|
| **version** | `certctl-cli version` | Version string |
|
||||||
|
|
||||||
**Implementation Details:**
|
**Implementation Details:**
|
||||||
- Stdlib-only (flag + text/tabwriter); no Cobra dependency
|
- Stdlib-only (flag + text/tabwriter); no Cobra dependency
|
||||||
@@ -922,9 +925,39 @@ The web dashboard is the primary operational interface for certctl. Built with *
|
|||||||
- CLI flags: `--server`, `--api-key`, `--format` (json/table)
|
- CLI flags: `--server`, `--api-key`, `--format` (json/table)
|
||||||
- Tested with httptest mock server; all commands covered
|
- Tested with httptest mock server; all commands covered
|
||||||
|
|
||||||
|
### EST Server (RFC 7030, M23)
|
||||||
|
**Enrollment over Secure Transport** — industry-standard protocol for device certificate enrollment. Enables WiFi/802.1X, MDM, IoT, and BYOD use cases where devices need certificates without direct API access.
|
||||||
|
|
||||||
|
**Endpoints** (under `/.well-known/est/` per RFC 7030):
|
||||||
|
|
||||||
|
| Endpoint | Method | Description | Wire Format |
|
||||||
|
|----------|--------|-------------|-------------|
|
||||||
|
| `/cacerts` | GET | CA certificate chain distribution | Base64 PKCS#7 certs-only (application/pkcs7-mime) |
|
||||||
|
| `/simpleenroll` | POST | Initial certificate enrollment | Request: PEM or base64-DER PKCS#10; Response: PKCS#7 |
|
||||||
|
| `/simplereenroll` | POST | Certificate re-enrollment (renewal) | Same as simpleenroll |
|
||||||
|
| `/csrattrs` | GET | CSR attributes the server requires | ASN.1 DER (application/csrattrs) |
|
||||||
|
|
||||||
|
**Architecture:**
|
||||||
|
- **ESTService** bridges handler to existing `IssuerConnector` — no new issuance logic, reuses existing CA connectors
|
||||||
|
- **CSR input handling** — accepts both base64-encoded DER (EST wire standard) and PEM-encoded PKCS#10 (convenience)
|
||||||
|
- **PKCS#7 output** — hand-rolled ASN.1 degenerate SignedData builder (no external PKCS#7 dependency)
|
||||||
|
- **CSR validation** — signature verification, Common Name extraction, SAN extraction (DNS, IP, email, URI)
|
||||||
|
- **Configurable issuer binding** — `CERTCTL_EST_ISSUER_ID` selects which issuer connector processes enrollment
|
||||||
|
- **Optional profile binding** — `CERTCTL_EST_PROFILE_ID` constrains enrollments to a specific certificate profile
|
||||||
|
- **Audit trail** — all EST enrollments recorded with protocol=EST, CN, SANs, issuer ID, serial, profile ID
|
||||||
|
|
||||||
|
**Configuration:**
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|----------|---------|-------------|
|
||||||
|
| `CERTCTL_EST_ENABLED` | `false` | Enable EST enrollment endpoints |
|
||||||
|
| `CERTCTL_EST_ISSUER_ID` | `iss-local` | Issuer connector for EST enrollments |
|
||||||
|
| `CERTCTL_EST_PROFILE_ID` | — | Optional profile ID to constrain enrollments |
|
||||||
|
|
||||||
|
**Note:** EST endpoints currently use the same middleware stack as the REST API (API key auth). TLS client certificate authentication for EST is planned for V3.
|
||||||
|
|
||||||
### OpenAPI 3.1 Specification
|
### OpenAPI 3.1 Specification
|
||||||
- **File** — `api/openapi.yaml`
|
- **File** — `api/openapi.yaml`
|
||||||
- **Scope** — 93 operations (91 API + /health + /ready), all request/response schemas, enums, pagination
|
- **Scope** — 97 operations (95 API + /health + /ready), all request/response schemas, enums, pagination
|
||||||
- **Schemas** — Complete domain models with examples
|
- **Schemas** — Complete domain models with examples
|
||||||
- **Enums** — Job types, states, policy rule types, notification types
|
- **Enums** — Job types, states, policy rule types, notification types
|
||||||
- **Pagination** — Standard envelope (data, total, page, per_page)
|
- **Pagination** — Standard envelope (data, total, page, per_page)
|
||||||
@@ -1092,9 +1125,9 @@ The web dashboard is the primary operational interface for certctl. Built with *
|
|||||||
| Variable | Type | Default | Purpose |
|
| Variable | Type | Default | Purpose |
|
||||||
|----------|------|---------|---------|
|
|----------|------|---------|---------|
|
||||||
| `CERTCTL_STEPCA_URL` | string | (empty) | step-ca server URL |
|
| `CERTCTL_STEPCA_URL` | string | (empty) | step-ca server URL |
|
||||||
| `CERTCTL_STEPCA_PROVISIONER_NAME` | string | (empty) | JWK provisioner name |
|
| `CERTCTL_STEPCA_PROVISIONER` | string | (empty) | JWK provisioner name |
|
||||||
| `CERTCTL_STEPCA_PROVISIONER_KEY_PATH` | string | (empty) | Path to provisioner JWK private key |
|
| `CERTCTL_STEPCA_KEY_PATH` | string | (empty) | Path to provisioner JWK private key |
|
||||||
| `CERTCTL_STEPCA_PROVISIONER_PASSWORD` | string | (empty) | Provisioner key password (if encrypted) |
|
| `CERTCTL_STEPCA_PASSWORD` | string | (empty) | Provisioner key password (if encrypted) |
|
||||||
|
|
||||||
#### OpenSSL/Custom CA Issuer
|
#### OpenSSL/Custom CA Issuer
|
||||||
| Variable | Type | Default | Purpose |
|
| Variable | Type | Default | Purpose |
|
||||||
@@ -1166,11 +1199,11 @@ Each guide includes an evidence summary table mapping specific criteria to certc
|
|||||||
| Policies + violations | ✓ | ✓ | Shipped |
|
| Policies + violations | ✓ | ✓ | Shipped |
|
||||||
| Profiles + crypto constraints | ✓ | ✓ | Shipped |
|
| Profiles + crypto constraints | ✓ | ✓ | Shipped |
|
||||||
| Revocation (RFC 5280, CRL, OCSP) | ✓ | ✓ | Shipped |
|
| Revocation (RFC 5280, CRL, OCSP) | ✓ | ✓ | Shipped |
|
||||||
| Dashboard + 19 pages | ✓ | ✓ | Shipped |
|
| Full web dashboard | ✓ | ✓ | Shipped |
|
||||||
| Observability (charts, metrics, stats) | ✓ | ✓ | Shipped |
|
| Observability (charts, metrics, stats) | ✓ | ✓ | Shipped |
|
||||||
| REST API (91 endpoints) | ✓ | ✓ | Shipped |
|
| REST API (91 endpoints) | ✓ | ✓ | Shipped |
|
||||||
| MCP server (78 tools) | ✓ | ✓ | Shipped v2.1 |
|
| MCP server (78 tools) | ✓ | ✓ | Shipped v2.1 |
|
||||||
| CLI tool (10 subcommands) | ✓ | ✓ | Shipped |
|
| CLI tool (12 subcommands) | ✓ | ✓ | Shipped |
|
||||||
| Compliance mapping docs (SOC 2, PCI-DSS, NIST) | ✓ | ✓ | Shipped |
|
| Compliance mapping docs (SOC 2, PCI-DSS, NIST) | ✓ | ✓ | Shipped |
|
||||||
| Filesystem cert discovery (M18b) | ✓ | ✓ | Shipped |
|
| Filesystem cert discovery (M18b) | ✓ | ✓ | Shipped |
|
||||||
| Network cert discovery (M21) | ✓ | ✓ | Shipped |
|
| Network cert discovery (M21) | ✓ | ✓ | Shipped |
|
||||||
@@ -1197,8 +1230,8 @@ Each guide includes an evidence summary table mapping specific criteria to certc
|
|||||||
|
|
||||||
| Category | Count |
|
| Category | Count |
|
||||||
|----------|-------|
|
|----------|-------|
|
||||||
| **API Endpoints** | 91 (under /api/v1/) |
|
| **API Endpoints** | 95 (under /api/v1/ + /.well-known/est/) |
|
||||||
| **Dashboard Pages** | 19 |
|
| **Dashboard** | Full web GUI |
|
||||||
| **Issuer Connectors** | 4 (Local CA, ACME, step-ca, OpenSSL) |
|
| **Issuer Connectors** | 4 (Local CA, ACME, step-ca, OpenSSL) |
|
||||||
| **Target Connectors** | 5 (3 impl: NGINX, Apache, HAProxy; 2 stubs: F5, IIS) |
|
| **Target Connectors** | 5 (3 impl: NGINX, Apache, HAProxy; 2 stubs: F5, IIS) |
|
||||||
| **Notifier Channels** | 6 (Email, Webhook, Slack, Teams, PagerDuty, OpsGenie) |
|
| **Notifier Channels** | 6 (Email, Webhook, Slack, Teams, PagerDuty, OpsGenie) |
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Quick Start Guide
|
# Quick Start Guide
|
||||||
|
|
||||||
Get certctl running locally and managing certificates in under 5 minutes. With TLS certificate lifespans dropping to 47 days by 2029, automated lifecycle management isn't optional — it's infrastructure. This guide gets you hands-on with certctl's automation loop: tracking, renewing, and deploying certificates without manual intervention.
|
Certificate lifespans are dropping to **47 days by 2029**. At that cadence, a team managing 100 certificates is processing 7+ renewals per week — every week, forever. Manual processes break. certctl automates the entire lifecycle: issuance, renewal, deployment, revocation, and audit — with zero human intervention.
|
||||||
|
|
||||||
|
This guide gets you running in 5 minutes and walks you through everything certctl does.
|
||||||
|
|
||||||
New to certificates? Read the [Concepts Guide](concepts.md) first — it explains TLS, CAs, and private keys in plain language.
|
New to certificates? Read the [Concepts Guide](concepts.md) first — it explains TLS, CAs, and private keys in plain language.
|
||||||
|
|
||||||
@@ -23,7 +25,7 @@ cd certctl
|
|||||||
docker compose -f deploy/docker-compose.yml up -d --build
|
docker compose -f deploy/docker-compose.yml up -d --build
|
||||||
```
|
```
|
||||||
|
|
||||||
The `--build` flag is important — it builds the server image including the React frontend. Without it, Docker may use a stale cached image that doesn't include the dashboard.
|
The `--build` flag builds the server image including the React frontend. Without it, Docker may use a stale cached image.
|
||||||
|
|
||||||
**For production deployments**, copy `deploy/.env.example` to `deploy/.env` and customize the credentials:
|
**For production deployments**, copy `deploy/.env.example` to `deploy/.env` and customize the credentials:
|
||||||
```bash
|
```bash
|
||||||
@@ -32,7 +34,7 @@ cp deploy/.env.example deploy/.env
|
|||||||
docker compose -f deploy/docker-compose.yml up -d --build
|
docker compose -f deploy/docker-compose.yml up -d --build
|
||||||
```
|
```
|
||||||
|
|
||||||
Wait about 30 seconds for PostgreSQL to initialize and the server to boot. Check that everything is healthy:
|
Wait about 30 seconds for PostgreSQL to initialize, then verify:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker compose -f deploy/docker-compose.yml ps
|
docker compose -f deploy/docker-compose.yml ps
|
||||||
@@ -46,7 +48,6 @@ certctl-server Up (healthy)
|
|||||||
certctl-agent Up
|
certctl-agent Up
|
||||||
```
|
```
|
||||||
|
|
||||||
Verify the server responds:
|
|
||||||
```bash
|
```bash
|
||||||
curl http://localhost:8443/health
|
curl http://localhost:8443/health
|
||||||
```
|
```
|
||||||
@@ -58,98 +59,123 @@ curl http://localhost:8443/health
|
|||||||
|
|
||||||
Open **http://localhost:8443** in your browser.
|
Open **http://localhost:8443** in your browser.
|
||||||
|
|
||||||
The dashboard comes pre-loaded with 15 demo certificates across multiple teams, environments, and statuses. You'll see expiring certs, expired certs, active certs, failed renewals — a realistic snapshot of what a certificate inventory looks like in a real organization.
|
The dashboard comes pre-loaded with 15 demo certificates across multiple teams, environments, and statuses — expiring certs, expired certs, active certs, failed renewals. A realistic snapshot of what certificate management looks like in a real organization.
|
||||||
|
|
||||||
Explore the sidebar: Certificates, Agents, Policies, Jobs, Audit Trail, Notifications. Everything you see in the dashboard is backed by the REST API.
|
### What you're looking at
|
||||||
|
|
||||||
|
The main dashboard shows total certificates, how many are expiring soon, how many have expired, the renewal success rate, and four charts: an **expiration heatmap** (90-day weekly buckets), **renewal success rate trends** (30-day line chart), **certificate status distribution** (donut chart), and **issuance rate** (30-day bar chart).
|
||||||
|
|
||||||
|
Explore the sidebar: Certificates, Agents, Policies, Jobs, Audit Trail, Notifications, Profiles, Teams, Owners, Agent Groups, Fleet Overview, Short-Lived Credentials, Discovery.
|
||||||
|
|
||||||
|
### Scenarios to walk through
|
||||||
|
|
||||||
|
**"We're about to have an outage"** — Filter certificates by status → Expiring. You'll see `auth-production` (12 days), `cdn-production` (8 days), and `mail-production` (5 days). At 47-day lifespans, this is every other week. certctl catches these automatically and triggers renewal before they expire.
|
||||||
|
|
||||||
|
**"A renewal failed"** — Look at `vpn-production` — status: Failed. Click it to see the audit trail showing the ACME challenge failure after 3 retry attempts. The system sent a webhook notification to the ops channel. No one had to notice manually.
|
||||||
|
|
||||||
|
**"Who owns this cert?"** — Click any certificate. Owner, team, environment, tags. Clear accountability. Notifications route to the owner's email automatically.
|
||||||
|
|
||||||
|
**"Can I revoke a compromised cert?"** — Click any active certificate, then "Revoke." A modal with RFC 5280 reason codes (Key Compromise, Superseded, Cessation of Operation). After revocation, CRL and OCSP are served automatically — clients stop trusting the cert immediately.
|
||||||
|
|
||||||
|
**"What about certificates already in production?"** — Click "Discovered Certificates." Agents scan local filesystems for existing certs. The server probes TLS endpoints on configured CIDR ranges. Both feed into a triage workflow: claim unmanaged certs to bring them under automation, or dismiss them.
|
||||||
|
|
||||||
|
**"Show me the agent fleet"** — Click "Agents." Four agents online, one offline. Click "Fleet Overview" for OS/architecture grouping, version distribution, and per-platform listing. Agents generate ECDSA P-256 keys locally — private keys never leave your infrastructure.
|
||||||
|
|
||||||
|
**"What about bulk operations?"** — On the Certificates page, select multiple certificates with checkboxes. A bulk action bar appears: trigger renewal, revoke with reason codes, or reassign ownership — all with progress tracking. At 47-day lifespans with hundreds of certs, bulk operations aren't optional.
|
||||||
|
|
||||||
|
**"Short-lived credentials?"** — Click "Short-Lived" in the sidebar. Live countdown timers for certificates with TTL under 1 hour. Auto-refresh every 10 seconds. These are for service-to-service auth where rapid expiry replaces revocation.
|
||||||
|
|
||||||
## Explore the API
|
## Explore the API
|
||||||
|
|
||||||
The dashboard reads from the same REST API you can call directly. All endpoints live under `/api/v1/` and return JSON.
|
Everything you see in the dashboard is backed by the REST API. All endpoints live under `/api/v1/` and return JSON.
|
||||||
|
|
||||||
### List all certificates
|
### Core operations
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
# List all certificates
|
||||||
curl -s http://localhost:8443/api/v1/certificates | jq .
|
curl -s http://localhost:8443/api/v1/certificates | jq .
|
||||||
```
|
|
||||||
|
|
||||||
The response has this shape:
|
# Filter by status
|
||||||
```json
|
|
||||||
{
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"id": "mc-api-prod",
|
|
||||||
"name": "API Production",
|
|
||||||
"common_name": "api.example.com",
|
|
||||||
"sans": ["api.example.com", "api-v2.example.com"],
|
|
||||||
"environment": "production",
|
|
||||||
"owner_id": "o-alice",
|
|
||||||
"team_id": "t-platform",
|
|
||||||
"issuer_id": "iss-local",
|
|
||||||
"status": "Active",
|
|
||||||
"expires_at": "2026-05-28T00:00:00Z",
|
|
||||||
"tags": {"service": "api-gateway", "tier": "critical"},
|
|
||||||
"created_at": "2026-03-14T00:00:00Z",
|
|
||||||
"updated_at": "2026-03-14T00:00:00Z"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"total": 15,
|
|
||||||
"page": 1,
|
|
||||||
"per_page": 50
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Filter by status
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Get only expiring certificates
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?status=Expiring" | jq .
|
curl -s "http://localhost:8443/api/v1/certificates?status=Expiring" | jq .
|
||||||
|
|
||||||
# Get only production certificates
|
# Filter by environment
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?environment=production" | jq .
|
curl -s "http://localhost:8443/api/v1/certificates?environment=production" | jq .
|
||||||
```
|
|
||||||
|
|
||||||
### Get a specific certificate
|
# Get a specific certificate
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -s http://localhost:8443/api/v1/certificates/mc-api-prod | jq .
|
curl -s http://localhost:8443/api/v1/certificates/mc-api-prod | jq .
|
||||||
```
|
|
||||||
|
|
||||||
### List agents
|
# Get deployment targets for a certificate
|
||||||
|
curl -s http://localhost:8443/api/v1/certificates/mc-api-prod/deployments | jq .
|
||||||
|
|
||||||
```bash
|
# List agents
|
||||||
curl -s http://localhost:8443/api/v1/agents | jq .
|
curl -s http://localhost:8443/api/v1/agents | jq .
|
||||||
```
|
|
||||||
|
|
||||||
### Check agent pending work
|
# Check agent pending work
|
||||||
|
curl -s http://localhost:8443/api/v1/agents/ag-web-prod/work | jq .
|
||||||
|
|
||||||
```bash
|
# View audit trail
|
||||||
# Replace with an actual agent ID from the list above
|
|
||||||
curl -s http://localhost:8443/api/v1/agents/agent-nginx-prod/work | jq .
|
|
||||||
```
|
|
||||||
|
|
||||||
### View audit trail
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -s http://localhost:8443/api/v1/audit | jq .
|
curl -s http://localhost:8443/api/v1/audit | jq .
|
||||||
```
|
|
||||||
|
|
||||||
### View policy rules
|
# View policies and violations
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -s http://localhost:8443/api/v1/policies | jq .
|
curl -s http://localhost:8443/api/v1/policies | jq .
|
||||||
|
curl -s http://localhost:8443/api/v1/policies/pr-require-owner/violations | jq .
|
||||||
|
|
||||||
|
# Notifications
|
||||||
|
curl -s http://localhost:8443/api/v1/notifications | jq .
|
||||||
|
|
||||||
|
# Profiles and agent groups
|
||||||
|
curl -s http://localhost:8443/api/v1/profiles | jq .
|
||||||
|
curl -s http://localhost:8443/api/v1/agent-groups | jq .
|
||||||
```
|
```
|
||||||
|
|
||||||
### View notifications
|
### Sorting, filtering, and pagination
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -s http://localhost:8443/api/v1/notifications | jq .
|
# Sort by expiration date (ascending)
|
||||||
|
curl -s "http://localhost:8443/api/v1/certificates?sort=notAfter" | jq .
|
||||||
|
|
||||||
|
# Sort descending (prefix with -)
|
||||||
|
curl -s "http://localhost:8443/api/v1/certificates?sort=-createdAt" | jq .
|
||||||
|
|
||||||
|
# Time-range filters (RFC3339)
|
||||||
|
curl -s "http://localhost:8443/api/v1/certificates?expires_before=2026-05-01T00:00:00Z" | jq .
|
||||||
|
curl -s "http://localhost:8443/api/v1/certificates?created_after=2026-03-01T00:00:00Z" | jq .
|
||||||
|
|
||||||
|
# Sparse fields — request only what you need
|
||||||
|
curl -s "http://localhost:8443/api/v1/certificates?fields=id,common_name,status,expires_at" | jq .
|
||||||
|
|
||||||
|
# Cursor pagination — efficient for large inventories
|
||||||
|
curl -s "http://localhost:8443/api/v1/certificates?page_size=5" | jq '{next_cursor: .next_cursor, count: (.data | length)}'
|
||||||
|
curl -s "http://localhost:8443/api/v1/certificates?cursor=<next_cursor_value>&page_size=5" | jq .
|
||||||
|
```
|
||||||
|
|
||||||
|
Supported sort fields: `notAfter`, `expiresAt`, `createdAt`, `updatedAt`, `commonName`, `name`, `status`, `environment`.
|
||||||
|
|
||||||
|
### Stats and metrics
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Dashboard summary
|
||||||
|
curl -s http://localhost:8443/api/v1/stats/summary | jq .
|
||||||
|
|
||||||
|
# Certificates by status
|
||||||
|
curl -s http://localhost:8443/api/v1/stats/certificates-by-status | jq .
|
||||||
|
|
||||||
|
# Expiration timeline (next 90 days)
|
||||||
|
curl -s "http://localhost:8443/api/v1/stats/expiration-timeline?days=90" | jq .
|
||||||
|
|
||||||
|
# Job trends (last 30 days)
|
||||||
|
curl -s "http://localhost:8443/api/v1/stats/job-trends?days=30" | jq .
|
||||||
|
|
||||||
|
# JSON metrics
|
||||||
|
curl -s http://localhost:8443/api/v1/metrics | jq .
|
||||||
|
|
||||||
|
# Prometheus format (for Prometheus, Grafana Agent, Datadog)
|
||||||
|
curl -s http://localhost:8443/api/v1/metrics/prometheus
|
||||||
```
|
```
|
||||||
|
|
||||||
## Create Your First Certificate
|
## Create Your First Certificate
|
||||||
|
|
||||||
Let's create a new managed certificate from scratch using the API. This will create a certificate record that certctl will track, renew, and deploy.
|
Create a certificate record that certctl will track, renew, and deploy automatically.
|
||||||
|
|
||||||
### Step 1: Create a certificate
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -s -X POST http://localhost:8443/api/v1/certificates \
|
curl -s -X POST http://localhost:8443/api/v1/certificates \
|
||||||
@@ -168,47 +194,26 @@ curl -s -X POST http://localhost:8443/api/v1/certificates \
|
|||||||
}' | jq .
|
}' | jq .
|
||||||
```
|
```
|
||||||
|
|
||||||
The server returns the created certificate. Since we didn't include an `id` field, the server auto-generates one using the name and a timestamp:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"id": "My First Certificate-1710403200000000000",
|
|
||||||
"name": "My First Certificate",
|
|
||||||
"common_name": "myapp.example.com",
|
|
||||||
"status": "Pending",
|
|
||||||
"created_at": "2026-03-14T..."
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Save the certificate ID (or provide your own `id` in the request body, e.g. `"id": "mc-my-first"`):
|
Save the certificate ID (or provide your own `id` in the request body, e.g. `"id": "mc-my-first"`):
|
||||||
```bash
|
```bash
|
||||||
CERT_ID="<paste the id from the response>"
|
CERT_ID="<paste the id from the response>"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 2: Trigger renewal
|
Trigger renewal:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -s -X POST http://localhost:8443/api/v1/certificates/$CERT_ID/renew | jq .
|
curl -s -X POST http://localhost:8443/api/v1/certificates/$CERT_ID/renew | jq .
|
||||||
```
|
```
|
||||||
|
|
||||||
This creates a renewal job that will be processed by the scheduler.
|
Check the result:
|
||||||
|
|
||||||
### Step 3: Check the certificate
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -s http://localhost:8443/api/v1/certificates/$CERT_ID | jq .
|
curl -s http://localhost:8443/api/v1/certificates/$CERT_ID | jq .
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 4: Check the audit trail
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -s http://localhost:8443/api/v1/audit | jq '.data[0:3]'
|
|
||||||
```
|
|
||||||
|
|
||||||
Refresh the dashboard at http://localhost:8443 — your new certificate appears in the inventory.
|
Refresh the dashboard at http://localhost:8443 — your new certificate appears in the inventory.
|
||||||
|
|
||||||
### Step 5: Revoke a certificate
|
### Revoke a certificate
|
||||||
|
|
||||||
If a certificate's private key is compromised or the service is decommissioned, revoke it:
|
When a private key is compromised or a service is decommissioned:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -s -X POST http://localhost:8443/api/v1/certificates/$CERT_ID/revoke \
|
curl -s -X POST http://localhost:8443/api/v1/certificates/$CERT_ID/revoke \
|
||||||
@@ -216,111 +221,17 @@ curl -s -X POST http://localhost:8443/api/v1/certificates/$CERT_ID/revoke \
|
|||||||
-d '{"reason": "superseded"}' | jq .
|
-d '{"reason": "superseded"}' | jq .
|
||||||
```
|
```
|
||||||
|
|
||||||
Supported RFC 5280 reason codes: `unspecified`, `keyCompromise`, `caCompromise`, `affiliationChanged`, `superseded`, `cessationOfOperation`, `certificateHold`, `privilegeWithdrawn`. If you omit the reason, it defaults to `unspecified`.
|
Supported RFC 5280 reason codes: `unspecified`, `keyCompromise`, `caCompromise`, `affiliationChanged`, `superseded`, `cessationOfOperation`, `certificateHold`, `privilegeWithdrawn`.
|
||||||
|
|
||||||
Check the CRL to confirm:
|
|
||||||
|
|
||||||
|
Confirm via CRL:
|
||||||
```bash
|
```bash
|
||||||
curl -s http://localhost:8443/api/v1/crl | jq .
|
curl -s http://localhost:8443/api/v1/crl | jq .
|
||||||
```
|
```
|
||||||
|
|
||||||
## Understanding the Demo Data
|
|
||||||
|
|
||||||
The demo comes pre-loaded with realistic data so you can explore certctl's features immediately:
|
|
||||||
|
|
||||||
| Resource | Count | Examples |
|
|
||||||
|----------|-------|---------|
|
|
||||||
| Teams | 5 | Platform, Security, Payments, Frontend, Data |
|
|
||||||
| Owners | 5 | Alice, Bob, Carol, Dave, Eve |
|
|
||||||
| Issuers | 4 | Local Dev CA, Let's Encrypt Staging, step-ca Internal, DigiCert (disabled) |
|
|
||||||
| Agents | 5 | nginx-prod, nginx-staging, f5-prod, iis-prod, data-agent |
|
|
||||||
| Targets | 5 | NGINX (prod/staging/data), F5 LB, IIS |
|
|
||||||
| Certificates | 15 | Various statuses: Active, Expiring, Expired, Failed, Wildcard |
|
|
||||||
| Policies | 4 | Required owner, allowed environments, max lifetime, min renewal window |
|
|
||||||
| Profiles | 3 | Default TLS, Short-Lived, High-Security |
|
|
||||||
| Agent Groups | 5 | Linux agents, ARM agents, Production subnet, etc. |
|
|
||||||
|
|
||||||
Certificates have varied statuses so you can see what each state looks like in the dashboard: healthy certs with 45+ days remaining, certs about to expire (5-12 days), certs that already expired, and a failed renewal.
|
|
||||||
|
|
||||||
## Advanced API Features
|
|
||||||
|
|
||||||
### Sorting and filtering
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Sort certificates by expiration date (ascending)
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?sort=notAfter" | jq .
|
|
||||||
|
|
||||||
# Sort descending (prefix with -)
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?sort=-createdAt" | jq .
|
|
||||||
|
|
||||||
# Time-range filters (RFC3339 format)
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?expires_before=2026-05-01T00:00:00Z" | jq .
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?created_after=2026-03-01T00:00:00Z" | jq .
|
|
||||||
```
|
|
||||||
|
|
||||||
Supported sort fields: `notAfter`, `expiresAt`, `createdAt`, `updatedAt`, `commonName`, `name`, `status`, `environment`.
|
|
||||||
|
|
||||||
### Sparse field selection
|
|
||||||
|
|
||||||
Request only the fields you need to reduce response size:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?fields=id,common_name,status,expires_at" | jq .
|
|
||||||
```
|
|
||||||
|
|
||||||
### Cursor-based pagination
|
|
||||||
|
|
||||||
For large datasets, cursor pagination is more efficient than page-based:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# First page
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?page_size=5" | jq '{next_cursor: .next_cursor, count: (.data | length)}'
|
|
||||||
|
|
||||||
# Next page (use the next_cursor from the previous response)
|
|
||||||
curl -s "http://localhost:8443/api/v1/certificates?cursor=<next_cursor_value>&page_size=5" | jq .
|
|
||||||
```
|
|
||||||
|
|
||||||
### Stats and metrics
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Dashboard summary
|
|
||||||
curl -s http://localhost:8443/api/v1/stats/summary | jq .
|
|
||||||
|
|
||||||
# Certificates by status
|
|
||||||
curl -s http://localhost:8443/api/v1/stats/certificates-by-status | jq .
|
|
||||||
|
|
||||||
# Expiration timeline (next 90 days)
|
|
||||||
curl -s "http://localhost:8443/api/v1/stats/expiration-timeline?days=90" | jq .
|
|
||||||
|
|
||||||
# Job trends (last 30 days)
|
|
||||||
curl -s "http://localhost:8443/api/v1/stats/job-trends?days=30" | jq .
|
|
||||||
|
|
||||||
# System metrics (JSON)
|
|
||||||
curl -s http://localhost:8443/api/v1/metrics | jq .
|
|
||||||
|
|
||||||
# System metrics (Prometheus format — for scraping by Prometheus, Grafana Agent, Datadog)
|
|
||||||
curl -s http://localhost:8443/api/v1/metrics/prometheus
|
|
||||||
```
|
|
||||||
|
|
||||||
### Certificate profiles
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# List all profiles
|
|
||||||
curl -s http://localhost:8443/api/v1/profiles | jq .
|
|
||||||
|
|
||||||
# Get a specific profile
|
|
||||||
curl -s http://localhost:8443/api/v1/profiles/prof-default | jq .
|
|
||||||
```
|
|
||||||
|
|
||||||
### Certificate deployments
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# View deployment targets for a certificate
|
|
||||||
curl -s http://localhost:8443/api/v1/certificates/mc-api-prod/deployments | jq .
|
|
||||||
```
|
|
||||||
|
|
||||||
### Interactive approval workflow
|
### Interactive approval workflow
|
||||||
|
|
||||||
|
For high-value certificates where you want human oversight:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Approve a pending job
|
# Approve a pending job
|
||||||
curl -s -X POST http://localhost:8443/api/v1/jobs/JOB_ID/approve \
|
curl -s -X POST http://localhost:8443/api/v1/jobs/JOB_ID/approve \
|
||||||
@@ -333,49 +244,25 @@ curl -s -X POST http://localhost:8443/api/v1/jobs/JOB_ID/reject \
|
|||||||
-d '{"reason": "Key type does not meet compliance requirements"}' | jq .
|
-d '{"reason": "Key type does not meet compliance requirements"}' | jq .
|
||||||
```
|
```
|
||||||
|
|
||||||
## Tear Down
|
## Certificate Discovery
|
||||||
|
|
||||||
```bash
|
Find certificates already running in your infrastructure — ones you didn't issue through certctl.
|
||||||
docker compose -f deploy/docker-compose.yml down -v
|
|
||||||
```
|
|
||||||
|
|
||||||
The `-v` flag removes the PostgreSQL data volume so you get a clean slate next time.
|
### Filesystem discovery (agent-based)
|
||||||
|
|
||||||
### Certificate Discovery
|
|
||||||
|
|
||||||
Agents can scan your infrastructure for existing certificates you're not yet managing:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Configure agent to scan directories
|
# Configure agent to scan directories
|
||||||
export CERTCTL_DISCOVERY_DIRS="/etc/nginx/certs,/etc/ssl/certs,/var/lib/certs"
|
export CERTCTL_DISCOVERY_DIRS="/etc/nginx/certs,/etc/ssl/certs,/var/lib/certs"
|
||||||
|
# Agent scans on startup + every 6 hours
|
||||||
# Agent scans on startup + every 6 hours, reports findings to control plane
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Query discovered certificates:
|
### Network discovery (agentless)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# List all discovered certs from a specific agent
|
# Enable network scanning
|
||||||
curl -s "http://localhost:8443/api/v1/discovered-certificates?agent_id=agent-nginx-prod" | jq .
|
|
||||||
|
|
||||||
# Get discovery summary (counts by status)
|
|
||||||
curl -s http://localhost:8443/api/v1/discovery-summary | jq .
|
|
||||||
|
|
||||||
# Claim a discovered cert (link to managed cert)
|
|
||||||
curl -s -X POST "http://localhost:8443/api/v1/discovered-certificates/DISCOVERY_ID/claim" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"managed_certificate_id": "mc-api-prod"}' | jq .
|
|
||||||
```
|
|
||||||
|
|
||||||
### Network Certificate Discovery
|
|
||||||
|
|
||||||
The server can also discover certificates by scanning TLS endpoints directly — no agent required:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Enable network scanning (set in environment or docker-compose)
|
|
||||||
export CERTCTL_NETWORK_SCAN_ENABLED=true
|
export CERTCTL_NETWORK_SCAN_ENABLED=true
|
||||||
|
|
||||||
# Create a scan target (e.g., scan your internal network on port 443)
|
# Create a scan target
|
||||||
curl -s -X POST http://localhost:8443/api/v1/network-scan-targets \
|
curl -s -X POST http://localhost:8443/api/v1/network-scan-targets \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
@@ -389,17 +276,105 @@ curl -s -X POST http://localhost:8443/api/v1/network-scan-targets \
|
|||||||
|
|
||||||
# Trigger an immediate scan
|
# Trigger an immediate scan
|
||||||
curl -s -X POST http://localhost:8443/api/v1/network-scan-targets/nst-internal-network/scan | jq .
|
curl -s -X POST http://localhost:8443/api/v1/network-scan-targets/nst-internal-network/scan | jq .
|
||||||
|
|
||||||
# List scan targets with results
|
|
||||||
curl -s http://localhost:8443/api/v1/network-scan-targets | jq .
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Discovered network certificates appear in the same `GET /api/v1/discovered-certificates` list as filesystem-discovered certs, with `agent_id=server-scanner` and `source_format=network`.
|
### Triage discovered certificates
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# List discovered certs
|
||||||
|
curl -s "http://localhost:8443/api/v1/discovered-certificates?agent_id=agent-nginx-prod" | jq .
|
||||||
|
|
||||||
|
# Summary counts
|
||||||
|
curl -s http://localhost:8443/api/v1/discovery-summary | jq .
|
||||||
|
|
||||||
|
# Claim a discovered cert (bring under management)
|
||||||
|
curl -s -X POST "http://localhost:8443/api/v1/discovered-certificates/DISCOVERY_ID/claim" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"managed_certificate_id": "mc-api-prod"}' | jq .
|
||||||
|
```
|
||||||
|
|
||||||
|
## CLI Tool
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd cmd/cli && go build -o certctl-cli .
|
||||||
|
|
||||||
|
export CERTCTL_SERVER_URL="http://localhost:8443"
|
||||||
|
export CERTCTL_API_KEY="test-key-123"
|
||||||
|
|
||||||
|
./certctl-cli certs list # List certificates
|
||||||
|
./certctl-cli certs get mc-api-prod # Certificate details
|
||||||
|
./certctl-cli certs renew mc-api-prod # Trigger renewal
|
||||||
|
./certctl-cli certs revoke mc-api-prod --reason keyCompromise
|
||||||
|
./certctl-cli agents list # List agents
|
||||||
|
./certctl-cli jobs list # List jobs
|
||||||
|
./certctl-cli import /path/to/certs.pem # Bulk import
|
||||||
|
./certctl-cli status # Health + stats
|
||||||
|
```
|
||||||
|
|
||||||
|
## MCP Server (AI Integration)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd cmd/mcp-server && go build -o mcp-server .
|
||||||
|
|
||||||
|
export CERTCTL_SERVER_URL="http://localhost:8443"
|
||||||
|
export CERTCTL_API_KEY="test-key-123"
|
||||||
|
|
||||||
|
./mcp-server
|
||||||
|
```
|
||||||
|
|
||||||
|
Exposes 78 MCP tools covering the REST API via stdio transport. Ask Claude: "What certificates are expiring in the next 30 days?", "Revoke the payments cert due to key compromise", "Show me the audit trail."
|
||||||
|
|
||||||
|
## Demo Data Reference
|
||||||
|
|
||||||
|
| Resource | Count | Examples |
|
||||||
|
|----------|-------|---------|
|
||||||
|
| Teams | 5 | Platform, Security, Payments, Frontend, Data |
|
||||||
|
| Owners | 5 | Alice, Bob, Carol, Dave, Eve |
|
||||||
|
| Issuers | 4 | Local Dev CA, Let's Encrypt Staging, step-ca Internal, DigiCert (disabled) |
|
||||||
|
| Agents | 5 | ag-web-prod, ag-web-staging, ag-lb-prod, ag-iis-prod, ag-data-prod |
|
||||||
|
| Targets | 5 | NGINX (prod/staging/data), F5 LB, IIS |
|
||||||
|
| Certificates | 15 | Various statuses: Active, Expiring, Expired, Failed, Wildcard |
|
||||||
|
| Policies | 4 | Required owner, allowed environments, max lifetime, min renewal window |
|
||||||
|
| Profiles | 3 | Default TLS, Short-Lived, High-Security |
|
||||||
|
| Agent Groups | 5 | Linux agents, ARM agents, Production subnet, etc. |
|
||||||
|
|
||||||
|
## Dashboard Demo Mode
|
||||||
|
|
||||||
|
The dashboard works without a backend for screenshots and presentations:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd web && npm install && npm run dev
|
||||||
|
# Dashboard at http://localhost:5173
|
||||||
|
```
|
||||||
|
|
||||||
|
When the API is unreachable, the dashboard loads realistic mock data with a "Demo Mode" badge.
|
||||||
|
|
||||||
|
## Presenting to Stakeholders
|
||||||
|
|
||||||
|
A suggested 5-minute flow:
|
||||||
|
|
||||||
|
1. **Dashboard** — "Certificate inventory at a glance. Real-time charts show expiration trends and renewal health."
|
||||||
|
2. **Expiring certs** — "These three would have caused outages. At 47-day lifespans, this happens every other week."
|
||||||
|
3. **Certificate detail** — "Full lifecycle: who owns it, where it's deployed, deployment timeline, version history with rollback."
|
||||||
|
4. **Revocation** — "One click revokes with an RFC 5280 reason code. CRL and OCSP served automatically."
|
||||||
|
5. **Failed renewal** — "System tried 3 times, then alerted the team via Slack, Teams, PagerDuty, or OpsGenie."
|
||||||
|
6. **Agent fleet** — "Agents handle key generation locally (ECDSA P-256). Private keys never leave your infrastructure."
|
||||||
|
7. **Discovery** — "Agents scan filesystems, server probes TLS endpoints. We find what you're not managing yet."
|
||||||
|
8. **Bulk operations** — "Select multiple certs, renew or revoke in bulk. At 47-day lifespans with hundreds of certs, this is essential."
|
||||||
|
9. **Audit trail** — "Every action recorded. Export to CSV/JSON for compliance."
|
||||||
|
10. **CLI + MCP** — "Terminal users get `certctl-cli`. AI assistants get MCP integration. Everything is API-first."
|
||||||
|
|
||||||
|
## Tear Down
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose -f deploy/docker-compose.yml down -v
|
||||||
|
```
|
||||||
|
|
||||||
|
The `-v` flag removes the PostgreSQL data volume for a clean slate.
|
||||||
|
|
||||||
## What's Next
|
## What's Next
|
||||||
|
|
||||||
- **[Advanced Demo](demo-advanced.md)** — Issue a real certificate via the Local CA and watch it appear in the dashboard
|
- **[Advanced Demo](demo-advanced.md)** — Issue a real certificate via the Local CA end-to-end
|
||||||
- **[Demo Walkthrough](demo-guide.md)** — Guided 5-minute stakeholder presentation
|
|
||||||
- **[Architecture](architecture.md)** — How the control plane, agents, and connectors work together
|
- **[Architecture](architecture.md)** — How the control plane, agents, and connectors work together
|
||||||
- **[Connector Guide](connectors.md)** — Build custom connectors for your infrastructure
|
- **[Connector Guide](connectors.md)** — Build custom connectors for your infrastructure
|
||||||
- **[CLI Reference](cli.md)** — Manage certificates from your terminal
|
- **[Concepts Guide](concepts.md)** — TLS certificates, CAs, and private keys explained from scratch
|
||||||
|
|||||||
|
After Width: | Height: | Size: 755 KiB |
|
After Width: | Height: | Size: 438 KiB |
|
After Width: | Height: | Size: 404 KiB |
|
After Width: | Height: | Size: 700 KiB |
|
After Width: | Height: | Size: 680 KiB |
|
After Width: | Height: | Size: 500 KiB |
|
After Width: | Height: | Size: 432 KiB |
|
After Width: | Height: | Size: 399 KiB |
|
After Width: | Height: | Size: 454 KiB |
|
After Width: | Height: | Size: 615 KiB |
|
After Width: | Height: | Size: 396 KiB |
|
After Width: | Height: | Size: 414 KiB |
|
After Width: | Height: | Size: 485 KiB |
|
After Width: | Height: | Size: 289 KiB |
|
After Width: | Height: | Size: 402 KiB |
|
After Width: | Height: | Size: 391 KiB |
@@ -1,6 +1,6 @@
|
|||||||
# certctl V2.0 Release QA Guide
|
# certctl V2.0 Release QA Guide
|
||||||
|
|
||||||
Comprehensive manual testing playbook. Every test has a concrete command, an explanation of what it validates and why it matters, exact expected output, and an unambiguous pass/fail criterion. Run every test before tagging v2.0.0.
|
Comprehensive manual testing playbook. Every test has a concrete command, an explanation of what it validates and why it matters, exact expected output, and an unambiguous pass/fail criterion.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -2094,6 +2094,49 @@ curl -s -w "\nHTTP %{http_code}\n" -X DELETE -H "$AUTH" "$SERVER/api/v1/agent-gr
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### 11.4 Foreign Key Constraint Behavior
|
||||||
|
|
||||||
|
**What this validates:** Delete operations correctly fail with 409 when referenced entities still exist.
|
||||||
|
|
||||||
|
**Why it matters:** Owners and issuers use `ON DELETE RESTRICT` — you can't delete them while certificates reference them. Teams use `ON DELETE CASCADE`, so team deletes succeed and cascade. If the server returns a silent 500 instead of 409, the GUI swallows the error and the user thinks nothing happened.
|
||||||
|
|
||||||
|
**Test 11.4.1 — Delete owner with assigned certificates (expect 409)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Try to delete Alice Chen (o-alice) — she owns certificates in the demo data
|
||||||
|
curl -s -w "\nHTTP %{http_code}\n" -X DELETE -H "$AUTH" "$SERVER/api/v1/owners/o-alice" | jq .
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 409 with message "Cannot delete owner: certificates are still assigned to this owner".
|
||||||
|
**PASS if** 409 Conflict. **FAIL** if 204 (data integrity violation) or 500 (unhelpful error).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 11.4.2 — Delete issuer with assigned certificates (expect 409)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Try to delete the Local Dev CA (iss-local) — certificates reference it
|
||||||
|
curl -s -w "\nHTTP %{http_code}\n" -X DELETE -H "$AUTH" "$SERVER/api/v1/issuers/iss-local" | jq .
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 409 with message "Cannot delete issuer: certificates are still using this issuer".
|
||||||
|
**PASS if** 409 Conflict. **FAIL** if 204 or 500.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 11.4.3 — Delete team cascades successfully**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create a test team, then delete it — teams use ON DELETE CASCADE
|
||||||
|
curl -s -X POST -H "$AUTH" -H "$CT" -d '{"id": "t-fk-test", "name": "FK Test Team"}' $SERVER/api/v1/teams > /dev/null
|
||||||
|
curl -s -w "\nHTTP %{http_code}\n" -X DELETE -H "$AUTH" "$SERVER/api/v1/teams/t-fk-test"
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 204 (cascade allows deletion).
|
||||||
|
**PASS if** 204. **FAIL** if 409 or 500.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Part 12: Notifications
|
## Part 12: Notifications
|
||||||
|
|
||||||
**What this validates:** Notification creation, listing, and read status management.
|
**What this validates:** Notification creation, listing, and read status management.
|
||||||
@@ -3192,7 +3235,7 @@ echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_certificate",
|
|||||||
|
|
||||||
## Part 19: GUI Testing
|
## Part 19: GUI Testing
|
||||||
|
|
||||||
**What this validates:** The web dashboard — 19 pages of operational UI.
|
**What this validates:** The full web dashboard — all pages of operational UI.
|
||||||
|
|
||||||
**Why it matters:** Operators spend 80% of their time in the GUI. If it's broken, the product is broken, regardless of how good the API is.
|
**Why it matters:** Operators spend 80% of their time in the GUI. If it's broken, the product is broken, regardless of how good the API is.
|
||||||
|
|
||||||
@@ -3665,7 +3708,7 @@ docker compose logs certctl-server 2>&1 | grep -v "^certctl-server" | grep -cv "
|
|||||||
| 24.1.4 | `docs/architecture.md` | Component diagram matches `docker compose ps`. Says "21 tables", "78 MCP Tools", "900+ tests". | PASS if numbers match |
|
| 24.1.4 | `docs/architecture.md` | Component diagram matches `docker compose ps`. Says "21 tables", "78 MCP Tools", "900+ tests". | PASS if numbers match |
|
||||||
| 24.1.5 | `docs/connectors.md` | All 5 issuer types and 5 target types documented. F5/IIS marked as stubs. | PASS if all documented |
|
| 24.1.5 | `docs/connectors.md` | All 5 issuer types and 5 target types documented. F5/IIS marked as stubs. | PASS if all documented |
|
||||||
| 24.1.6 | `docs/features.md` | Endpoint count (93), MCP tools (78), table count (21), test count (900+) all accurate. | PASS if numbers match |
|
| 24.1.6 | `docs/features.md` | Endpoint count (93), MCP tools (78), table count (21), test count (900+) all accurate. | PASS if numbers match |
|
||||||
| 24.1.7 | `docs/demo-guide.md` | Demo walkthrough works against fresh `docker compose up`. | PASS if all steps work |
|
| 24.1.7 | `docs/quickstart.md` | Quick start + demo walkthrough works against fresh `docker compose up`. | PASS if all steps work |
|
||||||
| 24.1.8 | `docs/demo-advanced.md` | All parts executable against running stack. Network discovery section present. | PASS if all executable |
|
| 24.1.8 | `docs/demo-advanced.md` | All parts executable against running stack. Network discovery section present. | PASS if all executable |
|
||||||
| 24.1.9 | `docs/compliance.md` | Framework links resolve, mapping references real features. | PASS if links work |
|
| 24.1.9 | `docs/compliance.md` | Framework links resolve, mapping references real features. | PASS if links work |
|
||||||
| 24.1.10 | `docs/compliance-soc2.md` | API endpoints cited actually exist in the router. | PASS if endpoints exist |
|
| 24.1.10 | `docs/compliance-soc2.md` | API endpoints cited actually exist in the router. | PASS if endpoints exist |
|
||||||
@@ -3741,7 +3784,28 @@ curl -s -H "$AUTH" "$SERVER/api/v1/network-scan-targets" | jq '{total, ids: [.it
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Test 25.1.4 — OpenAPI spec operations match router**
|
**Test 25.1.4 — GUI delete on FK-restricted entities shows error, not silent failure**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Try deleting owner o-alice via API — she owns demo certificates
|
||||||
|
CODE=$(curl -s -o /tmp/delete-resp.json -w "%{http_code}" -X DELETE -H "$AUTH" "$SERVER/api/v1/owners/o-alice")
|
||||||
|
echo "DELETE owner with certs: HTTP $CODE"
|
||||||
|
cat /tmp/delete-resp.json | jq .
|
||||||
|
|
||||||
|
# Try deleting issuer iss-local — certificates reference it
|
||||||
|
CODE=$(curl -s -o /tmp/delete-resp.json -w "%{http_code}" -X DELETE -H "$AUTH" "$SERVER/api/v1/issuers/iss-local")
|
||||||
|
echo "DELETE issuer with certs: HTTP $CODE"
|
||||||
|
cat /tmp/delete-resp.json | jq .
|
||||||
|
```
|
||||||
|
|
||||||
|
**What:** Verifies that deleting owners/issuers with assigned certificates returns 409 Conflict with a descriptive message.
|
||||||
|
**Why:** This was a real bug — the backend returned 500 (generic "Failed to delete"), `fetchJSON` threw on the error, and TanStack Query's `onError` wasn't wired up. The user clicked OK on the confirm dialog and nothing visibly happened. Fixed by: (1) backend returns 409 with descriptive message for FK constraint violations, (2) `fetchJSON` handles 204 No Content for successful deletes, (3) frontend mutation `onError` surfaces the error.
|
||||||
|
**Expected:** Both return HTTP 409 with descriptive conflict messages.
|
||||||
|
**PASS if** both 409 with messages. **FAIL** if 500 (unhelpful error) or 204 (data integrity violation).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 25.1.5 — OpenAPI spec operations match router**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo "OpenAPI operations: $(grep -c 'operationId:' api/openapi.yaml)"
|
echo "OpenAPI operations: $(grep -c 'operationId:' api/openapi.yaml)"
|
||||||
@@ -3768,9 +3832,248 @@ grep -rn "errors.Is.*errors.New\|errors.Is(.*err.*errors.New" internal/service/*
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## Part 26: EST Server (RFC 7030)
|
||||||
|
|
||||||
|
**Scope:** Enrollment over Secure Transport — 4 endpoints under `/.well-known/est/` for device certificate enrollment. Tests cover CA cert distribution, certificate enrollment (PEM and base64-DER CSR formats), re-enrollment, CSR attributes, wire format compliance, and error handling.
|
||||||
|
|
||||||
|
**Prerequisites:** Server running with `CERTCTL_EST_ENABLED=true`, `CERTCTL_EST_ISSUER_ID=iss-local` (or a valid issuer). An ECDSA P-256 key pair and CSR for enrollment tests.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.1 — GET /.well-known/est/cacerts returns PKCS#7 CA chain**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer $API_KEY" \
|
||||||
|
http://localhost:8443/.well-known/est/cacerts
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 200, `Content-Type: application/pkcs7-mime`, `Content-Transfer-Encoding: base64`. Body is base64-encoded degenerate PKCS#7 SignedData containing the CA certificate chain.
|
||||||
|
**PASS if** status = 200, correct content type, non-empty body.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.2 — GET /cacerts method enforcement**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" -X POST \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
http://localhost:8443/.well-known/est/cacerts
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 405 Method Not Allowed.
|
||||||
|
**PASS if** status = 405.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.3 — POST /.well-known/est/simpleenroll with PEM CSR**
|
||||||
|
|
||||||
|
Generate a test CSR and submit as PEM:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Generate ECDSA P-256 key and CSR
|
||||||
|
openssl ecparam -name prime256v1 -genkey -noout -out /tmp/est-test.key
|
||||||
|
openssl req -new -key /tmp/est-test.key -out /tmp/est-test.csr \
|
||||||
|
-subj "/CN=est-test.example.com" \
|
||||||
|
-addext "subjectAltName=DNS:est-test.example.com"
|
||||||
|
|
||||||
|
# Submit PEM CSR
|
||||||
|
curl -s -w "\n%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-H "Content-Type: application/pkcs10" \
|
||||||
|
--data-binary @/tmp/est-test.csr \
|
||||||
|
http://localhost:8443/.well-known/est/simpleenroll
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 200, `Content-Type: application/pkcs7-mime`, `Content-Transfer-Encoding: base64`. Body contains base64-encoded PKCS#7 with the signed certificate.
|
||||||
|
**PASS if** status = 200, response decodes to valid PKCS#7.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.4 — POST /simpleenroll with base64-encoded DER CSR**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Convert PEM CSR to base64-encoded DER (EST wire format)
|
||||||
|
openssl req -in /tmp/est-test.csr -outform DER | base64 > /tmp/est-test-b64der.csr
|
||||||
|
|
||||||
|
curl -s -w "\n%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-H "Content-Type: application/pkcs10" \
|
||||||
|
--data-binary @/tmp/est-test-b64der.csr \
|
||||||
|
http://localhost:8443/.well-known/est/simpleenroll
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 200. Server auto-detects base64-encoded DER and converts to PEM internally.
|
||||||
|
**PASS if** status = 200.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.5 — POST /simpleenroll with empty body**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-H "Content-Type: application/pkcs10" \
|
||||||
|
-X POST -d "" \
|
||||||
|
http://localhost:8443/.well-known/est/simpleenroll
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 400 Bad Request.
|
||||||
|
**PASS if** status = 400.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.6 — POST /simpleenroll with invalid CSR**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-H "Content-Type: application/pkcs10" \
|
||||||
|
-X POST -d "not-a-valid-csr-at-all" \
|
||||||
|
http://localhost:8443/.well-known/est/simpleenroll
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 400 Bad Request.
|
||||||
|
**PASS if** status = 400.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.7 — POST /simpleenroll with CSR missing Common Name**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
openssl ecparam -name prime256v1 -genkey -noout -out /tmp/est-nocn.key
|
||||||
|
openssl req -new -key /tmp/est-nocn.key -out /tmp/est-nocn.csr -subj "/"
|
||||||
|
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-H "Content-Type: application/pkcs10" \
|
||||||
|
--data-binary @/tmp/est-nocn.csr \
|
||||||
|
http://localhost:8443/.well-known/est/simpleenroll
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 500 (service returns error for missing CN). Error message should reference "Common Name".
|
||||||
|
**PASS if** status != 200.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.8 — POST /simpleenroll method enforcement (GET not allowed)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
http://localhost:8443/.well-known/est/simpleenroll
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 405 Method Not Allowed.
|
||||||
|
**PASS if** status = 405.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.9 — POST /.well-known/est/simplereenroll (re-enrollment)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
openssl ecparam -name prime256v1 -genkey -noout -out /tmp/est-renew.key
|
||||||
|
openssl req -new -key /tmp/est-renew.key -out /tmp/est-renew.csr \
|
||||||
|
-subj "/CN=renew-est.example.com" \
|
||||||
|
-addext "subjectAltName=DNS:renew-est.example.com"
|
||||||
|
|
||||||
|
curl -s -w "\n%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-H "Content-Type: application/pkcs10" \
|
||||||
|
--data-binary @/tmp/est-renew.csr \
|
||||||
|
http://localhost:8443/.well-known/est/simplereenroll
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 200. Functionally identical to simpleenroll per RFC 7030 Section 4.2.2.
|
||||||
|
**PASS if** status = 200, valid PKCS#7 response.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.10 — GET /simplereenroll method enforcement**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
http://localhost:8443/.well-known/est/simplereenroll
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 405 Method Not Allowed.
|
||||||
|
**PASS if** status = 405.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.11 — GET /.well-known/est/csrattrs returns 204 (no required attrs)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
http://localhost:8443/.well-known/est/csrattrs
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 204 No Content (default implementation requires no specific CSR attributes).
|
||||||
|
**PASS if** status = 204.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.12 — POST /csrattrs method enforcement**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
|
-X POST http://localhost:8443/.well-known/est/csrattrs
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 405 Method Not Allowed.
|
||||||
|
**PASS if** status = 405.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.13 — EST enrollment creates audit event**
|
||||||
|
|
||||||
|
After a successful simpleenroll request (Test 26.3), query the audit trail:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -H "Authorization: Bearer $API_KEY" \
|
||||||
|
"http://localhost:8443/api/v1/audit?page=1&per_page=10" | \
|
||||||
|
jq '.data[] | select(.action == "est_simple_enroll")'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** At least one audit event with `action: "est_simple_enroll"`, `protocol: "EST"` in details, and the enrolled CN in the details.
|
||||||
|
**PASS if** audit event found with correct action and details.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.14 — EST disabled returns 404**
|
||||||
|
|
||||||
|
With `CERTCTL_EST_ENABLED=false` (default), EST endpoints should not be registered:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s -o /dev/null -w "%{http_code}" http://localhost:8443/.well-known/est/cacerts
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** HTTP 404 Not Found (endpoints not registered when EST is disabled).
|
||||||
|
**PASS if** status = 404.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Test 26.15 — EST with profile binding**
|
||||||
|
|
||||||
|
With `CERTCTL_EST_PROFILE_ID=profile-wifi-client`, verify that audit events include the profile_id in their details:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# After enrollment with profile binding, check audit
|
||||||
|
curl -s -H "Authorization: Bearer $API_KEY" \
|
||||||
|
"http://localhost:8443/api/v1/audit?page=1&per_page=5" | \
|
||||||
|
jq '.data[0].details.profile_id'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Expected:** Profile ID appears in audit event details when configured.
|
||||||
|
**PASS if** `profile_id` present in audit details.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Release Sign-Off
|
## Release Sign-Off
|
||||||
|
|
||||||
All 25 parts must pass before tagging v2.0.0.
|
All 26 parts must pass before tagging v2.0.1.
|
||||||
|
|
||||||
| Section | Pass? | Tester | Date | Notes |
|
| Section | Pass? | Tester | Date | Notes |
|
||||||
|---------|-------|--------|------|-------|
|
|---------|-------|--------|------|-------|
|
||||||
@@ -3799,6 +4102,7 @@ All 25 parts must pass before tagging v2.0.0.
|
|||||||
| Part 23: Structured Logging | ☐ | | | |
|
| Part 23: Structured Logging | ☐ | | | |
|
||||||
| Part 24: Documentation Verification | ☐ | | | |
|
| Part 24: Documentation Verification | ☐ | | | |
|
||||||
| Part 25: Regression Tests | ☐ | | | |
|
| Part 25: Regression Tests | ☐ | | | |
|
||||||
|
| Part 26: EST Server (RFC 7030) | ☐ | | | |
|
||||||
|
|
||||||
**Automated tests (900+) must also be green.** CI passing is necessary but not sufficient — this manual QA catches integration issues that isolated unit tests miss.
|
**Automated tests (900+) must also be green.** CI passing is necessary but not sufficient — this manual QA catches integration issues that isolated unit tests miss.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,404 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/x509"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/pem"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/shankar0123/certctl/internal/api/middleware"
|
||||||
|
"github.com/shankar0123/certctl/internal/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ESTService defines the service interface for EST enrollment operations.
|
||||||
|
// EST (RFC 7030) is a protocol for certificate enrollment over HTTPS.
|
||||||
|
type ESTService interface {
|
||||||
|
// GetCACerts returns the PEM-encoded CA certificate chain for the EST issuer.
|
||||||
|
GetCACerts(ctx context.Context) (string, error)
|
||||||
|
|
||||||
|
// SimpleEnroll processes a PKCS#10 CSR and returns a signed certificate.
|
||||||
|
SimpleEnroll(ctx context.Context, csrPEM string) (*domain.ESTEnrollResult, error)
|
||||||
|
|
||||||
|
// SimpleReEnroll processes a re-enrollment CSR (same as enroll for our purposes).
|
||||||
|
SimpleReEnroll(ctx context.Context, csrPEM string) (*domain.ESTEnrollResult, error)
|
||||||
|
|
||||||
|
// GetCSRAttrs returns the CSR attributes the server wants clients to include.
|
||||||
|
GetCSRAttrs(ctx context.Context) ([]byte, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ESTHandler handles HTTP requests for the EST protocol (RFC 7030).
|
||||||
|
//
|
||||||
|
// EST endpoints are served under /.well-known/est/ per the RFC.
|
||||||
|
// Wire format: base64-encoded DER (PKCS#7 for certs, PKCS#10 for CSRs).
|
||||||
|
//
|
||||||
|
// Supported operations:
|
||||||
|
// - GET /.well-known/est/cacerts — CA certificate distribution
|
||||||
|
// - POST /.well-known/est/simpleenroll — initial enrollment
|
||||||
|
// - POST /.well-known/est/simplereenroll — re-enrollment
|
||||||
|
// - GET /.well-known/est/csrattrs — CSR attributes
|
||||||
|
type ESTHandler struct {
|
||||||
|
svc ESTService
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewESTHandler creates a new ESTHandler.
|
||||||
|
func NewESTHandler(svc ESTService) ESTHandler {
|
||||||
|
return ESTHandler{svc: svc}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CACerts handles GET /.well-known/est/cacerts
|
||||||
|
// Returns the CA certificate chain as base64-encoded PKCS#7 (certs-only).
|
||||||
|
// Per RFC 7030 Section 4.1, this is a "certs-only" CMC Simple PKI Response.
|
||||||
|
// For simplicity and broad client compatibility, we return base64-encoded DER certificates.
|
||||||
|
func (h ESTHandler) CACerts(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
caCertPEM, err := h.svc.GetCACerts(r.Context())
|
||||||
|
if err != nil {
|
||||||
|
requestID := middleware.GetRequestID(r.Context())
|
||||||
|
ErrorWithRequestID(w, http.StatusInternalServerError, fmt.Sprintf("Failed to get CA certificates: %v", err), requestID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse PEM to DER for PKCS#7 encoding
|
||||||
|
derCerts, err := pemToDERChain(caCertPEM)
|
||||||
|
if err != nil {
|
||||||
|
requestID := middleware.GetRequestID(r.Context())
|
||||||
|
ErrorWithRequestID(w, http.StatusInternalServerError, "Failed to encode CA certificates", requestID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build a simple PKCS#7 SignedData (certs-only, degenerate) structure
|
||||||
|
pkcs7Data, err := buildCertsOnlyPKCS7(derCerts)
|
||||||
|
if err != nil {
|
||||||
|
requestID := middleware.GetRequestID(r.Context())
|
||||||
|
ErrorWithRequestID(w, http.StatusInternalServerError, "Failed to build PKCS#7 response", requestID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// RFC 7030 Section 4.1.3: response is base64-encoded application/pkcs7-mime
|
||||||
|
w.Header().Set("Content-Type", "application/pkcs7-mime; smime-type=certs-only")
|
||||||
|
w.Header().Set("Content-Transfer-Encoding", "base64")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
encoded := base64.StdEncoding.EncodeToString(pkcs7Data)
|
||||||
|
// Write base64 with line breaks at 76 chars per RFC 2045
|
||||||
|
for i := 0; i < len(encoded); i += 76 {
|
||||||
|
end := i + 76
|
||||||
|
if end > len(encoded) {
|
||||||
|
end = len(encoded)
|
||||||
|
}
|
||||||
|
w.Write([]byte(encoded[i:end]))
|
||||||
|
w.Write([]byte("\r\n"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SimpleEnroll handles POST /.well-known/est/simpleenroll
|
||||||
|
// Accepts a base64-encoded PKCS#10 CSR and returns a base64-encoded PKCS#7 certificate.
|
||||||
|
func (h ESTHandler) SimpleEnroll(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
requestID := middleware.GetRequestID(r.Context())
|
||||||
|
|
||||||
|
csrPEM, err := h.readCSRFromRequest(r)
|
||||||
|
if err != nil {
|
||||||
|
ErrorWithRequestID(w, http.StatusBadRequest, fmt.Sprintf("Invalid CSR: %v", err), requestID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.svc.SimpleEnroll(r.Context(), csrPEM)
|
||||||
|
if err != nil {
|
||||||
|
ErrorWithRequestID(w, http.StatusInternalServerError, fmt.Sprintf("Enrollment failed: %v", err), requestID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.writeCertResponse(w, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SimpleReEnroll handles POST /.well-known/est/simplereenroll
|
||||||
|
// Same as SimpleEnroll but for re-enrollment (certificate renewal).
|
||||||
|
func (h ESTHandler) SimpleReEnroll(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
requestID := middleware.GetRequestID(r.Context())
|
||||||
|
|
||||||
|
csrPEM, err := h.readCSRFromRequest(r)
|
||||||
|
if err != nil {
|
||||||
|
ErrorWithRequestID(w, http.StatusBadRequest, fmt.Sprintf("Invalid CSR: %v", err), requestID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := h.svc.SimpleReEnroll(r.Context(), csrPEM)
|
||||||
|
if err != nil {
|
||||||
|
ErrorWithRequestID(w, http.StatusInternalServerError, fmt.Sprintf("Re-enrollment failed: %v", err), requestID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.writeCertResponse(w, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CSRAttrs handles GET /.well-known/est/csrattrs
|
||||||
|
// Returns the CSR attributes the server wants the client to include in enrollment requests.
|
||||||
|
func (h ESTHandler) CSRAttrs(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
attrs, err := h.svc.GetCSRAttrs(r.Context())
|
||||||
|
if err != nil {
|
||||||
|
requestID := middleware.GetRequestID(r.Context())
|
||||||
|
ErrorWithRequestID(w, http.StatusInternalServerError, fmt.Sprintf("Failed to get CSR attributes: %v", err), requestID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(attrs) == 0 {
|
||||||
|
// No specific attributes required — return 204
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/csrattrs")
|
||||||
|
w.Header().Set("Content-Transfer-Encoding", "base64")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write([]byte(base64.StdEncoding.EncodeToString(attrs)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// readCSRFromRequest reads and decodes the CSR from an EST enrollment request.
|
||||||
|
// EST sends CSRs as base64-encoded PKCS#10 DER with Content-Type application/pkcs10.
|
||||||
|
func (h ESTHandler) readCSRFromRequest(r *http.Request) (string, error) {
|
||||||
|
body, err := io.ReadAll(io.LimitReader(r.Body, 1<<20)) // 1MB limit
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to read request body: %w", err)
|
||||||
|
}
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
if len(body) == 0 {
|
||||||
|
return "", fmt.Errorf("empty request body")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's already PEM-encoded (some clients send PEM directly)
|
||||||
|
bodyStr := strings.TrimSpace(string(body))
|
||||||
|
if strings.HasPrefix(bodyStr, "-----BEGIN CERTIFICATE REQUEST-----") {
|
||||||
|
// Validate it parses
|
||||||
|
block, _ := pem.Decode([]byte(bodyStr))
|
||||||
|
if block == nil {
|
||||||
|
return "", fmt.Errorf("invalid PEM-encoded CSR")
|
||||||
|
}
|
||||||
|
if _, err := x509.ParseCertificateRequest(block.Bytes); err != nil {
|
||||||
|
return "", fmt.Errorf("invalid CSR: %w", err)
|
||||||
|
}
|
||||||
|
return bodyStr, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EST standard: base64-encoded DER PKCS#10
|
||||||
|
derBytes, err := base64.StdEncoding.DecodeString(bodyStr)
|
||||||
|
if err != nil {
|
||||||
|
// Try with padding/whitespace stripped
|
||||||
|
cleaned := strings.Map(func(r rune) rune {
|
||||||
|
if r == '\r' || r == '\n' || r == ' ' || r == '\t' {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}, bodyStr)
|
||||||
|
derBytes, err = base64.StdEncoding.DecodeString(cleaned)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to decode base64 CSR: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate it's a valid PKCS#10 CSR
|
||||||
|
if _, err := x509.ParseCertificateRequest(derBytes); err != nil {
|
||||||
|
return "", fmt.Errorf("invalid PKCS#10 CSR: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert DER to PEM for internal use (certctl services expect PEM)
|
||||||
|
csrPEM := pem.EncodeToMemory(&pem.Block{
|
||||||
|
Type: "CERTIFICATE REQUEST",
|
||||||
|
Bytes: derBytes,
|
||||||
|
})
|
||||||
|
return string(csrPEM), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeCertResponse writes an EST enrollment response as base64-encoded PKCS#7.
|
||||||
|
func (h ESTHandler) writeCertResponse(w http.ResponseWriter, result *domain.ESTEnrollResult) {
|
||||||
|
// Parse cert and chain PEM to DER
|
||||||
|
var derCerts [][]byte
|
||||||
|
|
||||||
|
// Add the issued certificate
|
||||||
|
certDER, err := pemToDERChain(result.CertPEM)
|
||||||
|
if err != nil || len(certDER) == 0 {
|
||||||
|
http.Error(w, "Failed to encode certificate", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
derCerts = append(derCerts, certDER...)
|
||||||
|
|
||||||
|
// Add the CA chain if present
|
||||||
|
if result.ChainPEM != "" {
|
||||||
|
chainDER, err := pemToDERChain(result.ChainPEM)
|
||||||
|
if err == nil {
|
||||||
|
derCerts = append(derCerts, chainDER...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build PKCS#7 certs-only
|
||||||
|
pkcs7Data, err := buildCertsOnlyPKCS7(derCerts)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "Failed to build PKCS#7 response", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/pkcs7-mime; smime-type=certs-only")
|
||||||
|
w.Header().Set("Content-Transfer-Encoding", "base64")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
encoded := base64.StdEncoding.EncodeToString(pkcs7Data)
|
||||||
|
for i := 0; i < len(encoded); i += 76 {
|
||||||
|
end := i + 76
|
||||||
|
if end > len(encoded) {
|
||||||
|
end = len(encoded)
|
||||||
|
}
|
||||||
|
w.Write([]byte(encoded[i:end]))
|
||||||
|
w.Write([]byte("\r\n"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// pemToDERChain converts PEM-encoded certificates to a slice of DER-encoded certificates.
|
||||||
|
func pemToDERChain(pemData string) ([][]byte, error) {
|
||||||
|
var derCerts [][]byte
|
||||||
|
rest := []byte(pemData)
|
||||||
|
for {
|
||||||
|
var block *pem.Block
|
||||||
|
block, rest = pem.Decode(rest)
|
||||||
|
if block == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if block.Type == "CERTIFICATE" {
|
||||||
|
derCerts = append(derCerts, block.Bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(derCerts) == 0 {
|
||||||
|
return nil, fmt.Errorf("no certificates found in PEM data")
|
||||||
|
}
|
||||||
|
return derCerts, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildCertsOnlyPKCS7 creates a degenerate PKCS#7 SignedData structure containing only certificates.
|
||||||
|
// This is the "certs-only" format specified in RFC 7030 Section 4.1.3 for /cacerts responses
|
||||||
|
// and enrollment responses.
|
||||||
|
//
|
||||||
|
// ASN.1 structure (simplified):
|
||||||
|
//
|
||||||
|
// ContentInfo {
|
||||||
|
// contentType: signedData (1.2.840.113549.1.7.2)
|
||||||
|
// content: SignedData {
|
||||||
|
// version: 1
|
||||||
|
// digestAlgorithms: {} (empty)
|
||||||
|
// encapContentInfo: { contentType: data (1.2.840.113549.1.7.1) }
|
||||||
|
// certificates: [cert1, cert2, ...]
|
||||||
|
// signerInfos: {} (empty)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
func buildCertsOnlyPKCS7(derCerts [][]byte) ([]byte, error) {
|
||||||
|
// We build the ASN.1 manually to avoid pulling in a PKCS#7 library.
|
||||||
|
// This is a well-defined, static structure — no signing needed.
|
||||||
|
|
||||||
|
// OID for signedData: 1.2.840.113549.1.7.2
|
||||||
|
oidSignedData := []byte{0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x02}
|
||||||
|
// OID for data: 1.2.840.113549.1.7.1
|
||||||
|
oidData := []byte{0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01}
|
||||||
|
|
||||||
|
// Build certificates [0] IMPLICIT SET OF Certificate
|
||||||
|
var certsContent []byte
|
||||||
|
for _, cert := range derCerts {
|
||||||
|
certsContent = append(certsContent, cert...)
|
||||||
|
}
|
||||||
|
certsField := asn1WrapImplicit(0, certsContent)
|
||||||
|
|
||||||
|
// Build encapContentInfo: SEQUENCE { OID data }
|
||||||
|
encapContentInfo := asn1WrapSequence(oidData)
|
||||||
|
|
||||||
|
// Build digestAlgorithms: SET {} (empty)
|
||||||
|
digestAlgorithms := asn1WrapSet(nil)
|
||||||
|
|
||||||
|
// Build signerInfos: SET {} (empty)
|
||||||
|
signerInfos := asn1WrapSet(nil)
|
||||||
|
|
||||||
|
// Version: INTEGER 1
|
||||||
|
version := []byte{0x02, 0x01, 0x01}
|
||||||
|
|
||||||
|
// Build SignedData SEQUENCE
|
||||||
|
var signedDataContent []byte
|
||||||
|
signedDataContent = append(signedDataContent, version...)
|
||||||
|
signedDataContent = append(signedDataContent, digestAlgorithms...)
|
||||||
|
signedDataContent = append(signedDataContent, encapContentInfo...)
|
||||||
|
signedDataContent = append(signedDataContent, certsField...)
|
||||||
|
signedDataContent = append(signedDataContent, signerInfos...)
|
||||||
|
signedData := asn1WrapSequence(signedDataContent)
|
||||||
|
|
||||||
|
// Wrap in [0] EXPLICIT for ContentInfo.content
|
||||||
|
contentField := asn1WrapExplicit(0, signedData)
|
||||||
|
|
||||||
|
// Build ContentInfo SEQUENCE
|
||||||
|
var contentInfoContent []byte
|
||||||
|
contentInfoContent = append(contentInfoContent, oidSignedData...)
|
||||||
|
contentInfoContent = append(contentInfoContent, contentField...)
|
||||||
|
contentInfo := asn1WrapSequence(contentInfoContent)
|
||||||
|
|
||||||
|
return contentInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// asn1WrapSequence wraps content in an ASN.1 SEQUENCE tag (0x30).
|
||||||
|
func asn1WrapSequence(content []byte) []byte {
|
||||||
|
return asn1Wrap(0x30, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
// asn1WrapSet wraps content in an ASN.1 SET tag (0x31).
|
||||||
|
func asn1WrapSet(content []byte) []byte {
|
||||||
|
return asn1Wrap(0x31, content)
|
||||||
|
}
|
||||||
|
|
||||||
|
// asn1WrapExplicit wraps content in an ASN.1 context-specific EXPLICIT tag.
|
||||||
|
func asn1WrapExplicit(tag int, content []byte) []byte {
|
||||||
|
return asn1Wrap(byte(0xa0|tag), content)
|
||||||
|
}
|
||||||
|
|
||||||
|
// asn1WrapImplicit wraps content in an ASN.1 context-specific IMPLICIT CONSTRUCTED tag.
|
||||||
|
func asn1WrapImplicit(tag int, content []byte) []byte {
|
||||||
|
return asn1Wrap(byte(0xa0|tag), content)
|
||||||
|
}
|
||||||
|
|
||||||
|
// asn1Wrap wraps content with an ASN.1 tag and length.
|
||||||
|
func asn1Wrap(tag byte, content []byte) []byte {
|
||||||
|
length := len(content)
|
||||||
|
var result []byte
|
||||||
|
result = append(result, tag)
|
||||||
|
result = append(result, asn1EncodeLength(length)...)
|
||||||
|
result = append(result, content...)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// asn1EncodeLength encodes a length in ASN.1 DER format.
|
||||||
|
func asn1EncodeLength(length int) []byte {
|
||||||
|
if length < 0x80 {
|
||||||
|
return []byte{byte(length)}
|
||||||
|
}
|
||||||
|
// Long form
|
||||||
|
var lengthBytes []byte
|
||||||
|
l := length
|
||||||
|
for l > 0 {
|
||||||
|
lengthBytes = append([]byte{byte(l & 0xff)}, lengthBytes...)
|
||||||
|
l >>= 8
|
||||||
|
}
|
||||||
|
return append([]byte{byte(0x80 | len(lengthBytes))}, lengthBytes...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,398 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"crypto/elliptic"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/x509"
|
||||||
|
"crypto/x509/pkix"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/pem"
|
||||||
|
"errors"
|
||||||
|
"math/big"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/shankar0123/certctl/internal/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
// mockESTService implements ESTService for testing.
|
||||||
|
type mockESTService struct {
|
||||||
|
CACertPEM string
|
||||||
|
CACertErr error
|
||||||
|
EnrollResult *domain.ESTEnrollResult
|
||||||
|
EnrollErr error
|
||||||
|
CSRAttrs []byte
|
||||||
|
CSRAttrsErr error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockESTService) GetCACerts(ctx context.Context) (string, error) {
|
||||||
|
return m.CACertPEM, m.CACertErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockESTService) SimpleEnroll(ctx context.Context, csrPEM string) (*domain.ESTEnrollResult, error) {
|
||||||
|
return m.EnrollResult, m.EnrollErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockESTService) SimpleReEnroll(ctx context.Context, csrPEM string) (*domain.ESTEnrollResult, error) {
|
||||||
|
return m.EnrollResult, m.EnrollErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockESTService) GetCSRAttrs(ctx context.Context) ([]byte, error) {
|
||||||
|
return m.CSRAttrs, m.CSRAttrsErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateTestCSRPEM creates a valid ECDSA P-256 CSR for testing.
|
||||||
|
func generateTestCSRPEM(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to generate key: %v", err)
|
||||||
|
}
|
||||||
|
template := &x509.CertificateRequest{
|
||||||
|
Subject: pkix.Name{CommonName: "test.example.com"},
|
||||||
|
DNSNames: []string{"test.example.com", "www.example.com"},
|
||||||
|
}
|
||||||
|
csrDER, err := x509.CreateCertificateRequest(rand.Reader, template, key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create CSR: %v", err)
|
||||||
|
}
|
||||||
|
return string(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csrDER}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateTestCSRBase64DER creates a valid base64-encoded DER CSR for EST wire format.
|
||||||
|
func generateTestCSRBase64DER(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to generate key: %v", err)
|
||||||
|
}
|
||||||
|
template := &x509.CertificateRequest{
|
||||||
|
Subject: pkix.Name{CommonName: "test.example.com"},
|
||||||
|
DNSNames: []string{"test.example.com"},
|
||||||
|
}
|
||||||
|
csrDER, err := x509.CreateCertificateRequest(rand.Reader, template, key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create CSR: %v", err)
|
||||||
|
}
|
||||||
|
return base64.StdEncoding.EncodeToString(csrDER)
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateTestCertPEM creates a real self-signed certificate PEM for testing.
|
||||||
|
func generateTestCertPEM(t *testing.T) string {
|
||||||
|
t.Helper()
|
||||||
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to generate key: %v", err)
|
||||||
|
}
|
||||||
|
template := &x509.Certificate{
|
||||||
|
SerialNumber: big.NewInt(1),
|
||||||
|
Subject: pkix.Name{CommonName: "Test CA"},
|
||||||
|
NotBefore: time.Now().Add(-1 * time.Hour),
|
||||||
|
NotAfter: time.Now().Add(24 * time.Hour),
|
||||||
|
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign,
|
||||||
|
IsCA: true,
|
||||||
|
BasicConstraintsValid: true,
|
||||||
|
}
|
||||||
|
certDER, err := x509.CreateCertificate(rand.Reader, template, template, &key.PublicKey, key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create certificate: %v", err)
|
||||||
|
}
|
||||||
|
return string(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certDER}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTCACerts_Success(t *testing.T) {
|
||||||
|
certPEM := generateTestCertPEM(t)
|
||||||
|
svc := &mockESTService{
|
||||||
|
CACertPEM: certPEM,
|
||||||
|
}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/.well-known/est/cacerts", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.CACerts(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("expected 200, got %d: %s", w.Code, w.Body.String())
|
||||||
|
}
|
||||||
|
ct := w.Header().Get("Content-Type")
|
||||||
|
if !strings.Contains(ct, "application/pkcs7-mime") {
|
||||||
|
t.Errorf("expected application/pkcs7-mime content type, got %s", ct)
|
||||||
|
}
|
||||||
|
cte := w.Header().Get("Content-Transfer-Encoding")
|
||||||
|
if cte != "base64" {
|
||||||
|
t.Errorf("expected base64 content-transfer-encoding, got %s", cte)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTCACerts_MethodNotAllowed(t *testing.T) {
|
||||||
|
svc := &mockESTService{}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/.well-known/est/cacerts", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.CACerts(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusMethodNotAllowed {
|
||||||
|
t.Errorf("expected 405, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTCACerts_ServiceError(t *testing.T) {
|
||||||
|
svc := &mockESTService{
|
||||||
|
CACertErr: errors.New("issuer unavailable"),
|
||||||
|
}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/.well-known/est/cacerts", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.CACerts(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusInternalServerError {
|
||||||
|
t.Errorf("expected 500, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTSimpleEnroll_Success_PEM(t *testing.T) {
|
||||||
|
csrPEM := generateTestCSRPEM(t)
|
||||||
|
certPEM := generateTestCertPEM(t)
|
||||||
|
svc := &mockESTService{
|
||||||
|
EnrollResult: &domain.ESTEnrollResult{
|
||||||
|
CertPEM: certPEM,
|
||||||
|
ChainPEM: certPEM,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/.well-known/est/simpleenroll", strings.NewReader(csrPEM))
|
||||||
|
req.Header.Set("Content-Type", "application/pkcs10")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.SimpleEnroll(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("expected 200, got %d: %s", w.Code, w.Body.String())
|
||||||
|
}
|
||||||
|
ct := w.Header().Get("Content-Type")
|
||||||
|
if !strings.Contains(ct, "application/pkcs7-mime") {
|
||||||
|
t.Errorf("expected application/pkcs7-mime, got %s", ct)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTSimpleEnroll_Success_Base64DER(t *testing.T) {
|
||||||
|
csrB64 := generateTestCSRBase64DER(t)
|
||||||
|
certPEM := generateTestCertPEM(t)
|
||||||
|
svc := &mockESTService{
|
||||||
|
EnrollResult: &domain.ESTEnrollResult{
|
||||||
|
CertPEM: certPEM,
|
||||||
|
ChainPEM: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/.well-known/est/simpleenroll", strings.NewReader(csrB64))
|
||||||
|
req.Header.Set("Content-Type", "application/pkcs10")
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.SimpleEnroll(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("expected 200, got %d: %s", w.Code, w.Body.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTSimpleEnroll_MethodNotAllowed(t *testing.T) {
|
||||||
|
svc := &mockESTService{}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/.well-known/est/simpleenroll", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.SimpleEnroll(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusMethodNotAllowed {
|
||||||
|
t.Errorf("expected 405, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTSimpleEnroll_EmptyBody(t *testing.T) {
|
||||||
|
svc := &mockESTService{}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/.well-known/est/simpleenroll", strings.NewReader(""))
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.SimpleEnroll(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusBadRequest {
|
||||||
|
t.Errorf("expected 400, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTSimpleEnroll_InvalidCSR(t *testing.T) {
|
||||||
|
svc := &mockESTService{}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/.well-known/est/simpleenroll", strings.NewReader("not-a-valid-csr"))
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.SimpleEnroll(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusBadRequest {
|
||||||
|
t.Errorf("expected 400, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTSimpleEnroll_ServiceError(t *testing.T) {
|
||||||
|
csrPEM := generateTestCSRPEM(t)
|
||||||
|
svc := &mockESTService{
|
||||||
|
EnrollErr: errors.New("issuance failed"),
|
||||||
|
}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/.well-known/est/simpleenroll", strings.NewReader(csrPEM))
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.SimpleEnroll(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusInternalServerError {
|
||||||
|
t.Errorf("expected 500, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTSimpleReEnroll_Success(t *testing.T) {
|
||||||
|
csrPEM := generateTestCSRPEM(t)
|
||||||
|
certPEM := generateTestCertPEM(t)
|
||||||
|
svc := &mockESTService{
|
||||||
|
EnrollResult: &domain.ESTEnrollResult{
|
||||||
|
CertPEM: certPEM,
|
||||||
|
ChainPEM: certPEM,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/.well-known/est/simplereenroll", strings.NewReader(csrPEM))
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.SimpleReEnroll(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("expected 200, got %d: %s", w.Code, w.Body.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTSimpleReEnroll_MethodNotAllowed(t *testing.T) {
|
||||||
|
svc := &mockESTService{}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/.well-known/est/simplereenroll", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.SimpleReEnroll(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusMethodNotAllowed {
|
||||||
|
t.Errorf("expected 405, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTCSRAttrs_NoContent(t *testing.T) {
|
||||||
|
svc := &mockESTService{
|
||||||
|
CSRAttrs: nil,
|
||||||
|
}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/.well-known/est/csrattrs", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.CSRAttrs(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusNoContent {
|
||||||
|
t.Errorf("expected 204, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTCSRAttrs_WithData(t *testing.T) {
|
||||||
|
svc := &mockESTService{
|
||||||
|
CSRAttrs: []byte{0x30, 0x00}, // empty SEQUENCE
|
||||||
|
}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/.well-known/est/csrattrs", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.CSRAttrs(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Errorf("expected 200, got %d", w.Code)
|
||||||
|
}
|
||||||
|
ct := w.Header().Get("Content-Type")
|
||||||
|
if ct != "application/csrattrs" {
|
||||||
|
t.Errorf("expected application/csrattrs, got %s", ct)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTCSRAttrs_MethodNotAllowed(t *testing.T) {
|
||||||
|
svc := &mockESTService{}
|
||||||
|
h := NewESTHandler(svc)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/.well-known/est/csrattrs", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
h.CSRAttrs(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusMethodNotAllowed {
|
||||||
|
t.Errorf("expected 405, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildCertsOnlyPKCS7(t *testing.T) {
|
||||||
|
// Test with a dummy DER certificate
|
||||||
|
dummyCert := []byte{0x30, 0x82, 0x01, 0x00} // minimal ASN.1 SEQUENCE
|
||||||
|
result, err := buildCertsOnlyPKCS7([][]byte{dummyCert})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("buildCertsOnlyPKCS7 failed: %v", err)
|
||||||
|
}
|
||||||
|
if len(result) == 0 {
|
||||||
|
t.Error("expected non-empty PKCS#7 output")
|
||||||
|
}
|
||||||
|
// Verify it starts with SEQUENCE tag
|
||||||
|
if result[0] != 0x30 {
|
||||||
|
t.Errorf("expected PKCS#7 to start with SEQUENCE tag (0x30), got 0x%02x", result[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPemToDERChain(t *testing.T) {
|
||||||
|
pemData := generateTestCertPEM(t)
|
||||||
|
certs, err := pemToDERChain(pemData)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("pemToDERChain failed: %v", err)
|
||||||
|
}
|
||||||
|
if len(certs) != 1 {
|
||||||
|
t.Errorf("expected 1 cert, got %d", len(certs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPemToDERChain_NoCerts(t *testing.T) {
|
||||||
|
_, err := pemToDERChain("not a PEM")
|
||||||
|
if err == nil {
|
||||||
|
t.Error("expected error for invalid PEM")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestASN1EncodeLength(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
length int
|
||||||
|
expected []byte
|
||||||
|
}{
|
||||||
|
{0, []byte{0x00}},
|
||||||
|
{1, []byte{0x01}},
|
||||||
|
{127, []byte{0x7f}},
|
||||||
|
{128, []byte{0x81, 0x80}},
|
||||||
|
{256, []byte{0x82, 0x01, 0x00}},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
result := asn1EncodeLength(tt.length)
|
||||||
|
if len(result) != len(tt.expected) {
|
||||||
|
t.Errorf("asn1EncodeLength(%d): expected %d bytes, got %d", tt.length, len(tt.expected), len(result))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for i := range result {
|
||||||
|
if result[i] != tt.expected[i] {
|
||||||
|
t.Errorf("asn1EncodeLength(%d): byte %d: expected 0x%02x, got 0x%02x", tt.length, i, tt.expected[i], result[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -184,7 +184,13 @@ func (h IssuerHandler) DeleteIssuer(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := h.svc.DeleteIssuer(id); err != nil {
|
if err := h.svc.DeleteIssuer(id); err != nil {
|
||||||
ErrorWithRequestID(w, http.StatusInternalServerError, "Failed to delete issuer", requestID)
|
if strings.Contains(err.Error(), "violates foreign key") || strings.Contains(err.Error(), "RESTRICT") {
|
||||||
|
ErrorWithRequestID(w, http.StatusConflict, "Cannot delete issuer: certificates are still using this issuer", requestID)
|
||||||
|
} else if strings.Contains(err.Error(), "not found") {
|
||||||
|
ErrorWithRequestID(w, http.StatusNotFound, "Issuer not found", requestID)
|
||||||
|
} else {
|
||||||
|
ErrorWithRequestID(w, http.StatusInternalServerError, "Failed to delete issuer", requestID)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -183,7 +183,13 @@ func (h OwnerHandler) DeleteOwner(w http.ResponseWriter, r *http.Request) {
|
|||||||
id = parts[0]
|
id = parts[0]
|
||||||
|
|
||||||
if err := h.svc.DeleteOwner(id); err != nil {
|
if err := h.svc.DeleteOwner(id); err != nil {
|
||||||
ErrorWithRequestID(w, http.StatusInternalServerError, "Failed to delete owner", requestID)
|
if strings.Contains(err.Error(), "violates foreign key") || strings.Contains(err.Error(), "RESTRICT") {
|
||||||
|
ErrorWithRequestID(w, http.StatusConflict, "Cannot delete owner: certificates are still assigned to this owner", requestID)
|
||||||
|
} else if strings.Contains(err.Error(), "not found") {
|
||||||
|
ErrorWithRequestID(w, http.StatusNotFound, "Owner not found", requestID)
|
||||||
|
} else {
|
||||||
|
ErrorWithRequestID(w, http.StatusInternalServerError, "Failed to delete owner", requestID)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,6 +209,16 @@ func (r *Router) RegisterHandlers(
|
|||||||
r.Register("POST /api/v1/network-scan-targets/{id}/scan", http.HandlerFunc(networkScan.TriggerNetworkScan))
|
r.Register("POST /api/v1/network-scan-targets/{id}/scan", http.HandlerFunc(networkScan.TriggerNetworkScan))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RegisterESTHandlers sets up EST (RFC 7030) routes under /.well-known/est/.
|
||||||
|
// EST endpoints use a separate middleware chain (no API key auth — EST uses TLS client certs).
|
||||||
|
func (r *Router) RegisterESTHandlers(est handler.ESTHandler) {
|
||||||
|
// EST endpoints per RFC 7030 Section 3.2.2
|
||||||
|
r.Register("GET /.well-known/est/cacerts", http.HandlerFunc(est.CACerts))
|
||||||
|
r.Register("POST /.well-known/est/simpleenroll", http.HandlerFunc(est.SimpleEnroll))
|
||||||
|
r.Register("POST /.well-known/est/simplereenroll", http.HandlerFunc(est.SimpleReEnroll))
|
||||||
|
r.Register("GET /.well-known/est/csrattrs", http.HandlerFunc(est.CSRAttrs))
|
||||||
|
}
|
||||||
|
|
||||||
// GetMux returns the underlying http.ServeMux for direct access if needed.
|
// GetMux returns the underlying http.ServeMux for direct access if needed.
|
||||||
func (r *Router) GetMux() *http.ServeMux {
|
func (r *Router) GetMux() *http.ServeMux {
|
||||||
return r.mux
|
return r.mux
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type Config struct {
|
|||||||
CA CAConfig
|
CA CAConfig
|
||||||
Notifiers NotifierConfig
|
Notifiers NotifierConfig
|
||||||
NetworkScan NetworkScanConfig
|
NetworkScan NetworkScanConfig
|
||||||
|
EST ESTConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifierConfig contains configuration for notification connectors.
|
// NotifierConfig contains configuration for notification connectors.
|
||||||
@@ -81,6 +82,14 @@ type OpenSSLConfig struct {
|
|||||||
TimeoutSeconds int
|
TimeoutSeconds int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ESTConfig controls the RFC 7030 Enrollment over Secure Transport server.
|
||||||
|
type ESTConfig struct {
|
||||||
|
Enabled bool // Enable EST endpoints (default false)
|
||||||
|
IssuerID string // Which issuer connector to use for EST enrollment (e.g., "iss-local")
|
||||||
|
// ProfileID optionally constrains EST enrollments to a specific certificate profile.
|
||||||
|
ProfileID string
|
||||||
|
}
|
||||||
|
|
||||||
// NetworkScanConfig controls the server-side active TLS scanner.
|
// NetworkScanConfig controls the server-side active TLS scanner.
|
||||||
type NetworkScanConfig struct {
|
type NetworkScanConfig struct {
|
||||||
Enabled bool // Enable network scanning (default false)
|
Enabled bool // Enable network scanning (default false)
|
||||||
@@ -189,6 +198,11 @@ func Load() (*Config, error) {
|
|||||||
Enabled: getEnvBool("CERTCTL_NETWORK_SCAN_ENABLED", false),
|
Enabled: getEnvBool("CERTCTL_NETWORK_SCAN_ENABLED", false),
|
||||||
ScanInterval: getEnvDuration("CERTCTL_NETWORK_SCAN_INTERVAL", 6*time.Hour),
|
ScanInterval: getEnvDuration("CERTCTL_NETWORK_SCAN_INTERVAL", 6*time.Hour),
|
||||||
},
|
},
|
||||||
|
EST: ESTConfig{
|
||||||
|
Enabled: getEnvBool("CERTCTL_EST_ENABLED", false),
|
||||||
|
IssuerID: getEnv("CERTCTL_EST_ISSUER_ID", "iss-local"),
|
||||||
|
ProfileID: getEnv("CERTCTL_EST_PROFILE_ID", ""),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cfg.Validate(); err != nil {
|
if err := cfg.Validate(); err != nil {
|
||||||
|
|||||||
@@ -619,3 +619,8 @@ func (c *Connector) GenerateCRL(ctx context.Context, revokedCerts []issuer.Revok
|
|||||||
func (c *Connector) SignOCSPResponse(ctx context.Context, req issuer.OCSPSignRequest) ([]byte, error) {
|
func (c *Connector) SignOCSPResponse(ctx context.Context, req issuer.OCSPSignRequest) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("ACME issuers do not support OCSP response signing")
|
return nil, fmt.Errorf("ACME issuers do not support OCSP response signing")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCACertPEM is not supported by ACME issuers (the CA chain is returned per-issuance).
|
||||||
|
func (c *Connector) GetCACertPEM(ctx context.Context) (string, error) {
|
||||||
|
return "", fmt.Errorf("ACME issuers do not provide a static CA certificate; chain is returned per-issuance")
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ type Connector interface {
|
|||||||
// SignOCSPResponse signs an OCSP response for the given certificate serial.
|
// SignOCSPResponse signs an OCSP response for the given certificate serial.
|
||||||
// Returns nil if the issuer does not support OCSP (e.g., ACME).
|
// Returns nil if the issuer does not support OCSP (e.g., ACME).
|
||||||
SignOCSPResponse(ctx context.Context, req OCSPSignRequest) ([]byte, error)
|
SignOCSPResponse(ctx context.Context, req OCSPSignRequest) ([]byte, error)
|
||||||
|
|
||||||
|
// GetCACertPEM returns the PEM-encoded CA certificate chain for this issuer.
|
||||||
|
// Used by the EST /cacerts endpoint. Returns empty string if not available.
|
||||||
|
GetCACertPEM(ctx context.Context) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssuanceRequest contains the parameters for issuing a new certificate.
|
// IssuanceRequest contains the parameters for issuing a new certificate.
|
||||||
|
|||||||
@@ -664,3 +664,12 @@ func (c *Connector) SignOCSPResponse(ctx context.Context, req issuer.OCSPSignReq
|
|||||||
|
|
||||||
return respBytes, nil
|
return respBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCACertPEM returns the PEM-encoded CA certificate for this issuer.
|
||||||
|
// Used by the EST /cacerts endpoint to distribute the CA trust chain.
|
||||||
|
func (c *Connector) GetCACertPEM(ctx context.Context) (string, error) {
|
||||||
|
if err := c.ensureCA(ctx); err != nil {
|
||||||
|
return "", fmt.Errorf("CA initialization failed: %w", err)
|
||||||
|
}
|
||||||
|
return c.caCertPEM, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -358,6 +358,11 @@ func (c *Connector) SignOCSPResponse(ctx context.Context, req issuer.OCSPSignReq
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCACertPEM is not supported by the custom CA connector (no CA cert access).
|
||||||
|
func (c *Connector) GetCACertPEM(ctx context.Context) (string, error) {
|
||||||
|
return "", fmt.Errorf("custom CA connector does not provide CA certificate access")
|
||||||
|
}
|
||||||
|
|
||||||
// --- Helper Methods ---
|
// --- Helper Methods ---
|
||||||
|
|
||||||
// writeTempFile writes data to a temporary file and returns its path.
|
// writeTempFile writes data to a temporary file and returns its path.
|
||||||
|
|||||||
@@ -467,5 +467,10 @@ func (c *Connector) SignOCSPResponse(ctx context.Context, req issuer.OCSPSignReq
|
|||||||
return nil, fmt.Errorf("step-ca provides its own OCSP responder; use step-ca's /ocsp directly")
|
return nil, fmt.Errorf("step-ca provides its own OCSP responder; use step-ca's /ocsp directly")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCACertPEM is not directly supported; step-ca serves its own /root endpoint.
|
||||||
|
func (c *Connector) GetCACertPEM(ctx context.Context) (string, error) {
|
||||||
|
return "", fmt.Errorf("step-ca serves its own CA certificate at /root; use step-ca's endpoint directly")
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure Connector implements the issuer.Connector interface.
|
// Ensure Connector implements the issuer.Connector interface.
|
||||||
var _ issuer.Connector = (*Connector)(nil)
|
var _ issuer.Connector = (*Connector)(nil)
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
// ESTEnrollResult holds the result of an EST (RFC 7030) enrollment operation.
|
||||||
|
type ESTEnrollResult struct {
|
||||||
|
CertPEM string `json:"cert_pem"` // PEM-encoded signed certificate
|
||||||
|
ChainPEM string `json:"chain_pem"` // PEM-encoded CA chain
|
||||||
|
}
|
||||||
@@ -2,9 +2,17 @@ package integration
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"crypto/elliptic"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/x509"
|
||||||
|
"crypto/x509/pkix"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/pem"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -892,3 +900,214 @@ func TestM20EnhancedQueryAPI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generateE2ECSRPEM creates a valid ECDSA P-256 CSR PEM for integration testing.
|
||||||
|
func generateE2ECSRPEM(t *testing.T, cn string, sans []string) string {
|
||||||
|
t.Helper()
|
||||||
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("generate key: %v", err)
|
||||||
|
}
|
||||||
|
template := &x509.CertificateRequest{
|
||||||
|
Subject: pkix.Name{CommonName: cn},
|
||||||
|
DNSNames: sans,
|
||||||
|
}
|
||||||
|
csrDER, err := x509.CreateCertificateRequest(rand.Reader, template, key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("create CSR: %v", err)
|
||||||
|
}
|
||||||
|
return string(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csrDER}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// generateE2ECSRBase64DER creates a valid base64-encoded DER CSR for EST wire format testing.
|
||||||
|
func generateE2ECSRBase64DER(t *testing.T, cn string, sans []string) string {
|
||||||
|
t.Helper()
|
||||||
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("generate key: %v", err)
|
||||||
|
}
|
||||||
|
template := &x509.CertificateRequest{
|
||||||
|
Subject: pkix.Name{CommonName: cn},
|
||||||
|
DNSNames: sans,
|
||||||
|
}
|
||||||
|
csrDER, err := x509.CreateCertificateRequest(rand.Reader, template, key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("create CSR: %v", err)
|
||||||
|
}
|
||||||
|
return base64.StdEncoding.EncodeToString(csrDER)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestESTEndpoints exercises the EST (RFC 7030) enrollment endpoints end-to-end (M23).
|
||||||
|
func TestESTEndpoints(t *testing.T) {
|
||||||
|
server, _, _, _ := setupTestServer(t)
|
||||||
|
|
||||||
|
// ===========================
|
||||||
|
// GET /cacerts — CA certificate chain
|
||||||
|
// ===========================
|
||||||
|
t.Run("GetCACerts_Success", func(t *testing.T) {
|
||||||
|
resp, err := http.Get(server.URL + "/.well-known/est/cacerts")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
t.Fatalf("expected 200, got %d: %s", resp.StatusCode, string(bodyBytes))
|
||||||
|
}
|
||||||
|
ct := resp.Header.Get("Content-Type")
|
||||||
|
if !strings.Contains(ct, "application/pkcs7-mime") {
|
||||||
|
t.Errorf("expected application/pkcs7-mime content type, got %s", ct)
|
||||||
|
}
|
||||||
|
cte := resp.Header.Get("Content-Transfer-Encoding")
|
||||||
|
if cte != "base64" {
|
||||||
|
t.Errorf("expected base64 content-transfer-encoding, got %s", cte)
|
||||||
|
}
|
||||||
|
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
if len(bodyBytes) == 0 {
|
||||||
|
t.Error("expected non-empty PKCS#7 response body")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("GetCACerts_MethodNotAllowed", func(t *testing.T) {
|
||||||
|
resp, err := http.Post(server.URL+"/.well-known/est/cacerts", "application/json", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusMethodNotAllowed {
|
||||||
|
t.Errorf("expected 405, got %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// ===========================
|
||||||
|
// POST /simpleenroll — certificate enrollment
|
||||||
|
// ===========================
|
||||||
|
t.Run("SimpleEnroll_PEM_Success", func(t *testing.T) {
|
||||||
|
csrPEM := generateE2ECSRPEM(t, "est-test.example.com", []string{"est-test.example.com"})
|
||||||
|
resp, err := http.Post(server.URL+"/.well-known/est/simpleenroll", "application/pkcs10", strings.NewReader(csrPEM))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
t.Fatalf("expected 200, got %d: %s", resp.StatusCode, string(bodyBytes))
|
||||||
|
}
|
||||||
|
ct := resp.Header.Get("Content-Type")
|
||||||
|
if !strings.Contains(ct, "application/pkcs7-mime") {
|
||||||
|
t.Errorf("expected application/pkcs7-mime, got %s", ct)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SimpleEnroll_Base64DER_Success", func(t *testing.T) {
|
||||||
|
csrB64 := generateE2ECSRBase64DER(t, "est-der.example.com", []string{"est-der.example.com"})
|
||||||
|
resp, err := http.Post(server.URL+"/.well-known/est/simpleenroll", "application/pkcs10", strings.NewReader(csrB64))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
t.Fatalf("expected 200, got %d: %s", resp.StatusCode, string(bodyBytes))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SimpleEnroll_EmptyBody", func(t *testing.T) {
|
||||||
|
resp, err := http.Post(server.URL+"/.well-known/est/simpleenroll", "application/pkcs10", strings.NewReader(""))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusBadRequest {
|
||||||
|
t.Errorf("expected 400 for empty body, got %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SimpleEnroll_InvalidCSR", func(t *testing.T) {
|
||||||
|
resp, err := http.Post(server.URL+"/.well-known/est/simpleenroll", "application/pkcs10", strings.NewReader("not-a-valid-csr"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusBadRequest {
|
||||||
|
t.Errorf("expected 400 for invalid CSR, got %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SimpleEnroll_MissingCN", func(t *testing.T) {
|
||||||
|
csrPEM := generateE2ECSRPEM(t, "", []string{"no-cn.example.com"})
|
||||||
|
resp, err := http.Post(server.URL+"/.well-known/est/simpleenroll", "application/pkcs10", strings.NewReader(csrPEM))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
// Should fail because EST requires a Common Name
|
||||||
|
if resp.StatusCode == http.StatusOK {
|
||||||
|
t.Error("expected error for CSR without Common Name")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SimpleEnroll_MethodNotAllowed", func(t *testing.T) {
|
||||||
|
resp, err := http.Get(server.URL + "/.well-known/est/simpleenroll")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusMethodNotAllowed {
|
||||||
|
t.Errorf("expected 405, got %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// ===========================
|
||||||
|
// POST /simplereenroll — certificate re-enrollment
|
||||||
|
// ===========================
|
||||||
|
t.Run("SimpleReEnroll_Success", func(t *testing.T) {
|
||||||
|
csrPEM := generateE2ECSRPEM(t, "renew-est.example.com", []string{"renew-est.example.com"})
|
||||||
|
resp, err := http.Post(server.URL+"/.well-known/est/simplereenroll", "application/pkcs10", strings.NewReader(csrPEM))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
t.Fatalf("expected 200, got %d: %s", resp.StatusCode, string(bodyBytes))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SimpleReEnroll_MethodNotAllowed", func(t *testing.T) {
|
||||||
|
resp, err := http.Get(server.URL + "/.well-known/est/simplereenroll")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusMethodNotAllowed {
|
||||||
|
t.Errorf("expected 405, got %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// ===========================
|
||||||
|
// GET /csrattrs — CSR attributes
|
||||||
|
// ===========================
|
||||||
|
t.Run("GetCSRAttrs_NoContent", func(t *testing.T) {
|
||||||
|
resp, err := http.Get(server.URL + "/.well-known/est/csrattrs")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
// Default implementation returns nil attrs → 204 No Content
|
||||||
|
if resp.StatusCode != http.StatusNoContent {
|
||||||
|
t.Errorf("expected 204, got %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("GetCSRAttrs_MethodNotAllowed", func(t *testing.T) {
|
||||||
|
resp, err := http.Post(server.URL+"/.well-known/est/csrattrs", "application/json", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("request failed: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode != http.StatusMethodNotAllowed {
|
||||||
|
t.Errorf("expected 405, got %d", resp.StatusCode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ func TestCertificateLifecycle(t *testing.T) {
|
|||||||
discoveryHandler := handler.NewDiscoveryHandler(&mockDiscoveryService{})
|
discoveryHandler := handler.NewDiscoveryHandler(&mockDiscoveryService{})
|
||||||
networkScanHandler := handler.NewNetworkScanHandler(&mockNetworkScanService{})
|
networkScanHandler := handler.NewNetworkScanHandler(&mockNetworkScanService{})
|
||||||
|
|
||||||
|
// EST handler — uses real Local CA issuer via ESTService
|
||||||
|
estService := service.NewESTService("iss-local", issuerRegistry["iss-local"], auditService, logger)
|
||||||
|
estHandler := handler.NewESTHandler(estService)
|
||||||
|
|
||||||
// Create router and register handlers
|
// Create router and register handlers
|
||||||
r := router.New()
|
r := router.New()
|
||||||
r.RegisterHandlers(
|
r.RegisterHandlers(
|
||||||
@@ -103,6 +107,7 @@ func TestCertificateLifecycle(t *testing.T) {
|
|||||||
discoveryHandler,
|
discoveryHandler,
|
||||||
networkScanHandler,
|
networkScanHandler,
|
||||||
)
|
)
|
||||||
|
r.RegisterESTHandlers(estHandler)
|
||||||
|
|
||||||
// Create test server
|
// Create test server
|
||||||
server := httptest.NewServer(r)
|
server := httptest.NewServer(r)
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ func setupTestServer(t *testing.T) (*httptest.Server, *mockCertificateRepository
|
|||||||
discoveryHandler := handler.NewDiscoveryHandler(&mockDiscoveryService{})
|
discoveryHandler := handler.NewDiscoveryHandler(&mockDiscoveryService{})
|
||||||
networkScanHandler := handler.NewNetworkScanHandler(&mockNetworkScanService{})
|
networkScanHandler := handler.NewNetworkScanHandler(&mockNetworkScanService{})
|
||||||
|
|
||||||
|
// EST handler — uses real Local CA issuer via ESTService
|
||||||
|
estService := service.NewESTService("iss-local", issuerRegistry["iss-local"], auditService, logger)
|
||||||
|
estHandler := handler.NewESTHandler(estService)
|
||||||
|
|
||||||
r := router.New()
|
r := router.New()
|
||||||
r.RegisterHandlers(
|
r.RegisterHandlers(
|
||||||
certificateHandler,
|
certificateHandler,
|
||||||
@@ -95,6 +99,7 @@ func setupTestServer(t *testing.T) (*httptest.Server, *mockCertificateRepository
|
|||||||
discoveryHandler,
|
discoveryHandler,
|
||||||
networkScanHandler,
|
networkScanHandler,
|
||||||
)
|
)
|
||||||
|
r.RegisterESTHandlers(estHandler)
|
||||||
|
|
||||||
server := httptest.NewServer(r)
|
server := httptest.NewServer(r)
|
||||||
t.Cleanup(func() { server.Close() })
|
t.Cleanup(func() { server.Close() })
|
||||||
|
|||||||
@@ -0,0 +1,153 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/x509"
|
||||||
|
"encoding/pem"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/shankar0123/certctl/internal/domain"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ESTService implements the EST (RFC 7030) enrollment protocol.
|
||||||
|
// It delegates certificate operations to an existing IssuerConnector and records
|
||||||
|
// enrollment events in the audit trail.
|
||||||
|
type ESTService struct {
|
||||||
|
issuer IssuerConnector
|
||||||
|
issuerID string
|
||||||
|
auditService *AuditService
|
||||||
|
logger *slog.Logger
|
||||||
|
profileID string // optional: constrain enrollments to a specific profile
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewESTService creates a new ESTService for the given issuer connector.
|
||||||
|
func NewESTService(issuerID string, issuer IssuerConnector, auditService *AuditService, logger *slog.Logger) *ESTService {
|
||||||
|
return &ESTService{
|
||||||
|
issuer: issuer,
|
||||||
|
issuerID: issuerID,
|
||||||
|
auditService: auditService,
|
||||||
|
logger: logger,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetProfileID constrains EST enrollments to a specific certificate profile.
|
||||||
|
func (s *ESTService) SetProfileID(profileID string) {
|
||||||
|
s.profileID = profileID
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCACerts returns the PEM-encoded CA certificate chain for this EST server.
|
||||||
|
// RFC 7030 Section 4.1: /cacerts distributes the current CA certificates.
|
||||||
|
func (s *ESTService) GetCACerts(ctx context.Context) (string, error) {
|
||||||
|
caPEM, err := s.issuer.GetCACertPEM(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to get CA certificates from issuer %s: %w", s.issuerID, err)
|
||||||
|
}
|
||||||
|
if caPEM == "" {
|
||||||
|
return "", fmt.Errorf("issuer %s does not provide CA certificates for EST", s.issuerID)
|
||||||
|
}
|
||||||
|
return caPEM, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SimpleEnroll processes an initial enrollment request.
|
||||||
|
// RFC 7030 Section 4.2: /simpleenroll accepts a PKCS#10 CSR and returns a signed cert.
|
||||||
|
func (s *ESTService) SimpleEnroll(ctx context.Context, csrPEM string) (*domain.ESTEnrollResult, error) {
|
||||||
|
return s.processEnrollment(ctx, csrPEM, "est_simple_enroll")
|
||||||
|
}
|
||||||
|
|
||||||
|
// SimpleReEnroll processes a re-enrollment request.
|
||||||
|
// RFC 7030 Section 4.2.2: /simplereenroll is functionally identical to /simpleenroll
|
||||||
|
// but is used when renewing an existing certificate.
|
||||||
|
func (s *ESTService) SimpleReEnroll(ctx context.Context, csrPEM string) (*domain.ESTEnrollResult, error) {
|
||||||
|
return s.processEnrollment(ctx, csrPEM, "est_simple_reenroll")
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCSRAttrs returns the CSR attributes the server wants clients to include.
|
||||||
|
// RFC 7030 Section 4.5: /csrattrs tells clients what to put in their CSR.
|
||||||
|
// Returns nil if no specific attributes are required.
|
||||||
|
func (s *ESTService) GetCSRAttrs(ctx context.Context) ([]byte, error) {
|
||||||
|
// For now, we don't require specific CSR attributes.
|
||||||
|
// In the future, this could return key type constraints from the profile.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// processEnrollment handles the common enrollment logic for both simpleenroll and simplereenroll.
|
||||||
|
func (s *ESTService) processEnrollment(ctx context.Context, csrPEM string, auditAction string) (*domain.ESTEnrollResult, error) {
|
||||||
|
// Parse the CSR to extract CN and SANs
|
||||||
|
block, _ := pem.Decode([]byte(csrPEM))
|
||||||
|
if block == nil {
|
||||||
|
return nil, fmt.Errorf("invalid CSR PEM")
|
||||||
|
}
|
||||||
|
|
||||||
|
csr, err := x509.ParseCertificateRequest(block.Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to parse CSR: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := csr.CheckSignature(); err != nil {
|
||||||
|
return nil, fmt.Errorf("CSR signature verification failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
commonName := csr.Subject.CommonName
|
||||||
|
if commonName == "" {
|
||||||
|
return nil, fmt.Errorf("CSR must include a Common Name")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect SANs
|
||||||
|
var sans []string
|
||||||
|
for _, dns := range csr.DNSNames {
|
||||||
|
sans = append(sans, dns)
|
||||||
|
}
|
||||||
|
for _, ip := range csr.IPAddresses {
|
||||||
|
sans = append(sans, ip.String())
|
||||||
|
}
|
||||||
|
for _, email := range csr.EmailAddresses {
|
||||||
|
sans = append(sans, email)
|
||||||
|
}
|
||||||
|
for _, uri := range csr.URIs {
|
||||||
|
sans = append(sans, uri.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
s.logger.Info("EST enrollment request",
|
||||||
|
"action", auditAction,
|
||||||
|
"common_name", commonName,
|
||||||
|
"sans", strings.Join(sans, ","),
|
||||||
|
"issuer", s.issuerID)
|
||||||
|
|
||||||
|
// Issue the certificate via the configured issuer connector
|
||||||
|
result, err := s.issuer.IssueCertificate(ctx, commonName, sans, csrPEM)
|
||||||
|
if err != nil {
|
||||||
|
s.logger.Error("EST enrollment failed",
|
||||||
|
"action", auditAction,
|
||||||
|
"common_name", commonName,
|
||||||
|
"error", err)
|
||||||
|
return nil, fmt.Errorf("certificate issuance failed: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Audit the enrollment
|
||||||
|
if s.auditService != nil {
|
||||||
|
details := map[string]interface{}{
|
||||||
|
"common_name": commonName,
|
||||||
|
"sans": sans,
|
||||||
|
"issuer_id": s.issuerID,
|
||||||
|
"serial": result.Serial,
|
||||||
|
"protocol": "EST",
|
||||||
|
}
|
||||||
|
if s.profileID != "" {
|
||||||
|
details["profile_id"] = s.profileID
|
||||||
|
}
|
||||||
|
_ = s.auditService.RecordEvent(ctx, "est-client", "system", auditAction, "certificate", result.Serial, details)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.logger.Info("EST enrollment successful",
|
||||||
|
"action", auditAction,
|
||||||
|
"common_name", commonName,
|
||||||
|
"serial", result.Serial,
|
||||||
|
"not_after", result.NotAfter)
|
||||||
|
|
||||||
|
return &domain.ESTEnrollResult{
|
||||||
|
CertPEM: result.CertPEM,
|
||||||
|
ChainPEM: result.ChainPEM,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"crypto/elliptic"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/x509"
|
||||||
|
"crypto/x509/pkix"
|
||||||
|
"encoding/pem"
|
||||||
|
"errors"
|
||||||
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// generateCSRPEM creates a valid ECDSA P-256 CSR for testing.
|
||||||
|
func generateCSRPEM(t *testing.T, cn string, sans []string) string {
|
||||||
|
t.Helper()
|
||||||
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("generate key: %v", err)
|
||||||
|
}
|
||||||
|
template := &x509.CertificateRequest{
|
||||||
|
Subject: pkix.Name{CommonName: cn},
|
||||||
|
DNSNames: sans,
|
||||||
|
}
|
||||||
|
csrDER, err := x509.CreateCertificateRequest(rand.Reader, template, key)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("create CSR: %v", err)
|
||||||
|
}
|
||||||
|
return string(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csrDER}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_GetCACerts_Success(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{}
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, nil, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
|
||||||
|
caPEM, err := svc.GetCACerts(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if caPEM == "" {
|
||||||
|
t.Error("expected non-empty CA PEM")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_GetCACerts_IssuerError(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{Err: errors.New("CA unavailable")}
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, nil, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
|
||||||
|
_, err := svc.GetCACerts(context.Background())
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "CA unavailable") {
|
||||||
|
t.Errorf("expected error to contain 'CA unavailable', got: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_SimpleEnroll_Success(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{}
|
||||||
|
auditRepo := newMockAuditRepository()
|
||||||
|
auditSvc := NewAuditService(auditRepo)
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, auditSvc, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
|
||||||
|
csrPEM := generateCSRPEM(t, "test.example.com", []string{"test.example.com"})
|
||||||
|
|
||||||
|
result, err := svc.SimpleEnroll(context.Background(), csrPEM)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if result == nil {
|
||||||
|
t.Fatal("expected non-nil result")
|
||||||
|
}
|
||||||
|
if result.CertPEM == "" {
|
||||||
|
t.Error("expected non-empty CertPEM")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify audit event was recorded
|
||||||
|
if len(auditRepo.Events) == 0 {
|
||||||
|
t.Error("expected audit event to be recorded")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_SimpleEnroll_InvalidCSR(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{}
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, nil, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
|
||||||
|
_, err := svc.SimpleEnroll(context.Background(), "not-valid-pem")
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error for invalid CSR")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_SimpleEnroll_MissingCN(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{}
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, nil, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
|
||||||
|
csrPEM := generateCSRPEM(t, "", []string{"test.example.com"})
|
||||||
|
|
||||||
|
_, err := svc.SimpleEnroll(context.Background(), csrPEM)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error for missing CN")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "Common Name") {
|
||||||
|
t.Errorf("expected 'Common Name' in error, got: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_SimpleEnroll_IssuerError(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{Err: errors.New("issuance failed")}
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, nil, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
|
||||||
|
csrPEM := generateCSRPEM(t, "test.example.com", nil)
|
||||||
|
|
||||||
|
_, err := svc.SimpleEnroll(context.Background(), csrPEM)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected error")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "issuance failed") {
|
||||||
|
t.Errorf("expected 'issuance failed', got: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_SimpleReEnroll_Success(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{}
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, nil, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
|
||||||
|
csrPEM := generateCSRPEM(t, "renew.example.com", []string{"renew.example.com"})
|
||||||
|
|
||||||
|
result, err := svc.SimpleReEnroll(context.Background(), csrPEM)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if result == nil {
|
||||||
|
t.Fatal("expected non-nil result")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_GetCSRAttrs_Empty(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{}
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, nil, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
|
||||||
|
attrs, err := svc.GetCSRAttrs(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if attrs != nil {
|
||||||
|
t.Errorf("expected nil attrs, got %v", attrs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestESTService_SimpleEnroll_WithProfile(t *testing.T) {
|
||||||
|
mockIssuer := &mockIssuerConnector{}
|
||||||
|
auditRepo := newMockAuditRepository()
|
||||||
|
auditSvc := NewAuditService(auditRepo)
|
||||||
|
svc := NewESTService("iss-local", mockIssuer, auditSvc, slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})))
|
||||||
|
svc.SetProfileID("profile-wifi-client")
|
||||||
|
|
||||||
|
csrPEM := generateCSRPEM(t, "device.example.com", nil)
|
||||||
|
|
||||||
|
result, err := svc.SimpleEnroll(context.Background(), csrPEM)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if result == nil {
|
||||||
|
t.Fatal("expected non-nil result")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify audit event includes profile_id
|
||||||
|
if len(auditRepo.Events) == 0 {
|
||||||
|
t.Fatal("expected audit event")
|
||||||
|
}
|
||||||
|
lastEvent := auditRepo.Events[len(auditRepo.Events)-1]
|
||||||
|
if lastEvent.Details == nil {
|
||||||
|
t.Fatal("expected audit details")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -95,3 +95,8 @@ func (a *IssuerConnectorAdapter) SignOCSPResponse(ctx context.Context, req OCSPS
|
|||||||
NextUpdate: req.NextUpdate,
|
NextUpdate: req.NextUpdate,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCACertPEM delegates to the underlying connector.
|
||||||
|
func (a *IssuerConnectorAdapter) GetCACertPEM(ctx context.Context) (string, error) {
|
||||||
|
return a.connector.GetCACertPEM(ctx)
|
||||||
|
}
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ func (m *mockConnectorLayerIssuer) SignOCSPResponse(ctx context.Context, req iss
|
|||||||
return []byte("mock-ocsp-response"), nil
|
return []byte("mock-ocsp-response"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockConnectorLayerIssuer) GetCACertPEM(ctx context.Context) (string, error) {
|
||||||
|
return "-----BEGIN CERTIFICATE-----\nmock-ca-cert\n-----END CERTIFICATE-----", nil
|
||||||
|
}
|
||||||
|
|
||||||
// Tests for IssueCertificate
|
// Tests for IssueCertificate
|
||||||
|
|
||||||
func TestIssuerConnectorAdapter_IssueCertificate_Success(t *testing.T) {
|
func TestIssuerConnectorAdapter_IssueCertificate_Success(t *testing.T) {
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ type IssuerConnector interface {
|
|||||||
GenerateCRL(ctx context.Context, revokedCerts []CRLEntry) ([]byte, error)
|
GenerateCRL(ctx context.Context, revokedCerts []CRLEntry) ([]byte, error)
|
||||||
// SignOCSPResponse signs an OCSP response for the given certificate serial.
|
// SignOCSPResponse signs an OCSP response for the given certificate serial.
|
||||||
SignOCSPResponse(ctx context.Context, req OCSPSignRequest) ([]byte, error)
|
SignOCSPResponse(ctx context.Context, req OCSPSignRequest) ([]byte, error)
|
||||||
|
// GetCACertPEM returns the PEM-encoded CA certificate chain for this issuer.
|
||||||
|
GetCACertPEM(ctx context.Context) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IssuanceResult holds the result of a certificate issuance or renewal operation.
|
// IssuanceResult holds the result of a certificate issuance or renewal operation.
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ func TestGetJobStats_Empty(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetJobStats_WithData(t *testing.T) {
|
func TestGetJobStats_WithData(t *testing.T) {
|
||||||
svc, _, jobRepo, _ := newTestStatsService()
|
svc, _, jobRepo, _ := newTestStatsService()
|
||||||
completedAt := time.Now().Add(-1 * time.Hour)
|
completedAt := time.Now()
|
||||||
jobRepo.AddJob(&domain.Job{ID: "j-1", Status: domain.JobStatusCompleted, CompletedAt: &completedAt})
|
jobRepo.AddJob(&domain.Job{ID: "j-1", Status: domain.JobStatusCompleted, CompletedAt: &completedAt})
|
||||||
jobRepo.AddJob(&domain.Job{ID: "j-2", Status: domain.JobStatusFailed, CompletedAt: &completedAt})
|
jobRepo.AddJob(&domain.Job{ID: "j-2", Status: domain.JobStatusFailed, CompletedAt: &completedAt})
|
||||||
|
|
||||||
|
|||||||
@@ -634,6 +634,13 @@ func (m *mockIssuerConnector) SignOCSPResponse(ctx context.Context, req OCSPSign
|
|||||||
return []byte("mock-ocsp-response"), nil
|
return []byte("mock-ocsp-response"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mockIssuerConnector) GetCACertPEM(ctx context.Context) (string, error) {
|
||||||
|
if m.Err != nil {
|
||||||
|
return "", m.Err
|
||||||
|
}
|
||||||
|
return "-----BEGIN CERTIFICATE-----\nmock-ca-cert\n-----END CERTIFICATE-----", nil
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor functions for mocks
|
// Constructor functions for mocks
|
||||||
|
|
||||||
func newMockCertificateRepository() *mockCertRepo {
|
func newMockCertificateRepository() *mockCertRepo {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ async function fetchJSON<T>(url: string, init?: RequestInit): Promise<T> {
|
|||||||
}
|
}
|
||||||
throw new Error(errorMsg || `HTTP ${res.status}`);
|
throw new Error(errorMsg || `HTTP ${res.status}`);
|
||||||
}
|
}
|
||||||
|
if (res.status === 204) return {} as T;
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export default function OwnersPage() {
|
|||||||
const deleteMutation = useMutation({
|
const deleteMutation = useMutation({
|
||||||
mutationFn: deleteOwner,
|
mutationFn: deleteOwner,
|
||||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['owners'] }),
|
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['owners'] }),
|
||||||
|
onError: (err: Error) => alert(`Delete failed: ${err.message}`),
|
||||||
});
|
});
|
||||||
|
|
||||||
const teamMap = new Map<string, Team>();
|
const teamMap = new Map<string, Team>();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export default function TeamsPage() {
|
|||||||
const deleteMutation = useMutation({
|
const deleteMutation = useMutation({
|
||||||
mutationFn: deleteTeam,
|
mutationFn: deleteTeam,
|
||||||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['teams'] }),
|
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['teams'] }),
|
||||||
|
onError: (err: Error) => alert(`Delete failed: ${err.message}`),
|
||||||
});
|
});
|
||||||
|
|
||||||
const columns: Column<Team>[] = [
|
const columns: Column<Team>[] = [
|
||||||
|
|||||||