rayketcham-lab/PKI-Client

GitHub: rayketcham-lab/PKI-Client

一款纯 Rust 实现的 PKI 工具箱,整合证书检查、密钥管理、TLS 探测和多种注册协议于一体。

Stars: 0 | Forks: 0

# PKI-Client **现代 PKI CLI 工具** — 证书检查、密钥管理、TLS 探测和注册协议。 纯 Rust 实现。无 OpenSSL 依赖。人性化的输出。 ### 项目健康状态 [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/e69c31bdeb172455.svg)](https://github.com/rayketcham-lab/PKI-Client/actions/workflows/ci.yml) [![每日健康检查](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0b6a412604172504.svg)](https://github.com/rayketcham-lab/PKI-Client/actions/workflows/daily-check.yml) [![互操作性测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/4846798e15172515.svg)](https://github.com/rayketcham-lab/PKI-Client/actions/workflows/interop.yml) [![安全审计](https://img.shields.io/badge/cargo--audit-passing-brightgreen?logo=hackthebox&logoColor=white)](https://rustsec.org/) [![供应链](https://img.shields.io/badge/cargo--deny-passing-brightgreen?logo=checkmarx&logoColor=white)](https://embarkstudios.github.io/cargo-deny/) [![许可证扫描](https://img.shields.io/badge/license%20scan-clean-brightgreen?logo=opensourceinitiative&logoColor=white)](https://embarkstudios.github.io/cargo-deny/) [![无 Unsafe](https://img.shields.io/badge/unsafe-zero-brightgreen?logo=rust&logoColor=white)](https://github.com/rayketcham-lab/PKI-Client) [![OpenSSL](https://img.shields.io/badge/OpenSSL-not%20required-brightgreen?logo=openssl&logoColor=white)](https://github.com/rayketcham-lab/PKI-Client) [![版本](https://img.shields.io/badge/version-0.5.0--beta.1-blue?logo=semver&logoColor=white)](https://github.com/rayketcham-lab/PKI-Client/releases) [![许可证: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-green?logo=apache&logoColor=white)](LICENSE) [![Rust](https://img.shields.io/badge/language-Rust-orange?logo=rust&logoColor=white)](https://www.rust-lang.org/) [![MSRV](https://img.shields.io/badge/MSRV-1.88.0-orange?logo=rust&logoColor=white)](https://blog.rust-lang.org/) [![Clippy](https://img.shields.io/badge/clippy--D%20warnings-passing-brightgreen?logo=rust&logoColor=white)](https://github.com/rayketcham-lab/PKI-Client/actions/workflows/ci.yml) [![格式化](https://img.shields.io/badge/rustfmt-checked-brightgreen?logo=rust&logoColor=white)](https://github.com/rayketcham-lab/PKI-Client/actions/workflows/ci.yml) [![PQC](https://img.shields.io/badge/post--quantum-supported-blueviolet?logo=quantcast&logoColor=white)](https://github.com/rayketcham-lab/PKI-Client) [![FIPS](https://img.shields.io/badge/FIPS%20140--3-optional-blue?logo=nist&logoColor=white)](https://github.com/rayketcham-lab/PKI-Client) [![静态二进制](https://img.shields.io/badge/static%20binary-musl-blue?logo=linux&logoColor=white)](https://github.com/rayketcham-lab/PKI-Client/releases) ## 目录 - [概述](#overview) - [快速开始](#quick-start) - [命令](#commands) - [功能特性](#features) - [输出格式](#output-formats) - [架构](#architecture) - [安装](#install) - [从源码构建](#building-from-source) - [互操作性测试](#interop-testing) - [安全性](#security) - [贡献](#contributing) - [许可证](#license) ## 概述 `pki` 是一个单一二进制文件,用于替代分散的 `openssl`、`certutil`、`step` 和自定义脚本的 PKI 操作工具箱。它提供: - **`pki show`** — 自动检测并显示任何 PKI 文件(证书、密钥、CSR、CRL、PKCS#12) - **`pki probe`** — 检查任何 TLS 服务器的握手、密码套件、链和安全态势 - **`pki acme`** — 完整的 ACME 客户端 (Let's Encrypt),具有类似 certbot 的 `certonly` 工作流 - **`pki est`** / **`pki scep`** — 企业 CA 注册协议 (RFC 7030, RFC 8894) - **`pki compliance`** — 根据 FIPS 140-3、NIST SP 800-57 和 Federal Bridge 策略进行验证 - **`pki dane`** — 生成和验证 DANE/TLSA 记录 (RFC 6698) 所有命令支持四种输出格式:**text**(人类可读)、**json**(脚本)、**compact**(仪表盘)、**forensic**(深度分析,包含十六进制转储和安全评级)。 ## 快速开始 ``` # 检查任意 PKI 文件(自动检测类型) pki show server.pem # 利用 hex dumps 和安全等级进行深度取证分析 pki cert show server.pem --format forensic # 检查哪些证书将在 30 天内过期 pki cert expires *.pem --within 30d # 探测 TLS 服务器 — 版本、cipher、chain、安全检测 pki probe server example.com:443 # 生成密钥对和 CSR pki key gen ec --curve p256 -o server.key pki csr create --key server.key --cn example.com --san dns:www.example.com -o server.csr # 获取 Let's Encrypt 证书 pki acme certonly -d example.com --email admin@example.com # 构建并验证证书 chain pki chain build server.pem # 并排比较两个证书 pki diff old-cert.pem new-cert.pem # 交互式 shell 模式 pki ``` ## 命令 | 命令 | 描述 | RFC / 标准 | |---|---|---| | **`show`** | 自动检测并显示任何 PKI 文件 | — | | **`cert`** | 证书检查、指纹、过期时间 | X.509 (RFC 5280) | | **`key`** | 密钥生成 (RSA, EC, Ed25519) 和检查 | PKCS#8 (RFC 5958) | | **`chain`** | 证书链构建和验证 | RFC 5280 路径验证 | | **`csr`** | CSR 创建和检查 | PKCS#10 (RFC 2986) | | **`crl`** | CRL 查看和吊销检查 | RFC 5280 | | **`revoke`** | OCSP 和 CRL 吊销状态 | OCSP (RFC 6960) | | **`probe`** | TLS 服务器检查和安全检测 | TLS 1.3 (RFC 8446) | | **`acme`** | Let's Encrypt / ACME 证书注册 | RFC 8555 | | **`est`** | 通过安全传输进行注册 | RFC 7030 | | **`scep`** | SCEP CA 发现和能力 | RFC 8894 | | **`compliance`** | FIPS 140-3, NIST, Federal Bridge 验证 | NIST SP 800-57 | | **`dane`** | TLSA 记录生成和验证 | RFC 6698 | | **`diff`** | 并排证书比较 | — | | **`convert`** | 格式转换 (PEM / DER / PKCS#12) | — | | **`pki`** | 声明式 PKI 层级构建器 | — | | **`completions`** | Shell 补全脚本 (bash, zsh, fish) | — | | **`manpages`** | 生成 man 手册页 | — | | **`shell`** | 交互式 REPL 会话 | — | ## 功能特性 ### 证书与密钥管理 - 解码、验证、指纹和过期检查 X.509 证书 - 生成 RSA (2048–4096)、ECDSA (P-256, P-384) 和 Ed25519 密钥 - 创建和检查证书签名请求 (CSR) - 查看 CRL 并通过 OCSP 和 CRL 检查吊销状态 - 在 PEM、DER、PKCS#12 和 Base64 之间转换 ### TLS 与网络 - 完整的 TLS 服务器检查 — 协议版本、密码套件、密钥交换 - 带有安全评级的证书链检测 - 具有 AIA chasing 功能的证书链构建 - DANE/TLSA 记录生成和验证 ### 注册协议 - **ACME** — 完整的 RFC 8555 客户端,支持 HTTP-01 和 DNS-01 挑战、自动续订、服务器部署 - **EST** — RFC 7030 注册、重新注册、服务器密钥生成、CSR 属性 - **SCEP** — RFC 8894 CA 功能和证书发现;完整注册功能计划中 ([#1](https://github.com/rayketcham-lab/PKI-Client/issues/1)) ### 合规性与安全性 - **FIPS 140-3 模式** — 使用 `--fips` 将所有操作限制为已批准的算法 - **后量子密码学** — 通过 `--features pqc` 支持 ML-DSA (FIPS 204) 和 SLH-DSA (FIPS 205) - **合规性验证** — 根据 NIST、FIPS 和 Federal Bridge 策略检查 CA 配置 - **静态二进制文件** — musl 构建,零运行时依赖 ### 开发者体验 - **四种输出格式** — text(人类可读)、JSON(脚本)、compact(仪表盘)、forensic(深度分析) - **交互式 Shell** — 不带参数运行 `pki` 进入 REPL 会话 - **Shell 补全** — bash, zsh, fish - **Man 手册页** — 从 CLI 定义生成 ## 输出格式 | 格式 | 标志 | 用例 | |---|---|---| | `text` | `--format text` (默认) | 人类可读,带颜色 | | `json` | `--format json` | 脚本和自动化 | | `compact` | `--format compact` | 每个证书一行的仪表盘 | | `forensic` | `--format forensic` | 深度分析:每个字段、十六进制转储、安全评级 | ## 架构 ``` ┌──────────────────────────────────────────────────────────┐ │ pki (binary) │ │ 19 subcommands + interactive shell │ ├───────────┬───────────────┬──────────────────────────────┤ │ │ │ │ │ pki-client-output │ pki-probe │ │ Formatting, OID │ TLS inspection │ │ registry, display │ & linting │ │ │ │ │ │ │ pki-hierarchy │ │ │ Declarative PKI │ │ │ hierarchy builder │ │ │ │ │ ├───────────┴───────────────┴──────────────────────────────┤ │ spork-core (vendored CA engine) │ │ Crypto primitives, signing, certificates │ └──────────────────────────────────────────────────────────┘ ``` | Crate | 角色 | |---|---| | `pki-client` | 二进制文件 — CLI 入口点,19 个子命令 + shell | | `pki-client-output` | 库 — 格式化、OID 注册表 | | `pki-probe` | 库 — TLS 检查和 linting | | `pki-hierarchy` | 库 — 声明式 PKI 层级构建器 | | `spork-core` | Vendored — CA 密码引擎(密钥生成、签名、证书构建) | ## 安装 ### 预构建二进制文件(推荐) 下载静态二进制文件 — 无需 Rust、无需构建工具、无依赖: **Linux (x86_64):** ``` curl -fsSL https://raw.githubusercontent.com/rayketcham-lab/PKI-Client/main/install.sh | bash ``` 或从 [GitHub Releases](https://github.com/rayketcham-lab/PKI-Client/releases) 手动下载: ``` # 下载并安装 curl -fSL -o pki.tar.gz https://github.com/rayketcham-lab/PKI-Client/releases/latest/download/pki-v0.5.0-beta.1-x86_64-linux.tar.gz tar xzf pki.tar.gz sudo mv pki /usr/local/bin/ ``` **平台:** x86_64 Linux。该二进制文件是静态链接的 (musl) — 零运行时依赖。 ### 验证发布完整性 每个版本都包含 SHA256 校验和、[SLSA 构建来源](https://slsa.dev/) 和 [Sigstore](https://www.sigstore.dev/) cosign 签名。所有构件均由 GitHub Actions 从源码构建 — 无人为触碰二进制文件。 **SHA256 校验和:** ``` curl -fSL -o SHA256SUMS.txt https://github.com/rayketcham-lab/PKI-Client/releases/latest/download/SHA256SUMS.txt sha256sum -c SHA256SUMS.txt ``` **GitHub 证明 (SLSA provenance):** ``` gh attestation verify pki-v0.5.0-beta.1-x86_64-linux.tar.gz --repo rayketcham-lab/PKI-Client ``` **Cosign 签名 (Sigstore):** ``` curl -fSL -o pki.tar.gz.bundle https://github.com/rayketcham-lab/PKI-Client/releases/latest/download/pki-v0.5.0-beta.1-x86_64-linux.tar.gz.bundle cosign verify-blob \ --bundle pki-v0.5.0-beta.1-x86_64-linux.tar.gz.bundle \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ --certificate-identity-regexp "github.com/rayketcham-lab/PKI-Client" \ pki-v0.5.0-beta.1-x86_64-linux.tar.gz ``` ### Shell 补全 ``` # Bash pki completions bash > /etc/bash_completion.d/pki # Zsh pki completions zsh > ~/.zfunc/_pki # Fish pki completions fish > ~/.config/fish/completions/pki.fish ``` ## 从源码构建 ### 前置条件 TLS 协议栈(`rustls` + `aws-lc-rs`)从 C 源码编译原生加密库。你需要: | 工具 | 原因 | 安装 (Debian/Ubuntu) | |------|-----|------------------------| | C 编译器 | aws-lc-sys, ring | `sudo apt install build-essential` | | CMake | aws-lc-sys | `sudo apt install cmake` | | Perl | aws-lc-sys 构建脚本 | 通常已预装 | 大多数用户应使用 [预构建二进制文件](#pre-built-binaries-recommended) 而不是从源码构建。 ### 构建 ``` git clone https://github.com/rayketcham-lab/PKI-Client.git cd PKI-Client cargo build --release # Binary 位于 target/release/pki ``` 该二进制文件仅动态链接到 `libc` — 无 OpenSSL,无系统加密库。TLS 根证书已捆绑(Mozilla WebPKI 根),并以系统证书存储为主。 **静态 musl 二进制文件**(零运行时依赖): ``` sudo apt install musl-tools # provides musl-gcc rustup target add x86_64-unknown-linux-musl cargo build --release --target x86_64-unknown-linux-musl ``` **后量子支持** (ML-DSA, SLH-DSA) — 纯 Rust,无额外依赖: ``` cargo build --release --features pqc ``` **FIPS 140-3 模式** — 在应用层将算法限制为 FIPS 批准的集合: ``` pki --fips cert show server.pem ``` ## 互操作性测试 PKI-Client 针对真实协议实现运行自动化互操作性测试: | 测试套件 | 目标 | 验证内容 | |---|---|---| | **ACME vs Pebble** | [Pebble](https://github.com/letsencrypt/pebble) (Let's Encrypt 测试 CA) | 账户注册、订单创建、证书颁发 | | **TLS Probe** | google.com, cloudflare.com, github.com | TLS 版本检测、链获取、证书检查 | | **Cert Round-Trip** | 本地密钥/CSR 生成 | 密钥生成、CSR 创建、PEM/DER 转换、格式一致性 | 互操作性测试每天运行,并在涉及协议代码的 PR 上运行。本地运行: ``` cargo build --release bash tests/interop/cert_roundtrip.sh bash tests/interop/tls_probe.sh ``` ## 安全性 - **无 OpenSSL 依赖** — 纯 Rust 密码栈(`rustls`、`ring`、`aws-lc-rs`)消除了 C 内存安全漏洞 - **应用逻辑中无 unsafe 代码** — 仅存在于经过审查的依赖项中 - **常量时间比较** — 通过底层库对加密材料进行常量时间比较 - **不记录秘密** — 密钥和私有材料从不写入 stdout 或日志 - **静态二进制文件** — mus 构建消除了共享库供应链风险 - **FIPS 140-3 模式** — 将所有操作限制为已批准的算法 - **输入验证** — 所有文件解析均使用安全的、边界检查的 Rust 解码器 - **依赖审计** — `cargo audit` 和 `cargo deny` 在 CI 中运行,实行零容忍策略 - **签名发布** — 每个二进制文件都使用 [Sigstore cosign](https://www.sigstore.dev/)(无密钥)签名,并通过 GitHub Actions 包含 [SLSA provenance](https://slsa.dev/) 证明 - **Vendored 依赖** — 所有 crate 依赖均已 vendored 并在 CI 中根据 `Cargo.lock` 进行验证;不允许 git 依赖 有关漏洞报告,请参阅 [SECURITY.md](SECURITY.md)。 ## 贡献 我们欢迎贡献。请在提交 PR 之前查看 CI 检查: ``` cargo fmt --all --check # Format cargo clippy -- -D warnings # Lint (zero warnings) cargo test --all # Tests ``` 所有提交均遵循 [Conventional Commits](https://www.conventionalcommits.org/):`feat:`、`fix:`、`refactor:`、`test:`、`docs:`、`ci:`、`security:`。 ## 许可证 Apache-2.0 — 详见 [LICENSE](LICENSE)。
标签:ACME, enrollment, EST, Rust, SCEP, SSL, TLS, 公钥基础设施, 加密, 可视化界面, 密码学, 手动系统调用, 数字证书, 漏洞扫描器, 系统管理员, 网络安全, 网络流量审计, 证书检查, 证书管理, 通知系统, 防御工具, 隐私保护, 零依赖