Files
pruefwerk/compliance-core/src/models/sbom.rs
T
sharang 44b2f38841
CI / Check (push) Skipped
CI / Detect Changes (push) Successful in 5s
CI / Deploy Dashboard (push) Successful in 5m49s
CI / Deploy Docs (push) Successful in 1m15s
CI / Deploy MCP (push) Successful in 3m33s
CI / Deploy Agent (push) Successful in 8m37s
fix(vex): CVE is the primary vulnerability id in VEX, CSAF and CycloneDX, GHSA an alias (#542)
2026-10-09 13:22:05 +00:00

143 lines
5.4 KiB
Rust

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VulnRef {
pub id: String,
pub source: String,
pub severity: Option<String>,
pub url: Option<String>,
/// Exploitation of the advisory's CVE (KEV, EPSS, SSVC; #493).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub exploitation: Option<super::cve::Exploitation>,
/// Other ids of the advisory (a GHSA's `CVE-…`), as OSV lists them.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub aliases: Vec<String>,
}
impl VulnRef {
/// The id the vulnerability is listed under: its CVE when one is known
/// (see [`super::cve::primary_id`]).
pub fn cve(&self) -> &str {
super::cve::primary_id(&self.id, &self.aliases)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SbomEntry {
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
pub id: Option<bson::oid::ObjectId>,
pub repo_id: String,
pub name: String,
pub version: String,
pub package_manager: String,
/// The version requirement a manifest declares where it pins no exact version (`^1.2.0`,
/// `>=5.1.2`, a branch). Kept apart from `version`, which CVE matching joins on: a range must
/// never be read as the version in use.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub version_requirement: Option<String>,
pub license: Option<String>,
pub purl: Option<String>,
pub known_vulnerabilities: Vec<VulnRef>,
/// Where the component was found, when more than its name tells: the
/// manifests and DLLs one NuGet package was read from (`Hmi/packages.config`,
/// `lib/Ionic.Zip.dll (DLL metadata: DotNetZip Library 1.9.1.5)`). Kept when
/// duplicates of one package are merged.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub evidence: Vec<String>,
/// Hashes of the file the component is distributed as, from its lockfile
/// (npm's `integrity`, NuGet's `contentHash`, Cargo's `checksum`; #508).
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub hashes: Vec<ComponentHash>,
/// Where that file is downloaded from: the lockfile's URL, or the public
/// registry's when the project uses no other.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub download_url: Option<String>,
/// The web page of whoever makes and maintains the component: its
/// project's homepage or repository, from its registry or purl (BSI
/// TR-03183-2's component creator; #508). A URL only, never a person.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub manufacturer_url: Option<String>,
#[serde(with = "super::serde_helpers::bson_datetime")]
pub created_at: DateTime<Utc>,
#[serde(with = "super::serde_helpers::bson_datetime")]
pub updated_at: DateTime<Utc>,
}
/// A hash of a component's distributed file, as CycloneDX writes it.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ComponentHash {
/// CycloneDX's algorithm name: `SHA-512`, `SHA-384`, `SHA-256`, `SHA-1`.
pub alg: String,
/// The digest, lowercase hex.
pub content: String,
}
impl SbomEntry {
pub fn new(repo_id: String, name: String, version: String, package_manager: String) -> Self {
let now = Utc::now();
Self {
id: None,
repo_id,
name,
version,
package_manager,
version_requirement: None,
license: None,
purl: None,
known_vulnerabilities: Vec::new(),
evidence: Vec::new(),
hashes: Vec::new(),
download_url: None,
manufacturer_url: None,
created_at: now,
updated_at: now,
}
}
}
/// How well a scan's SBOM meets the SBOM standards (#496), as sbomqs scores
/// the CycloneDX document Prüfwerk exports for the target. Supporting evidence
/// for the CRA SBOM requirement (cra-ai-23), not a source of findings.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SbomQuality {
/// The scoring tool (`sbomqs`).
pub tool: String,
/// Its version (`v2.1.2`).
pub tool_version: String,
/// The format scored (`cyclonedx 1.5`).
pub spec: String,
/// Components the document lists, as the tool counted them.
pub components: u32,
/// One score per profile, in the order they were asked for.
pub profiles: Vec<SbomQualityProfile>,
}
/// One profile's score.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SbomQualityProfile {
/// The profile as Prüfwerk asks for it (`bsi-v2.1`, `ntia-2021`).
pub id: String,
/// Its name as the tool reports it (`BSI TR-03183-2 v2.1`).
pub name: String,
/// 0 to 10.
pub score: f64,
/// The tool's grade (`A` to `F`).
pub grade: String,
/// The profile's checks the SBOM does not fully meet.
pub failed: Vec<SbomQualityCheck>,
}
/// One check of a profile that the SBOM does not fully meet.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct SbomQualityCheck {
/// The tool's key (`comp_supplier`).
pub key: String,
/// What the tool found (`supplier missing for all 3 components`).
pub description: String,
/// 0 to 10.
pub score: f64,
/// Whether the profile requires it (otherwise it is additional).
pub required: bool,
}