shiftleftcyber/sbom-validator

GitHub: shiftleftcyber/sbom-validator

轻量级 Go 库,用于验证 SBOM 是否符合 CycloneDX 与 SPDX 等标准规范。

Stars: 8 | Forks: 0

# ShiftSBOM Validator [![Go Reference](https://pkg.go.dev/badge/github.com/shiftleftcyber/sbom-validator/v2.svg)](https://pkg.go.dev/github.com/shiftleftcyber/sbom-validator/v2) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/shiftleftcyber/sbom-validator/v2)](https://goreportcard.com/report/github.com/shiftleftcyber/sbom-validator/v2) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/shiftleftcyber/sbom-validator) ## 概述 **sbom-validator** 是一个 Go 库,用于验证 **软件物料清单(SBOM)** 是否符合官方 SBOM 规范。它确保符合 **CycloneDX** 和 **SPDX** 等格式,并有助于维护软件供应链安全。 ## 功能特性 ✅ 检测 SBOM 类型(例如 CycloneDX、SPDX) ✅ 提取 SBOM 版本 ✅ 根据官方模式验证 SBOM ✅ 提供详细的验证错误信息 ## 安装 使用 `go get` 安装该包: ``` go get github.com/shiftleftcyber/sbom-validator/v2@latest ``` ## 升级到 v2 已锁定在旧版 `v1` 的项目 `github.com/shiftleftcyber/sbom-validator` 将继续无需修改即可工作。 要升级到 `v2`,请更新导入路径和依赖: ``` go get github.com/shiftleftcyber/sbom-validator/v2@latest ``` ``` import sbomvalidator "github.com/shiftleftcyber/sbom-validator/v2" ``` 仍导入 `github.com/shiftleftcyber/sbom-validator` 而不带 `/v2` 后缀的项目应继续使用 `v1` 行,直到准备迁移。 ## 用法 ``` package main import ( "fmt" "log" "os" sbomvalidator "github.com/shiftleftcyber/sbom-validator/v2" ) func main() { sbomPath := flag.String("file", "", "Path to the SBOM JSON file") debug := flag.Bool("debug", false, "Enable debug logging") flag.Parse() sbomvalidator.SetDebugLogging(*debug) // Ensure the file path is provided if *sbomPath == "" { log.Fatal("Usage: go run main.go -file= [-debug]") } // Read SBOM file jsonData, err := os.ReadFile(*sbomPath) if err != nil { log.Fatalf("Failed to read SBOM file: %v", err) } result, err := sbomvalidator.ValidateSBOMData(jsonData) if err != nil { log.Fatalf("Error during validation - %v", err) } if result.IsValid { output, _ := json.MarshalIndent(result, "", " ") fmt.Println(string(output)) } else { fmt.Printf("Validation failed! Showing up to %d errors:\n", 10) for i, errMsg := range result.ValidationErrors { if i >= 10 { fmt.Printf("...and %d more errors.\n", len(result.ValidationErrors)-10) break } fmt.Printf("- %s\n", errMsg) } } } ``` ## 运行测试 ``` go test ./... ``` 或者你可以使用包含的 Makefile ``` make test ``` ## 运行示例 你可以构建一个示例应用并传入一个 SBOM ``` make build ./bin/sbom-validator-example -file sample-sboms/sample-1.6.cdx.json { "isValid": true, "sbomType": "CycloneDX", "sbomVersion": "1.6", "detectedFormat": "JSON" } ./bin/sbom-validator-example -file sample-sboms/sample-1.6.cdx.json -debug DEBUG: 2026/04/07 14:00:00 CycloneDX SBOM type detected DEBUG: 2026/04/07 14:00:00 CycloneDX version is set to: 1.6 { "isValid": true, "sbomType": "CycloneDX", "sbomVersion": "1.6", "detectedFormat": "JSON" } ``` ## 许可证 该项目根据 MIT 许可证授权。 ## 贡献 欢迎贡献!请打开问题或提交拉取请求。
标签:CycloneDX, EVTX分析, Go库, Go语言, SBOM, Schema验证, SPDX, 依赖管理, 威胁情报, 开发者工具, 日志审计, 硬件无关, 程序破解, 跌倒检测, 软件合规, 软件审计, 软件物料清单, 轻量级库