126 lines
4.7 KiB
Rust
126 lines
4.7 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>,
|
|
}
|
|
|
|
#[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>,
|
|
#[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,
|
|
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,
|
|
}
|