csnp/cryptodeps

GitHub: csnp/cryptodeps

面向软件供应链的抗量子依赖分析工具,通过深度扫描依赖树和可达性分析,精准识别并评估代码中实际使用的量子脆弱加密算法。

Stars: 2 | Forks: 1

# CryptoDeps **面向软件供应链的抗量子依赖分析** 查找依赖项中的每一个加密漏洞。了解您的量子风险。专注于重要事项。 [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/c5afa8ea11191718.svg)](https://github.com/csnp/qramm-cryptodeps/actions/workflows/ci.yml) [![Go Report Card](https://img.shields.io/badge/go%20report-A-brightgreen)](https://goreportcard.com/report/github.com/csnp/qramm-cryptodeps) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![Go Version](https://img.shields.io/github/go-mod/go-version/csnp/qramm-cryptodeps)](go.mod) [为什么选择 CryptoDeps](#why-cryptodeps) | [快速开始](#quick-start) | [功能特性](#features) | [完整文档](#cli-reference) | [模式](PATTERNS.md) | [贡献指南](#contributing) ## 量子计算挑战 量子计算机将在未来十年内攻破 RSA、ECDSA 和 Diffie-Hellman。这并非猜测——NSA、NIST 和主要科技公司已经在向后量子密码学 迁移。 挑战在于?**你无法迁移你找不到的东西。** 您的代码可能是抗量子的,但您的**依赖项**呢?平均软件项目有 300-1000+ 个传递依赖。每一个都可能使用量子计算机将攻破的加密算法。传统的安全扫描器会遗漏这一点——它们关注的是 CVE,而不是加密准备情况。 CryptoDeps 通过分析您的整个依赖树并使用**可达性分析** 来解决这个问题,确切显示您的代码实际使用了哪些加密算法,而不仅仅是库中存在的算法。 ## 为什么选择 CryptoDeps CryptoDeps 专为量子准备度评估而构建: | 能力 | CryptoDeps | grep/ripgrep | 商业工具 | |------------|------------|--------------|------------------| | 依赖树分析 | 是 | 否 | 部分支持 | | 可达性分析 | 是 | 否 | 极少支持 | | 量子风险分类 | 是 | 否 | 部分支持 | | 上下文感知置信度 | 是 | 否 | 视情况而定 | | CBOM 输出 | 是 | 否 | 极少支持 | | GitHub Security SARIF | 是 | 否 | 是 | | GitHub URL 扫描 | 是 | 否 | 部分支持 | | 迁移指导 | 是 | 否 | 视情况而定 | | 多生态系统支持 | 是 | 手动 | 视情况而定 | | 开源 | 是 | 是 | 否 | | 价格 | 免费 | 免费 | $$ |
这些能力的含义 - **依赖树分析**:扫描所有传递依赖,而不仅仅是直接依赖 - **可达性分析**:追踪调用图以查找您的代码实际调用的加密算法 - **量子风险分类**:按威胁级别分类 (VULNERABLE, PARTIAL, SAFE) - **上下文感知置信度**:区分已确认的使用与仅可用性 - **CBOM 输出**:用于符合 OMB M-23-02 标准的加密物料清单 (Cryptographic Bill of Materials) - **SARIF 输出**:与 GitHub Security 选项卡集成 - **GitHub URL 扫描**:直接分析任何公共/私有 GitHub 仓库 - **迁移指导**:包含 NIST 标准参考的可操作建议 - **多生态系统支持**:单一工具支持 Go, npm, Python, Maven
## 快速开始 ### 安装 **选项 1:从源码构建** 需要 Go 1.21+ ([安装 Go](https://golang.org/doc/install)) 复制并粘贴整个代码块: ``` git clone https://github.com/csnp/qramm-cryptodeps.git cd qramm-cryptodeps make build sudo mv cryptodeps /usr/local/bin/ cd .. cryptodeps version ``` **选项 2:Go Install** 对于 Go 开发者: ``` go install github.com/csnp/qramm-cryptodeps/cmd/cryptodeps@latest ``` **选项 3:下载二进制文件** 从 [GitHub Releases](https://github.com/csnp/qramm-cryptodeps/releases) 下载预构建的二进制文件。 ### 基本用法 ``` # 分析本地目录 cryptodeps analyze . # 直接分析 GitHub 仓库 cryptodeps analyze hashicorp/vault cryptodeps analyze https://github.com/golang-jwt/jwt # 输出到 JSON 以便自动化 cryptodeps analyze . --format json > findings.json # 生成 SARIF 用于 GitHub Security 集成 cryptodeps analyze . --format sarif > results.sarif # 生成 CBOM 用于合规 cryptodeps analyze . --format cbom > crypto-bom.json ``` ### 试用 此仓库包含一个用于测试的示例漏洞项目: ``` # Clone 和 build git clone https://github.com/csnp/qramm-cryptodeps.git cd qramm-cryptodeps make build # 扫描示例项目 ./cryptodeps analyze ./examples/vulnerable-demo # 预期:显示 Ed25519、RSA、ECDSA 用法的发现结果 # - 已确认代码调用的 crypto # - 依赖项中可用的 crypto # - 针对每项的 Remediation 建议 ``` ## 功能特性 ### 可达性分析 CryptoDeps 通过分析代码的调用图,超越了简单的依赖扫描: | 级别 | 含义 | 操作 | |-------|---------|--------| | **CONFIRMED** | 您的代码直接调用此加密算法 | 需要立即修复 | | **REACHABLE** | 位于从您的代码出发的调用图中 | 监控并规划迁移 | | **AVAILABLE** | 在依赖项中但未被调用 | 较低优先级(未来规划) | ### 多生态系统支持 | 生态系统 | 清单文件 | |-----------|----------------| | Go | `go.mod`, `go.sum` | | npm | `package.json`, `package-lock.json` | | Python | `requirements.txt`, `pyproject.toml`, `Pipfile` | | Maven | `pom.xml` | ### Workspace 与 Monorepo 支持 CryptoDeps 自动发现 workspace 和 monorepo 中的所有清单文件: - **npm/yarn/pnpm**:检测 package.json 和 pnpm-workspace.yaml 中的 `workspaces` - **Go**:检测 `go.work` 文件和子目录中的所有 `go.mod` - **递归发现**:遍历目录树以查找所有清单 - **智能过滤**:跳过 node_modules、vendor、.git、build 目录 ``` # 扫描整个 monorepo - 自动发现所有项目 cryptodeps analyze /path/to/monorepo # 禁用 workspace 发现(仅扫描单个 manifest) cryptodeps analyze /path/to/monorepo --no-workspaces ``` ### 量子风险分类 每个发现都按量子计算威胁级别进行分类: | 符号 | 风险级别 | 量子威胁 | 示例 | |--------|------------|----------------|----------| | 🔴 | VULNERABLE | Shor 算法 | RSA, ECDSA, Ed25519, ECDH, DH, DSA | | 🟡 | PARTIAL | Grover 算法 | AES-128, SHA-256, HMAC-SHA256 | | 🟢 | SAFE | 抗量子 | AES-256, SHA-384+, ChaCha20, Argon2 | ### 智能修复 上下文感知的建议,考虑了: - Token 生命周期(短期 JWT 与长期证书) - 行业标准(等待 PQ-JWT 与立即迁移) - 迁移工作量(简单更改与架构 overhaul) - NIST 标准参考(FIPS 203, 204, 205) ### 多种输出格式 ``` # 人类可读表格(默认) cryptodeps analyze . # 用于自动化的 JSON cryptodeps analyze . --format json # 用于合规的 CycloneDX CBOM cryptodeps analyze . --format cbom # 用于 GitHub Security 的 SARIF cryptodeps analyze . --format sarif # 用于报告的 Markdown cryptodeps analyze . --format markdown ``` ## CLI 参考 ``` cryptodeps [flags] Commands: analyze Analyze project dependencies for cryptographic usage update Download latest crypto knowledge database status Show database statistics and cache info version Print version information Analyze Flags: -f, --format string Output format: table, json, cbom, sarif, markdown (default "table") --fail-on string Fail threshold: vulnerable, partial, any, none (default "vulnerable") --reachability Analyze call graph for actual crypto usage (default true, Go only) --deep Force AST analysis for packages not in database --offline Use only local database, skip auto-updates --no-workspaces Disable workspace discovery (scan single manifest only) --risk string Filter by risk: vulnerable, partial, all --min-severity string Minimum severity to report -h, --help Show help ``` ### 常见工作流 ``` # 仅关注已确认的漏洞(实际使用的内容) cryptodeps analyze . --reachability # CI/CD:如果检测到 quantum-vulnerable crypto 则失败 cryptodeps analyze . --fail-on vulnerable # 不进行 call graph 分析的快速扫描 cryptodeps analyze . --reachability=false # 分析特定的 manifest 文件 cryptodeps analyze ./go.mod # Offline 模式(使用缓存的 database) cryptodeps analyze . --offline # 更新 crypto 知识库 cryptodeps update # 检查 database 状态 cryptodeps status ``` ## 示例输出 ``` [*] Scanning go.mod... found 36 dependencies [!] CONFIRMED - Actually used by your code (requires action): ────────────────────────────────────────────────────────────────────────────────────────── 🔴 Ed25519 VULNERABLE 1-2yr low └─ golang.org/x/crypto@v0.31.0 > Called from: crypto.GenerateEd25519KeyPair > Called from: crypto.SignMessage 🟡 HS256 PARTIAL - low └─ github.com/golang-jwt/jwt/v5@v5.3.0 > Called from: auth.JWTService.GenerateAccessToken 🟢 bcrypt SAFE - - └─ golang.org/x/crypto@v0.31.0 > Called from: auth.HashPassword [.] AVAILABLE - In dependencies but not called (lower priority): ────────────────────────────────────────────────────────────────────────────────────────── golang.org/x/crypto@v0.31.0 └─ 🔴 X25519, 🟢 ChaCha20-Poly1305, 🟢 Argon2 ══════════════════════════════════════════════════════════════════════════════════════════ SUMMARY: 36 deps | 2 with crypto | 8 vulnerable | 2 partial REACHABILITY: 3 confirmed | 0 reachable | 11 available-only REMEDIATION GUIDANCE: ══════════════════════════════════════════════════════════════════════════════════════════ 🔴 Ed25519 [PRIORITY] ────────────────────────────────────────────────── Action: Plan migration to ML-DSA; prioritize if signing long-lived data Replace with: ML-DSA-65 (FIPS 204) NIST: FIPS 204 Timeline: Short-term (1-2 years) Effort: Low (simple change) Libraries: github.com/cloudflare/circl/sign/mldsa ``` ## CI/CD 集成 ### 使用 SARIF 的 GitHub Actions ``` # .github/workflows/crypto-scan.yml name: Quantum Security Scan on: push: branches: [main] pull_request: branches: [main] jobs: cryptodeps: runs-on: ubuntu-latest permissions: security-events: write contents: read steps: - uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version: '1.22' - name: Install CryptoDeps run: go install github.com/csnp/qramm-cryptodeps/cmd/cryptodeps@latest - name: Run Scan run: cryptodeps analyze . --format sarif > results.sarif - name: Upload SARIF to GitHub Security uses: github/codeql-action/upload-sarif@v3 with: sarif_file: results.sarif - name: Fail on Vulnerable Crypto run: cryptodeps analyze . --fail-on vulnerable ``` ### GitLab CI ``` cryptodeps: stage: security image: golang:1.22 script: - go install github.com/csnp/qramm-cryptodeps/cmd/cryptodeps@latest - cryptodeps analyze . --format json > crypto-findings.json - cryptodeps analyze . --fail-on vulnerable artifacts: paths: - crypto-findings.json ``` ### 退出代码 | 代码 | 含义 | 触发条件 | |------|---------|---------| | `0` | 成功 | 未发现匹配 `--fail-on` 阈值的结果 | | `1` | 易受攻击 | 检测到量子易受攻击的加密算法 | | `2` | 错误 | 分析失败(清单无效、网络错误) | | `3` | 部分风险 | 检测到部分风险加密算法(使用 `--fail-on partial` 时) | ## 输出格式详解 ### SARIF (静态分析结果交换格式) SARIF 输出与 GitHub Code Scanning、VS Code SARIF Viewer 和其他安全工具集成: ``` { "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", "version": "2.1.0", "runs": [{ "tool": { "driver": { "name": "CryptoDeps", "informationUri": "https://github.com/csnp/qramm-cryptodeps" } }, "results": [...] }] } ``` ### CBOM (加密物料清单) 就像 SBOM 对软件依赖进行盘点一样,CBOM 对系统中的所有加密算法进行盘点。这是新兴法规(OMB M-23-02, NIST 指南)所要求的。 ``` { "bomFormat": "CycloneDX", "specVersion": "1.5", "serialNumber": "urn:uuid:...", "components": [ { "type": "cryptographic-asset", "name": "RSA-2048", "cryptoProperties": { "assetType": "algorithm", "algorithmProperties": { "primitive": "pke", "parameterSetIdentifier": "2048" } } } ] } ``` ## 架构 ``` qramm-cryptodeps/ ├── cmd/cryptodeps/ # CLI entry point ├── internal/ │ ├── analyzer/ # Core analysis engine │ │ ├── ast/ # Language-specific AST parsing │ │ ├── ondemand/ # Source code fetching & analysis │ │ ├── reachability/ # Call graph analysis (Go) │ │ └── source/ # Package source resolution │ ├── database/ # Crypto knowledge database │ ├── manifest/ # Dependency manifest parsers │ └── registry/ # Package registry fetchers ├── pkg/ │ ├── crypto/ # Algorithm patterns & remediation │ ├── output/ # Formatters (table, JSON, CBOM, SARIF) │ └── types/ # Shared type definitions ├── data/ # Curated crypto database (1,100+ packages) └── examples/ # Sample projects for testing ``` ## 路线图 ### v1.2 (当前版本) - [x] 多生态系统依赖扫描 (Go, npm, Python, Maven) - [x] Go 项目的可达性分析 - [x] 多种输出格式 (table, JSON, CBOM, SARIF, Markdown) - [x] 包含 CNSA 2.0 时间表的量子风险分类 - [x] 包含 NIST 参考的智能修复指导 - [x] GitHub 仓库 URL 扫描 - [x] 涵盖 1,100+ 个包的精选数据库 - [x] Workspace 与 monorepo 支持 (npm, pnpm, Go workspaces) - [x] 多项目聚合结果 ### v1.3 (下一步) - [ ] 改进 npm/Python 项目的可达性 - [ ] 传递依赖加密继承 - [ ] 配置文件支持 - [ ] 用于持续监控的 Watch 模式 ### v2.0 (未来) - [ ] 与 SBOM 直接集成(合并 SBOM + CBOM) - [ ] 云 KMS 检测 (AWS, Azure, GCP) - [ ] 证书链分析 - [ ] IDE 插件 (VS Code, JetBrains) ### 开发设置 ``` # Clone 仓库 git clone https://github.com/csnp/qramm-cryptodeps.git cd qramm-cryptodeps # Install dependencies go mod download # Run tests go test -race ./... # Build go build -o cryptodeps ./cmd/cryptodeps # Run linter golangci-lint run ``` ### 添加包数据 通过为新包贡献分析来帮助扩展加密知识数据库。包条目格式请参见 [CONTRIBUTING.md](CONTRIBUTING.md)。 ## 关于 CSNP CryptoDeps 由 [Cyber Security Non-Profit (CSNP)](https://csnp.org) 开发,这是一个 501(c)(3) 组织,致力于通过教育、社区和实用资源让每个人都能获取网络安全知识。 ### 我们的使命 我们相信: - **可及性**:网络安全知识应向所有人开放 - **社区**:互助的社区帮助人们共同学习和成长 - **教育**:实用资源使人们能够实施更好的安全措施 - **诚信**:在所有运营中保持最高的道德标准 ### QRAMM 工具包 CryptoDeps 是量子准备保障成熟度模型 工具包的一部分: | 工具 | 描述 | |------|-------------| | **CryptoDeps** | 依赖项加密分析(本项目) | | [CryptoScan](https://github.com/csnp/qramm-cryptoscan) | 源代码加密发现 | | [TLS Analyzer](https://github.com/csnp/qramm-tls-analyzer) | TLS/SSL 配置分析 | 了解更多信息,请访问 [qramm.org](https://qramm.org) 和 [csnp.org](https://csnp.org)。 ## 参考资料 ### NIST 后量子密码学标准 - [FIPS 203 - ML-KEM](https://csrc.nist.gov/pubs/fips/203/final) — 模块格基密钥封装机制(取代 RSA/ECDH) - [FIPS 204 - ML-DSA](https://csrc.nist.gov/pubs/fips/204/final) — 模块格基数字签名算法(取代 RSA/ECDSA) - [FIPS 205 - SLH-DSA](https://csrc.nist.gov/pubs/fips/205/final) — 无状态哈希基数字签名算法 - [NIST SP 800-131A Rev 2](https://csrc.nist.gov/publications/detail/sp/800-131a/rev-2/final) — 过渡加密算法和密钥长度 ### 其他资源 - [NSA CNSA 2.0](https://media.defense.gov/2022/Sep/07/2003071834/-1/-1/0/CSA_CNSA_2.0_ALGORITHMS_.PDF) — 商业国家安全算法套件 - [OMB M-23-02](https://www.whitehouse.gov/wp-content/uploads/2022/11/M-23-02-M-Memo-on-Migrating-to-Post-Quantum-Cryptography.pdf) — 联邦 PQC 迁移要求 - [CISA 后量子密码学倡议](https://www.cisa.gov/quantum) - [CycloneDX CBOM](https://cyclonedx.org/capabilities/cbom/) — 加密物料清单 ## 许可证 Apache License 2.0 — 详情见 [LICENSE](LICENSE)。 版权所有 2025 Cyber Security Non-Profit (CSNP) 由 [CSNP](https://csnp.org) 倾力打造 — 推动全民网络安全 [QRAMM](https://qramm.org) | [CSNP](https://csnp.org) | [Issues](https://github.com/csnp/qramm-cryptodeps/issues) | [Twitter](https://twitter.com/caborgsec)
标签:DNS 反向解析, DNS 解析, ECDSA, EVTX分析, Go, PQC, QRAMM, RSA, Ruby工具, 云安全监控, 依赖性分析, 加密算法识别, 可达性分析, 后量子密码学, 密码学扫描, 文档结构分析, 日志审计, 软件供应链安全, 远程方法调用, 量子安全, 量子计算威胁, 静态分析