Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbc1139626 | ||
|
|
ffcd555324 |
No files matched your search
Generated
+9
-9
@@ -601,7 +601,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "compliance-agent"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"base64 0.22.1",
|
||||
@@ -657,7 +657,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "compliance-core"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"aes-gcm",
|
||||
"axum",
|
||||
@@ -689,7 +689,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "compliance-dashboard"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"axum",
|
||||
@@ -727,7 +727,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "compliance-dast"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"base64 0.22.1",
|
||||
@@ -749,7 +749,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "compliance-graph"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"bson",
|
||||
"chrono",
|
||||
@@ -774,7 +774,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "compliance-mcp"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"bson",
|
||||
@@ -797,7 +797,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "compliance-smoke"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"compliance-core",
|
||||
@@ -932,7 +932,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "control-map"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -7127,7 +7127,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "werkbank-exec"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
dependencies = [
|
||||
"compliance-core",
|
||||
"compliance-dast",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "compliance-agent"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -173,9 +173,8 @@ impl ComplianceAgent {
|
||||
}
|
||||
|
||||
/// Store which of the tenant's targets are the plan's included ones and
|
||||
/// which are extra (t72), from the plan's `included_targets`; a plan that
|
||||
/// allows no extra target includes them all. Without a registry every
|
||||
/// target is included. Best-effort: when the plan cannot
|
||||
/// which are extra (t72), from the plan's `included_targets`. Without a
|
||||
/// registry every target is included. Best-effort: when the plan cannot
|
||||
/// be read or the targets not updated, the stored split stays.
|
||||
///
|
||||
/// # Returns
|
||||
@@ -188,7 +187,7 @@ impl ComplianceAgent {
|
||||
) -> Vec<BillingChange> {
|
||||
match self.plan(tenant_id).await {
|
||||
Some(plan) => {
|
||||
self.assign_billing(tenant_id, db, plan.billed_included())
|
||||
self.assign_billing(tenant_id, db, plan.included_targets)
|
||||
.await
|
||||
}
|
||||
None => Vec::new(),
|
||||
@@ -206,7 +205,6 @@ impl ComplianceAgent {
|
||||
match registry.check_entitlement(tenant_id, None, None).await {
|
||||
Ok(check) => Some(crate::metering::Plan {
|
||||
included_targets: check.included_targets(),
|
||||
extra_targets: check.extra_targets(),
|
||||
limits: check.plan_limits(),
|
||||
}),
|
||||
Err(e) => {
|
||||
@@ -218,7 +216,7 @@ impl ComplianceAgent {
|
||||
|
||||
/// Store the billing of the tenant's targets for a plan that includes
|
||||
/// `included` targets; best-effort.
|
||||
pub(crate) async fn assign_billing(
|
||||
async fn assign_billing(
|
||||
&self,
|
||||
tenant_id: &str,
|
||||
db: &crate::database::Database,
|
||||
@@ -361,7 +359,7 @@ impl ComplianceAgent {
|
||||
// counts, and the plan's limits whether a counted one may run (t72).
|
||||
let plan = self.plan(tenant_id).await;
|
||||
if let Some(plan) = &plan {
|
||||
self.assign_billing(tenant_id, &db, plan.billed_included())
|
||||
self.assign_billing(tenant_id, &db, plan.included_targets)
|
||||
.await;
|
||||
}
|
||||
let orchestrator =
|
||||
|
||||
@@ -1,222 +0,0 @@
|
||||
//! A target's Siemens controllers against Siemens' advisories (SPS item 4a):
|
||||
//! `GET /api/v1/targets/{id}/devices` for its page, and
|
||||
//! `GET /api/v1/devices/lookup` to recognise an order number while it is
|
||||
//! typed.
|
||||
//!
|
||||
//! Both read the advisory index as it is now, so a device shows its state
|
||||
//! as soon as it is entered; its CVE alerts follow at the target's next scan.
|
||||
|
||||
use axum::extract::{Extension, Path, Query};
|
||||
use axum::http::StatusCode;
|
||||
use axum::Json;
|
||||
use mongodb::bson::doc;
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::dto::{tenant_db, AgentExt, ApiResponse, ApiResult};
|
||||
use crate::pipeline::csaf_match::{AdvisoryIndex, Wanted};
|
||||
use compliance_core::csaf_ingest::Advisory;
|
||||
use compliance_core::device_check::{DeviceCheck, DeviceLookup};
|
||||
use compliance_core::models::plc_device::normalised_order_number;
|
||||
use compliance_core::models::PlcDevice;
|
||||
use compliance_core::tenant_ctx::TenantCtx;
|
||||
|
||||
/// The provider whose advisories name devices by order number.
|
||||
const PROVIDER: &str = "siemens";
|
||||
|
||||
/// Siemens' advisories naming any of `order_numbers` (normalised).
|
||||
async fn advisories_naming(
|
||||
index: &dyn AdvisoryIndex,
|
||||
order_numbers: Vec<String>,
|
||||
) -> Result<Vec<Advisory>, StatusCode> {
|
||||
let wanted = Wanted {
|
||||
order_numbers,
|
||||
..Wanted::default()
|
||||
};
|
||||
let rows = index.relevant(&wanted).await.map_err(|e| {
|
||||
tracing::warn!("Failed to read the advisory index: {e}");
|
||||
StatusCode::INTERNAL_SERVER_ERROR
|
||||
})?;
|
||||
Ok(rows
|
||||
.into_iter()
|
||||
.filter(|(provider, _)| provider == PROVIDER)
|
||||
.map(|(_, advisory)| advisory)
|
||||
.collect())
|
||||
}
|
||||
|
||||
/// Each of `devices` against `advisories`.
|
||||
fn checks(devices: Vec<PlcDevice>, advisories: &[Advisory]) -> Vec<DeviceCheck> {
|
||||
devices
|
||||
.into_iter()
|
||||
.map(|device| DeviceCheck::new(device, advisories))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The Siemens controllers a target runs on.
|
||||
///
|
||||
/// Each with the Siemens advisories naming it.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/targets/{id}/devices",
|
||||
tag = "Targets",
|
||||
params(("id" = String, Path, description = "The target's id")),
|
||||
responses(
|
||||
(status = 200, description = "The target's devices in the order entered, each with the Siemens advisories naming it and whether one affects its firmware"),
|
||||
(status = 400, description = "Not a target id"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
(status = 404, description = "No such target"),
|
||||
(status = 500, description = "The target or the advisory index could not be read"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all, fields(target_id = %id))]
|
||||
pub async fn list_devices(
|
||||
Extension(agent): AgentExt,
|
||||
tenant: TenantCtx,
|
||||
Path(id): Path<String>,
|
||||
) -> ApiResult<Vec<DeviceCheck>> {
|
||||
let oid = mongodb::bson::oid::ObjectId::parse_str(&id).map_err(|_| StatusCode::BAD_REQUEST)?;
|
||||
let db = tenant_db(&agent, &tenant).await?;
|
||||
let target = db
|
||||
.onboarded_targets()
|
||||
.find_one(doc! { "_id": oid })
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
||||
.ok_or(StatusCode::NOT_FOUND)?;
|
||||
let mut order_numbers: Vec<String> = target
|
||||
.devices
|
||||
.iter()
|
||||
.map(|d| d.order_number.clone())
|
||||
.collect();
|
||||
order_numbers.sort();
|
||||
order_numbers.dedup();
|
||||
let advisories = if order_numbers.is_empty() {
|
||||
Vec::new()
|
||||
} else {
|
||||
advisories_naming(agent.advisory_index.as_ref(), order_numbers).await?
|
||||
};
|
||||
let devices = checks(target.devices, &advisories);
|
||||
Ok(Json(ApiResponse {
|
||||
total: Some(devices.len() as u64),
|
||||
data: devices,
|
||||
page: None,
|
||||
}))
|
||||
}
|
||||
|
||||
/// `?order_number=` of [`lookup_device`].
|
||||
#[derive(Debug, Deserialize, utoipa::IntoParams)]
|
||||
pub struct LookupParams {
|
||||
/// The order number as typed (`6es7511-1ak02-0ab0`).
|
||||
pub order_number: String,
|
||||
}
|
||||
|
||||
/// What Siemens' advisories know of an order number.
|
||||
///
|
||||
/// For recognising one while it is typed. Public data only: nothing of the
|
||||
/// tenant is read.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "/api/v1/devices/lookup",
|
||||
tag = "Targets",
|
||||
params(LookupParams),
|
||||
responses(
|
||||
(status = 200, description = "The order number normalised, whether it has a Siemens order number's shape, and, when advisories name it, the product's name and how many"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
(status = 500, description = "The advisory index could not be read"),
|
||||
)
|
||||
)]
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn lookup_device(
|
||||
Extension(agent): AgentExt,
|
||||
_tenant: TenantCtx,
|
||||
Query(params): Query<LookupParams>,
|
||||
) -> ApiResult<DeviceLookup> {
|
||||
let order_number = normalised_order_number(¶ms.order_number);
|
||||
// Any firmware: only the shape of the order number is checked here.
|
||||
let Ok(device) = PlcDevice::new(&order_number, "0", None) else {
|
||||
return Ok(Json(ApiResponse {
|
||||
data: DeviceLookup {
|
||||
order_number,
|
||||
valid: false,
|
||||
product: None,
|
||||
advisories: 0,
|
||||
},
|
||||
total: None,
|
||||
page: None,
|
||||
}));
|
||||
};
|
||||
let advisories =
|
||||
advisories_naming(agent.advisory_index.as_ref(), vec![order_number.clone()]).await?;
|
||||
let check = DeviceCheck::new(device, &advisories);
|
||||
Ok(Json(ApiResponse {
|
||||
data: DeviceLookup {
|
||||
order_number,
|
||||
valid: true,
|
||||
product: check.product,
|
||||
advisories: check.advisories.len(),
|
||||
},
|
||||
total: None,
|
||||
page: None,
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use futures_util::future::BoxFuture;
|
||||
|
||||
/// An index answering with the synthetic Siemens advisory, and a CODESYS
|
||||
/// one that must never reach a device.
|
||||
struct Fixture;
|
||||
|
||||
impl AdvisoryIndex for Fixture {
|
||||
fn relevant<'a>(
|
||||
&'a self,
|
||||
wanted: &'a Wanted,
|
||||
) -> BoxFuture<'a, Result<Vec<(String, Advisory)>, String>> {
|
||||
assert!(wanted.providers.is_empty() && wanted.purls.is_empty());
|
||||
let doc: serde_json::Value = serde_json::from_str(include_str!(
|
||||
"../../../../compliance-core/tests/fixtures/csaf/siemens-synthetic.json"
|
||||
))
|
||||
.unwrap();
|
||||
let siemens = compliance_core::csaf_ingest::parse(&doc).unwrap();
|
||||
let mut codesys = siemens.clone();
|
||||
codesys.id = "VDE-2026-0001".into();
|
||||
Box::pin(async move {
|
||||
Ok(vec![
|
||||
("siemens".to_string(), siemens),
|
||||
("codesys".to_string(), codesys),
|
||||
])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn devices_are_checked_against_siemens_advisories_only() {
|
||||
let advisories = advisories_naming(&Fixture, vec!["6ES7511-1AK02-0AB0".into()])
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(advisories.len(), 1);
|
||||
let devices = checks(
|
||||
vec![
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.4", None).unwrap(),
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.5", None).unwrap(),
|
||||
PlcDevice::new("6ES7516-3AN02-0AB0", "3.0", None).unwrap(),
|
||||
],
|
||||
&advisories,
|
||||
);
|
||||
use compliance_core::device_check::DeviceState;
|
||||
let states: Vec<DeviceState> = devices.iter().map(DeviceCheck::state).collect();
|
||||
assert_eq!(
|
||||
states,
|
||||
[
|
||||
DeviceState::Affected,
|
||||
DeviceState::NotAffected,
|
||||
DeviceState::NotNamed
|
||||
]
|
||||
);
|
||||
assert_eq!(
|
||||
devices[0].advisories[0].fixed_from.as_deref(),
|
||||
Some("3.1.5")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ pub mod cve_matrix;
|
||||
pub mod dast;
|
||||
mod delivery;
|
||||
pub mod demo_seed;
|
||||
pub mod devices;
|
||||
pub mod dto;
|
||||
pub mod evidence;
|
||||
pub mod finding_breakdown;
|
||||
|
||||
@@ -490,7 +490,7 @@ pub async fn list_offers(
|
||||
responses(
|
||||
(status = 200, description = "Accepted (`data`: the offer)"),
|
||||
(status = 404, description = "No such offer, or no such component"),
|
||||
(status = 409, description = "Already answered (`answered`), the release or connection ended (`ended`), or the component already receives another release (`target_taken`), or the plan allows no further active target (`target_limit`)"),
|
||||
(status = 409, description = "Already answered (`answered`), the release or connection ended (`ended`), or the component already receives another release (`target_taken`)"),
|
||||
(status = 422, description = "The component is not a supplier component (`not_supplier_component`), or an unknown project"),
|
||||
(status = 503, description = "The registry cannot be asked"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
@@ -601,9 +601,9 @@ pub async fn accept_offer(
|
||||
.await
|
||||
{
|
||||
Ok(created) => created,
|
||||
Err(e) => {
|
||||
Err(status) => {
|
||||
unclaim(&db, offer.id).await?;
|
||||
return Ok(super::onboarding::target_refused(e));
|
||||
return Err(status);
|
||||
}
|
||||
};
|
||||
let created_id = created.id.map(|o| o.to_hex()).unwrap_or_default();
|
||||
|
||||
@@ -13,14 +13,13 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use compliance_core::models::{
|
||||
ArtifactKind, ComplianceProfile, Credentials, DetectedFact, Finding, OnboardedTarget,
|
||||
PlcDevice, PlcFormat, ScanRun, TargetType, WebhookDelivery, DELIVERIES_SHOWN,
|
||||
PlcFormat, ScanRun, TargetType, WebhookDelivery, DELIVERIES_SHOWN,
|
||||
};
|
||||
use compliance_core::scan_matrix::{applicable_scans, supports_pentest};
|
||||
use compliance_core::tenant_ctx::TenantCtx;
|
||||
|
||||
use crate::agent::ComplianceAgent;
|
||||
use crate::classify::{classify_target, MockFirmwareDetector};
|
||||
use crate::error::AgentError;
|
||||
use crate::secrets::SecretError;
|
||||
use crate::targets::{upload_dest, uploaded_artifact, MAX_UPLOAD_BYTES};
|
||||
|
||||
@@ -47,42 +46,6 @@ pub struct CreateTargetRequest {
|
||||
/// Who supplies the component, for one bought in (#1025).
|
||||
#[serde(default)]
|
||||
pub supplier: Option<SupplierInput>,
|
||||
/// The Siemens controllers the target runs on, matched against Siemens'
|
||||
/// CSAF advisories by order number and firmware.
|
||||
#[serde(default)]
|
||||
pub devices: Vec<DeviceInput>,
|
||||
}
|
||||
|
||||
/// A Siemens controller as a client sends it.
|
||||
#[derive(Deserialize, utoipa::ToSchema)]
|
||||
pub struct DeviceInput {
|
||||
/// The order number (MLFB).
|
||||
#[schema(example = "6ES7511-1AK02-0AB0")]
|
||||
pub order_number: String,
|
||||
/// The firmware version installed, with or without a leading `V`.
|
||||
#[schema(example = "V3.1.4")]
|
||||
pub firmware: String,
|
||||
/// What the customer calls it.
|
||||
#[serde(default)]
|
||||
pub label: Option<String>,
|
||||
}
|
||||
|
||||
/// The devices to store.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// 422 for a device whose order number or firmware is not one
|
||||
/// ([`PlcDevice::new`]).
|
||||
fn build_devices(inputs: &[DeviceInput]) -> Result<Vec<PlcDevice>, StatusCode> {
|
||||
inputs
|
||||
.iter()
|
||||
.map(|d| {
|
||||
PlcDevice::new(&d.order_number, &d.firmware, d.label.as_deref()).map_err(|e| {
|
||||
tracing::debug!(code = e.code(), "device refused: {e}");
|
||||
StatusCode::UNPROCESSABLE_ENTITY
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A supplier as a client sends it (#1025). An empty `name` removes it.
|
||||
@@ -178,10 +141,6 @@ pub struct UpdateTargetRequest {
|
||||
/// Who supplies the component (#1025); an empty `name` removes it.
|
||||
#[serde(default)]
|
||||
pub supplier: Option<SupplierInput>,
|
||||
/// The Siemens controllers the target runs on; replaces the stored list
|
||||
/// (an empty list removes them all).
|
||||
#[serde(default)]
|
||||
pub devices: Option<Vec<DeviceInput>>,
|
||||
}
|
||||
|
||||
/// One applicable-scan option, serialized for the wizard.
|
||||
@@ -406,7 +365,6 @@ async fn findings_counts(
|
||||
request_body = CreateTargetRequest,
|
||||
responses(
|
||||
(status = 200, description = "The new target"),
|
||||
(status = 409, description = "The plan allows no further active target (`target_limit`)"),
|
||||
(status = 422, description = "A malformed body"),
|
||||
(status = 503, description = "A credential cannot be sealed"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
@@ -417,25 +375,19 @@ pub async fn create_target(
|
||||
Extension(agent): AgentExt,
|
||||
tenant: TenantCtx,
|
||||
Json(req): Json<CreateTargetRequest>,
|
||||
) -> Result<Json<ApiResponse<OnboardedTarget>>, axum::response::Response> {
|
||||
use axum::response::IntoResponse;
|
||||
|
||||
) -> Result<Json<ApiResponse<OnboardedTarget>>, StatusCode> {
|
||||
let mut target = OnboardedTarget::new(req.name, req.target_type);
|
||||
target.description = req.description;
|
||||
if let Some(supplier) = req.supplier {
|
||||
target.supplier = supplier.build().map_err(IntoResponse::into_response)?;
|
||||
target.supplier = supplier.build()?;
|
||||
}
|
||||
target.artifacts = merge_artifacts(&agent.secrets, &req.artifacts, &[]).map_err(|e| {
|
||||
tracing::error!("storing a credential: {e}");
|
||||
StatusCode::SERVICE_UNAVAILABLE.into_response()
|
||||
StatusCode::SERVICE_UNAVAILABLE
|
||||
})?;
|
||||
|
||||
let db = tenant_db(&agent, &tenant)
|
||||
.await
|
||||
.map_err(IntoResponse::into_response)?;
|
||||
let target = insert_target(&agent, &db, &tenant.0.tenant_id, target)
|
||||
.await
|
||||
.map_err(target_refused)?;
|
||||
let db = tenant_db(&agent, &tenant).await?;
|
||||
let target = insert_target(&agent, &db, &tenant.0.tenant_id, target).await?;
|
||||
Ok(Json(ApiResponse {
|
||||
data: target.redacted(),
|
||||
total: None,
|
||||
@@ -443,45 +395,36 @@ pub async fn create_target(
|
||||
}))
|
||||
}
|
||||
|
||||
/// Store a new `target` of tenant `tenant_id` and count it
|
||||
/// ([`crate::targets::create_target`]), then read its supplier's CSAF feed.
|
||||
/// What the API and accepting a supplier's SBOM release (#1028) do.
|
||||
/// Store a new `target` of tenant `tenant_id` and count it: what every way
|
||||
/// of adding a target does (the API, and accepting a supplier's SBOM release,
|
||||
/// #1028), so each counts the same under the plan.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// [`AgentError::TargetLimit`] when the plan has no room for it; a database
|
||||
/// error.
|
||||
/// 500 when it cannot be stored.
|
||||
pub(super) async fn insert_target(
|
||||
agent: &Arc<ComplianceAgent>,
|
||||
db: &crate::database::Database,
|
||||
tenant_id: &str,
|
||||
target: OnboardedTarget,
|
||||
) -> Result<OnboardedTarget, AgentError> {
|
||||
let target = crate::targets::create_target(agent, db, tenant_id, target).await?;
|
||||
mut target: OnboardedTarget,
|
||||
) -> Result<OnboardedTarget, StatusCode> {
|
||||
let res = db
|
||||
.onboarded_targets()
|
||||
.insert_one(&target)
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
target.id = res.inserted_id.as_object_id();
|
||||
refresh_supplier_csaf(agent, tenant_id, target.supplier.as_ref());
|
||||
let target_id = target.id.map(|id| id.to_hex()).unwrap_or_default();
|
||||
agent.emit_usage(
|
||||
tenant_id,
|
||||
"target.added",
|
||||
format!("target:{tenant_id}:{target_id}"),
|
||||
serde_json::json!({ "target_id": target_id, "target_type": format!("{:?}", target.target_type) }),
|
||||
);
|
||||
Ok(target)
|
||||
}
|
||||
|
||||
/// A new target refused, as the API answers: 409 `{"error": "target_limit"}`
|
||||
/// when the plan has no room for it, else 500.
|
||||
pub(super) fn target_refused(e: AgentError) -> axum::response::Response {
|
||||
use axum::response::IntoResponse;
|
||||
match e {
|
||||
AgentError::TargetLimit(cap) => {
|
||||
tracing::info!(cap, "new target refused: the plan's targets are all active");
|
||||
(
|
||||
StatusCode::CONFLICT,
|
||||
Json(serde_json::json!({ "error": "target_limit" })),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
e => {
|
||||
tracing::error!("storing a target: {e}");
|
||||
StatusCode::INTERNAL_SERVER_ERROR.into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One target, credentials redacted.
|
||||
#[utoipa::path(
|
||||
get,
|
||||
@@ -576,8 +519,7 @@ pub async fn list_webhook_deliveries(
|
||||
(status = 200, description = "The changed target"),
|
||||
(status = 400, description = "Not an id"),
|
||||
(status = 404, description = "No such target"),
|
||||
(status = 409, description = "`target_limit`: other artifacts would make a demo target the tenant's own, and the plan has no room for it"),
|
||||
(status = 422, description = "A malformed body, a project that is not the tenant's, or a device whose order number or firmware is not one"),
|
||||
(status = 422, description = "A malformed body, or a project that is not the tenant's"),
|
||||
(status = 503, description = "A credential cannot be sealed"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
)
|
||||
@@ -588,7 +530,7 @@ pub async fn update_target(
|
||||
tenant: TenantCtx,
|
||||
Path(id): Path<String>,
|
||||
Json(req): Json<UpdateTargetRequest>,
|
||||
) -> Result<Json<ApiResponse<OnboardedTarget>>, UploadRefusal> {
|
||||
) -> Result<Json<ApiResponse<OnboardedTarget>>, StatusCode> {
|
||||
let oid = parse_oid(&id)?;
|
||||
let db = tenant_db(&agent, &tenant).await?;
|
||||
|
||||
@@ -660,27 +602,15 @@ pub async fn update_target(
|
||||
);
|
||||
set.insert("project_ids", ids);
|
||||
}
|
||||
// A demo target given other sources becomes the tenant's own (below).
|
||||
let mut claimed_demo = None;
|
||||
if let (Some(arts), Some(stored)) = (req.artifacts, stored.as_ref()) {
|
||||
let built =
|
||||
merge_artifacts(&agent.secrets, &arts, &stored.artifacts).map_err(credential_error)?;
|
||||
if !crate::targets::same_sources(&stored.artifacts, &built) {
|
||||
claimed_demo = Some(stored);
|
||||
}
|
||||
set.insert(
|
||||
"artifacts",
|
||||
to_bson(&built).map_err(|_| StatusCode::BAD_REQUEST)?,
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(devices) = req.devices {
|
||||
set.insert(
|
||||
"devices",
|
||||
to_bson(&build_devices(&devices)?).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?,
|
||||
);
|
||||
}
|
||||
|
||||
let mut update = doc! {};
|
||||
let mut supplier = None;
|
||||
if let Some(input) = req.supplier {
|
||||
@@ -699,11 +629,6 @@ pub async fn update_target(
|
||||
}
|
||||
update.insert("$set", set);
|
||||
|
||||
if let Some(stored) = claimed_demo {
|
||||
crate::targets::claim_demo(&agent, &db, &tenant.0.tenant_id, stored)
|
||||
.await
|
||||
.map_err(demo_refused)?;
|
||||
}
|
||||
db.onboarded_targets()
|
||||
.update_one(doc! { "_id": oid }, update)
|
||||
.await
|
||||
@@ -719,22 +644,7 @@ pub async fn update_target(
|
||||
});
|
||||
}
|
||||
|
||||
Ok(get_target(Extension(agent), tenant, Path(id)).await?)
|
||||
}
|
||||
|
||||
/// A demo target not made the tenant's own, as the API answers: 409
|
||||
/// `target_limit` when the plan has no room for it, else 500.
|
||||
fn demo_refused(e: AgentError) -> UploadRefusal {
|
||||
match e {
|
||||
AgentError::TargetLimit(cap) => {
|
||||
tracing::info!(cap, "demo target kept: the plan's targets are all active");
|
||||
UploadRefusal::because(StatusCode::CONFLICT, "target_limit", "target_limit")
|
||||
}
|
||||
e => {
|
||||
tracing::error!("claiming a demo target: {e}");
|
||||
StatusCode::INTERNAL_SERVER_ERROR.into()
|
||||
}
|
||||
}
|
||||
get_target(Extension(agent), tenant, Path(id)).await
|
||||
}
|
||||
|
||||
/// Remove a deleted target's clones, uploads, work trees and blobs from disk.
|
||||
@@ -914,8 +824,6 @@ async fn delete_session_data(db: &crate::database::Database, session_id: &str) {
|
||||
responses(
|
||||
(status = 200, description = "The target with the artifact"),
|
||||
(status = 400, description = "Not an id"),
|
||||
(status = 404, description = "No such target"),
|
||||
(status = 409, description = "`target_limit`: the artifact would make a demo target the tenant's own, and the plan has no room for it"),
|
||||
(status = 422, description = "A malformed body"),
|
||||
(status = 503, description = "A credential cannot be sealed"),
|
||||
(status = 401, description = "No valid bearer token"),
|
||||
@@ -927,18 +835,9 @@ pub async fn add_artifact(
|
||||
tenant: TenantCtx,
|
||||
Path(id): Path<String>,
|
||||
Json(input): Json<ArtifactInput>,
|
||||
) -> Result<Json<ApiResponse<OnboardedTarget>>, UploadRefusal> {
|
||||
) -> Result<Json<ApiResponse<OnboardedTarget>>, StatusCode> {
|
||||
let oid = parse_oid(&id)?;
|
||||
let db = tenant_db(&agent, &tenant).await?;
|
||||
let stored = db
|
||||
.onboarded_targets()
|
||||
.find_one(doc! { "_id": oid })
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
|
||||
.ok_or(StatusCode::NOT_FOUND)?;
|
||||
crate::targets::claim_demo(&agent, &db, &tenant.0.tenant_id, &stored)
|
||||
.await
|
||||
.map_err(demo_refused)?;
|
||||
let artifact = input.build(&agent.secrets, None).map_err(|e| {
|
||||
tracing::error!("storing a credential: {e}");
|
||||
StatusCode::SERVICE_UNAVAILABLE
|
||||
@@ -951,7 +850,7 @@ pub async fn add_artifact(
|
||||
)
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
Ok(get_target(Extension(agent), tenant, Path(id)).await?)
|
||||
get_target(Extension(agent), tenant, Path(id)).await
|
||||
}
|
||||
|
||||
/// The multipart form of an artifact upload.
|
||||
@@ -994,7 +893,6 @@ pub struct UploadArtifactForm {
|
||||
responses(
|
||||
(status = 200, description = "The target with the artifact"),
|
||||
(status = 404, description = "No such target"),
|
||||
(status = 409, description = "`target_limit`: the file would make a demo target the tenant's own, and the plan has no room for it"),
|
||||
(status = 400, description = "Not an id, or a missing or unknown field"),
|
||||
(status = 413, description = "The file is too large (a supplier SBOM: over 20 MiB)"),
|
||||
(status = 415, description = "An archive format that cannot be unpacked"),
|
||||
@@ -1019,11 +917,6 @@ pub async fn upload_artifact(
|
||||
else {
|
||||
return Err(StatusCode::NOT_FOUND.into());
|
||||
};
|
||||
// Refused before the file streams in. A demo target becomes the
|
||||
// tenant's own even when the file then turns out unreadable.
|
||||
crate::targets::claim_demo(&agent, &db, &tenant.0.tenant_id, &stored_target)
|
||||
.await
|
||||
.map_err(demo_refused)?;
|
||||
|
||||
let mut kind: Option<ArtifactKind> = None;
|
||||
let mut plc_format: Option<PlcFormat> = None;
|
||||
@@ -1802,7 +1695,7 @@ pub async fn swap_target_billing(
|
||||
&db,
|
||||
incoming,
|
||||
outgoing,
|
||||
plan.billed_included().is_some(),
|
||||
plan.included_targets.is_some(),
|
||||
chrono::Utc::now(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -250,16 +250,14 @@ pub async fn export(
|
||||
|
||||
/// `DELETE /api/v1/platform/tenants/{id}/data` — GDPR erasure: drops the
|
||||
/// tenant database and removes its code from disk (clones, uploads, work
|
||||
/// trees, blobs, runner artifacts). Requires `{"confirm": "<tenant id>"}`:
|
||||
/// the same id as in the path, so a call can only erase the tenant it names
|
||||
/// twice; anything else is refused with 400 before anything is touched.
|
||||
/// trees, blobs, runner artifacts). Requires `{"confirm": "<slug or id>"}`.
|
||||
pub async fn delete_data(
|
||||
State(st): State<PlatformState>,
|
||||
Path(tenant_id): Path<String>,
|
||||
body: Option<Json<LifecycleBody>>,
|
||||
) -> Result<Json<serde_json::Value>, StatusCode> {
|
||||
let confirm = body.and_then(|Json(b)| b.confirm);
|
||||
if !confirms_erasure(&tenant_id, confirm.as_deref()) {
|
||||
let confirm = body.and_then(|Json(b)| b.confirm).unwrap_or_default();
|
||||
if confirm.is_empty() {
|
||||
return Err(StatusCode::BAD_REQUEST);
|
||||
}
|
||||
// Where the tenant's code lies on disk, read before its records go.
|
||||
@@ -301,12 +299,6 @@ pub async fn delete_data(
|
||||
})))
|
||||
}
|
||||
|
||||
/// Whether `confirm` confirms erasing `tenant_id`: it must be that id,
|
||||
/// exactly. A missing or empty value, or another tenant's id, does not.
|
||||
fn confirms_erasure(tenant_id: &str, confirm: Option<&str>) -> bool {
|
||||
!tenant_id.is_empty() && confirm == Some(tenant_id)
|
||||
}
|
||||
|
||||
/// `POST /api/v1/platform/tenants/demo/reset` — drops and re-creates the
|
||||
/// demo tenant database. With `{"seed": true}` it then re-seeds the bundled
|
||||
/// demo targets and starts their scans, which is what the nightly reset of the
|
||||
@@ -856,20 +848,3 @@ mod target_count_tests {
|
||||
assert!(stages[0].contains_key("$match") && stages[1].contains_key("$group"));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod erasure_tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn only_the_tenants_own_id_confirms_its_erasure() {
|
||||
assert!(confirms_erasure("t-1", Some("t-1")));
|
||||
assert!(!confirms_erasure("t-1", None));
|
||||
assert!(!confirms_erasure("t-1", Some("")));
|
||||
assert!(!confirms_erasure("t-1", Some("t-2")));
|
||||
assert!(!confirms_erasure("t-1", Some("T-1")));
|
||||
assert!(!confirms_erasure("t-1", Some(" t-1")));
|
||||
assert!(!confirms_erasure("t-1", Some("yes")));
|
||||
assert!(!confirms_erasure("", Some("")));
|
||||
}
|
||||
}
|
||||
@@ -98,9 +98,6 @@ fn described_routes() -> OpenApiRouter {
|
||||
handlers::onboarding::delete_target
|
||||
))
|
||||
.routes(routes!(handlers::onboarding::add_artifact))
|
||||
// A target's Siemens controllers against Siemens' advisories (SPS 4a).
|
||||
.routes(routes!(handlers::devices::list_devices))
|
||||
.routes(routes!(handlers::devices::lookup_device))
|
||||
.routes(routes!(handlers::onboarding::list_webhook_deliveries))
|
||||
// The one route that takes large bodies — and it streams them to
|
||||
// disk. Every other route keeps axum's 2 MiB default, so a JSON
|
||||
|
||||
@@ -166,7 +166,6 @@ async fn seed_one(
|
||||
let mut target =
|
||||
compliance_core::models::OnboardedTarget::new(full_name.to_string(), demo.target_type);
|
||||
target.description = demo.description.clone();
|
||||
target.demo = true;
|
||||
for a in demo.artifacts.iter().filter(|a| !a.is_upload()) {
|
||||
match a.resolved_source_ref() {
|
||||
Some(source_ref) => target.artifacts.push(targets::reference_artifact(
|
||||
|
||||
@@ -47,11 +47,6 @@ pub enum AgentError {
|
||||
#[error("not run: {0:?}")]
|
||||
NotAdmitted(compliance_core::models::Refusal),
|
||||
|
||||
/// A new target the plan has no room for: as many targets are active
|
||||
/// as it allows (the entry plan's `extra_targets: 0`).
|
||||
#[error("the plan allows {0} active targets")]
|
||||
TargetLimit(u32),
|
||||
|
||||
#[error("{0}")]
|
||||
Other(String),
|
||||
}
|
||||
@@ -84,7 +79,6 @@ impl AgentError {
|
||||
| Self::Secret(_)
|
||||
| Self::Exec(_)
|
||||
| Self::NotAdmitted(_)
|
||||
| Self::TargetLimit(_)
|
||||
| Self::Other(_) => (
|
||||
RunErrorCode::Internal,
|
||||
"the scan stopped because of an internal error",
|
||||
@@ -97,7 +91,6 @@ impl From<AgentError> for axum::http::StatusCode {
|
||||
fn from(err: AgentError) -> Self {
|
||||
match err {
|
||||
AgentError::Core(CoreError::NotFound(_)) => axum::http::StatusCode::NOT_FOUND,
|
||||
AgentError::TargetLimit(_) => axum::http::StatusCode::CONFLICT,
|
||||
_ => axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,7 +349,7 @@ fn json<T: Serialize>(value: &T) -> Result<Vec<u8>, AgentError> {
|
||||
/// The findings as CSV, one row each, for a spreadsheet.
|
||||
fn findings_csv(findings: &[Finding]) -> String {
|
||||
let mut out =
|
||||
String::from("id,severity,status,type,scanner,rule_id,cwe,location,title,cra_controls,cra_requirements\n");
|
||||
String::from("id,severity,status,type,scanner,rule_id,cwe,location,title,cra_controls\n");
|
||||
for f in findings {
|
||||
let location = match (&f.file_path, f.line_number) {
|
||||
(Some(file), Some(line)) => format!("{file}:{line}"),
|
||||
@@ -367,13 +367,6 @@ fn findings_csv(findings: &[Finding]) -> String {
|
||||
location,
|
||||
f.title.clone(),
|
||||
f.control_refs.join(" "),
|
||||
// The same requirements by name, for a person reading the sheet.
|
||||
f.control_refs
|
||||
.iter()
|
||||
.filter_map(|id| compliance_core::cra_requirements::name(id))
|
||||
.map(|name| name.de)
|
||||
.collect::<Vec<_>>()
|
||||
.join("; "),
|
||||
];
|
||||
let cells: Vec<String> = row.iter().map(|c| csv_cell(c)).collect();
|
||||
out.push_str(&cells.join(","));
|
||||
@@ -643,10 +636,6 @@ mod tests {
|
||||
"{csv}"
|
||||
);
|
||||
assert!(csv.contains("Core/Src/comms.c:9"));
|
||||
assert!(
|
||||
csv.contains(",cra-ai-8,Keine Standardpasswörter\n"),
|
||||
"{csv}"
|
||||
);
|
||||
assert_eq!(csv_cell("=HYPERLINK(1)"), "'=HYPERLINK(1)");
|
||||
assert_eq!(csv_cell("plain"), "plain");
|
||||
}
|
||||
|
||||
@@ -467,10 +467,6 @@ pub enum Outcome {
|
||||
Ignored(&'static str),
|
||||
}
|
||||
|
||||
/// Why a delivery for a repository without a target makes none: the plan's
|
||||
/// targets are all active (`extra_targets: 0`).
|
||||
const NO_ROOM: &str = "the plan allows no further active target";
|
||||
|
||||
/// Carry out a routed delivery for `tenant_id`.
|
||||
///
|
||||
/// # Errors
|
||||
@@ -489,10 +485,7 @@ pub async fn apply_action(
|
||||
archive_target(db, &source.base_url, repo.id).await?,
|
||||
)),
|
||||
SourceAction::Created(repo) => {
|
||||
let ensured = match ensure_target(agent, db, tenant_id, source, &repo).await {
|
||||
Err(AgentError::TargetLimit(_)) => return Ok(Outcome::Ignored(NO_ROOM)),
|
||||
ensured => ensured?,
|
||||
};
|
||||
let ensured = ensure_target(agent, db, tenant_id, source, &repo).await?;
|
||||
// An empty repository has nothing to scan; its first push will.
|
||||
let scan = ensured.created && !repo.empty;
|
||||
if scan {
|
||||
@@ -504,10 +497,7 @@ pub async fn apply_action(
|
||||
})
|
||||
}
|
||||
SourceAction::Push(repo) => {
|
||||
let ensured = match ensure_target(agent, db, tenant_id, source, &repo).await {
|
||||
Err(AgentError::TargetLimit(_)) => return Ok(Outcome::Ignored(NO_ROOM)),
|
||||
ensured => ensured?,
|
||||
};
|
||||
let ensured = ensure_target(agent, db, tenant_id, source, &repo).await?;
|
||||
spawn_scan(agent, tenant_id, &ensured.target_id, ScanTrigger::Webhook);
|
||||
Ok(Outcome::Ensured {
|
||||
target_id: ensured.target_id,
|
||||
@@ -618,11 +608,6 @@ pub async fn sync_with<L: RepoLister>(
|
||||
}
|
||||
}
|
||||
Ok(_) => report.refreshed += 1,
|
||||
// Not an error: the next sync tries again, once a target is
|
||||
// archived or the plan changed.
|
||||
Err(AgentError::TargetLimit(cap)) => {
|
||||
tracing::info!(tenant_id, repo = %repo.full_name, cap, "managed git sync: no target, the plan's targets are all active");
|
||||
}
|
||||
Err(err) => {
|
||||
tracing::warn!(tenant_id, repo = %repo.full_name, "managed git sync: {err}");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
//!
|
||||
//! **Included and extra targets.** The oldest active targets are included,
|
||||
//! up to the plan's `included_targets`; every other active target is extra.
|
||||
//! A plan that allows no extra target (the entry plan) includes them all.
|
||||
//! The split is stored on each target ([`OnboardedTarget::billing`]) and
|
||||
//! brought up to date before each scan and when a target is created, so
|
||||
//! archiving an included target moves the oldest extra one up.
|
||||
@@ -180,31 +179,10 @@ pub async fn swap(
|
||||
pub struct Plan {
|
||||
/// How many targets the plan includes; `None` is unlimited.
|
||||
pub included_targets: Option<u32>,
|
||||
/// How many extra targets may be active besides; `None` is unlimited.
|
||||
pub extra_targets: Option<u32>,
|
||||
/// The quota and the customer's Prüftag cap.
|
||||
pub limits: PlanLimits,
|
||||
}
|
||||
|
||||
impl Plan {
|
||||
/// How many targets may be active at once: the included ones and the
|
||||
/// extra ones the plan allows. `None` when either is unlimited, as on
|
||||
/// every plan that bills extra targets.
|
||||
pub fn target_cap(&self) -> Option<u32> {
|
||||
Some(self.included_targets?.saturating_add(self.extra_targets?))
|
||||
}
|
||||
|
||||
/// How many targets the billing split includes; `None` includes every
|
||||
/// active target. A plan that allows no extra target bills none as
|
||||
/// extra, not even those already active beyond its included ones.
|
||||
pub fn billed_included(&self) -> Option<u32> {
|
||||
match self.extra_targets {
|
||||
Some(0) => None,
|
||||
_ => self.included_targets,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The tenant's counted Prüfungen and booked Prüftage per month.
|
||||
const MONTHS: &str = "metering_months";
|
||||
/// Each target's Prüftag per day, once the quota was used up.
|
||||
@@ -469,33 +447,6 @@ mod tests {
|
||||
use super::*;
|
||||
use chrono::TimeZone;
|
||||
|
||||
#[test]
|
||||
fn only_a_plan_capping_both_counts_caps_the_active_targets() {
|
||||
let plan = |included_targets, extra_targets| Plan {
|
||||
included_targets,
|
||||
extra_targets,
|
||||
..Plan::default()
|
||||
};
|
||||
assert_eq!(plan(Some(3), Some(0)).target_cap(), Some(3), "entry");
|
||||
assert_eq!(plan(Some(3), Some(2)).target_cap(), Some(5));
|
||||
assert_eq!(plan(Some(5), None).target_cap(), None, "extras billed");
|
||||
assert_eq!(plan(None, Some(0)).target_cap(), None, "all included");
|
||||
assert_eq!(plan(Some(u32::MAX), Some(1)).target_cap(), Some(u32::MAX));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_plan_allowing_no_extra_target_bills_none_as_extra() {
|
||||
let plan = |included_targets, extra_targets| Plan {
|
||||
included_targets,
|
||||
extra_targets,
|
||||
limits: PlanLimits::default(),
|
||||
};
|
||||
assert_eq!(plan(Some(2), Some(0)).billed_included(), None, "entry");
|
||||
assert_eq!(plan(Some(5), None).billed_included(), Some(5));
|
||||
assert_eq!(plan(Some(5), Some(2)).billed_included(), Some(5));
|
||||
assert_eq!(plan(None, None).billed_included(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_swap_holds_until_the_berlin_month_ends() {
|
||||
let at = |y, m, d, h| {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//! A target's components against the vendor CSAF advisories in the index
|
||||
//! (#515, see [`super::csaf_feed`]): a CODESYS runtime or library by its
|
||||
//! name and version against CODESYS's advisories, a Siemens device by its
|
||||
//! order number and firmware against Siemens' (SPS item 4a), and any
|
||||
//! component with a purl against an advisory product with the same purl. A match raises a CVE
|
||||
//! name and version against CODESYS's advisories, any component with a purl
|
||||
//! against an advisory product with the same purl. A match raises a CVE
|
||||
//! alert with source `csaf`, or, where OSV or NVD already reported the CVE,
|
||||
//! adds the advisory to that alert; either way the alert links the advisory
|
||||
//! and carries the vendor's remediation and fixed versions.
|
||||
@@ -18,10 +17,6 @@ use compliance_core::version::Vers;
|
||||
|
||||
use super::csaf_feed::{MongoAdvisoryStore, StoredAdvisory};
|
||||
|
||||
/// The provider whose advisories name devices by order number
|
||||
/// ([`compliance_core::models::PlcDevice`]).
|
||||
const ORDER_NUMBER_PROVIDER: &str = "siemens";
|
||||
|
||||
/// The provider whose advisories name the components of a package manager
|
||||
/// by product name.
|
||||
fn provider_for(package_manager: &str) -> Option<&'static str> {
|
||||
@@ -31,46 +26,29 @@ fn provider_for(package_manager: &str) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
/// What the advisory index is asked for, for some components ([`wanted`]).
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub(crate) struct Wanted {
|
||||
/// Providers whose advisories all count ([`provider_for`]).
|
||||
pub providers: Vec<String>,
|
||||
/// Purls without version.
|
||||
pub purls: Vec<String>,
|
||||
/// Device order numbers, normalised.
|
||||
pub order_numbers: Vec<String>,
|
||||
}
|
||||
|
||||
impl Wanted {
|
||||
fn is_empty(&self) -> bool {
|
||||
self.providers.is_empty() && self.purls.is_empty() && self.order_numbers.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads the advisory index, behind a trait so tests keep it in memory.
|
||||
pub(crate) trait AdvisoryIndex: Send + Sync {
|
||||
/// The advisories of `wanted`'s providers, and those naming any of its
|
||||
/// purls (without version) or, of [`ORDER_NUMBER_PROVIDER`], any of its
|
||||
/// order numbers, as `(provider, advisory)`.
|
||||
/// The advisories of `providers`, and those naming any of `purls`
|
||||
/// (without version), as `(provider, advisory)`.
|
||||
fn relevant<'a>(
|
||||
&'a self,
|
||||
wanted: &'a Wanted,
|
||||
providers: &'a [String],
|
||||
purls: &'a [String],
|
||||
) -> BoxFuture<'a, Result<Vec<(String, Advisory)>, String>>;
|
||||
}
|
||||
|
||||
impl AdvisoryIndex for MongoAdvisoryStore {
|
||||
fn relevant<'a>(
|
||||
&'a self,
|
||||
wanted: &'a Wanted,
|
||||
providers: &'a [String],
|
||||
purls: &'a [String],
|
||||
) -> BoxFuture<'a, Result<Vec<(String, Advisory)>, String>> {
|
||||
Box::pin(async move {
|
||||
if wanted.is_empty() {
|
||||
if providers.is_empty() && purls.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
// A product's purl may carry a version; compare from the start.
|
||||
let purl_patterns: Vec<mongodb::bson::Regex> = wanted
|
||||
.purls
|
||||
let purl_patterns: Vec<mongodb::bson::Regex> = purls
|
||||
.iter()
|
||||
.map(|p| mongodb::bson::Regex {
|
||||
pattern: format!("^{}(@|$)", regex::escape(p)),
|
||||
@@ -80,12 +58,8 @@ impl AdvisoryIndex for MongoAdvisoryStore {
|
||||
let rows: Vec<StoredAdvisory> = self
|
||||
.collection()
|
||||
.find(doc! { "$or": [
|
||||
{ "provider": { "$in": &wanted.providers } },
|
||||
{ "provider": { "$in": providers } },
|
||||
{ "advisory.products.purl": { "$in": purl_patterns } },
|
||||
{
|
||||
"provider": ORDER_NUMBER_PROVIDER,
|
||||
"advisory.products.model_numbers": { "$in": &wanted.order_numbers },
|
||||
},
|
||||
] })
|
||||
.await
|
||||
.map_err(|e| e.to_string())?
|
||||
@@ -109,11 +83,6 @@ fn purl_base(purl: &str) -> Option<String> {
|
||||
/// Whether advisory product `p` (of `provider`) is `entry`'s component at
|
||||
/// its version.
|
||||
fn names(p: &AdvisoryProduct, provider: &str, entry: &SbomEntry) -> bool {
|
||||
// A device, by its order number and firmware, only in the advisories of
|
||||
// the vendor whose order numbers they are.
|
||||
if let Some(order_number) = entry.order_number.as_deref() {
|
||||
return provider == ORDER_NUMBER_PROVIDER && p.covers_device(order_number, &entry.version);
|
||||
}
|
||||
if provider_for(&entry.package_manager) == Some(provider)
|
||||
&& p.covers(&entry.name, &entry.version)
|
||||
{
|
||||
@@ -234,12 +203,7 @@ pub(crate) fn apply(
|
||||
aliases: Vec::new(),
|
||||
});
|
||||
}
|
||||
let fixed = match entry.order_number.as_deref() {
|
||||
Some(order_number) => hit
|
||||
.advisory
|
||||
.fixed_device_versions(hit.vulnerability, order_number),
|
||||
None => hit.advisory.fixed_versions(hit.vulnerability, &entry.name),
|
||||
};
|
||||
let fixed = hit.advisory.fixed_versions(hit.vulnerability, &entry.name);
|
||||
let alert = match alerts.iter_mut().position(|a| a.cve_id == hit.cve) {
|
||||
Some(i) => &mut alerts[i],
|
||||
None => {
|
||||
@@ -291,27 +255,23 @@ pub(crate) fn apply(
|
||||
count
|
||||
}
|
||||
|
||||
/// What the index is asked for, for `entries`.
|
||||
pub(crate) fn wanted(entries: &[SbomEntry]) -> Wanted {
|
||||
let mut wanted = Wanted::default();
|
||||
/// The providers and purls the index is asked for, for `entries`.
|
||||
pub(crate) fn wanted(entries: &[SbomEntry]) -> (Vec<String>, Vec<String>) {
|
||||
let mut providers: Vec<String> = Vec::new();
|
||||
let mut purls: Vec<String> = Vec::new();
|
||||
for entry in entries {
|
||||
if let Some(p) = provider_for(&entry.package_manager) {
|
||||
if !wanted.providers.iter().any(|q| q == p) {
|
||||
wanted.providers.push(p.to_string());
|
||||
if !providers.iter().any(|q| q == p) {
|
||||
providers.push(p.to_string());
|
||||
}
|
||||
}
|
||||
if let Some(base) = entry.purl.as_deref().and_then(purl_base) {
|
||||
if !wanted.purls.contains(&base) {
|
||||
wanted.purls.push(base);
|
||||
}
|
||||
}
|
||||
if let Some(order_number) = entry.order_number.as_deref() {
|
||||
if !wanted.order_numbers.iter().any(|o| o == order_number) {
|
||||
wanted.order_numbers.push(order_number.to_string());
|
||||
if !purls.contains(&base) {
|
||||
purls.push(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
wanted
|
||||
(providers, purls)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -504,104 +464,10 @@ mod tests {
|
||||
assert_eq!(alerts[0].affected_version, "3.1.0");
|
||||
assert_eq!(
|
||||
wanted(&entries),
|
||||
Wanted {
|
||||
purls: vec!["pkg:generic/example/fieldbus-stack".to_string()],
|
||||
..Wanted::default()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// The synthetic Siemens-shaped advisory of the core fixtures, as
|
||||
/// `provider`'s.
|
||||
fn siemens_advisory(provider: &str) -> (String, Advisory) {
|
||||
let doc: serde_json::Value = serde_json::from_str(include_str!(
|
||||
"../../../compliance-core/tests/fixtures/csaf/siemens-synthetic.json"
|
||||
))
|
||||
.unwrap();
|
||||
(
|
||||
provider.to_string(),
|
||||
compliance_core::csaf_ingest::parse(&doc).unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
fn device(order_number: &str, firmware: &str) -> SbomEntry {
|
||||
let device = compliance_core::models::PlcDevice::new(order_number, firmware, None).unwrap();
|
||||
crate::pipeline::sbom::devices::entries(&[device], "t").remove(0)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_device_matches_the_advisories_naming_its_order_number_and_firmware() {
|
||||
let advisories = vec![siemens_advisory(ORDER_NUMBER_PROVIDER)];
|
||||
let mut entries = vec![
|
||||
device("6es7511-1ak02-0ab0", "V3.1.4"),
|
||||
device("6ES7511-1AK02-0AB0", "3.1.5"),
|
||||
device("6ES7513-1AL02-0AB0", "2.9.7"),
|
||||
device("6ES7512-1DK01-0AB0", "1.0"),
|
||||
];
|
||||
let mut alerts = Vec::new();
|
||||
|
||||
let matched = apply("t", &mut entries, &advisories, &mut alerts);
|
||||
|
||||
// Below the fixed firmware, and in an advisory for every version; not
|
||||
// at the fixed firmware, and not a CPU the advisory does not name.
|
||||
assert_eq!(matched, 2);
|
||||
let affected: Vec<(&str, &str)> = alerts
|
||||
.iter()
|
||||
.map(|a| (a.affected_package.as_str(), a.affected_version.as_str()))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
affected,
|
||||
[("6ES7511-1AK02-0AB0", "3.1.4")],
|
||||
"one alert per CVE"
|
||||
);
|
||||
let alert = &alerts[0];
|
||||
assert_eq!(alert.cve_id, "CVE-2026-90101");
|
||||
assert_eq!(alert.fixed_versions, ["3.1.5"]);
|
||||
assert_eq!(alert.severity.as_deref(), Some("HIGH"));
|
||||
let advisory = &alert.advisories[0];
|
||||
assert_eq!(advisory.id, "SSA-900001");
|
||||
assert!(advisory
|
||||
.remediation
|
||||
.as_deref()
|
||||
.is_some_and(|r| r.contains("Update to V3.1.5")));
|
||||
assert!(entries[2]
|
||||
.known_vulnerabilities
|
||||
.iter()
|
||||
.any(|v| v.id == "CVE-2026-90101"));
|
||||
assert!(entries[1].known_vulnerabilities.is_empty());
|
||||
assert!(entries[3].known_vulnerabilities.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_device_is_matched_only_against_the_vendor_of_its_order_number() {
|
||||
let advisories = vec![siemens_advisory("codesys"), siemens_advisory("supplier:x")];
|
||||
let mut entries = vec![device("6ES7511-1AK02-0AB0", "3.1.4")];
|
||||
let mut alerts = Vec::new();
|
||||
assert_eq!(apply("t", &mut entries, &advisories, &mut alerts), 0);
|
||||
|
||||
// And a component with that name is not a device.
|
||||
let named = SbomEntry::new(
|
||||
"t".into(),
|
||||
"Example S7-1500 CPU 1511-1 PN (6ES7511-1AK02-0AB0)".into(),
|
||||
"3.1.4".into(),
|
||||
"supplier-product".into(),
|
||||
);
|
||||
let advisories = vec![siemens_advisory(ORDER_NUMBER_PROVIDER)];
|
||||
assert_eq!(apply("t", &mut [named], &advisories, &mut alerts), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_index_is_asked_for_each_order_number_once() {
|
||||
let entries = vec![
|
||||
device("6ES7511-1AK02-0AB0", "3.1.4"),
|
||||
device("6es7511-1ak02-0ab0", "3.1.5"),
|
||||
];
|
||||
assert_eq!(
|
||||
wanted(&entries),
|
||||
Wanted {
|
||||
order_numbers: vec!["6ES7511-1AK02-0AB0".to_string()],
|
||||
..Wanted::default()
|
||||
}
|
||||
(
|
||||
Vec::new(),
|
||||
vec!["pkg:generic/example/fieldbus-stack".to_string()]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -466,6 +466,10 @@ fn issue_body(alert: &CveAlert, severity: &str, target_id: &str, dashboard: &str
|
||||
.push_str("- Behoben in / Fixed in: keine Version bekannt / no fixed version known\n"),
|
||||
fixed => body.push_str(&format!("- Behoben in / Fixed in: {}\n", fixed.join(", "))),
|
||||
}
|
||||
body.push_str(&format!(
|
||||
"- Advisory: https://osv.dev/vulnerability/{}\n",
|
||||
alert.cve_id
|
||||
));
|
||||
if alert
|
||||
.exploitation
|
||||
.as_ref()
|
||||
@@ -477,8 +481,14 @@ fn issue_body(alert: &CveAlert, severity: &str, target_id: &str, dashboard: &str
|
||||
));
|
||||
}
|
||||
body.push_str("\n### CRA\n\n");
|
||||
for requirement in crate::pipeline::issue_creation::cra_requirements(&CVE_CONTROLS) {
|
||||
body.push_str(&format!("- {requirement}\n"));
|
||||
let map = control_map::ControlMap::cra().ok();
|
||||
for id in CVE_CONTROLS {
|
||||
let title = map
|
||||
.as_ref()
|
||||
.and_then(|m| m.coverage(id))
|
||||
.map(|c| c.title.clone())
|
||||
.unwrap_or_default();
|
||||
body.push_str(&format!("- {id} — {title} (Annex I)\n"));
|
||||
}
|
||||
let dashboard = dashboard.trim_end_matches('/');
|
||||
if dashboard.starts_with("https://") {
|
||||
@@ -799,8 +809,7 @@ mod tests {
|
||||
// pruefwerk (1), cra:annex-i (2), severity:high (4), cve (7).
|
||||
assert!(calls[0].ends_with("labels=[1,2,4,7]"), "{}", calls[0]);
|
||||
assert!(calls[1].contains("Fixed in: 4.9.2"));
|
||||
assert!(calls[1].contains("Bekannte Schwachstellen in Komponenten"));
|
||||
assert!(!calls[1].contains("cra-ai-22"));
|
||||
assert!(calls[1].contains("cra-ai-22"));
|
||||
assert!(calls[1].contains("https://pruefwerk.example/targets/target-1"));
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ pub async fn notify_new_cves(
|
||||
);
|
||||
notification.cvss_score = alert.cvss_score;
|
||||
notification.summary = alert.summary.clone();
|
||||
notification.url = Some(format!("https://osv.dev/vulnerability/{}", alert.cve_id));
|
||||
let notification = match mongodb::bson::to_bson(¬ification) {
|
||||
Ok(n) => n,
|
||||
Err(e) => {
|
||||
|
||||
@@ -687,18 +687,23 @@ pub(super) fn format_issue_body(finding: &Finding) -> String {
|
||||
body
|
||||
}
|
||||
|
||||
/// The CRA requirements a finding is evidence for, from its stamped
|
||||
/// `control_refs`, by the name a customer reads in both languages
|
||||
/// (`Keine Standardpasswörter / No default passwords (Annex I)`). An id
|
||||
/// outside the 40 requirements stays as it is.
|
||||
pub(crate) fn cra_requirements<S: AsRef<str>>(control_refs: &[S]) -> Vec<String> {
|
||||
/// The CRA requirements a finding is evidence for, as `cra-ai-8 — <title>`,
|
||||
/// from its stamped `control_refs`. Titles come from the CRA control map.
|
||||
fn cra_requirements(control_refs: &[String]) -> Vec<String> {
|
||||
let map = control_map::ControlMap::cra().ok();
|
||||
control_refs
|
||||
.iter()
|
||||
.map(AsRef::as_ref)
|
||||
.filter(|id| id.starts_with("cra-"))
|
||||
.map(|id| match compliance_core::cra_requirements::name(id) {
|
||||
Some(name) => format!("{} / {} (Annex I)", name.de, name.en),
|
||||
None => format!("{id} (Annex I)"),
|
||||
.map(|id| {
|
||||
match map
|
||||
.as_ref()
|
||||
.and_then(|m| m.coverage(id))
|
||||
.map(|c| c.title.as_str())
|
||||
.filter(|t| !t.is_empty())
|
||||
{
|
||||
Some(title) => format!("{id} — {title} (Annex I)"),
|
||||
None => format!("{id} (Annex I)"),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -732,10 +737,9 @@ mod tests {
|
||||
fn cra_requirements_name_the_control() {
|
||||
let refs = vec!["cra-ai-1".to_string(), "iec-x".to_string()];
|
||||
let lines = cra_requirements(&refs);
|
||||
assert_eq!(
|
||||
lines,
|
||||
["Sichere Werkseinstellungen / Secure factory settings (Annex I)"]
|
||||
);
|
||||
assert_eq!(lines.len(), 1);
|
||||
assert!(lines[0].starts_with("cra-ai-1 — "), "{lines:?}");
|
||||
assert!(lines[0].ends_with("(Annex I)"));
|
||||
assert_eq!(
|
||||
cra_requirements(&["cra-unknown".to_string()]),
|
||||
["cra-unknown (Annex I)"]
|
||||
@@ -757,8 +761,7 @@ mod tests {
|
||||
f.control_refs = vec!["cra-ai-1".into()];
|
||||
let body = format_issue_body(&f);
|
||||
assert!(body.contains("**CWE:** CWE-89"));
|
||||
assert!(body.contains("**CRA:** Sichere Werkseinstellungen / Secure factory settings"));
|
||||
assert!(!body.contains("cra-ai-1"));
|
||||
assert!(body.contains("**CRA:** cra-ai-1"));
|
||||
assert!(body.contains("`fp1`"));
|
||||
}
|
||||
|
||||
|
||||
@@ -88,11 +88,6 @@ pub struct PipelineOrchestrator {
|
||||
pub(super) charged_as: Option<ScanTrigger>,
|
||||
}
|
||||
|
||||
/// The package managers of the control-application SBOM the PLC scan stores
|
||||
/// (`PipelineOrchestrator::persist_control_app_sbom`): CODESYS libraries and
|
||||
/// runtime, and the Siemens devices the target runs on.
|
||||
const CONTROL_APP_MANAGERS: [&str; 2] = ["codesys", crate::pipeline::sbom::devices::DEVICE_MANAGER];
|
||||
|
||||
/// Why a target with only a build output skips its code stages: what the
|
||||
/// dashboard words from it (`coverage::reason`).
|
||||
const NO_CODE_BUILD_OUTPUT: &str = "the target has no source code (a git repository or a \
|
||||
@@ -177,15 +172,10 @@ impl PipelineOrchestrator {
|
||||
else {
|
||||
return;
|
||||
};
|
||||
// The supplier's advisories name its product and components by name
|
||||
// and purl; devices are matched against the vendor index instead.
|
||||
let wanted = crate::pipeline::csaf_match::Wanted {
|
||||
providers: vec![crate::pipeline::csaf_feed::supplier_key(url)],
|
||||
purls: crate::pipeline::csaf_match::wanted(entries).purls,
|
||||
order_numbers: Vec::new(),
|
||||
};
|
||||
let providers = [crate::pipeline::csaf_feed::supplier_key(url)];
|
||||
let (_, purls) = crate::pipeline::csaf_match::wanted(entries);
|
||||
let store = crate::pipeline::csaf_feed::MongoAdvisoryStore::supplier(self.db.inner());
|
||||
match store.relevant(&wanted).await {
|
||||
match store.relevant(&providers, &purls).await {
|
||||
Ok(advisories) if advisories.is_empty() => {}
|
||||
Ok(advisories) => {
|
||||
let matched =
|
||||
@@ -210,8 +200,8 @@ impl PipelineOrchestrator {
|
||||
let Some(index) = &self.advisory_index else {
|
||||
return;
|
||||
};
|
||||
let wanted = crate::pipeline::csaf_match::wanted(entries);
|
||||
match index.relevant(&wanted).await {
|
||||
let (providers, purls) = crate::pipeline::csaf_match::wanted(entries);
|
||||
match index.relevant(&providers, &purls).await {
|
||||
Ok(advisories) if advisories.is_empty() => {}
|
||||
Ok(advisories) => {
|
||||
let matched =
|
||||
@@ -697,10 +687,6 @@ impl PipelineOrchestrator {
|
||||
.as_ref()
|
||||
.and_then(|s| crate::pipeline::sbom::supplied::product_entry(s, &repo_id)),
|
||||
);
|
||||
supplied.extend(crate::pipeline::sbom::devices::entries(
|
||||
&repo.devices,
|
||||
&repo_id,
|
||||
));
|
||||
for entry in embedded
|
||||
.into_iter()
|
||||
.chain(codesys)
|
||||
@@ -1925,21 +1911,6 @@ impl PipelineOrchestrator {
|
||||
.await?;
|
||||
}
|
||||
None => {
|
||||
// A control application known only by the Siemens controllers
|
||||
// it runs on (SPS item 4a): they are its SBOM, matched against
|
||||
// Siemens' advisories as with a project.
|
||||
// Also when the last one was removed, so its components and
|
||||
// alerts go with it.
|
||||
if target.target_type == TargetType::PlcSps || !target.devices.is_empty() {
|
||||
let devices =
|
||||
crate::pipeline::sbom::devices::entries(&target.devices, &target_id);
|
||||
if let Err(e) = self
|
||||
.persist_control_app_sbom(target, &target_id, scan_run_id, devices)
|
||||
.await
|
||||
{
|
||||
tracing::warn!(target_id = %target_id, error = %e, "device SBOM persist failed");
|
||||
}
|
||||
}
|
||||
// No code to scan. DAST is attempted for a target the matrix
|
||||
// plans it for, and for a migrated DAST target, which carries no
|
||||
// artifacts at all and relies on its DastTarget row. Anywhere
|
||||
@@ -2151,10 +2122,6 @@ impl PipelineOrchestrator {
|
||||
.spawn(left_out_run.status_changed().to_vec());
|
||||
}
|
||||
|
||||
all_sbom.extend(crate::pipeline::sbom::devices::entries(
|
||||
&target.devices,
|
||||
target_id,
|
||||
));
|
||||
if !all_sbom.is_empty() {
|
||||
if let Err(e) = self
|
||||
.persist_control_app_sbom(target, target_id, scan_run_id, all_sbom)
|
||||
@@ -2310,10 +2277,9 @@ impl PipelineOrchestrator {
|
||||
Ok(new_count)
|
||||
}
|
||||
|
||||
/// Store a control-application SBOM (CODESYS libraries + runtime, and the
|
||||
/// Siemens devices the target runs on) for a target and match it against
|
||||
/// known CVEs. Scoped to those package managers so it refreshes on re-scan
|
||||
/// and coexists with any firmware/source SBOM. The
|
||||
/// Store a control-application SBOM (CODESYS libraries + runtime) for a target
|
||||
/// and match it against known CVEs. Scoped to `package_manager = "codesys"` so
|
||||
/// it refreshes on re-scan and coexists with any firmware/source SBOM. The
|
||||
/// runtime `Cmp*` / `3SLicense` components carry real CODESYS advisories, so
|
||||
/// this is where PLC-device CVE coverage comes from.
|
||||
async fn persist_control_app_sbom(
|
||||
@@ -2323,22 +2289,20 @@ impl PipelineOrchestrator {
|
||||
scan_run_id: &str,
|
||||
mut entries: Vec<SbomEntry>,
|
||||
) -> Result<(), AgentError> {
|
||||
// Empty entries are stored too: the components and alerts of the
|
||||
// last scan are then gone (callers skip it when nothing was read).
|
||||
if entries.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
crate::pipeline::component_changes::record(
|
||||
&self.db,
|
||||
scan_run_id,
|
||||
target_id,
|
||||
doc! { "package_manager": { "$in": CONTROL_APP_MANAGERS.to_vec() } },
|
||||
doc! { "package_manager": "codesys" },
|
||||
&entries,
|
||||
)
|
||||
.await;
|
||||
self.db
|
||||
.sbom_entries()
|
||||
.delete_many(doc! {
|
||||
"repo_id": target_id,
|
||||
"package_manager": { "$in": CONTROL_APP_MANAGERS.to_vec() },
|
||||
})
|
||||
.delete_many(doc! { "repo_id": target_id, "package_manager": "codesys" })
|
||||
.await?;
|
||||
|
||||
let cve_scanner = CveScanner::new(
|
||||
|
||||
@@ -65,8 +65,6 @@ pub struct RepoView {
|
||||
pub supplier_sboms: Vec<(std::path::PathBuf, String)>,
|
||||
/// Who supplies the component, for one bought in (#1025).
|
||||
pub supplier: Option<compliance_core::models::SupplierComponent>,
|
||||
/// The Siemens controllers the target runs on (SPS item 4a).
|
||||
pub devices: Vec<compliance_core::models::PlcDevice>,
|
||||
}
|
||||
|
||||
impl RepoView {
|
||||
@@ -104,7 +102,6 @@ impl RepoView {
|
||||
build_outputs: Vec::new(),
|
||||
supplier_sboms: Vec::new(),
|
||||
supplier: target.supplier.clone(),
|
||||
devices: target.devices.clone(),
|
||||
};
|
||||
if let Some(git) = &code.git {
|
||||
view.default_branch = git.default_branch.clone();
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
//! The Siemens controllers a target runs on ([`PlcDevice`], SPS item 4a) as
|
||||
//! SBOM entries: one per device, named and versioned as the customer
|
||||
//! entered it, with the order number the vendor's CSAF advisories name it by
|
||||
//! (matched in [`crate::pipeline::csaf_match`]).
|
||||
|
||||
use compliance_core::models::{PlcDevice, SbomEntry};
|
||||
|
||||
/// The package manager of a device entry.
|
||||
pub(crate) const DEVICE_MANAGER: &str = "siemens-device";
|
||||
|
||||
/// The SBOM entries of target `repo_id`'s `devices`. A device is named by its
|
||||
/// order number, so two devices of one type at one firmware are one entry;
|
||||
/// its label, if any, is kept as evidence.
|
||||
pub(crate) fn entries(devices: &[PlcDevice], repo_id: &str) -> Vec<SbomEntry> {
|
||||
let mut entries: Vec<SbomEntry> = Vec::with_capacity(devices.len());
|
||||
for device in devices {
|
||||
let evidence = device.label.as_deref().map_or_else(
|
||||
|| "entered with the target".to_string(),
|
||||
|l| format!("entered as {l}"),
|
||||
);
|
||||
if let Some(known) = entries
|
||||
.iter_mut()
|
||||
.find(|e| e.name == device.order_number && e.version == device.firmware)
|
||||
{
|
||||
if !known.evidence.contains(&evidence) {
|
||||
known.evidence.push(evidence);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let mut entry = SbomEntry::new(
|
||||
repo_id.to_string(),
|
||||
device.order_number.clone(),
|
||||
device.firmware.clone(),
|
||||
DEVICE_MANAGER.to_string(),
|
||||
);
|
||||
entry.order_number = Some(device.order_number.clone());
|
||||
entry.evidence = vec![evidence];
|
||||
entries.push(entry);
|
||||
}
|
||||
entries
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn each_device_type_and_firmware_is_one_entry() {
|
||||
let devices = [
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", "V3.1.4", Some("Zelle 1")).unwrap(),
|
||||
PlcDevice::new("6es7511-1ak02-0ab0", "3.1.4", Some("Zelle 2")).unwrap(),
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.5", None).unwrap(),
|
||||
];
|
||||
|
||||
let entries = entries(&devices, "t");
|
||||
|
||||
assert_eq!(entries.len(), 2);
|
||||
let first = &entries[0];
|
||||
assert_eq!(
|
||||
(
|
||||
first.name.as_str(),
|
||||
first.version.as_str(),
|
||||
first.package_manager.as_str()
|
||||
),
|
||||
("6ES7511-1AK02-0AB0", "3.1.4", DEVICE_MANAGER)
|
||||
);
|
||||
assert_eq!(first.order_number.as_deref(), Some("6ES7511-1AK02-0AB0"));
|
||||
assert_eq!(first.evidence, ["entered as Zelle 1", "entered as Zelle 2"]);
|
||||
assert_eq!(entries[1].evidence, ["entered with the target"]);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
mod cargo_audit;
|
||||
pub(crate) mod carthage;
|
||||
pub(crate) mod coverage;
|
||||
pub(crate) mod devices;
|
||||
mod distribution;
|
||||
mod gradle;
|
||||
mod mobile;
|
||||
|
||||
@@ -134,13 +134,6 @@ impl EntitlementCheck {
|
||||
self.limit("included_targets")
|
||||
}
|
||||
|
||||
/// How many targets beyond the included ones the plan lets be active:
|
||||
/// `limits.extra_targets` (`0` on the entry plan). `None` when the key is
|
||||
/// missing or null: extra targets are allowed and billed.
|
||||
pub fn extra_targets(&self) -> Option<u32> {
|
||||
self.limit("extra_targets")
|
||||
}
|
||||
|
||||
/// The plan's monthly quota and the customer's Prüftag cap (t72), from
|
||||
/// `limits.monthly_pruefungen` and `limits.prueftag_cap`; a missing or
|
||||
/// null key is no limit.
|
||||
@@ -884,27 +877,6 @@ mod tests {
|
||||
assert_eq!(check(serde_json::Value::Null).included_targets(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_plan_may_allow_no_extra_targets() {
|
||||
let check = |limits: serde_json::Value| -> EntitlementCheck {
|
||||
serde_json::from_value(serde_json::json!({ "allowed": true, "limits": limits }))
|
||||
.expect("an entitlement answer")
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
check(serde_json::json!({ "included_targets": 1, "extra_targets": 0 })).extra_targets(),
|
||||
Some(0)
|
||||
);
|
||||
assert_eq!(
|
||||
check(serde_json::json!({ "extra_targets": null })).extra_targets(),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
check(serde_json::json!({ "included_targets": 5 })).extra_targets(),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_plan_sets_the_quota_and_the_cap() {
|
||||
let check: EntitlementCheck = serde_json::from_value(serde_json::json!({
|
||||
|
||||
@@ -16,101 +16,24 @@ use crate::classify::{classify_target, MockFirmwareDetector};
|
||||
use crate::database::Database;
|
||||
use crate::error::AgentError;
|
||||
|
||||
/// Whether one more counted target fits under `cap`: the active targets
|
||||
/// other than demo ones are fewer.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// [`AgentError::TargetLimit`] when they are not; a database error.
|
||||
async fn room_for_one(db: &Database, cap: u32) -> Result<(), AgentError> {
|
||||
let counted = db
|
||||
.onboarded_targets()
|
||||
.count_documents(doc! { "archived_at": null, "demo": { "$ne": true } })
|
||||
.await?;
|
||||
if counted >= u64::from(cap) {
|
||||
return Err(AgentError::TargetLimit(cap));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Make a demo target the tenant's own before its artifacts change: from
|
||||
/// then on it counts under the plan's cap like any other target. Without
|
||||
/// that, a demo target pointed at the tenant's own code would sit outside
|
||||
/// the cap. A target that is not a demo one is left as it is, and an
|
||||
/// archived one is not checked against the cap (it does not count yet).
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// [`AgentError::TargetLimit`] when the plan has no room for one more
|
||||
/// counted target; the target then stays a demo one. A database error.
|
||||
pub async fn claim_demo(
|
||||
agent: &ComplianceAgent,
|
||||
db: &Database,
|
||||
tenant_id: &str,
|
||||
target: &OnboardedTarget,
|
||||
) -> Result<(), AgentError> {
|
||||
let Some(id) = target.id.filter(|_| target.demo) else {
|
||||
return Ok(());
|
||||
};
|
||||
if target.archived_at.is_none() {
|
||||
if let Some(cap) = agent.plan(tenant_id).await.and_then(|p| p.target_cap()) {
|
||||
room_for_one(db, cap).await?;
|
||||
}
|
||||
}
|
||||
db.onboarded_targets()
|
||||
.update_one(doc! { "_id": id }, doc! { "$unset": { "demo": "" } })
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Whether two artifact lists point at the same sources: the same kinds and
|
||||
/// references, in any order. Credentials, branches and scan state may
|
||||
/// differ; the dashboard's editor sends every artifact on each save.
|
||||
pub fn same_sources(a: &[Artifact], b: &[Artifact]) -> bool {
|
||||
let mut taken = vec![false; b.len()];
|
||||
a.len() == b.len()
|
||||
&& a.iter().all(|x| {
|
||||
let found = (0..b.len())
|
||||
.find(|&i| !taken[i] && b[i].kind == x.kind && b[i].source_ref == x.source_ref);
|
||||
found.map(|i| taken[i] = true).is_some()
|
||||
})
|
||||
}
|
||||
|
||||
/// Insert a new target for `tenant_id` and emit the `target.added` usage
|
||||
/// event: what every way of adding a target does (the API, accepting a
|
||||
/// supplier's SBOM release, Managed Git, the demo seeder), so each counts
|
||||
/// the same under the plan. Returns the stored record with its id set.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// [`AgentError::TargetLimit`] when the plan has no room for another active
|
||||
/// target (the entry plan's `extra_targets: 0`); demo targets are outside
|
||||
/// that count. A database error.
|
||||
/// event. Returns the stored record with its id set.
|
||||
pub async fn create_target(
|
||||
agent: &ComplianceAgent,
|
||||
db: &Database,
|
||||
tenant_id: &str,
|
||||
mut target: OnboardedTarget,
|
||||
) -> Result<OnboardedTarget, AgentError> {
|
||||
// The plan is read once for the cap and the billing. Without an answer
|
||||
// from the registry the target is added, as a scan then runs unmetered.
|
||||
let plan = agent.plan(tenant_id).await;
|
||||
// Demo targets are outside the cap: neither refused nor counted.
|
||||
if let Some(cap) = plan.and_then(|p| p.target_cap()).filter(|_| !target.demo) {
|
||||
room_for_one(db, cap).await?;
|
||||
}
|
||||
let res = db.onboarded_targets().insert_one(&target).await?;
|
||||
target.id = res.inserted_id.as_object_id();
|
||||
// A target beyond the plan's included ones is extra from the start (t72).
|
||||
if let Some(plan) = plan {
|
||||
if let Some((_, billing)) = agent
|
||||
.assign_billing(tenant_id, db, plan.billed_included())
|
||||
.await
|
||||
.into_iter()
|
||||
.find(|(id, _)| Some(*id) == target.id)
|
||||
{
|
||||
target.billing = billing;
|
||||
}
|
||||
if let Some((_, billing)) = agent
|
||||
.refresh_billing(tenant_id, db)
|
||||
.await
|
||||
.into_iter()
|
||||
.find(|(id, _)| Some(*id) == target.id)
|
||||
{
|
||||
target.billing = billing;
|
||||
}
|
||||
let target_id = target.id.map(|id| id.to_hex()).unwrap_or_default();
|
||||
agent.emit_usage(
|
||||
@@ -277,27 +200,6 @@ pub async fn detect_target(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn only_another_source_changes_a_targets_sources() {
|
||||
let repo = Artifact::git_repo("https://git.example/demo.git", "main");
|
||||
let site = Artifact::live_url("https://demo.example");
|
||||
let other_branch = Artifact::git_repo("https://git.example/demo.git", "dev");
|
||||
let own = Artifact::git_repo("https://git.example/own.git", "main");
|
||||
let both = [repo.clone(), site.clone()];
|
||||
let reordered = [site, repo.clone()];
|
||||
let just_repo = std::slice::from_ref(&repo);
|
||||
let repo_twice = [repo.clone(), repo.clone()];
|
||||
|
||||
assert!(same_sources(&both, &reordered));
|
||||
assert!(
|
||||
same_sources(just_repo, &[other_branch]),
|
||||
"a branch is no new source"
|
||||
);
|
||||
assert!(!same_sources(just_repo, &[own]));
|
||||
assert!(!same_sources(just_repo, &both));
|
||||
assert!(!same_sources(&repo_twice, just_repo));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uploaded_artifact_records_stored_path_for_file_kinds() {
|
||||
let a = uploaded_artifact(
|
||||
|
||||
@@ -1,356 +0,0 @@
|
||||
//! The entry plan's target cap against a fake tenant registry: with
|
||||
//! `extra_targets: 0` a new target is refused (409 `target_limit`) once the
|
||||
//! included ones are all active, archiving one frees its place, targets
|
||||
//! already beyond it are never billed as extra, demo targets are outside the
|
||||
//! cap until they are given the tenant's own sources, and a plan without
|
||||
//! the key keeps adding extra targets as before.
|
||||
//! Needs a live Mongo for the agent itself; skips cleanly without one.
|
||||
|
||||
#![allow(clippy::expect_used, clippy::unwrap_used)]
|
||||
|
||||
mod common;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::body::Body;
|
||||
use axum::extract::Request;
|
||||
use axum::http::StatusCode;
|
||||
use axum::middleware::{from_fn, Next};
|
||||
use axum::routing::{patch, post};
|
||||
use axum::{Extension, Json, Router};
|
||||
use mongodb::bson::doc;
|
||||
use tower::ServiceExt;
|
||||
|
||||
use compliance_agent::agent::ComplianceAgent;
|
||||
use compliance_agent::api::handlers::onboarding::{create_target, update_target};
|
||||
use compliance_agent::database::DatabasePool;
|
||||
use compliance_core::models::{OnboardedTarget, TargetBilling, TargetType};
|
||||
use compliance_core::{OrgRole, TenantContext, TenantStatus};
|
||||
|
||||
use common::dev_config;
|
||||
|
||||
/// A registry where `t-entry` includes two targets and allows no extra one,
|
||||
/// and `t-standard` includes one and bills the others.
|
||||
async fn fake_registry() -> String {
|
||||
let app = Router::new().route(
|
||||
"/v1/internal/entitlements/check",
|
||||
post(|Json(body): Json<serde_json::Value>| async move {
|
||||
let limits = match body["tenant_id"].as_str() {
|
||||
Some("t-entry") => serde_json::json!({ "included_targets": 2, "extra_targets": 0 }),
|
||||
_ => serde_json::json!({ "included_targets": 1 }),
|
||||
};
|
||||
Json(serde_json::json!({ "allowed": true, "status": "active", "limits": limits }))
|
||||
}),
|
||||
);
|
||||
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
tokio::spawn(async move { axum::serve(listener, app).await.ok() });
|
||||
format!("http://{addr}")
|
||||
}
|
||||
|
||||
/// An agent whose registry is `registry`, or `None` without Mongo.
|
||||
async fn agent(registry: &str) -> Option<Arc<ComplianceAgent>> {
|
||||
let uri = std::env::var("TEST_MONGODB_URI")
|
||||
.unwrap_or_else(|_| "mongodb://root:example@localhost:27017/?authSource=admin".into());
|
||||
let db_name = format!("cap_{}", &uuid::Uuid::new_v4().simple().to_string()[..10]);
|
||||
let Ok(pool) = DatabasePool::connect(&uri, &db_name).await else {
|
||||
eprintln!("SKIP target_limit: no MongoDB reachable at {uri}");
|
||||
return None;
|
||||
};
|
||||
let mut config = dev_config(uri, db_name);
|
||||
config.tenant_registry_url = Some(registry.to_string());
|
||||
Some(Arc::new(ComplianceAgent::new(config, pool)))
|
||||
}
|
||||
|
||||
fn member(tenant: &str) -> TenantContext {
|
||||
TenantContext {
|
||||
tenant_id: tenant.into(),
|
||||
tenant_slug: "acme".into(),
|
||||
org_roles: vec![OrgRole::ItAdmin],
|
||||
products: vec!["compliance-scanner".into()],
|
||||
plan: "entry".into(),
|
||||
status: TenantStatus::Active,
|
||||
user_id: "u-1".into(),
|
||||
user_name: None,
|
||||
staff: None,
|
||||
api_key: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// `POST /api/v1/targets` named `name` as a member of `tenant`.
|
||||
async fn add(
|
||||
agent: &Arc<ComplianceAgent>,
|
||||
tenant: &str,
|
||||
name: &str,
|
||||
) -> (StatusCode, serde_json::Value) {
|
||||
let ctx = member(tenant);
|
||||
let inject = move |mut req: Request, next: Next| {
|
||||
let ctx = ctx.clone();
|
||||
async move {
|
||||
req.extensions_mut().insert(ctx);
|
||||
next.run(req).await
|
||||
}
|
||||
};
|
||||
let app = Router::new()
|
||||
.route("/api/v1/targets", post(create_target))
|
||||
.layer(Extension(agent.clone()))
|
||||
.layer(from_fn(inject));
|
||||
let body = serde_json::json!({ "name": name, "target_type": "web_app" });
|
||||
let resp = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/api/v1/targets")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(body.to_string()))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let status = resp.status();
|
||||
let bytes = axum::body::to_bytes(resp.into_body(), 1 << 16)
|
||||
.await
|
||||
.unwrap();
|
||||
(status, serde_json::from_slice(&bytes).unwrap_or_default())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn the_entry_plan_refuses_a_target_beyond_its_included_ones() {
|
||||
let registry = fake_registry().await;
|
||||
let Some(agent) = agent(®istry).await else {
|
||||
return;
|
||||
};
|
||||
|
||||
// Arrange: both included places taken.
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Steuerung A").await.0,
|
||||
StatusCode::OK
|
||||
);
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Steuerung B").await.0,
|
||||
StatusCode::OK
|
||||
);
|
||||
|
||||
// Act + Assert: the third is refused and not stored.
|
||||
let (status, body) = add(&agent, "t-entry", "Steuerung C").await;
|
||||
assert_eq!(status, StatusCode::CONFLICT);
|
||||
assert_eq!(body["error"], "target_limit");
|
||||
let db = agent.db_pool.for_tenant_id("t-entry").await.unwrap();
|
||||
assert_eq!(
|
||||
db.onboarded_targets()
|
||||
.count_documents(doc! { "name": "Steuerung C" })
|
||||
.await
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
|
||||
// Archiving one frees its place.
|
||||
db.onboarded_targets()
|
||||
.update_one(
|
||||
doc! { "name": "Steuerung A" },
|
||||
doc! { "$set": { "archived_at": mongodb::bson::DateTime::now() } },
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let (status, body) = add(&agent, "t-entry", "Steuerung C").await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
assert_eq!(body["data"]["billing"], "included");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_plan_without_the_key_adds_extra_targets_as_before() {
|
||||
let registry = fake_registry().await;
|
||||
let Some(agent) = agent(®istry).await else {
|
||||
return;
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
add(&agent, "t-standard", "Anlage 1").await.0,
|
||||
StatusCode::OK
|
||||
);
|
||||
let (status, body) = add(&agent, "t-standard", "Anlage 2").await;
|
||||
assert_eq!(status, StatusCode::OK);
|
||||
assert_eq!(body["data"]["billing"], "extra");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn targets_already_beyond_the_entry_plan_are_never_billed_extra() {
|
||||
let registry = fake_registry().await;
|
||||
let Some(agent) = agent(®istry).await else {
|
||||
return;
|
||||
};
|
||||
// Arrange: three active targets from before the plan, one billed extra.
|
||||
let db = agent.db_pool.for_tenant_id("t-entry").await.unwrap();
|
||||
for (name, billing) in [
|
||||
("Anlage 1", TargetBilling::Included),
|
||||
("Anlage 2", TargetBilling::Included),
|
||||
("Anlage 3", TargetBilling::Extra),
|
||||
] {
|
||||
let mut target = OnboardedTarget::new(name.into(), TargetType::WebApp);
|
||||
target.billing = billing;
|
||||
db.onboarded_targets().insert_one(&target).await.unwrap();
|
||||
}
|
||||
|
||||
// Act
|
||||
agent.refresh_billing("t-entry", &db).await;
|
||||
|
||||
// Assert: all three stay, none is extra, and a fourth is refused.
|
||||
let extra = mongodb::bson::to_bson(&TargetBilling::Extra).unwrap();
|
||||
assert_eq!(
|
||||
db.onboarded_targets()
|
||||
.count_documents(doc! { "billing": extra })
|
||||
.await
|
||||
.unwrap(),
|
||||
0
|
||||
);
|
||||
assert_eq!(
|
||||
db.onboarded_targets()
|
||||
.count_documents(doc! {})
|
||||
.await
|
||||
.unwrap(),
|
||||
3
|
||||
);
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Anlage 4").await.0,
|
||||
StatusCode::CONFLICT
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn demo_targets_are_neither_counted_nor_refused() {
|
||||
let registry = fake_registry().await;
|
||||
let Some(agent) = agent(®istry).await else {
|
||||
return;
|
||||
};
|
||||
let db = agent.db_pool.for_tenant_id("t-entry").await.unwrap();
|
||||
let demo = |name: &str| {
|
||||
let mut target = OnboardedTarget::new(name.into(), TargetType::WebApp);
|
||||
target.demo = true;
|
||||
target
|
||||
};
|
||||
|
||||
// A demo target leaves both included places free.
|
||||
compliance_agent::targets::create_target(&agent, &db, "t-entry", demo("Demo A"))
|
||||
.await
|
||||
.expect("demo target added");
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Steuerung A").await.0,
|
||||
StatusCode::OK
|
||||
);
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Steuerung B").await.0,
|
||||
StatusCode::OK
|
||||
);
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Steuerung C").await.0,
|
||||
StatusCode::CONFLICT
|
||||
);
|
||||
|
||||
// With the places taken, the seeder still adds its targets.
|
||||
compliance_agent::targets::create_target(&agent, &db, "t-entry", demo("Demo B"))
|
||||
.await
|
||||
.expect("demo target added at the cap");
|
||||
}
|
||||
|
||||
/// `PATCH /api/v1/targets/{id}` with `body` as a member of `tenant`.
|
||||
async fn edit(
|
||||
agent: &Arc<ComplianceAgent>,
|
||||
tenant: &str,
|
||||
id: &str,
|
||||
body: serde_json::Value,
|
||||
) -> (StatusCode, serde_json::Value) {
|
||||
let ctx = member(tenant);
|
||||
let inject = move |mut req: Request, next: Next| {
|
||||
let ctx = ctx.clone();
|
||||
async move {
|
||||
req.extensions_mut().insert(ctx);
|
||||
next.run(req).await
|
||||
}
|
||||
};
|
||||
let app = Router::new()
|
||||
.route("/api/v1/targets/{id}", patch(update_target))
|
||||
.layer(Extension(agent.clone()))
|
||||
.layer(from_fn(inject));
|
||||
let resp = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("PATCH")
|
||||
.uri(format!("/api/v1/targets/{id}"))
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(body.to_string()))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
let status = resp.status();
|
||||
let bytes = axum::body::to_bytes(resp.into_body(), 1 << 16)
|
||||
.await
|
||||
.unwrap();
|
||||
(status, serde_json::from_slice(&bytes).unwrap_or_default())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_demo_target_given_the_tenants_own_sources_counts() {
|
||||
let registry = fake_registry().await;
|
||||
let Some(agent) = agent(®istry).await else {
|
||||
return;
|
||||
};
|
||||
let db = agent.db_pool.for_tenant_id("t-entry").await.unwrap();
|
||||
let mut demo = OnboardedTarget::new("Demo · Pumpe".into(), TargetType::WebApp);
|
||||
demo.demo = true;
|
||||
demo.artifacts
|
||||
.push(compliance_core::models::Artifact::live_url(
|
||||
"https://demo.example",
|
||||
));
|
||||
let demo = compliance_agent::targets::create_target(&agent, &db, "t-entry", demo)
|
||||
.await
|
||||
.unwrap();
|
||||
let id = demo.id.unwrap().to_hex();
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Steuerung A").await.0,
|
||||
StatusCode::OK
|
||||
);
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Steuerung B").await.0,
|
||||
StatusCode::OK
|
||||
);
|
||||
let is_demo = || async {
|
||||
db.onboarded_targets()
|
||||
.find_one(doc! { "_id": demo.id.unwrap() })
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.demo
|
||||
};
|
||||
let own = serde_json::json!({ "artifacts": [
|
||||
{ "kind": "git_repo", "source_ref": "https://git.example/own.git", "branch": "main" }
|
||||
] });
|
||||
|
||||
// A new name and the same sources keep it a demo target.
|
||||
let same = serde_json::json!({ "name": "Pumpe", "artifacts": [
|
||||
{ "kind": "live_url", "source_ref": "https://demo.example" }
|
||||
] });
|
||||
assert_eq!(edit(&agent, "t-entry", &id, same).await.0, StatusCode::OK);
|
||||
assert!(is_demo().await);
|
||||
|
||||
// Act + Assert: the tenant's own sources need a place, and none is free.
|
||||
let (status, body) = edit(&agent, "t-entry", &id, own.clone()).await;
|
||||
assert_eq!(status, StatusCode::CONFLICT);
|
||||
assert_eq!(body["error"], "target_limit");
|
||||
assert!(is_demo().await, "refused: still a demo target");
|
||||
|
||||
// With a place free, it becomes the tenant's own and takes that place.
|
||||
db.onboarded_targets()
|
||||
.update_one(
|
||||
doc! { "name": "Steuerung A" },
|
||||
doc! { "$set": { "archived_at": mongodb::bson::DateTime::now() } },
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(edit(&agent, "t-entry", &id, own).await.0, StatusCode::OK);
|
||||
assert!(!is_demo().await);
|
||||
assert_eq!(
|
||||
add(&agent, "t-entry", "Steuerung C").await.0,
|
||||
StatusCode::CONFLICT
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "compliance-core"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -1,683 +0,0 @@
|
||||
//! The 40 CRA Annex I requirements in the words a customer reads: a name
|
||||
//! that says what the requirement is about, and for each state what it means
|
||||
//! for that requirement (#sps2026 item 10).
|
||||
//!
|
||||
//! The catalog (`cra-ai-1` … `cra-ai-40`) stays the source of the ids and of
|
||||
//! the legal wording; people never see those ids. Machine-readable exports
|
||||
//! (CSAF, VEX, OSCAL, JSON) keep them.
|
||||
|
||||
/// One text in both languages of the product.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Words {
|
||||
/// German.
|
||||
pub de: &'static str,
|
||||
/// English.
|
||||
pub en: &'static str,
|
||||
}
|
||||
|
||||
/// The area a requirement belongs to, in the catalog's group order.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum CraArea {
|
||||
/// Secure by design (`cra-ai-1` … `6`).
|
||||
SecureDesign,
|
||||
/// Sign-in and access (`7` … `12`).
|
||||
Access,
|
||||
/// Encryption (`13` … `17`).
|
||||
Encryption,
|
||||
/// Development (`18` … `20`).
|
||||
Development,
|
||||
/// Supply chain (`21` … `23`).
|
||||
SupplyChain,
|
||||
/// Logs (`24` … `27`).
|
||||
Logging,
|
||||
/// Updates (`28` … `31`).
|
||||
Updates,
|
||||
/// Vulnerabilities and incidents (`32` … `40`).
|
||||
Vulnerabilities,
|
||||
}
|
||||
|
||||
impl CraArea {
|
||||
/// Every area, in the order the views show them.
|
||||
pub const ALL: [Self; 8] = [
|
||||
Self::SecureDesign,
|
||||
Self::Access,
|
||||
Self::Encryption,
|
||||
Self::Development,
|
||||
Self::SupplyChain,
|
||||
Self::Logging,
|
||||
Self::Updates,
|
||||
Self::Vulnerabilities,
|
||||
];
|
||||
|
||||
/// The area's name.
|
||||
pub const fn name(self) -> Words {
|
||||
match self {
|
||||
Self::SecureDesign => w("Sicher entworfen", "Secure by design"),
|
||||
Self::Access => w("Anmeldung und Zugriff", "Sign-in and access"),
|
||||
Self::Encryption => w("Verschlüsselung", "Encryption"),
|
||||
Self::Development => w("Entwicklung", "Development"),
|
||||
Self::SupplyChain => w("Lieferkette", "Supply chain"),
|
||||
Self::Logging => w("Protokolle", "Logs"),
|
||||
Self::Updates => w("Updates", "Updates"),
|
||||
Self::Vulnerabilities => w(
|
||||
"Schwachstellen und Vorfälle",
|
||||
"Vulnerabilities and incidents",
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One requirement as a customer reads it.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct CraRequirement {
|
||||
/// The catalog id (`cra-ai-8`).
|
||||
pub id: &'static str,
|
||||
/// Its area.
|
||||
pub area: CraArea,
|
||||
/// Its name (`Keine Standardpasswörter`).
|
||||
pub name: Words,
|
||||
/// What red means here: what an open finding against it shows. `None`
|
||||
/// for a requirement a code scan cannot decide.
|
||||
pub against: Option<Words>,
|
||||
/// What green means here: what the scan did not find.
|
||||
pub clear: Option<Words>,
|
||||
/// The document that proves a requirement no code scan decides, as the
|
||||
/// end of "Sie weisen sie nach mit …" (`ein Rechtekonzept`).
|
||||
pub proof: Option<Words>,
|
||||
}
|
||||
|
||||
/// What orange means for every requirement: only part of what it covers was
|
||||
/// checked.
|
||||
pub const PARTLY_CHECKED: Words = w(
|
||||
"Nur ein Teil wurde geprüft, zum Beispiel bei einem Yocto-Image die Rezeptliste statt des \
|
||||
fertigen Images.",
|
||||
"Only part was checked, for example a Yocto image's recipe list instead of the built image.",
|
||||
);
|
||||
|
||||
/// The requirement with catalog id `id`, if it is one of the 40.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use compliance_core::cra_requirements::requirement;
|
||||
/// assert_eq!(requirement("cra-ai-8").unwrap().name.de, "Keine Standardpasswörter");
|
||||
/// assert!(requirement("cra-ai-20-csharp-xxe").is_none());
|
||||
/// ```
|
||||
pub fn requirement(id: &str) -> Option<&'static CraRequirement> {
|
||||
let number: usize = id.strip_prefix("cra-ai-")?.parse().ok()?;
|
||||
CRA_REQUIREMENTS
|
||||
.get(number.checked_sub(1)?)
|
||||
.filter(|r| r.id == id)
|
||||
}
|
||||
|
||||
/// The name of requirement `id` in German and English, or `None` for an id
|
||||
/// that is not one of the 40.
|
||||
pub fn name(id: &str) -> Option<Words> {
|
||||
requirement(id).map(|r| r.name)
|
||||
}
|
||||
|
||||
const fn w(de: &'static str, en: &'static str) -> Words {
|
||||
Words { de, en }
|
||||
}
|
||||
|
||||
/// A requirement a code scan checks.
|
||||
const fn checked(
|
||||
id: &'static str,
|
||||
area: CraArea,
|
||||
name: Words,
|
||||
against: Words,
|
||||
clear: Words,
|
||||
) -> CraRequirement {
|
||||
CraRequirement {
|
||||
id,
|
||||
area,
|
||||
name,
|
||||
against: Some(against),
|
||||
clear: Some(clear),
|
||||
proof: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// A requirement proven by a document.
|
||||
const fn proven(id: &'static str, area: CraArea, name: Words, proof: Words) -> CraRequirement {
|
||||
CraRequirement {
|
||||
id,
|
||||
area,
|
||||
name,
|
||||
against: None,
|
||||
clear: None,
|
||||
proof: Some(proof),
|
||||
}
|
||||
}
|
||||
|
||||
use CraArea::{
|
||||
Access, Development, Encryption, Logging, SecureDesign, SupplyChain, Updates, Vulnerabilities,
|
||||
};
|
||||
|
||||
/// The 40 requirements, `cra-ai-1` first.
|
||||
pub const CRA_REQUIREMENTS: [CraRequirement; 40] = [
|
||||
checked(
|
||||
"cra-ai-1",
|
||||
SecureDesign,
|
||||
w("Sichere Werkseinstellungen", "Secure factory settings"),
|
||||
w(
|
||||
"Im Auslieferungszustand ist etwas offen, das es nicht sein muss, etwa eine \
|
||||
Debug-Schnittstelle oder ein unnötiger Dienst.",
|
||||
"Something is open as shipped that need not be, such as a debug interface or an \
|
||||
unneeded service.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand keine unsicheren Voreinstellungen.",
|
||||
"The scan found no insecure defaults.",
|
||||
),
|
||||
),
|
||||
// Decided in code only on a Yocto layer tree, so it has both.
|
||||
CraRequirement {
|
||||
id: "cra-ai-2",
|
||||
area: SecureDesign,
|
||||
name: w("Nur nötige Dienste aktiv", "Only needed services running"),
|
||||
against: Some(w(
|
||||
"Das Image startet Dienste oder öffnet Schnittstellen, die das Gerät nicht braucht.",
|
||||
"The image starts services or opens interfaces the device does not need.",
|
||||
)),
|
||||
clear: Some(w(
|
||||
"Im Image fand der Scan keine unnötig aktiven Dienste.",
|
||||
"The scan found no needlessly running services in the image.",
|
||||
)),
|
||||
proof: Some(w(
|
||||
"eine Liste der Dienste und Schnittstellen mit ihrem Zweck",
|
||||
"a list of services and interfaces with their purpose",
|
||||
)),
|
||||
},
|
||||
proven(
|
||||
"cra-ai-3",
|
||||
SecureDesign,
|
||||
w("Getrennte Sicherheitsbereiche", "Separated security zones"),
|
||||
w(
|
||||
"eine Architekturbeschreibung",
|
||||
"an architecture description",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-4",
|
||||
SecureDesign,
|
||||
w("Nur die nötigen Rechte", "Only the rights needed"),
|
||||
w("ein Rechtekonzept", "a permissions concept"),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-5",
|
||||
SecureDesign,
|
||||
w("Schutz vor Manipulation", "Protection against tampering"),
|
||||
w(
|
||||
"eine Beschreibung von Secure Boot und Code-Signatur",
|
||||
"a description of secure boot and code signing",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-6",
|
||||
SecureDesign,
|
||||
w("Prüfung auf Veränderung", "Checks for modification"),
|
||||
w(
|
||||
"Software oder Firmware wird geladen, ohne vorher zu prüfen, ob sie verändert wurde.",
|
||||
"Software or firmware is loaded without first checking whether it was modified.",
|
||||
),
|
||||
w(
|
||||
"An den Stellen, an denen Software geladen wird, fand der Scan eine Prüfung auf \
|
||||
Veränderung.",
|
||||
"Where software is loaded, the scan found a check for modification.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-7",
|
||||
Access,
|
||||
w("Sichere Anmeldung", "Secure sign-in"),
|
||||
w(
|
||||
"Eine Anmeldung ist schwach umgesetzt, etwa ohne Passwortprüfung oder mit einem \
|
||||
veralteten Verfahren.",
|
||||
"A sign-in is weakly built, for example without a password check or with an \
|
||||
outdated method.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand keine schwach umgesetzte Anmeldung.",
|
||||
"The scan found no weakly built sign-in.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-8",
|
||||
Access,
|
||||
w("Keine Standardpasswörter", "No default passwords"),
|
||||
w(
|
||||
"Im Code oder im Image steckt ein fest eingebautes Passwort, das auf jedem Gerät \
|
||||
gleich ist.",
|
||||
"The code or image holds a built-in password that is the same on every device.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand kein fest eingebautes Passwort.",
|
||||
"The scan found no built-in password.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-9",
|
||||
Access,
|
||||
w("Zugangsdaten sicher verwahrt", "Credentials kept safe"),
|
||||
w(
|
||||
"Zugangsdaten, Tokens oder Schlüssel liegen im Klartext im Code oder in Dateien.",
|
||||
"Credentials, tokens or keys are in plain text in the code or in files.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand keine Zugangsdaten im Klartext.",
|
||||
"The scan found no credentials in plain text.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-10",
|
||||
Access,
|
||||
w("Sitzungen enden sicher", "Sessions end safely"),
|
||||
w(
|
||||
"Sitzungen laufen nicht ab oder sind nicht gegen untergeschobene Anfragen geschützt.",
|
||||
"Sessions do not expire or are not protected against forged requests.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand keine unsicher verwalteten Sitzungen.",
|
||||
"The scan found no unsafely managed sessions.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-11",
|
||||
Access,
|
||||
w(
|
||||
"Schutz vor Passwort-Raten",
|
||||
"Protection against password guessing",
|
||||
),
|
||||
w(
|
||||
"Eine Anmeldung erlaubt beliebig viele Versuche.",
|
||||
"A sign-in allows any number of attempts.",
|
||||
),
|
||||
w(
|
||||
"Wo man sich anmeldet, ist die Zahl der Versuche begrenzt.",
|
||||
"Where people sign in, the number of attempts is limited.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-12",
|
||||
Access,
|
||||
w("Rollen und Rechte", "Roles and permissions"),
|
||||
w(
|
||||
"Funktionen für Administratoren sind ohne Rechteprüfung erreichbar.",
|
||||
"Administrator functions can be reached without a permission check.",
|
||||
),
|
||||
w(
|
||||
"Vor den geschützten Funktionen fand der Scan eine Rechteprüfung.",
|
||||
"The scan found a permission check before the protected functions.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-13",
|
||||
Encryption,
|
||||
w(
|
||||
"Vertrauliche Daten verschlüsselt",
|
||||
"Sensitive data encrypted",
|
||||
),
|
||||
w(
|
||||
"Vertrauliche Daten werden unverschlüsselt oder mit einem veralteten Verfahren \
|
||||
verarbeitet.",
|
||||
"Sensitive data is handled unencrypted or with an outdated method.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand keine unverschlüsselten vertraulichen Daten.",
|
||||
"The scan found no unencrypted sensitive data.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-14",
|
||||
Encryption,
|
||||
w("Gespeicherte Daten verschlüsselt", "Stored data encrypted"),
|
||||
w(
|
||||
"Daten werden unverschlüsselt oder mit einem schwachen Verfahren gespeichert.",
|
||||
"Data is stored unencrypted or with a weak method.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand keine unverschlüsselt gespeicherten Daten.",
|
||||
"The scan found no data stored unencrypted.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-15",
|
||||
Encryption,
|
||||
w("Verbindungen verschlüsselt", "Connections encrypted"),
|
||||
w(
|
||||
"Eine Verbindung läuft unverschlüsselt oder mit altem SSL/TLS.",
|
||||
"A connection runs unencrypted or over old SSL/TLS.",
|
||||
),
|
||||
w(
|
||||
"Alle gefundenen Verbindungen nutzen aktuelle Verschlüsselung.",
|
||||
"Every connection found uses current encryption.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-16",
|
||||
Encryption,
|
||||
w("Schlüssel sicher verwahrt", "Keys kept safe"),
|
||||
w(
|
||||
"Ein kryptografischer Schlüssel steht im Code oder liegt ungeschützt bei den Dateien.",
|
||||
"A cryptographic key is written in the code or lies unprotected among the files.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand keinen ungeschützten Schlüssel.",
|
||||
"The scan found no unprotected key.",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-17",
|
||||
Encryption,
|
||||
w("Nur nötige Daten erfassen", "Collect only the data needed"),
|
||||
w("ein Datenschutzkonzept", "a data protection concept"),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-18",
|
||||
Development,
|
||||
w(
|
||||
"Sicherheit im Entwicklungsablauf",
|
||||
"Security in the development process",
|
||||
),
|
||||
w(
|
||||
"eine Beschreibung Ihres Entwicklungsablaufs",
|
||||
"a description of your development process",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-19",
|
||||
Development,
|
||||
w("Code-Prüfung durch Kollegen", "Code review by colleagues"),
|
||||
w("Ihre Regeln für Code-Reviews", "your code review rules"),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-20",
|
||||
Development,
|
||||
w("Sicherer Programmcode", "Safe program code"),
|
||||
w(
|
||||
"Im Code stecken unsichere Muster, etwa ungeprüfte Eingaben oder unsichere \
|
||||
C-Funktionen.",
|
||||
"The code holds unsafe patterns, such as unchecked input or unsafe C functions.",
|
||||
),
|
||||
w(
|
||||
"Die Sicherheitstests fanden keine unsicheren Muster.",
|
||||
"The security tests found no unsafe patterns.",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-21",
|
||||
SupplyChain,
|
||||
w("Fremdkomponenten geprüft", "Third-party components vetted"),
|
||||
w(
|
||||
"Ihren Prüfablauf für zugekaufte Komponenten",
|
||||
"your vetting process for bought-in components",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-22",
|
||||
SupplyChain,
|
||||
w(
|
||||
"Bekannte Schwachstellen in Komponenten",
|
||||
"Known vulnerabilities in components",
|
||||
),
|
||||
w(
|
||||
"Eine eingesetzte Komponente hat eine bekannte Schwachstelle, die noch offen ist.",
|
||||
"A component in use has a known vulnerability that is still open.",
|
||||
),
|
||||
w(
|
||||
"Für keine eingesetzte Komponente ist eine offene Schwachstelle bekannt.",
|
||||
"No component in use has a known open vulnerability.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-23",
|
||||
SupplyChain,
|
||||
w(
|
||||
"Vollständige Stückliste (SBOM)",
|
||||
"Complete bill of materials (SBOM)",
|
||||
),
|
||||
w(
|
||||
"Die Stückliste fehlt, oder ihr fehlen Angaben wie Version oder Lizenz.",
|
||||
"The bill of materials is missing, or lacks details such as version or licence.",
|
||||
),
|
||||
w(
|
||||
"Die Stückliste ist vollständig und maschinenlesbar.",
|
||||
"The bill of materials is complete and machine-readable.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-24",
|
||||
Logging,
|
||||
w(
|
||||
"Sicherheitsereignisse protokolliert",
|
||||
"Security events logged",
|
||||
),
|
||||
w(
|
||||
"Anmeldungen, Rechteänderungen oder Aktionen von Administratoren werden nicht \
|
||||
protokolliert.",
|
||||
"Sign-ins, permission changes or administrator actions are not logged.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand eine Protokollierung der sicherheitsrelevanten Ereignisse.",
|
||||
"The scan found the security-relevant events being logged.",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-25",
|
||||
Logging,
|
||||
w("Zentrale Überwachung", "Central monitoring"),
|
||||
w("Ihr Überwachungskonzept", "your monitoring concept"),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-26",
|
||||
Logging,
|
||||
w(
|
||||
"Angriffe automatisch erkannt",
|
||||
"Attacks detected automatically",
|
||||
),
|
||||
w(
|
||||
"eine Beschreibung Ihrer Angriffserkennung",
|
||||
"a description of your attack detection",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-27",
|
||||
Logging,
|
||||
w("Fälschungssichere Protokolle", "Tamper-proof logs"),
|
||||
w(
|
||||
"Protokolle lassen sich nachträglich ändern oder werden zu kurz aufbewahrt.",
|
||||
"Logs can be changed afterwards or are kept too briefly.",
|
||||
),
|
||||
w(
|
||||
"Der Scan fand keine änderbaren oder zu kurz aufbewahrten Protokolle.",
|
||||
"The scan found no logs that can be changed or are kept too briefly.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-28",
|
||||
Updates,
|
||||
w("Sicherer Update-Weg", "Secure update channel"),
|
||||
w(
|
||||
"Updates kommen über einen ungesicherten Weg, etwa per HTTP.",
|
||||
"Updates arrive over an unsecured channel, such as plain HTTP.",
|
||||
),
|
||||
w(
|
||||
"Updates kommen über einen gesicherten Weg.",
|
||||
"Updates arrive over a secured channel.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-29",
|
||||
Updates,
|
||||
w("Signierte Updates", "Signed updates"),
|
||||
w(
|
||||
"Ein Update wird installiert, ohne vorher seine Signatur zu prüfen.",
|
||||
"An update is installed without first checking its signature.",
|
||||
),
|
||||
w(
|
||||
"Vor der Installation wird die Signatur eines Updates geprüft.",
|
||||
"An update's signature is checked before it is installed.",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-30",
|
||||
Updates,
|
||||
w("Unversehrte Update-Pakete", "Intact update packages"),
|
||||
w(
|
||||
"Update-Pakete werden ohne Prüfsumme oder Signatur übernommen.",
|
||||
"Update packages are taken without a checksum or signature.",
|
||||
),
|
||||
w(
|
||||
"Update-Pakete werden vor der Übernahme geprüft.",
|
||||
"Update packages are checked before they are taken.",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-31",
|
||||
Updates,
|
||||
w(
|
||||
"Updates über die Lebensdauer",
|
||||
"Updates over the product's lifetime",
|
||||
),
|
||||
w(
|
||||
"eine Support-Zusage mit Enddatum",
|
||||
"a support commitment with an end date",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-32",
|
||||
Vulnerabilities,
|
||||
w(
|
||||
"Schwachstellen werden gesucht",
|
||||
"Vulnerabilities are looked for",
|
||||
),
|
||||
w(
|
||||
"Ihren Meldeweg und Ihre Überwachung",
|
||||
"your reporting channel and monitoring",
|
||||
),
|
||||
),
|
||||
checked(
|
||||
"cra-ai-33",
|
||||
Vulnerabilities,
|
||||
w(
|
||||
"Stückliste laufend geprüft",
|
||||
"Bill of materials checked continuously",
|
||||
),
|
||||
w(
|
||||
"Die Stückliste nennt Komponenten mit neu bekannt gewordenen Schwachstellen.",
|
||||
"The bill of materials lists components with newly known vulnerabilities.",
|
||||
),
|
||||
w(
|
||||
"Bei jedem Scan wird die Stückliste gegen bekannte Schwachstellen geprüft; nichts \
|
||||
ist offen.",
|
||||
"Every scan checks the bill of materials against known vulnerabilities; nothing is \
|
||||
open.",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-34",
|
||||
Vulnerabilities,
|
||||
w("Wichtiges zuerst beheben", "Fix what matters first"),
|
||||
w("Ihre Fristen für die Behebung", "your deadlines for fixes"),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-35",
|
||||
Vulnerabilities,
|
||||
w(
|
||||
"Meldestelle für Schwachstellen",
|
||||
"Vulnerability reporting contact",
|
||||
),
|
||||
w(
|
||||
"eine veröffentlichte Kontaktadresse für Meldungen",
|
||||
"a published contact address for reports",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-36",
|
||||
Vulnerabilities,
|
||||
w("Plan für Sicherheitsvorfälle", "Incident response plan"),
|
||||
w("Ihren Notfallplan", "your emergency plan"),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-37",
|
||||
Vulnerabilities,
|
||||
w(
|
||||
"Frühwarnung binnen 24 Stunden",
|
||||
"Early warning within 24 hours",
|
||||
),
|
||||
w(
|
||||
"Ihren Meldeablauf an ENISA und CSIRT",
|
||||
"your reporting procedure to ENISA and the CSIRT",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-38",
|
||||
Vulnerabilities,
|
||||
w(
|
||||
"Vorfallsbericht binnen 72 Stunden",
|
||||
"Incident report within 72 hours",
|
||||
),
|
||||
w("Ihre Berichtsvorlage", "your report template"),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-39",
|
||||
Vulnerabilities,
|
||||
w("Sicherheits-Updates bereitstellen", "Ship security updates"),
|
||||
w(
|
||||
"Ihren Ablauf für Sicherheits-Updates",
|
||||
"your procedure for security updates",
|
||||
),
|
||||
),
|
||||
proven(
|
||||
"cra-ai-40",
|
||||
Vulnerabilities,
|
||||
w("Lückenlos dokumentiert", "Fully documented"),
|
||||
w(
|
||||
"Ihre Dokumentation, zehn Jahre aufbewahrt",
|
||||
"your documentation, kept for ten years",
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_table_is_in_id_order_and_every_id_resolves() {
|
||||
for (i, r) in CRA_REQUIREMENTS.iter().enumerate() {
|
||||
assert_eq!(r.id, format!("cra-ai-{}", i + 1));
|
||||
assert_eq!(requirement(r.id), Some(r));
|
||||
}
|
||||
assert!(requirement("cra-ai-0").is_none());
|
||||
assert!(requirement("cra-ai-41").is_none());
|
||||
assert!(requirement("cra-ai-8-csharp-hardcoded-credential").is_none());
|
||||
assert!(requirement("mc-1").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_requirement_says_what_its_states_mean() {
|
||||
for r in &CRA_REQUIREMENTS {
|
||||
assert_eq!(r.against.is_some(), r.clear.is_some(), "{}", r.id);
|
||||
assert!(r.against.is_some() || r.proof.is_some(), "{}", r.id);
|
||||
for words in [Some(r.name), r.against, r.clear, r.proof]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
assert!(!words.de.is_empty() && !words.en.is_empty(), "{}", r.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn names_are_unique_and_every_area_has_requirements() {
|
||||
let mut names: Vec<&str> = CRA_REQUIREMENTS.iter().map(|r| r.name.de).collect();
|
||||
names.sort_unstable();
|
||||
names.dedup();
|
||||
assert_eq!(names.len(), CRA_REQUIREMENTS.len());
|
||||
for area in CraArea::ALL {
|
||||
assert!(CRA_REQUIREMENTS.iter().any(|r| r.area == area), "{area:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,27 +53,9 @@ impl AdvisoryProduct {
|
||||
/// `version`: its exact version, or one its range contains. A product
|
||||
/// without either covers every version of it.
|
||||
pub fn covers(&self, name: &str, version: &str) -> bool {
|
||||
normalised_name(&self.name) == normalised_name(name) && self.covers_version(version)
|
||||
}
|
||||
|
||||
/// Whether the product is the device with order number `order_number`
|
||||
/// (compared as [`crate::models::plc_device::normalised_order_number`])
|
||||
/// at firmware `version`, as [`Self::covers`] compares versions.
|
||||
pub fn covers_device(&self, order_number: &str, version: &str) -> bool {
|
||||
self.has_order_number(order_number) && self.covers_version(version)
|
||||
}
|
||||
|
||||
/// Whether `order_number` is one of the product's order numbers.
|
||||
pub fn has_order_number(&self, order_number: &str) -> bool {
|
||||
let wanted = crate::models::plc_device::normalised_order_number(order_number);
|
||||
self.model_numbers
|
||||
.iter()
|
||||
.any(|m| crate::models::plc_device::normalised_order_number(m) == wanted)
|
||||
}
|
||||
|
||||
/// Whether `version` is the product's exact version or in its range; a
|
||||
/// product without either covers every version.
|
||||
fn covers_version(&self, version: &str) -> bool {
|
||||
if normalised_name(&self.name) != normalised_name(name) {
|
||||
return false;
|
||||
}
|
||||
match (&self.version, &self.version_range) {
|
||||
(Some(exact), _) => cmp_dotted(exact, version).is_eq(),
|
||||
(None, Some(range)) => Vers::parse(range).is_some_and(|r| r.contains(version)),
|
||||
@@ -172,48 +154,11 @@ impl Advisory {
|
||||
/// (`3.5.22.40`), lowest first.
|
||||
pub fn fixed_versions(&self, vulnerability: &AdvisoryVulnerability, name: &str) -> Vec<String> {
|
||||
let wanted = normalised_name(name);
|
||||
self.fixed_versions_where(vulnerability, |p| normalised_name(&p.name) == wanted)
|
||||
}
|
||||
|
||||
/// The fixed firmware of `vulnerability` for the device with order
|
||||
/// number `order_number`, lowest first: the exact versions of its fixed
|
||||
/// products, and the version a vendor fix for one of its products names
|
||||
/// (Siemens marks its products only affected and writes the fix as
|
||||
/// `Update to V3.1.5 or later version`).
|
||||
pub fn fixed_device_versions(
|
||||
&self,
|
||||
vulnerability: &AdvisoryVulnerability,
|
||||
order_number: &str,
|
||||
) -> Vec<String> {
|
||||
let is_it = |id: &String| {
|
||||
self.product(id)
|
||||
.is_some_and(|p| p.has_order_number(order_number))
|
||||
};
|
||||
let mut versions =
|
||||
self.fixed_versions_where(vulnerability, |p| p.has_order_number(order_number));
|
||||
versions.extend(
|
||||
vulnerability
|
||||
.remediations
|
||||
.iter()
|
||||
.filter(|r| r.category == "vendor_fix" && r.product_ids.iter().any(is_it))
|
||||
.filter_map(|r| version_in_text(&r.details)),
|
||||
);
|
||||
versions.sort_by(|a, b| cmp_dotted(a, b));
|
||||
versions.dedup();
|
||||
versions
|
||||
}
|
||||
|
||||
/// The exact versions of the fixed products `is_it` picks, oldest first.
|
||||
fn fixed_versions_where(
|
||||
&self,
|
||||
vulnerability: &AdvisoryVulnerability,
|
||||
is_it: impl Fn(&AdvisoryProduct) -> bool,
|
||||
) -> Vec<String> {
|
||||
let mut versions: Vec<String> = vulnerability
|
||||
.fixed
|
||||
.iter()
|
||||
.filter_map(|id| self.product(id))
|
||||
.filter(|p| is_it(p))
|
||||
.filter(|p| normalised_name(&p.name) == wanted)
|
||||
.filter_map(|p| p.version.clone())
|
||||
.collect();
|
||||
versions.sort_by(|a, b| cmp_dotted(a, b));
|
||||
@@ -222,21 +167,6 @@ impl Advisory {
|
||||
}
|
||||
}
|
||||
|
||||
/// The firmware a vendor fix's text updates to, when it says so the way
|
||||
/// Siemens does: `Update to V3.1.5 or later version` is `3.1.5`. Anything
|
||||
/// else gives none: a version with letters (`V3.X.18`), or a text about
|
||||
/// something other than an update (`A hardware upgrade to LOGO! V9 BM`).
|
||||
fn version_in_text(text: &str) -> Option<String> {
|
||||
let rest = text.trim_start().strip_prefix("Update to V")?;
|
||||
let end = rest
|
||||
.find(|c: char| !(c.is_ascii_digit() || c == '.'))
|
||||
.unwrap_or(rest.len());
|
||||
let (version, after) = rest.split_at(end);
|
||||
let version = version.trim_end_matches('.');
|
||||
let ends_cleanly = after.is_empty() || after.starts_with([' ', ',', '.', ';']);
|
||||
(version.starts_with(|c: char| c.is_ascii_digit()) && ends_cleanly).then(|| version.to_string())
|
||||
}
|
||||
|
||||
/// The text at `key` of `value`, trimmed, if not empty.
|
||||
fn text(value: &serde_json::Value, key: &str) -> Option<String> {
|
||||
value
|
||||
@@ -513,32 +443,3 @@ pub fn parse(doc: &serde_json::Value) -> Result<Advisory, CsafError> {
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::version_in_text;
|
||||
|
||||
#[test]
|
||||
fn only_an_update_to_a_numeric_version_names_a_fix() {
|
||||
let read = |t: &str| version_in_text(t);
|
||||
assert_eq!(
|
||||
read("Update to V3.1.5 or later version").as_deref(),
|
||||
Some("3.1.5")
|
||||
);
|
||||
assert_eq!(read("Update to V9 or later version").as_deref(), Some("9"));
|
||||
assert_eq!(
|
||||
read("Update to V4.2.1 or later version, migrate project").as_deref(),
|
||||
Some("4.2.1")
|
||||
);
|
||||
assert_eq!(read("Update to V2.9.8.").as_deref(), Some("2.9.8"));
|
||||
assert_eq!(read("Update to V3.X.18 or later version"), None);
|
||||
assert_eq!(
|
||||
read("Note: A hardware upgrade to LOGO! V9 BM or later is also required"),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
read("To obtain SIMATIC S7-410 V10.1 contact your local support."),
|
||||
None
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,435 +0,0 @@
|
||||
//! A Siemens controller against the advisories that name it (SPS item 4a):
|
||||
//! what its page shows before the next scan does.
|
||||
//!
|
||||
//! The matching is the scan's ([`AdvisoryProduct::covers_device`],
|
||||
//! [`Advisory::fixed_device_versions`]), so a device's light and its CVE
|
||||
//! alerts never disagree once the target is scanned.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::csaf_ingest::{Advisory, AdvisoryProduct, AdvisoryVulnerability};
|
||||
use crate::models::PlcDevice;
|
||||
use crate::version::cmp_dotted;
|
||||
|
||||
/// What Siemens calls the device, from an advisory's product name.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct DeviceName {
|
||||
/// The full name without the order number (`SIMATIC S7-1500 CPU 1511-1 PN`).
|
||||
pub name: String,
|
||||
/// The part from `CPU` on (`CPU 1511-1 PN`), or the full name.
|
||||
pub short: String,
|
||||
/// The series before `CPU` without the brand (`S7-1500`, `ET 200SP`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub family: Option<String>,
|
||||
}
|
||||
|
||||
impl DeviceName {
|
||||
/// The name in an advisory product's name `product` (`SIMATIC S7-1500
|
||||
/// CPU 1511-1 PN (6ES7511-1AK02-0AB0)`): the order number in brackets
|
||||
/// and a version after it are dropped. `None` for an empty name.
|
||||
pub fn from_product(product: &str) -> Option<Self> {
|
||||
let name = product
|
||||
.split_once(" (")
|
||||
.map_or(product, |(name, _)| name)
|
||||
.trim();
|
||||
if name.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let (short, family) = match name.find("CPU ") {
|
||||
Some(at) if at > 0 => {
|
||||
let series = name[..at].trim();
|
||||
let series = series.strip_prefix("SIMATIC").unwrap_or(series).trim();
|
||||
(
|
||||
&name[at..],
|
||||
(!series.is_empty()).then(|| series.to_string()),
|
||||
)
|
||||
}
|
||||
_ => (name, None),
|
||||
};
|
||||
Some(Self {
|
||||
name: name.to_string(),
|
||||
short: short.to_string(),
|
||||
family,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// One advisory naming the device, as its page lists it.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct DeviceAdvisory {
|
||||
/// Its id (`SSA-019113`).
|
||||
pub id: String,
|
||||
pub title: String,
|
||||
/// Its page, which Siemens' terms ask every use to link.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub url: Option<String>,
|
||||
/// The CVEs it lists for the device.
|
||||
pub cves: Vec<String>,
|
||||
/// The highest CVSS base severity of those (`HIGH`).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub severity: Option<String>,
|
||||
/// Whether one of them affects the device's firmware.
|
||||
pub affected: bool,
|
||||
/// The firmware that fixes all of them that apply: those affecting the
|
||||
/// device when it is affected, otherwise all it lists. `None` when one
|
||||
/// has no fix.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub fixed_from: Option<String>,
|
||||
}
|
||||
|
||||
/// What Siemens' advisories know of an order number, to recognise it while
|
||||
/// it is typed.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct DeviceLookup {
|
||||
/// The order number, normalised (`6ES7511-1AK02-0AB0`).
|
||||
pub order_number: String,
|
||||
/// Whether it has a Siemens order number's shape.
|
||||
pub valid: bool,
|
||||
/// What Siemens calls it, from the newest advisory naming it.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub product: Option<DeviceName>,
|
||||
/// How many advisories name it.
|
||||
pub advisories: usize,
|
||||
}
|
||||
|
||||
/// A device's state in the advisories.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DeviceState {
|
||||
/// An advisory affects its firmware.
|
||||
Affected,
|
||||
/// Advisories name it, none affects its firmware.
|
||||
NotAffected,
|
||||
/// No advisory names its order number.
|
||||
NotNamed,
|
||||
}
|
||||
|
||||
/// A device and the advisories naming it.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct DeviceCheck {
|
||||
#[serde(flatten)]
|
||||
pub device: PlcDevice,
|
||||
/// What Siemens calls it, from the newest advisory naming it.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub product: Option<DeviceName>,
|
||||
/// The advisories naming it: affecting it first, then by severity.
|
||||
pub advisories: Vec<DeviceAdvisory>,
|
||||
}
|
||||
|
||||
impl DeviceCheck {
|
||||
/// The device against `advisories`, Siemens' in any order.
|
||||
pub fn new(device: PlcDevice, advisories: &[Advisory]) -> Self {
|
||||
let mut naming: Vec<&Advisory> = advisories
|
||||
.iter()
|
||||
.filter(|a| {
|
||||
a.products
|
||||
.iter()
|
||||
.any(|p| p.has_order_number(&device.order_number))
|
||||
})
|
||||
.collect();
|
||||
// Newest first, so the name is the one Siemens uses now.
|
||||
naming.sort_by(|a, b| b.updated.cmp(&a.updated).then_with(|| a.id.cmp(&b.id)));
|
||||
let product = naming.iter().find_map(|a| {
|
||||
a.products
|
||||
.iter()
|
||||
.filter(|p| p.has_order_number(&device.order_number))
|
||||
.find_map(|p| DeviceName::from_product(&p.name))
|
||||
});
|
||||
let mut rows: Vec<DeviceAdvisory> =
|
||||
naming.into_iter().filter_map(|a| row(a, &device)).collect();
|
||||
rows.sort_by(|a, b| {
|
||||
b.affected
|
||||
.cmp(&a.affected)
|
||||
.then_with(|| severity_rank(&b.severity).cmp(&severity_rank(&a.severity)))
|
||||
.then_with(|| a.id.cmp(&b.id))
|
||||
});
|
||||
Self {
|
||||
device,
|
||||
product,
|
||||
advisories: rows,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether an advisory affects it, names it only, or none names it.
|
||||
pub fn state(&self) -> DeviceState {
|
||||
if self.advisories.iter().any(|a| a.affected) {
|
||||
DeviceState::Affected
|
||||
} else if self.advisories.is_empty() {
|
||||
DeviceState::NotNamed
|
||||
} else {
|
||||
DeviceState::NotAffected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Advisory `advisory`'s row for `device`, when one of its vulnerabilities
|
||||
/// lists one of the device's products.
|
||||
fn row(advisory: &Advisory, device: &PlcDevice) -> Option<DeviceAdvisory> {
|
||||
let order_number = device.order_number.as_str();
|
||||
let products: Vec<&AdvisoryProduct> = advisory
|
||||
.products
|
||||
.iter()
|
||||
.filter(|p| p.has_order_number(order_number))
|
||||
.collect();
|
||||
let lists = |ids: &[String]| {
|
||||
ids.iter()
|
||||
.any(|id| products.iter().any(|p| &p.product_id == id))
|
||||
};
|
||||
let named: Vec<&AdvisoryVulnerability> = advisory
|
||||
.vulnerabilities
|
||||
.iter()
|
||||
.filter(|v| lists(&v.affected) || lists(&v.fixed) || lists(&v.not_affected))
|
||||
.collect();
|
||||
if named.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let affects = |v: &AdvisoryVulnerability| {
|
||||
v.affected.iter().any(|id| {
|
||||
advisory
|
||||
.product(id)
|
||||
.is_some_and(|p| p.covers_device(order_number, &device.firmware))
|
||||
})
|
||||
};
|
||||
let affecting: Vec<&AdvisoryVulnerability> =
|
||||
named.iter().copied().filter(|v| affects(v)).collect();
|
||||
let affected = !affecting.is_empty();
|
||||
let fixing = if affected { &affecting } else { &named };
|
||||
// The fix of each: the lowest fixed firmware above the device's when it
|
||||
// is affected, the lowest at all otherwise. The row's is the highest.
|
||||
let fixed_from = fixing
|
||||
.iter()
|
||||
.map(|v| {
|
||||
advisory
|
||||
.fixed_device_versions(v, order_number)
|
||||
.into_iter()
|
||||
.find(|f| !affected || cmp_dotted(f, &device.firmware).is_gt())
|
||||
})
|
||||
.try_fold(None::<String>, |highest, fix| {
|
||||
let fix = fix?;
|
||||
Some(Some(match highest {
|
||||
Some(h) if cmp_dotted(&h, &fix).is_ge() => h,
|
||||
_ => fix,
|
||||
}))
|
||||
})
|
||||
.flatten();
|
||||
let severity = named
|
||||
.iter()
|
||||
.filter_map(|v| v.severity.clone())
|
||||
.max_by_key(|s| severity_rank(&Some(s.clone())));
|
||||
let mut cves: Vec<String> = named.iter().filter_map(|v| v.cve.clone()).collect();
|
||||
cves.sort();
|
||||
cves.dedup();
|
||||
Some(DeviceAdvisory {
|
||||
id: advisory.id.clone(),
|
||||
title: advisory.title.clone(),
|
||||
url: advisory.url.clone(),
|
||||
cves,
|
||||
severity,
|
||||
affected,
|
||||
fixed_from,
|
||||
})
|
||||
}
|
||||
|
||||
/// A CVSS base severity's order: `CRITICAL` highest, none lowest.
|
||||
fn severity_rank(severity: &Option<String>) -> u8 {
|
||||
match severity.as_deref().map(str::to_ascii_uppercase).as_deref() {
|
||||
Some("CRITICAL") => 4,
|
||||
Some("HIGH") => 3,
|
||||
Some("MEDIUM") => 2,
|
||||
Some("LOW") => 1,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used, clippy::expect_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::csaf_ingest::Remediation;
|
||||
|
||||
fn product(id: &str, name: &str, range: &str) -> AdvisoryProduct {
|
||||
let order_number = name
|
||||
.split_once('(')
|
||||
.and_then(|(_, rest)| rest.split_once(')'))
|
||||
.map(|(on, _)| on.to_string());
|
||||
AdvisoryProduct {
|
||||
product_id: id.into(),
|
||||
vendor: Some("Siemens".into()),
|
||||
family: None,
|
||||
name: name.into(),
|
||||
version: None,
|
||||
version_range: Some(range.into()),
|
||||
cpe: None,
|
||||
purl: None,
|
||||
model_numbers: order_number.into_iter().collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn vulnerability(
|
||||
cve: &str,
|
||||
severity: &str,
|
||||
affected: &[&str],
|
||||
fix: Option<(&str, &[&str])>,
|
||||
) -> AdvisoryVulnerability {
|
||||
AdvisoryVulnerability {
|
||||
cve: Some(cve.into()),
|
||||
severity: Some(severity.into()),
|
||||
affected: affected.iter().map(|s| s.to_string()).collect(),
|
||||
remediations: fix
|
||||
.map(|(details, ids)| Remediation {
|
||||
category: "vendor_fix".into(),
|
||||
details: details.into(),
|
||||
url: None,
|
||||
product_ids: ids.iter().map(|s| s.to_string()).collect(),
|
||||
})
|
||||
.into_iter()
|
||||
.collect(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn advisory(
|
||||
id: &str,
|
||||
updated: &str,
|
||||
products: Vec<AdvisoryProduct>,
|
||||
vulnerabilities: Vec<AdvisoryVulnerability>,
|
||||
) -> Advisory {
|
||||
Advisory {
|
||||
id: id.into(),
|
||||
title: format!("{id} title"),
|
||||
publisher: "Siemens ProductCERT".into(),
|
||||
url: Some(format!(
|
||||
"https://cert-portal.siemens.com/productcert/html/{id}.html"
|
||||
)),
|
||||
tlp: Some("WHITE".into()),
|
||||
updated: updated.into(),
|
||||
products,
|
||||
vulnerabilities,
|
||||
}
|
||||
}
|
||||
|
||||
const CPU: &str = "SIMATIC S7-1500 CPU 1511-1 PN (6ES7511-1AK02-0AB0)";
|
||||
|
||||
fn device(firmware: &str) -> PlcDevice {
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", firmware, Some("Hauptsteuerung")).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn siemens_names_split_into_series_and_cpu() {
|
||||
assert_eq!(
|
||||
DeviceName::from_product(CPU),
|
||||
Some(DeviceName {
|
||||
name: "SIMATIC S7-1500 CPU 1511-1 PN".into(),
|
||||
short: "CPU 1511-1 PN".into(),
|
||||
family: Some("S7-1500".into()),
|
||||
})
|
||||
);
|
||||
let et =
|
||||
DeviceName::from_product("SIMATIC ET 200SP CPU 1512SP-1 PN (6ES7512-1DK01-0AB0) V3.0")
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
(et.short.as_str(), et.family.as_deref()),
|
||||
("CPU 1512SP-1 PN", Some("ET 200SP"))
|
||||
);
|
||||
let logo = DeviceName::from_product("LOGO! 8 BM (6ED1052-1MD08-0BA2)").unwrap();
|
||||
assert_eq!((logo.short.as_str(), logo.family), ("LOGO! 8 BM", None));
|
||||
assert_eq!(DeviceName::from_product(" (6ES7511-1AK02-0AB0)"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_device_is_affected_until_the_firmware_fixing_all_its_advisorys_cves() {
|
||||
let advisories = [advisory(
|
||||
"SSA-100001",
|
||||
"2026-10-01",
|
||||
vec![
|
||||
product("1", CPU, "vers:intdot/<3.1.5"),
|
||||
product("2", CPU, "vers:intdot/<3.1.7"),
|
||||
],
|
||||
vec![
|
||||
vulnerability(
|
||||
"CVE-2026-1",
|
||||
"MEDIUM",
|
||||
&["1"],
|
||||
Some(("Update to V3.1.5 or later version", &["1"])),
|
||||
),
|
||||
vulnerability(
|
||||
"CVE-2026-2",
|
||||
"HIGH",
|
||||
&["2"],
|
||||
Some(("Update to V3.1.7 or later version", &["2"])),
|
||||
),
|
||||
],
|
||||
)];
|
||||
|
||||
let old = DeviceCheck::new(device("3.1.4"), &advisories);
|
||||
assert_eq!(old.state(), DeviceState::Affected);
|
||||
let row = &old.advisories[0];
|
||||
assert_eq!(row.cves, ["CVE-2026-1", "CVE-2026-2"]);
|
||||
assert_eq!(row.severity.as_deref(), Some("HIGH"));
|
||||
assert_eq!(row.fixed_from.as_deref(), Some("3.1.7"));
|
||||
assert_eq!(old.product.as_ref().unwrap().short, "CPU 1511-1 PN");
|
||||
|
||||
let between = DeviceCheck::new(device("3.1.6"), &advisories);
|
||||
assert_eq!(between.advisories[0].fixed_from.as_deref(), Some("3.1.7"));
|
||||
|
||||
let current = DeviceCheck::new(device("3.1.7"), &advisories);
|
||||
assert_eq!(current.state(), DeviceState::NotAffected);
|
||||
assert!(!current.advisories[0].affected);
|
||||
assert_eq!(current.advisories[0].fixed_from.as_deref(), Some("3.1.7"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_affecting_cve_without_a_fix_leaves_no_fixed_firmware() {
|
||||
let advisories = [advisory(
|
||||
"SSA-100002",
|
||||
"2026-10-01",
|
||||
vec![product("1", CPU, "vers:all/*")],
|
||||
vec![vulnerability("CVE-2026-3", "LOW", &["1"], None)],
|
||||
)];
|
||||
let check = DeviceCheck::new(device("3.1.4"), &advisories);
|
||||
assert!(check.advisories[0].affected);
|
||||
assert_eq!(check.advisories[0].fixed_from, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_put_affecting_and_severe_first_and_skip_other_devices() {
|
||||
let other = "SIMATIC S7-1500 CPU 1513-1 PN (6ES7513-1AL02-0AB0)";
|
||||
let advisories = [
|
||||
advisory(
|
||||
"SSA-1",
|
||||
"2026-01-01",
|
||||
vec![product("1", CPU, "vers:intdot/<2.0")],
|
||||
vec![vulnerability("CVE-1", "CRITICAL", &["1"], None)],
|
||||
),
|
||||
advisory(
|
||||
"SSA-2",
|
||||
"2026-02-01",
|
||||
vec![product("1", CPU, "vers:all/*")],
|
||||
vec![vulnerability("CVE-2", "MEDIUM", &["1"], None)],
|
||||
),
|
||||
advisory(
|
||||
"SSA-3",
|
||||
"2026-03-01",
|
||||
vec![product("1", CPU, "vers:all/*")],
|
||||
vec![vulnerability("CVE-3", "HIGH", &["1"], None)],
|
||||
),
|
||||
advisory(
|
||||
"SSA-4",
|
||||
"2026-04-01",
|
||||
vec![product("1", other, "vers:all/*")],
|
||||
vec![vulnerability("CVE-4", "CRITICAL", &["1"], None)],
|
||||
),
|
||||
];
|
||||
let check = DeviceCheck::new(device("3.1.4"), &advisories);
|
||||
let ids: Vec<&str> = check.advisories.iter().map(|a| a.id.as_str()).collect();
|
||||
assert_eq!(ids, ["SSA-3", "SSA-2", "SSA-1"]);
|
||||
assert_eq!(
|
||||
DeviceCheck::new(
|
||||
PlcDevice::new("6ES7516-3AN02-0AB0", "3.0", None).unwrap(),
|
||||
&advisories
|
||||
)
|
||||
.state(),
|
||||
DeviceState::NotNamed
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,12 @@ pub mod build_info;
|
||||
pub mod component_changes;
|
||||
pub mod config;
|
||||
pub mod control_check;
|
||||
pub mod cra_requirements;
|
||||
pub mod csaf_docs;
|
||||
pub mod csaf_ingest;
|
||||
pub mod cve_groups;
|
||||
pub mod cve_history;
|
||||
pub mod cve_matrix;
|
||||
pub mod db;
|
||||
pub mod device_check;
|
||||
pub mod encoding;
|
||||
pub mod enisa_docs;
|
||||
pub mod error;
|
||||
|
||||
@@ -28,20 +28,6 @@ pub struct AdvisoryRef {
|
||||
pub remediation: Option<String>,
|
||||
}
|
||||
|
||||
/// The providers whose terms ask every use of an advisory to link it.
|
||||
const BACKLINK_PROVIDERS: &[&str] = &["siemens"];
|
||||
|
||||
impl AdvisoryRef {
|
||||
/// The advisory's page when its provider's terms require a link back to
|
||||
/// it (Siemens ProductCERT); `None` otherwise. The views link nothing
|
||||
/// else off-site: a customer copies the id instead.
|
||||
pub fn required_backlink(&self) -> Option<&str> {
|
||||
self.url
|
||||
.as_deref()
|
||||
.filter(|_| BACKLINK_PROVIDERS.contains(&self.provider.as_str()))
|
||||
}
|
||||
}
|
||||
|
||||
/// What is known about the exploitation of one CVE (#493), from public
|
||||
/// sources: CISA's Known Exploited Vulnerabilities catalog, FIRST's EPSS and
|
||||
/// CISA's Vulnrichment SSVC decision points.
|
||||
@@ -298,31 +284,6 @@ mod tests {
|
||||
a
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_a_provider_that_asks_for_it_keeps_its_link() {
|
||||
let advisory = |provider: &str| AdvisoryRef {
|
||||
provider: provider.into(),
|
||||
id: "X-1".into(),
|
||||
title: "t".into(),
|
||||
url: Some("https://vendor.example/x-1".into()),
|
||||
remediation: None,
|
||||
};
|
||||
assert_eq!(
|
||||
advisory("siemens").required_backlink(),
|
||||
Some("https://vendor.example/x-1")
|
||||
);
|
||||
assert_eq!(advisory("codesys").required_backlink(), None);
|
||||
assert_eq!(
|
||||
advisory("supplier:https://s.example/pm.json").required_backlink(),
|
||||
None
|
||||
);
|
||||
let unlinked = AdvisoryRef {
|
||||
url: None,
|
||||
..advisory("siemens")
|
||||
};
|
||||
assert_eq!(unlinked.required_backlink(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_not_affected_and_fixed_resolve_an_alert() {
|
||||
use crate::models::vex::{VexAssessment, VexStatus};
|
||||
|
||||
@@ -21,7 +21,6 @@ pub mod onboarding;
|
||||
pub mod oscal;
|
||||
pub mod oscal_assessment;
|
||||
pub mod pentest;
|
||||
pub mod plc_device;
|
||||
pub mod project;
|
||||
pub mod repository;
|
||||
pub mod sbom;
|
||||
@@ -82,7 +81,6 @@ pub use pentest::{
|
||||
PentestStatus, PentestStrategy, SeverityDistribution, TestUserRecord, TesterInfo,
|
||||
ToolCallRecord,
|
||||
};
|
||||
pub use plc_device::{PlcDevice, PlcDeviceError};
|
||||
pub use project::{Project, ProjectKind, ProjectLevel};
|
||||
pub use repository::ScanTrigger;
|
||||
pub use sbom::{
|
||||
|
||||
@@ -704,14 +704,6 @@ pub struct OnboardedTarget {
|
||||
/// advisories. `None` for what the tenant makes itself.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub supplier: Option<SupplierComponent>,
|
||||
/// The Siemens controllers the target runs on (SPS item 4a), matched by
|
||||
/// order number and firmware against Siemens' CSAF advisories.
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub devices: Vec<super::PlcDevice>,
|
||||
/// Whether the demo seeder added the target: a plan's cap on active
|
||||
/// targets neither counts nor refuses it. Not settable through the API.
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
pub demo: bool,
|
||||
/// Creation timestamp.
|
||||
#[serde(
|
||||
default = "chrono::Utc::now",
|
||||
@@ -774,8 +766,6 @@ impl OnboardedTarget {
|
||||
included_choice: None,
|
||||
included_until: None,
|
||||
supplier: None,
|
||||
devices: Vec::new(),
|
||||
demo: false,
|
||||
created_at: now,
|
||||
updated_at: now,
|
||||
}
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
//! A Siemens controller a target runs on, by its order number (SPS item 4a).
|
||||
//!
|
||||
//! Siemens ProductCERT names each affected CPU in its CSAF advisories by its
|
||||
//! order number (MLFB, `6ES7511-1AK02-0AB0`) and a firmware range. A device
|
||||
//! entered with both is matched against them, so an advisory about the CPU
|
||||
//! a machine uses reaches its target even when no project file names it.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A controller the target runs on: a Siemens order number and the firmware
|
||||
/// version installed.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PlcDevice {
|
||||
/// The order number, upper case without spaces (`6ES7511-1AK02-0AB0`).
|
||||
pub order_number: String,
|
||||
/// The firmware version installed, without a leading `V` (`3.1.4`).
|
||||
pub firmware: String,
|
||||
/// What the customer calls it (`Hauptsteuerung Zelle 2`), if anything.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub label: Option<String>,
|
||||
}
|
||||
|
||||
/// Why a device cannot be stored.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
pub enum PlcDeviceError {
|
||||
/// Not a Siemens order number (`6ES7511-1AK02-0AB0`).
|
||||
#[error("not a Siemens order number (such as 6ES7511-1AK02-0AB0): {0}")]
|
||||
OrderNumber(String),
|
||||
/// No firmware version, or not one of dot-separated numbers (`3.1.4`).
|
||||
/// Advisories name affected firmware by range, so a device without one
|
||||
/// could not be matched.
|
||||
#[error("not a firmware version (such as V3.1.4): {0}")]
|
||||
Firmware(String),
|
||||
}
|
||||
|
||||
impl PlcDeviceError {
|
||||
/// A stable name of the refusal, for a client to word it in its own
|
||||
/// language: `order_number` or `firmware`.
|
||||
pub fn code(&self) -> &'static str {
|
||||
match self {
|
||||
Self::OrderNumber(_) => "order_number",
|
||||
Self::Firmware(_) => "firmware",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PlcDevice {
|
||||
/// A device from what a person entered: the order number is upper-cased
|
||||
/// with spaces removed, a leading `V` of the firmware dropped, and a
|
||||
/// blank label left out.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// [`PlcDeviceError::OrderNumber`] when the order number does not have a
|
||||
/// Siemens order number's shape (`7 characters - 5 - 4`, starting with a
|
||||
/// digit); [`PlcDeviceError::Firmware`] when the firmware is not
|
||||
/// dot-separated numbers.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use compliance_core::models::PlcDevice;
|
||||
///
|
||||
/// let device = PlcDevice::new("6es7511-1ak02-0ab0 ", "V3.1.4", None).unwrap();
|
||||
/// assert_eq!(device.order_number, "6ES7511-1AK02-0AB0");
|
||||
/// assert_eq!(device.firmware, "3.1.4");
|
||||
/// ```
|
||||
pub fn new(
|
||||
order_number: &str,
|
||||
firmware: &str,
|
||||
label: Option<&str>,
|
||||
) -> Result<Self, PlcDeviceError> {
|
||||
let order_number = normalised_order_number(order_number);
|
||||
if !is_order_number(&order_number) {
|
||||
return Err(PlcDeviceError::OrderNumber(order_number));
|
||||
}
|
||||
let trimmed = firmware.trim();
|
||||
let firmware = trimmed
|
||||
.strip_prefix(['V', 'v'])
|
||||
.unwrap_or(trimmed)
|
||||
.trim()
|
||||
.to_string();
|
||||
let numeric = !firmware.is_empty()
|
||||
&& firmware
|
||||
.split('.')
|
||||
.all(|part| !part.is_empty() && part.bytes().all(|b| b.is_ascii_digit()));
|
||||
if !numeric {
|
||||
return Err(PlcDeviceError::Firmware(trimmed.to_string()));
|
||||
}
|
||||
Ok(Self {
|
||||
order_number,
|
||||
firmware,
|
||||
label: label
|
||||
.map(str::trim)
|
||||
.filter(|l| !l.is_empty())
|
||||
.map(str::to_string),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// An order number as advisories and devices compare: upper case, without
|
||||
/// spaces (` 6es7511-1ak02-0ab0` is `6ES7511-1AK02-0AB0`).
|
||||
pub fn normalised_order_number(text: &str) -> String {
|
||||
text.chars()
|
||||
.filter(|c| !c.is_whitespace())
|
||||
.collect::<String>()
|
||||
.to_uppercase()
|
||||
}
|
||||
|
||||
/// Whether `text` (normalised) has a Siemens order number's shape: three
|
||||
/// dash-separated groups of 7, 5 and 4 letters or digits, the first a digit
|
||||
/// (`6ES7511-1AK02-0AB0`, `6AG1518-4AX00-4AC0`, `6ED1052-1MD08-0BA2`).
|
||||
fn is_order_number(text: &str) -> bool {
|
||||
let groups: Vec<&str> = text.split('-').collect();
|
||||
groups.len() == 3
|
||||
&& [7, 5, 4]
|
||||
.iter()
|
||||
.zip(&groups)
|
||||
.all(|(len, g)| g.len() == *len && g.bytes().all(|b| b.is_ascii_alphanumeric()))
|
||||
&& text.as_bytes().first().is_some_and(u8::is_ascii_digit)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn an_entered_device_is_stored_as_advisories_name_it() {
|
||||
let device = PlcDevice::new(" 6es7511-1ak02-0ab0", " v3.1.4 ", Some(" ")).unwrap();
|
||||
assert_eq!(
|
||||
device,
|
||||
PlcDevice {
|
||||
order_number: "6ES7511-1AK02-0AB0".into(),
|
||||
firmware: "3.1.4".into(),
|
||||
label: None,
|
||||
}
|
||||
);
|
||||
let logo = PlcDevice::new("6ED1052-1MD08-0BA2", "8.4", Some("Pumpe")).unwrap();
|
||||
assert_eq!(logo.label.as_deref(), Some("Pumpe"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_device_that_could_not_be_matched_is_refused() {
|
||||
for bad in [
|
||||
"",
|
||||
"CPU 1511-1 PN",
|
||||
"6ES7511-1AK02",
|
||||
"6ES7511-1AK02-0AB0X",
|
||||
"XES7511-1AK02-0AB0",
|
||||
] {
|
||||
assert_eq!(
|
||||
PlcDevice::new(bad, "3.1.4", None).unwrap_err().code(),
|
||||
"order_number",
|
||||
"{bad}"
|
||||
);
|
||||
}
|
||||
for bad in ["", "V", "latest", "3..1", "V3.1.4a"] {
|
||||
assert_eq!(
|
||||
PlcDevice::new("6ES7511-1AK02-0AB0", bad, None)
|
||||
.unwrap_err()
|
||||
.code(),
|
||||
"firmware",
|
||||
"{bad}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,11 +124,6 @@ pub struct SbomEntry {
|
||||
/// advisory database could look up (a Yocto recipe's CVE_PRODUCT).
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub cpe: Option<String>,
|
||||
/// The vendor's order number of a device (Siemens MLFB
|
||||
/// `6ES7511-1AK02-0AB0`; [`super::PlcDevice`]), which the vendor's CSAF
|
||||
/// advisories name it by.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub order_number: Option<String>,
|
||||
/// The images the component is in, where that is known (a Yocto recipe
|
||||
/// an image recipe installs); `None` when it is not, and on components
|
||||
/// stored before it was recorded.
|
||||
@@ -185,7 +180,6 @@ impl SbomEntry {
|
||||
download_url: None,
|
||||
manufacturer_url: None,
|
||||
cpe: None,
|
||||
order_number: None,
|
||||
in_image: None,
|
||||
concluded: None,
|
||||
policy: None,
|
||||
|
||||
@@ -241,12 +241,6 @@ pub fn cdx_components(entries: &[SbomEntry]) -> Vec<serde_json::Value> {
|
||||
"name": e.name,
|
||||
"version": e.version,
|
||||
});
|
||||
// A Siemens device (`PlcDevice`) is hardware named by its order
|
||||
// number, at the firmware version installed.
|
||||
if e.order_number.is_some() {
|
||||
comp["type"] = serde_json::Value::String("device".into());
|
||||
comp["manufacturer"] = serde_json::json!({ "name": "Siemens" });
|
||||
}
|
||||
if let Some(purl) = &e.purl {
|
||||
comp["purl"] = serde_json::Value::String(purl.clone());
|
||||
if let Some(parsed) = Purl::parse(purl) {
|
||||
@@ -1179,24 +1173,4 @@ mod tests {
|
||||
assert_eq!(spdx["packages"][1]["licenseDeclared"], "MIT");
|
||||
assert!(spdx.get("hasExtractedLicensingInfos").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_siemens_device_is_a_device_by_its_manufacturer() {
|
||||
let mut device = SbomEntry::new(
|
||||
"t".into(),
|
||||
"6ES7511-1AK02-0AB0".into(),
|
||||
"3.1.4".into(),
|
||||
"siemens-device".into(),
|
||||
);
|
||||
device.order_number = Some("6ES7511-1AK02-0AB0".into());
|
||||
let library = SbomEntry::new("t".into(), "zlib".into(), "1.3".into(), "conan".into());
|
||||
|
||||
let components = cdx_components(&[device, library]);
|
||||
|
||||
assert_eq!(components[0]["type"], "device");
|
||||
assert_eq!(components[0]["manufacturer"]["name"], "Siemens");
|
||||
assert_eq!(components[0]["version"], "3.1.4");
|
||||
assert_eq!(components[1]["type"], "library");
|
||||
assert!(components[1].get("manufacturer").is_none());
|
||||
}
|
||||
}
|
||||
@@ -148,14 +148,3 @@ fn live_advisories_of_the_default_providers_are_read() {
|
||||
assert!(!advisory.vulnerabilities.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_siemens_fix_is_read_from_its_vendor_fix_text_for_the_device_only() {
|
||||
let a = fixture("siemens-synthetic.json");
|
||||
let v = &a.vulnerabilities[0];
|
||||
// Product 2 is fixed at 3.1.5, and the vendor fix for product 1 says
|
||||
// "Update to V3.1.5 or later version": one version.
|
||||
assert_eq!(a.fixed_device_versions(v, "6es7511-1ak02-0ab0"), ["3.1.5"]);
|
||||
// The fix names product 1 only, not the other CPU.
|
||||
assert!(a.fixed_device_versions(v, "6ES7513-1AL02-0AB0").is_empty());
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
{
|
||||
"document": {
|
||||
"category": "csaf_security_advisory",
|
||||
"csaf_version": "2.0",
|
||||
"title": "Example CPUs: a synthetic advisory shaped like Siemens ProductCERT's",
|
||||
"publisher": { "category": "vendor", "name": "Example ProductCERT", "namespace": "https://example.invalid" },
|
||||
"distribution": { "tlp": { "label": "WHITE", "url": "https://www.first.org/tlp/" } },
|
||||
"references": [
|
||||
{ "category": "self", "summary": "CSAF", "url": "https://example.invalid/productcert/csaf/ssa-900001.json" },
|
||||
{ "category": "self", "summary": "Advisory", "url": "https://example.invalid/productcert/html/ssa-900001.html" }
|
||||
],
|
||||
"tracking": {
|
||||
"id": "SSA-900001",
|
||||
"status": "final",
|
||||
"version": "1",
|
||||
"current_release_date": "2026-11-10T00:00:00.000Z",
|
||||
"initial_release_date": "2026-11-10T00:00:00.000Z",
|
||||
"revision_history": [{ "date": "2026-11-10T00:00:00.000Z", "number": "1", "summary": "Initial" }]
|
||||
}
|
||||
},
|
||||
"product_tree": {
|
||||
"branches": [
|
||||
{
|
||||
"category": "vendor",
|
||||
"name": "Example",
|
||||
"branches": [
|
||||
{
|
||||
"category": "product_name",
|
||||
"name": "Example S7-1500 CPU 1511-1 PN (6ES7511-1AK02-0AB0)",
|
||||
"branches": [
|
||||
{
|
||||
"category": "product_version_range",
|
||||
"name": "vers:intdot/<3.1.5",
|
||||
"product": {
|
||||
"name": "Example S7-1500 CPU 1511-1 PN (6ES7511-1AK02-0AB0)",
|
||||
"product_id": "1",
|
||||
"product_identification_helper": { "model_numbers": ["6ES7511-1AK02-0AB0"] }
|
||||
}
|
||||
},
|
||||
{
|
||||
"category": "product_version",
|
||||
"name": "3.1.5",
|
||||
"product": {
|
||||
"name": "Example S7-1500 CPU 1511-1 PN (6ES7511-1AK02-0AB0) V3.1.5",
|
||||
"product_id": "2",
|
||||
"product_identification_helper": { "model_numbers": ["6ES7511-1AK02-0AB0"] }
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"category": "product_name",
|
||||
"name": "Example S7-1500 CPU 1513-1 PN (6ES7513-1AL02-0AB0)",
|
||||
"branches": [
|
||||
{
|
||||
"category": "product_version_range",
|
||||
"name": "vers:all/*",
|
||||
"product": {
|
||||
"name": "Example S7-1500 CPU 1513-1 PN (6ES7513-1AL02-0AB0)",
|
||||
"product_id": "3",
|
||||
"product_identification_helper": { "model_numbers": ["6ES7513-1AL02-0AB0"] }
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"category": "product_name",
|
||||
"name": "Example S7-1200 CPU family (incl. SIPLUS variants)",
|
||||
"branches": [
|
||||
{
|
||||
"category": "product_version_range",
|
||||
"name": "vers:all/*",
|
||||
"product": { "name": "Example S7-1200 CPU family (incl. SIPLUS variants)", "product_id": "4" }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"vulnerabilities": [
|
||||
{
|
||||
"cve": "CVE-2026-90101",
|
||||
"title": "Improper input validation in the web server",
|
||||
"notes": [{ "category": "description", "text": "A crafted request can restart the CPU." }],
|
||||
"product_status": { "known_affected": ["1", "3", "4"], "fixed": ["2"] },
|
||||
"remediations": [
|
||||
{ "category": "vendor_fix", "details": "Update to V3.1.5 or later version", "product_ids": ["1"] },
|
||||
{ "category": "mitigation", "details": "Restrict access to port 443/tcp", "product_ids": ["1", "3", "4"] }
|
||||
],
|
||||
"scores": [
|
||||
{
|
||||
"products": ["1", "3", "4"],
|
||||
"cvss_v3": { "version": "3.1", "vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H", "baseScore": 7.5, "baseSeverity": "HIGH" }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "compliance-dashboard"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
default-run = "compliance-dashboard"
|
||||
|
||||
|
||||
@@ -884,12 +884,6 @@ tbody tr:last-child td {
|
||||
}
|
||||
|
||||
/* Neutral: skipped because a feature is disabled in this environment — not an error. */
|
||||
.badge-open {
|
||||
background: var(--bg-elevated);
|
||||
color: var(--text-secondary);
|
||||
border: 1px dashed var(--text-faint);
|
||||
}
|
||||
|
||||
.badge-neutral {
|
||||
background: transparent;
|
||||
color: var(--text-tertiary);
|
||||
@@ -2961,6 +2955,18 @@ tbody tr:last-child td {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.sbom-vuln-link {
|
||||
font-size: 12px;
|
||||
color: var(--accent);
|
||||
text-decoration: none;
|
||||
transition: color 0.15s;
|
||||
}
|
||||
|
||||
.sbom-vuln-link:hover {
|
||||
color: var(--accent-hover);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* License compliance */
|
||||
.sbom-license-badge {
|
||||
font-size: 12px;
|
||||
@@ -4237,7 +4243,9 @@ tbody tr:last-child td {
|
||||
.notification-sev.sev-high { background: rgba(255,140,0,0.12); color: #ff8c00; }
|
||||
.notification-sev.sev-medium { background: var(--warning-bg); color: var(--warning); }
|
||||
.notification-sev.sev-low { background: rgba(0,200,255,0.08); color: var(--accent); }
|
||||
.notification-cve-id { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-primary); font-family: var(--font-mono); }
|
||||
.notification-cve-id { font-size: 12px; font-weight: 600; color: var(--text-primary); font-family: var(--font-mono); }
|
||||
.notification-cve-id a { color: var(--accent); text-decoration: none; }
|
||||
.notification-cve-id a:hover { text-decoration: underline; }
|
||||
.notification-cvss { font-size: 10px; color: var(--text-secondary); margin-left: auto; font-family: var(--font-mono); }
|
||||
.notification-dismiss-btn { background: none; border: none; color: var(--text-tertiary); cursor: pointer; padding: 2px; margin-left: 4px; }
|
||||
.notification-dismiss-btn:hover { color: var(--danger); }
|
||||
@@ -4474,17 +4482,6 @@ tbody tr:last-child td {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.finding-control {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 2px 8px;
|
||||
border-radius: 999px;
|
||||
background: var(--accent-muted);
|
||||
color: var(--text-primary);
|
||||
font-size: 12px;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.finding-controls-more,
|
||||
.finding-controls-none {
|
||||
font-size: 11px;
|
||||
@@ -4495,8 +4492,7 @@ tbody tr:last-child td {
|
||||
.finding-refs {
|
||||
list-style: none;
|
||||
display: grid;
|
||||
justify-items: start;
|
||||
gap: 6px;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.finding-refs-catalog {
|
||||
@@ -4586,8 +4582,8 @@ tbody tr:last-child td {
|
||||
}
|
||||
|
||||
.cra-violated { background: var(--danger); }
|
||||
.cra-open { background: var(--text-faint); }
|
||||
.cra-partial { background: var(--warning); }
|
||||
.cra-open { background: var(--warning); }
|
||||
.cra-partial { background: var(--info); }
|
||||
.cra-clear { background: var(--success); }
|
||||
.cra-process { background: color-mix(in srgb, var(--accent) 28%, var(--bg-elevated)); }
|
||||
|
||||
@@ -5589,20 +5585,7 @@ tbody tr:last-child td {
|
||||
}
|
||||
|
||||
.vex-advisory {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11.5px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.vex-cve-id,
|
||||
.vex-advisory-line {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 4px 6px;
|
||||
}
|
||||
|
||||
.vex-advisory-source {
|
||||
display: block;
|
||||
font-size: 11.5px;
|
||||
color: var(--accent);
|
||||
}
|
||||
@@ -5759,6 +5742,13 @@ tbody tr:last-child td {
|
||||
gap: 6px 10px;
|
||||
}
|
||||
|
||||
.cra-control-id {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 11.5px;
|
||||
color: var(--text-tertiary);
|
||||
min-width: 72px;
|
||||
}
|
||||
|
||||
.cra-control-title {
|
||||
font-weight: 500;
|
||||
}
|
||||
@@ -5769,6 +5759,7 @@ tbody tr:last-child td {
|
||||
}
|
||||
|
||||
.cra-control-reason {
|
||||
padding-left: 82px;
|
||||
font-size: 12.5px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
@@ -5777,6 +5768,7 @@ tbody tr:last-child td {
|
||||
list-style: none;
|
||||
display: grid;
|
||||
gap: 3px;
|
||||
padding-left: 82px;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
@@ -8070,18 +8062,14 @@ span.repo-crumb-name {
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
/* ── CRA Annex I map (#957): requirements by name, grouped by area ── */
|
||||
/* ── CRA Annex I tiles (#957) ── */
|
||||
.ct-card,
|
||||
.sh-card {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.ct-head {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.ct-head,
|
||||
.sh-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@@ -8096,6 +8084,7 @@ span.repo-crumb-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ct-legend,
|
||||
.sh-legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@@ -8104,248 +8093,95 @@ span.repo-crumb-name {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.ct-legend-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.ct-swatch {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 20px;
|
||||
height: 16px;
|
||||
padding: 0 3px;
|
||||
border-radius: 3px;
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* Ten to a row, as the 40 requirements make four rows; five on a phone. */
|
||||
.ct-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(10, minmax(0, 1fr));
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.ct-grid {
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
.ct-tile {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
min-height: 56px;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.ct-tile:hover,
|
||||
.ct-tile:focus-visible {
|
||||
outline: 2px solid var(--text-primary);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
|
||||
.ct-tile-mark {
|
||||
align-self: flex-end;
|
||||
font-family: var(--font-body);
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* A state's colour, always with its sign beside it. */
|
||||
.ct-ok { background: var(--success); color: #fff; }
|
||||
.ct-bad { background: var(--danger); color: #fff; }
|
||||
.ct-open { background: var(--warning-bg); border-color: var(--border-bright); color: var(--text-primary); }
|
||||
.ct-partial { background: var(--info-bg); border-color: var(--border-bright); color: var(--text-primary); }
|
||||
.ct-process { background: var(--bg-elevated); border-color: var(--border-bright); color: var(--text-secondary); }
|
||||
|
||||
.ct-hint,
|
||||
.sh-hint {
|
||||
color: var(--text-tertiary);
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
/* The areas beside the open requirement; the panel goes below on a phone. */
|
||||
.ct-layout {
|
||||
.ct-crumbs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.ct-areas {
|
||||
flex: 999 1 560px;
|
||||
min-width: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.ct-area {
|
||||
display: grid;
|
||||
align-content: start;
|
||||
gap: 8px;
|
||||
padding: 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--bg-card);
|
||||
}
|
||||
|
||||
.ct-area-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ct-area-bar {
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
.ct-chips {
|
||||
list-style: none;
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
/* A requirement: its state's sign, its name, and its open findings. */
|
||||
.ct-chip {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-height: 44px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius);
|
||||
color: var(--text-primary);
|
||||
font-size: 13.5px;
|
||||
font-weight: 500;
|
||||
line-height: 1.3;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.ct-chip:hover {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.ct-chip:focus-visible,
|
||||
.ct-chip.is-selected {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.ct-chip-name {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ct-chip-n {
|
||||
flex-shrink: 0;
|
||||
min-width: 22px;
|
||||
height: 22px;
|
||||
padding: 0 6px;
|
||||
border-radius: 11px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--bg-card);
|
||||
color: var(--danger);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.ct-chip.ct-ok { background: var(--success-bg); }
|
||||
.ct-chip.ct-unknown { border-color: var(--border-bright); }
|
||||
.ct-chip.ct-bad { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
|
||||
.ct-chip.ct-partial { background: var(--warning-bg); border-color: var(--warning); }
|
||||
.ct-chip.ct-open { background: var(--bg-elevated); border: 1px dashed var(--text-faint); color: var(--text-secondary); }
|
||||
.ct-chip.ct-process { background: transparent; border: 1px dotted var(--text-faint); color: var(--text-secondary); }
|
||||
|
||||
/* A state's sign in a round mark: never colour alone. */
|
||||
.ct-mark {
|
||||
flex-shrink: 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-radius: 50%;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.ct-mark.ct-ok { background: var(--success); color: #fff; }
|
||||
.ct-mark.ct-bad { background: var(--danger); color: #fff; }
|
||||
.ct-mark.ct-partial { background: var(--warning); color: #fff; }
|
||||
.ct-mark.ct-open { background: var(--bg-elevated); border: 1px dashed var(--text-faint); color: var(--text-secondary); }
|
||||
.ct-mark.ct-process { background: var(--bg-card); border: 1px dotted var(--text-faint); color: var(--text-secondary); }
|
||||
.ct-chip.ct-bad .ct-mark { background: #fff; color: var(--danger); }
|
||||
|
||||
/* The open requirement. */
|
||||
.ct-panel {
|
||||
flex: 1 1 320px;
|
||||
min-width: 0;
|
||||
max-width: 440px;
|
||||
display: grid;
|
||||
align-content: start;
|
||||
gap: 14px;
|
||||
padding: 16px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--bg-card);
|
||||
}
|
||||
|
||||
/* Where the map and panel no longer fit side by side, the panel goes first,
|
||||
so the requirement a tap opens is not below all forty. */
|
||||
@media (max-width: 1200px) {
|
||||
.ct-panel {
|
||||
order: -1;
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
.ct-panel-empty {
|
||||
color: var(--text-tertiary);
|
||||
font-size: 13.5px;
|
||||
}
|
||||
|
||||
.ct-panel-head {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.ct-panel-area {
|
||||
color: var(--text-tertiary);
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
.ct-panel-name {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.ct-panel-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.ct-panel-what {
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.ct-meanings,
|
||||
.ct-proof {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.ct-meanings h4,
|
||||
.ct-proof h4 {
|
||||
gap: 4px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ct-meanings ul {
|
||||
list-style: none;
|
||||
.ct-crumbs a {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.ct-back {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.ct-detail {
|
||||
display: grid;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.ct-meaning {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
font-size: 13.5px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.ct-meaning div {
|
||||
display: grid;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.ct-meaning span {
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.ct-meaning.is-now {
|
||||
border-color: var(--accent);
|
||||
background: var(--bg-card-hover);
|
||||
}
|
||||
|
||||
.ct-proof {
|
||||
padding: 12px;
|
||||
border: 1px dotted var(--text-faint);
|
||||
border-radius: var(--radius);
|
||||
font-size: 13.5px;
|
||||
line-height: 1.45;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.ct-panel-detail:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ct-panel-detail .cra-control {
|
||||
padding-top: 0;
|
||||
border-top: 0;
|
||||
}
|
||||
|
||||
.ct-panel-links {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 16px;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
/* ── Verlauf: per scan, new CVEs above the line, gone below (#957) ── */
|
||||
@@ -8566,6 +8402,10 @@ span.repo-crumb-name {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.vex-advisory-line .vex-advisory {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.vex-advisory-note {
|
||||
font-size: 11px;
|
||||
color: var(--text-tertiary);
|
||||
@@ -9684,258 +9524,3 @@ div.offer-option { flex-direction: column; align-items: flex-start; justify-cont
|
||||
}
|
||||
.offer-waiting-dot { width: 8px; height: 8px; border-radius: 4px; background: var(--accent); }
|
||||
.offer-waiting-go { margin-left: auto; font-weight: 600; color: var(--accent); }
|
||||
|
||||
/* A target's Siemens controllers (SPS item 4a): modules on a DIN rail. */
|
||||
.dev-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 22px;
|
||||
min-width: 0;
|
||||
max-width: 1280px;
|
||||
}
|
||||
.dev-page > * { min-width: 0; }
|
||||
.dev-rail-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding: 24px 24px 20px;
|
||||
}
|
||||
.dev-legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 28px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.dev-legend li { display: flex; align-items: center; gap: 8px; }
|
||||
.dev-led {
|
||||
display: inline-block;
|
||||
flex: none;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.dev-led-affected { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
|
||||
.dev-led-clear { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
|
||||
.dev-led-unnamed { background: #8C91AE; box-shadow: 0 0 0 3px rgb(140 145 174 / 0.25); }
|
||||
.dev-rail-scroll { overflow-x: auto; padding-bottom: 4px; }
|
||||
.dev-rail {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 6px;
|
||||
min-width: max-content;
|
||||
padding: 8px 12px 18px;
|
||||
}
|
||||
.dev-rail-bar {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 4px;
|
||||
height: 26px;
|
||||
border-radius: 3px;
|
||||
background: repeating-linear-gradient(90deg, var(--border-bright) 0 22px, var(--border-strong) 22px 24px);
|
||||
border-top: 2px solid var(--border);
|
||||
border-bottom: 2px solid var(--border-strong);
|
||||
}
|
||||
/* The module is a device's housing: dark in either theme. */
|
||||
.dev-module {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
width: 148px;
|
||||
height: 236px;
|
||||
box-sizing: border-box;
|
||||
padding: 12px;
|
||||
border: none;
|
||||
border-radius: 8px 8px 4px 4px;
|
||||
background: linear-gradient(180deg, #2E3250 0%, #262A44 100%);
|
||||
box-shadow: 0 4px 12px rgb(20 22 43 / 0.18);
|
||||
color: #fff;
|
||||
text-align: left;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
transition: transform 160ms ease, box-shadow 160ms ease;
|
||||
}
|
||||
.dev-module-on {
|
||||
transform: translateY(-6px);
|
||||
box-shadow: 0 0 0 3px var(--accent), 0 10px 24px rgb(20 22 43 / 0.25);
|
||||
}
|
||||
.dev-module:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
|
||||
.dev-module-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.dev-module-brand { font-size: 11px; letter-spacing: 0.02em; color: #C9CDE0; }
|
||||
.dev-module-face {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 40px;
|
||||
border-radius: 4px;
|
||||
background: #1D2033;
|
||||
color: #8C91AE;
|
||||
font-size: 12px;
|
||||
}
|
||||
.dev-module-names { display: flex; flex-direction: column; gap: 2px; }
|
||||
.dev-module-short { font-size: 13px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
|
||||
.dev-module-label { font-size: 12px; color: #C9CDE0; overflow-wrap: anywhere; }
|
||||
.dev-module-vents { display: flex; flex-direction: column; gap: 3px; }
|
||||
.dev-module-vents span { height: 3px; border-radius: 2px; background: #3A3F5C; }
|
||||
.dev-module-fw { font-size: 12px; color: #C9CDE0; font-variant-numeric: tabular-nums; }
|
||||
.dev-add {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
width: 148px;
|
||||
height: 236px;
|
||||
box-sizing: border-box;
|
||||
padding: 12px;
|
||||
border: 2px dashed var(--border-strong);
|
||||
border-radius: 8px 8px 4px 4px;
|
||||
background: var(--bg-card);
|
||||
color: var(--text-tertiary);
|
||||
font: inherit;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
.dev-add-on { border-color: var(--accent); background: var(--accent-muted); color: var(--accent); }
|
||||
.dev-add:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
|
||||
.dev-empty { margin: 0; color: var(--text-secondary); }
|
||||
.dev-body { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
|
||||
.dev-detail,
|
||||
.dev-form {
|
||||
flex: 999 1 560px;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
padding: 24px;
|
||||
}
|
||||
.dev-detail h2,
|
||||
.dev-form h2 { margin: 0; font-size: 22px; font-weight: 600; }
|
||||
.dev-detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-start; }
|
||||
.dev-detail-head > div:first-child { display: flex; flex-direction: column; gap: 4px; }
|
||||
.dev-detail-label { font-size: 14px; color: var(--text-tertiary); }
|
||||
.dev-detail-actions { display: flex; gap: 8px; }
|
||||
.dev-detail-actions .btn { min-height: 44px; }
|
||||
.btn-danger-ghost { color: var(--danger); border-color: var(--danger-bg); }
|
||||
.dev-figures {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
.dev-figures > div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 12px 14px;
|
||||
border-radius: 10px;
|
||||
background: var(--bg-primary);
|
||||
}
|
||||
.dev-figures dt { font-size: 13px; color: var(--text-tertiary); }
|
||||
.dev-figures dd {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.dev-firmware-edit { flex-wrap: wrap; }
|
||||
.dev-firmware-edit input { width: 9em; min-height: 40px; }
|
||||
.dev-field-note { margin: 0; font-size: 13px; color: var(--warning); }
|
||||
.dev-state {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
border-radius: 10px;
|
||||
font-size: 15px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
.dev-state .dev-led { width: 12px; height: 12px; }
|
||||
.dev-state-affected { background: var(--danger-bg); }
|
||||
.dev-state-clear { background: var(--success-bg); }
|
||||
.dev-state-unnamed { background: var(--bg-elevated); }
|
||||
.dev-advisories { display: flex; flex-direction: column; gap: 10px; }
|
||||
.dev-advisories h3 { margin: 0; font-size: 15px; font-weight: 600; }
|
||||
.dev-advisory {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12px 16px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
}
|
||||
.dev-advisory-clear { opacity: 0.72; }
|
||||
.dev-advisory .badge { flex: none; min-width: 72px; text-align: center; }
|
||||
.dev-advisory-text { flex: 1 1 260px; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
||||
.dev-advisory-title { font-size: 14px; font-weight: 500; }
|
||||
.dev-advisory-meta { font-size: 13px; color: var(--text-tertiary); }
|
||||
.dev-verdict { font-size: 13px; font-weight: 500; color: var(--success); white-space: nowrap; }
|
||||
.dev-verdict-affected { color: var(--danger); }
|
||||
.dev-source { font-size: 13px; }
|
||||
.dev-to-cves { align-self: flex-start; font-size: 14px; font-weight: 500; }
|
||||
.dev-form-fields {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
.dev-form-fields label {
|
||||
font-family: var(--font-body);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
letter-spacing: normal;
|
||||
text-transform: none;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.dev-form-fields input { min-height: 44px; font-size: 16px; font-variant-numeric: tabular-nums; }
|
||||
.dev-recognised {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 12px 14px;
|
||||
border-radius: 10px;
|
||||
background: var(--bg-elevated);
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
.dev-recognised svg { flex: none; margin-top: 2px; }
|
||||
.dev-recognised-bad { background: var(--warning-bg); color: var(--warning); }
|
||||
.dev-recognised-known { background: var(--success-bg); color: var(--success); }
|
||||
.dev-help { font-size: 14px; color: var(--text-secondary); }
|
||||
.dev-help summary { min-height: 32px; color: var(--text-primary); font-weight: 500; cursor: pointer; }
|
||||
.dev-help ul { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 0; padding-left: 20px; line-height: 1.45; }
|
||||
.dev-form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.dev-form-actions .btn { min-height: 44px; }
|
||||
.dev-how {
|
||||
flex: 1 1 280px;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding-top: 4px;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.dev-how h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-primary); }
|
||||
.dev-how p { margin: 0; }
|
||||
.dev-card-lights { display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 3px; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.dev-module { transition: none; }
|
||||
.dev-module-on { transform: none; }
|
||||
}
|
||||
@@ -48,10 +48,6 @@ pub enum Route {
|
||||
// and its published versions (#1028).
|
||||
#[route("/targets/:id/releases")]
|
||||
TargetReleasesPage { id: String },
|
||||
// The Siemens controllers it runs on, against Siemens' advisories
|
||||
// (SPS item 4a).
|
||||
#[route("/targets/:id/devices")]
|
||||
TargetDevicesPage { id: String },
|
||||
// A machine (#1026): a product project and its targets; `?tab=`
|
||||
// `parts` (the default), `cves` or `history`.
|
||||
#[route("/projects/:id?:tab")]
|
||||
|
||||
@@ -2,22 +2,12 @@ use dioxus::prelude::*;
|
||||
use dioxus_free_icons::icons::bs_icons::*;
|
||||
use dioxus_free_icons::Icon;
|
||||
|
||||
use crate::i18n::texts::common;
|
||||
use crate::i18n::use_lang;
|
||||
|
||||
/// A small copy-to-clipboard button that shows a checkmark after copying.
|
||||
///
|
||||
/// Usage: `CopyButton { value: "text to copy" }`
|
||||
#[component]
|
||||
pub fn CopyButton(value: String, #[props(default = false)] small: bool) -> Element {
|
||||
let lang = use_lang()();
|
||||
let mut copied = use_signal(|| false);
|
||||
let label = if copied() {
|
||||
common::COPIED
|
||||
} else {
|
||||
common::COPY
|
||||
};
|
||||
let tip = format!("{}: {value}", label.get(lang));
|
||||
|
||||
let size = if small { 12 } else { 14 };
|
||||
let class = if small {
|
||||
@@ -29,9 +19,7 @@ pub fn CopyButton(value: String, #[props(default = false)] small: bool) -> Eleme
|
||||
rsx! {
|
||||
button {
|
||||
class: class,
|
||||
r#type: "button",
|
||||
title: "{tip}",
|
||||
"aria-label": "{tip}",
|
||||
title: if copied() { "Copied!" } else { "Copy to clipboard" },
|
||||
onclick: move |_| {
|
||||
let val = value.clone();
|
||||
// Escape for JS single-quoted string
|
||||
|
||||
@@ -1,90 +1,37 @@
|
||||
//! The CRA Annex I view of a target (#957): its 40 requirements by name,
|
||||
//! grouped by area, each marked with its state's colour and sign so the
|
||||
//! state is never told by colour alone. A requirement opens beside the map
|
||||
//! with what its colour means for it and what the state rests on.
|
||||
//! The CRA Annex I view of a target (#957): its 40 requirements as tiles,
|
||||
//! coloured by state and marked with a sign, so the state is never told by
|
||||
//! colour alone. A tile opens the requirement with what its state rests on.
|
||||
|
||||
use compliance_core::cra_requirements::{self as cra, CraArea, CraRequirement};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
use crate::app::Route;
|
||||
use crate::components::cra_bar::CraBar;
|
||||
use crate::i18n::texts::{common, compliance, cra_tiles as tx};
|
||||
use crate::i18n::{use_lang, Lang, Text};
|
||||
use crate::infrastructure::evidence::{fetch_compliance, CraCounts};
|
||||
use crate::pages::compliance::{requirement_name, ControlRow, STATES};
|
||||
use crate::i18n::use_lang;
|
||||
use crate::infrastructure::evidence::fetch_compliance;
|
||||
use crate::pages::compliance::{ControlRow, STATES};
|
||||
use crate::pages::target_views::RepoView;
|
||||
|
||||
/// A state's sign (an SVG path) and CSS tone, for a control `state` as the
|
||||
/// API names it.
|
||||
/// A tile's sign and CSS tone for a control `state` (as the API names it).
|
||||
fn mark(state: &str) -> (&'static str, &'static str) {
|
||||
match state {
|
||||
"not_satisfied" => ("M12 5v9M12 19v.5", "ct-bad"),
|
||||
"partial" => ("M5 12h14", "ct-partial"),
|
||||
"no_violation_found" => ("M5 12.5l4.5 4.5L19 7.5", "ct-ok"),
|
||||
"not_assessed" => ("M9 9a3 3 0 1 1 4 2.8c-.7.3-1 .9-1 1.7M12 18v.5", "ct-open"),
|
||||
_ => ("M7 4h7l4 4v12H7zM14 4v4h4M10 13h5M10 16h5", "ct-process"),
|
||||
"not_satisfied" => ("!", "ct-bad"),
|
||||
"not_assessed" => ("?", "ct-open"),
|
||||
"partial" => ("~", "ct-partial"),
|
||||
"no_violation_found" => ("OK", "ct-ok"),
|
||||
_ => ("–", "ct-process"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The CSS tone of a requirement in `state`, or of one whose state is not
|
||||
/// known (`None`).
|
||||
pub(crate) fn cra_tone(state: Option<&str>) -> &'static str {
|
||||
state.map_or("ct-unknown", |s| mark(s).1)
|
||||
/// The short name a tile shows for control `id`: `cra-ai-7` is `AI-07`;
|
||||
/// another id stays as it is.
|
||||
fn short_id(id: &str) -> String {
|
||||
id.strip_prefix("cra-ai-")
|
||||
.and_then(|n| n.parse::<u32>().ok())
|
||||
.map_or_else(|| id.to_string(), |n| format!("AI-{n:02}"))
|
||||
}
|
||||
|
||||
/// The CraBar segment class of a control `state`, so an area's small bar
|
||||
/// uses the target bar's colours.
|
||||
fn bar_modifier(state: &str) -> &'static str {
|
||||
match state {
|
||||
"not_satisfied" => "violated",
|
||||
"not_assessed" => "open",
|
||||
"partial" => "partial",
|
||||
"no_violation_found" => "clear",
|
||||
_ => "process",
|
||||
}
|
||||
}
|
||||
|
||||
/// A state's label (`Offene Befunde`).
|
||||
fn state_label(state: &str, lang: Lang) -> &'static str {
|
||||
STATES
|
||||
.iter()
|
||||
.find(|(s, _, _)| *s == state)
|
||||
.map_or("", |(_, label, _)| label.get(lang))
|
||||
}
|
||||
|
||||
/// The sign of `state` in a round mark of its tone.
|
||||
#[component]
|
||||
pub(crate) fn StateMark(state: String) -> Element {
|
||||
let (path, tone) = mark(&state);
|
||||
rsx! {
|
||||
span { class: "ct-mark {tone}", "aria-hidden": "true",
|
||||
svg {
|
||||
width: "12",
|
||||
height: "12",
|
||||
view_box: "0 0 24 24",
|
||||
fill: "none",
|
||||
stroke: "currentColor",
|
||||
stroke_width: "3",
|
||||
stroke_linecap: "round",
|
||||
stroke_linejoin: "round",
|
||||
path { d: path }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One area of the map: the API's controls of that area, in id order.
|
||||
struct AreaControls {
|
||||
name: Text,
|
||||
controls: Vec<serde_json::Value>,
|
||||
}
|
||||
|
||||
/// `controls` (the compliance API's) grouped by area in the catalog's order;
|
||||
/// a control outside the 40 goes to a last group of its own.
|
||||
fn by_area(controls: &[serde_json::Value]) -> Vec<AreaControls> {
|
||||
let requirement = |c: &serde_json::Value| -> Option<&'static CraRequirement> {
|
||||
c["control"].as_str().and_then(cra::requirement)
|
||||
};
|
||||
/// `controls` in tile order: by the number of their id, others last.
|
||||
fn in_tile_order(mut controls: Vec<serde_json::Value>) -> Vec<serde_json::Value> {
|
||||
let number = |c: &serde_json::Value| {
|
||||
c["control"]
|
||||
.as_str()
|
||||
@@ -92,69 +39,12 @@ fn by_area(controls: &[serde_json::Value]) -> Vec<AreaControls> {
|
||||
.and_then(|n| n.parse::<u32>().ok())
|
||||
.unwrap_or(u32::MAX)
|
||||
};
|
||||
let mut areas: Vec<AreaControls> = CraArea::ALL
|
||||
.iter()
|
||||
.map(|area| {
|
||||
let mut list: Vec<serde_json::Value> = controls
|
||||
.iter()
|
||||
.filter(|c| requirement(c).is_some_and(|r| r.area == *area))
|
||||
.cloned()
|
||||
.collect();
|
||||
list.sort_by_key(number);
|
||||
AreaControls {
|
||||
name: area.name().into(),
|
||||
controls: list,
|
||||
}
|
||||
})
|
||||
.filter(|a| !a.controls.is_empty())
|
||||
.collect();
|
||||
let others: Vec<serde_json::Value> = controls
|
||||
.iter()
|
||||
.filter(|c| requirement(c).is_none())
|
||||
.cloned()
|
||||
.collect();
|
||||
if !others.is_empty() {
|
||||
areas.push(AreaControls {
|
||||
name: tx::OTHER_AREA,
|
||||
controls: others,
|
||||
});
|
||||
}
|
||||
areas
|
||||
controls.sort_by_key(number);
|
||||
controls
|
||||
}
|
||||
|
||||
/// The number of open findings `control` lists.
|
||||
fn finding_count(control: &serde_json::Value) -> usize {
|
||||
control["findings"].as_array().map_or(0, Vec::len)
|
||||
}
|
||||
|
||||
/// What the state of `control` means right now, in one sentence.
|
||||
fn state_sentence(control: &serde_json::Value, lang: Lang) -> String {
|
||||
let req = control["control"].as_str().and_then(cra::requirement);
|
||||
match control["state"].as_str().unwrap_or_default() {
|
||||
"not_satisfied" => {
|
||||
let against = req
|
||||
.and_then(|r| r.against)
|
||||
.map_or(tx::AGAINST_GENERIC, Text::from);
|
||||
format!(
|
||||
"{} {}",
|
||||
tx::against_count(finding_count(control), lang),
|
||||
against.get(lang)
|
||||
)
|
||||
}
|
||||
"no_violation_found" => req
|
||||
.and_then(|r| r.clear)
|
||||
.map_or(tx::CLEAR_GENERIC, Text::from)
|
||||
.get(lang)
|
||||
.to_string(),
|
||||
"partial" => Text::from(cra::PARTLY_CHECKED).get(lang).to_string(),
|
||||
"not_assessed" => compliance::not_assessed_reason(&control["reason"], lang)
|
||||
.unwrap_or_else(|| tx::OPEN_GENERIC.get(lang).to_string()),
|
||||
_ => tx::PROCESS_GENERIC.get(lang).to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The map of target `target_id`'s requirements, with `control` (from the
|
||||
/// URL) open beside it.
|
||||
/// The tiles of target `target_id`, or, with `control` (from the URL) set,
|
||||
/// that requirement with its state, findings and reasons.
|
||||
#[component]
|
||||
pub fn CraTiles(target_id: String, control: Option<String>) -> Element {
|
||||
let lang = use_lang()();
|
||||
@@ -169,9 +59,7 @@ pub fn CraTiles(target_id: String, control: Option<String>) -> Element {
|
||||
let Some(data) = loaded else {
|
||||
return rsx! { div { class: "card", p { {tx::LOAD_FAILED.get(lang)} } } };
|
||||
};
|
||||
let controls = data["controls"].as_array().cloned().unwrap_or_default();
|
||||
let counts: CraCounts = serde_json::from_value(data["counts"].clone()).unwrap_or_default();
|
||||
let areas = by_area(&controls);
|
||||
let controls = in_tile_order(data["controls"].as_array().cloned().unwrap_or_default());
|
||||
let to_tile = |control: Option<String>| Route::TargetViewsPage {
|
||||
id: target_id.clone(),
|
||||
view: RepoView::Cra.slug().to_string(),
|
||||
@@ -180,152 +68,96 @@ pub fn CraTiles(target_id: String, control: Option<String>) -> Element {
|
||||
control,
|
||||
scan: None,
|
||||
};
|
||||
let chosen = control.as_ref().map(|wanted| {
|
||||
controls
|
||||
|
||||
if let Some(wanted) = control {
|
||||
let back = to_tile(None);
|
||||
let Some(chosen) = controls
|
||||
.iter()
|
||||
.find(|c| c["control"].as_str() == Some(wanted.as_str()))
|
||||
.cloned()
|
||||
});
|
||||
else {
|
||||
return rsx! {
|
||||
div { class: "card",
|
||||
p { {tx::UNKNOWN.get(lang)} }
|
||||
Link { class: "repo-view-list", to: back, {tx::BACK.get(lang)} }
|
||||
}
|
||||
};
|
||||
};
|
||||
let state = chosen["state"].as_str().unwrap_or_default().to_string();
|
||||
let (label, badge) = STATES
|
||||
.iter()
|
||||
.find(|(s, _, _)| *s == state)
|
||||
.map_or(("", "badge"), |(_, label, badge)| (label.get(lang), *badge));
|
||||
return rsx! {
|
||||
nav { class: "ct-crumbs", "aria-label": tx::BREADCRUMB.get(lang),
|
||||
Link { to: back.clone(), "CRA" }
|
||||
span { "aria-hidden": "true", " › " }
|
||||
strong { "{short_id(&wanted)} {chosen[\"title\"].as_str().unwrap_or_default()}" }
|
||||
Link { class: "btn btn-sm btn-ghost ct-back", to: back, {tx::BACK.get(lang)} }
|
||||
}
|
||||
section { class: "card ct-detail",
|
||||
p { span { class: "{badge}", "{label}" } }
|
||||
ul { class: "cra-controls",
|
||||
ControlRow { control: chosen, lang, show_reason: true }
|
||||
}
|
||||
Link {
|
||||
class: "repo-view-list",
|
||||
to: Route::CompliancePage { id: target_id.clone() },
|
||||
{tx::ALL_REQUIREMENTS.get(lang)}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
rsx! {
|
||||
section { class: "card ct-card", "aria-label": tx::TITLE.get(lang),
|
||||
div { class: "ct-head",
|
||||
h3 { class: "ct-title", {tx::title(controls.len(), lang)} }
|
||||
CraBar { counts }
|
||||
p { class: "ct-hint", {compliance::NOT_LEGAL_ADVICE.get(lang)} }
|
||||
}
|
||||
div { class: "ct-layout",
|
||||
div { class: "ct-areas",
|
||||
for area in areas {
|
||||
section { class: "ct-area", "aria-label": area.name.get(lang),
|
||||
h4 { class: "ct-area-name", {area.name.get(lang)} }
|
||||
div { class: "cra-bar-track ct-area-bar", "aria-hidden": "true",
|
||||
for (state, _, _) in STATES {
|
||||
{
|
||||
let n = area.controls.iter().filter(|c| c["state"].as_str() == Some(state)).count();
|
||||
rsx! {
|
||||
if n > 0 {
|
||||
span { class: "cra-bar-seg cra-{bar_modifier(state)}", style: "flex: {n} 0 0;" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ul { class: "ct-chips",
|
||||
for c in area.controls.iter() {
|
||||
{
|
||||
let cid = c["control"].as_str().unwrap_or_default().to_string();
|
||||
let state = c["state"].as_str().unwrap_or_default().to_string();
|
||||
let (_, tone) = mark(&state);
|
||||
let selected = control.as_deref() == Some(cid.as_str());
|
||||
let n = finding_count(c);
|
||||
let name = requirement_name(c, lang);
|
||||
let label = state_label(&state, lang);
|
||||
rsx! {
|
||||
li { key: "{cid}",
|
||||
Link {
|
||||
class: if selected { "ct-chip {tone} is-selected" } else { "ct-chip {tone}" },
|
||||
"aria-current": if selected { "true" } else { "false" },
|
||||
to: to_tile(Some(cid.clone())),
|
||||
StateMark { state: state.clone() }
|
||||
span { class: "ct-chip-name", "{name}" }
|
||||
if n > 0 {
|
||||
span { class: "ct-chip-n", "{n}" }
|
||||
}
|
||||
span { class: "sr-only", ", {label}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
div { class: "ct-legend",
|
||||
for (state, label, _) in STATES {
|
||||
{
|
||||
let (sign, tone) = mark(state);
|
||||
let n = controls.iter().filter(|c| c["state"].as_str() == Some(state)).count();
|
||||
rsx! {
|
||||
span { key: "{state}", class: "ct-legend-item",
|
||||
span { class: "ct-swatch {tone}", "aria-hidden": "true", "{sign}" }
|
||||
"{label.get(lang)} ({n})"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
aside { class: "ct-panel", "aria-label": tx::SELECTED.get(lang),
|
||||
match chosen {
|
||||
None => rsx! { p { class: "ct-panel-empty", {tx::PICK.get(lang)} } },
|
||||
Some(None) => rsx! {
|
||||
p { {tx::UNKNOWN.get(lang)} }
|
||||
Link { class: "repo-view-list", to: to_tile(None), {tx::CLOSE.get(lang)} }
|
||||
},
|
||||
Some(Some(c)) => rsx! {
|
||||
RequirementPanel { control: c, lang, close: to_tile(None), all: Route::CompliancePage { id: target_id.clone() } }
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The open requirement: its name and state, what each colour means for it
|
||||
/// (or the document that proves it), and what its state rests on.
|
||||
#[component]
|
||||
fn RequirementPanel(control: serde_json::Value, lang: Lang, close: Route, all: Route) -> Element {
|
||||
let req = control["control"].as_str().and_then(cra::requirement);
|
||||
let state = control["state"].as_str().unwrap_or_default().to_string();
|
||||
let area = req.map(|r| Text::from(r.area.name()).get(lang));
|
||||
let name = requirement_name(&control, lang);
|
||||
let sentence = state_sentence(&control, lang);
|
||||
// Red, orange, green: what each would mean for this requirement.
|
||||
let meanings: Vec<(&str, Text, Text)> = req
|
||||
.and_then(|r| r.against.zip(r.clear))
|
||||
.map(|(against, clear)| {
|
||||
vec![
|
||||
("not_satisfied", tx::RED, against.into()),
|
||||
("partial", tx::ORANGE, cra::PARTLY_CHECKED.into()),
|
||||
("no_violation_found", tx::GREEN, clear.into()),
|
||||
]
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let proof = req.and_then(|r| r.proof).map(Text::from);
|
||||
|
||||
rsx! {
|
||||
div { class: "ct-panel-head",
|
||||
if let Some(area) = area {
|
||||
span { class: "ct-panel-area", "{area}" }
|
||||
}
|
||||
h3 { class: "ct-panel-name", "{name}" }
|
||||
p { class: "ct-panel-state",
|
||||
StateMark { state: state.clone() }
|
||||
strong { {state_label(&state, lang)} }
|
||||
}
|
||||
p { class: "ct-panel-what", "{sentence}" }
|
||||
}
|
||||
if !meanings.is_empty() {
|
||||
div { class: "ct-meanings",
|
||||
h4 { {tx::MEANINGS.get(lang)} }
|
||||
ul {
|
||||
for (meaning_state, colour, text) in meanings {
|
||||
li { class: if meaning_state == state { "ct-meaning is-now" } else { "ct-meaning" },
|
||||
StateMark { state: meaning_state.to_string() }
|
||||
div {
|
||||
strong {
|
||||
{colour.get(lang)}
|
||||
if meaning_state == state {
|
||||
{tx::NOW.get(lang)}
|
||||
}
|
||||
}
|
||||
span { {text.get(lang)} }
|
||||
div { class: "ct-grid",
|
||||
for c in controls.iter() {
|
||||
{
|
||||
let id = c["control"].as_str().unwrap_or_default().to_string();
|
||||
let state = c["state"].as_str().unwrap_or_default();
|
||||
let (sign, tone) = mark(state);
|
||||
let state_label = STATES
|
||||
.iter()
|
||||
.find(|(s, _, _)| *s == state)
|
||||
.map_or("", |(_, label, _)| label.get(lang));
|
||||
let tip = format!(
|
||||
"{}: {} ({state_label})",
|
||||
short_id(&id),
|
||||
c["title"].as_str().unwrap_or_default()
|
||||
);
|
||||
rsx! {
|
||||
Link {
|
||||
key: "{id}",
|
||||
class: "ct-tile {tone}",
|
||||
title: "{tip}",
|
||||
"aria-label": "{tip}",
|
||||
to: to_tile(Some(id.clone())),
|
||||
span { class: "ct-tile-id", "{short_id(&id)}" }
|
||||
span { class: "ct-tile-mark", "{sign}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(proof) = proof {
|
||||
div { class: "ct-proof",
|
||||
h4 { {tx::PROOF_TITLE.get(lang)} }
|
||||
p { {tx::proof(proof.get(lang), lang)} }
|
||||
}
|
||||
}
|
||||
ul { class: "cra-controls ct-panel-detail",
|
||||
ControlRow { control, lang, show_reason: false, headless: true }
|
||||
}
|
||||
div { class: "ct-panel-links",
|
||||
Link { class: "repo-view-list", to: close, {tx::CLOSE.get(lang)} }
|
||||
Link { class: "repo-view-list", to: all, {tx::ALL_REQUIREMENTS.get(lang)} }
|
||||
p { class: "ct-hint", {tx::HINT.get(lang)} " " {compliance::NOT_LEGAL_ADVICE.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,60 +167,25 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn controls_are_grouped_by_area_in_id_order() {
|
||||
let controls = vec![
|
||||
serde_json::json!({ "control": "cra-ai-9" }),
|
||||
serde_json::json!({ "control": "custom" }),
|
||||
serde_json::json!({ "control": "cra-ai-7" }),
|
||||
serde_json::json!({ "control": "cra-ai-1" }),
|
||||
];
|
||||
let areas = by_area(&controls);
|
||||
let ids: Vec<Vec<&str>> = areas
|
||||
fn a_tile_names_its_requirement_short_and_in_number_order() {
|
||||
assert_eq!(short_id("cra-ai-7"), "AI-07");
|
||||
assert_eq!(short_id("cra-ai-40"), "AI-40");
|
||||
assert_eq!(short_id("custom"), "custom");
|
||||
let ordered = in_tile_order(vec![
|
||||
serde_json::json!({ "control": "cra-ai-10" }),
|
||||
serde_json::json!({ "control": "other" }),
|
||||
serde_json::json!({ "control": "cra-ai-2" }),
|
||||
]);
|
||||
let ids: Vec<&str> = ordered
|
||||
.iter()
|
||||
.map(|a| {
|
||||
a.controls
|
||||
.iter()
|
||||
.filter_map(|c| c["control"].as_str())
|
||||
.collect()
|
||||
})
|
||||
.filter_map(|c| c["control"].as_str())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
ids,
|
||||
[
|
||||
vec!["cra-ai-1"],
|
||||
vec!["cra-ai-7", "cra-ai-9"],
|
||||
vec!["custom"]
|
||||
]
|
||||
);
|
||||
assert_eq!(areas[0].name.de, "Sicher entworfen");
|
||||
assert_eq!(areas[2].name, tx::OTHER_AREA);
|
||||
assert_eq!(ids, ["cra-ai-2", "cra-ai-10", "other"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_state_has_its_own_sign() {
|
||||
let mut signs: Vec<&str> = STATES.iter().map(|(s, _, _)| mark(s).0).collect();
|
||||
signs.sort_unstable();
|
||||
signs.dedup();
|
||||
assert_eq!(signs.len(), STATES.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_sentence_says_what_the_state_means_for_the_requirement() {
|
||||
let red = serde_json::json!({
|
||||
"control": "cra-ai-8", "state": "not_satisfied",
|
||||
"findings": [{ "id": "a" }, { "id": "b" }],
|
||||
});
|
||||
let text = state_sentence(&red, Lang::De);
|
||||
assert!(text.starts_with("2 offene Befunde"), "{text}");
|
||||
assert!(text.contains("fest eingebautes Passwort"), "{text}");
|
||||
|
||||
let green = serde_json::json!({ "control": "cra-ai-8", "state": "no_violation_found" });
|
||||
assert_eq!(
|
||||
state_sentence(&green, Lang::En),
|
||||
"The scan found no built-in password."
|
||||
);
|
||||
|
||||
let process = serde_json::json!({ "control": "cra-ai-36", "state": "not_code_checkable" });
|
||||
assert_eq!(state_sentence(&process, Lang::De), tx::PROCESS_GENERIC.de);
|
||||
let signs: Vec<&str> = STATES.iter().map(|(s, _, _)| mark(s).0).collect();
|
||||
assert_eq!(signs, ["!", "?", "~", "OK", "–"]);
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,13 @@
|
||||
//! The help assistant answers in markdown, and semgrep rule messages are
|
||||
//! markdown (the finding description). Neither is ours, so nothing in it may
|
||||
//! reach the page as markup of its own: raw HTML is shown as text, and links
|
||||
//! keep only Breakpilot's own pages, relative paths and mail targets.
|
||||
//! Prüfwerk sends nobody to another site: a link anywhere else (an advisory
|
||||
//! database, a vendor page) is shown as its text, and an image from another
|
||||
//! site as its description.
|
||||
//! keep only web and mail targets.
|
||||
|
||||
use pulldown_cmark::{CowStr, Event, Options, Parser, Tag, TagEnd};
|
||||
use pulldown_cmark::{CowStr, Event, Options, Parser, Tag};
|
||||
|
||||
/// The domain whose pages (and subdomains) a link may open.
|
||||
const OWN_DOMAIN: &str = "breakpilot.com";
|
||||
/// Link targets kept as they are; anything else (`javascript:`, `data:`, …)
|
||||
/// becomes an inert `#`.
|
||||
const SAFE_SCHEMES: &[&str] = &["https://", "http://", "mailto:"];
|
||||
|
||||
/// Render `markdown` to HTML that is safe to insert into the page.
|
||||
///
|
||||
@@ -21,9 +19,8 @@ const OWN_DOMAIN: &str = "breakpilot.com";
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// HTML with every raw HTML tag escaped and every link pointing at a
|
||||
/// Breakpilot page, a mail address or a relative path; other links are left
|
||||
/// as their text.
|
||||
/// HTML with every raw HTML tag escaped and every link pointing at a web
|
||||
/// address, a mail address, a relative path, or `#`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -32,50 +29,47 @@ const OWN_DOMAIN: &str = "breakpilot.com";
|
||||
/// ```
|
||||
pub fn render_markdown(markdown: &str) -> String {
|
||||
let options = Options::ENABLE_TABLES | Options::ENABLE_STRIKETHROUGH;
|
||||
// Links and images do not nest, so one flag per kind says whether the
|
||||
// open one was dropped and its end tag must go too.
|
||||
let (mut link_dropped, mut image_dropped) = (false, false);
|
||||
let events = Parser::new_ext(markdown, options).filter_map(move |event| match event {
|
||||
let events = Parser::new_ext(markdown, options).map(|event| match event {
|
||||
// Shown as the text it is; `push_html` escapes text.
|
||||
Event::Html(html) | Event::InlineHtml(html) => Some(Event::Text(html)),
|
||||
Event::Start(Tag::Link { ref dest_url, .. }) => {
|
||||
link_dropped = !allowed(dest_url);
|
||||
(!link_dropped).then_some(event)
|
||||
}
|
||||
Event::End(TagEnd::Link) => (!std::mem::take(&mut link_dropped)).then_some(event),
|
||||
// An image's inner text is its description: a dropped image leaves it.
|
||||
Event::Start(Tag::Image { ref dest_url, .. }) => {
|
||||
image_dropped = !allowed(dest_url);
|
||||
(!image_dropped).then_some(event)
|
||||
}
|
||||
Event::End(TagEnd::Image) => (!std::mem::take(&mut image_dropped)).then_some(event),
|
||||
other => Some(other),
|
||||
Event::Html(html) | Event::InlineHtml(html) => Event::Text(html),
|
||||
Event::Start(Tag::Link {
|
||||
link_type,
|
||||
dest_url,
|
||||
title,
|
||||
id,
|
||||
}) => Event::Start(Tag::Link {
|
||||
link_type,
|
||||
dest_url: safe_url(dest_url),
|
||||
title,
|
||||
id,
|
||||
}),
|
||||
Event::Start(Tag::Image {
|
||||
link_type,
|
||||
dest_url,
|
||||
title,
|
||||
id,
|
||||
}) => Event::Start(Tag::Image {
|
||||
link_type,
|
||||
dest_url: safe_url(dest_url),
|
||||
title,
|
||||
id,
|
||||
}),
|
||||
other => other,
|
||||
});
|
||||
let mut html = String::with_capacity(markdown.len() * 3 / 2);
|
||||
pulldown_cmark::html::push_html(&mut html, events);
|
||||
html
|
||||
}
|
||||
|
||||
/// Whether a link to `url` may stay a link: a relative path, a mail
|
||||
/// address, or a web page on Breakpilot's own domain.
|
||||
fn allowed(url: &CowStr<'_>) -> bool {
|
||||
/// `url` when it is a web or mail address or a relative path, else `#`.
|
||||
fn safe_url(url: CowStr<'_>) -> CowStr<'_> {
|
||||
let lower = url.trim().to_ascii_lowercase();
|
||||
if lower.starts_with("mailto:") {
|
||||
return true;
|
||||
let relative = !lower.contains(':');
|
||||
if relative || SAFE_SCHEMES.iter().any(|scheme| lower.starts_with(scheme)) {
|
||||
url
|
||||
} else {
|
||||
CowStr::Borrowed("#")
|
||||
}
|
||||
let Some(rest) = lower
|
||||
.strip_prefix("https://")
|
||||
.or_else(|| lower.strip_prefix("http://"))
|
||||
else {
|
||||
// `//host/…` is another site, `javascript:` and the like are not pages.
|
||||
return !lower.contains(':') && !lower.starts_with("//");
|
||||
};
|
||||
// The host ends at the path, query or fragment; a `user@` before it and
|
||||
// a port after it are not part of it.
|
||||
let authority = rest.split(['/', '?', '#']).next().unwrap_or_default();
|
||||
let host = authority.rsplit('@').next().unwrap_or_default();
|
||||
let host = host.split(':').next().unwrap_or_default();
|
||||
host == OWN_DOMAIN || host.ends_with(&format!(".{OWN_DOMAIN}"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -105,38 +99,11 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_breakpilot_pages_and_relative_paths_stay_links() {
|
||||
let html = render_markdown(
|
||||
"[x](javascript:alert(1)) [osv](https://osv.dev/vulnerability/CVE-1) \
|
||||
[docs](https://docs.breakpilot.com/pruefwerk/) [z](/guide) [m](mailto:a@b.example)",
|
||||
);
|
||||
fn script_links_are_made_inert() {
|
||||
let html = render_markdown("[x](javascript:alert(1)) [y](https://example.com) [z](/guide)");
|
||||
assert!(!html.contains("javascript:"));
|
||||
assert!(!html.contains("osv.dev"));
|
||||
assert!(html.contains("osv"), "the text stays: {html}");
|
||||
assert!(html.contains("href=\"https://docs.breakpilot.com/pruefwerk/\""));
|
||||
assert!(html.contains("href=\"#\""));
|
||||
assert!(html.contains("href=\"https://example.com\""));
|
||||
assert!(html.contains("href=\"/guide\""));
|
||||
assert!(html.contains("href=\"mailto:a@b.example\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_look_alike_host_is_another_site() {
|
||||
for url in [
|
||||
"https://breakpilot.com.evil.example/x",
|
||||
"https://evilbreakpilot.com/x",
|
||||
"https://breakpilot.com@evil.example/x",
|
||||
"//evil.example/x",
|
||||
] {
|
||||
let html = render_markdown(&format!("[a]({url})"));
|
||||
assert!(!html.contains("href"), "{url}: {html}");
|
||||
}
|
||||
let html = render_markdown("[a](https://user@cloud.breakpilot.com:443/x)");
|
||||
assert!(html.contains("href"), "{html}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_image_from_another_site_leaves_its_description() {
|
||||
let html = render_markdown("");
|
||||
assert!(!html.contains("<img"));
|
||||
assert!(html.contains("diagram"));
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@ use dioxus::prelude::*;
|
||||
use dioxus_free_icons::icons::bs_icons::*;
|
||||
use dioxus_free_icons::Icon;
|
||||
|
||||
use crate::components::copy_button::CopyButton;
|
||||
|
||||
use crate::infrastructure::notifications::{
|
||||
dismiss_notification, fetch_notification_count, fetch_notifications,
|
||||
mark_all_notifications_read,
|
||||
@@ -120,10 +118,12 @@ pub fn NotificationBell() -> Element {
|
||||
span { class: "notification-sev {sev_class}",
|
||||
"{notif.severity.to_uppercase()}"
|
||||
}
|
||||
// The id to copy, never a link off-site.
|
||||
span { class: "notification-cve-id",
|
||||
"{notif.cve_id}"
|
||||
CopyButton { value: notif.cve_id.clone(), small: true }
|
||||
if let Some(ref url) = notif.url {
|
||||
a { href: "{url}", target: "_blank", "{notif.cve_id}" }
|
||||
} else {
|
||||
"{notif.cve_id}"
|
||||
}
|
||||
}
|
||||
if let Some(score) = notif.cvss_score {
|
||||
span { class: "notification-cvss", "CVSS {score:.1}" }
|
||||
|
||||
@@ -15,7 +15,6 @@ use compliance_core::cve_matrix::CveFilter;
|
||||
use compliance_core::models::{CveAlert, SupplierVex, VexAssessment, VexJustification, VexStatus};
|
||||
use compliance_core::vex_docs::status_of;
|
||||
|
||||
use crate::components::copy_button::CopyButton;
|
||||
use crate::components::no_access::use_can_write;
|
||||
use crate::components::severity_badge::SeverityBadge;
|
||||
use crate::components::toast::{ToastType, Toasts};
|
||||
@@ -183,36 +182,6 @@ pub(crate) fn is_supplier_product(alert: &CveAlert) -> bool {
|
||||
/// agent stores it (`csaf_feed::SUPPLIER_PREFIX`).
|
||||
pub(crate) const SUPPLIER_PROVIDER_PREFIX: &str = "supplier:";
|
||||
|
||||
/// A vendor advisory that names a CVE alert: its id to copy, the vendor's
|
||||
/// remediation on hover, and a link to its page only where the provider's
|
||||
/// terms require one (Siemens ProductCERT). Nothing else leads off-site.
|
||||
#[component]
|
||||
pub(crate) fn AdvisoryLine(advisory: compliance_core::models::AdvisoryRef) -> Element {
|
||||
let lang = use_lang()();
|
||||
let hint = advisory
|
||||
.remediation
|
||||
.clone()
|
||||
.unwrap_or_else(|| advisory.title.clone());
|
||||
rsx! {
|
||||
div { class: "vex-advisory-line",
|
||||
span { class: "vex-advisory", title: "{hint}", "{advisory.id}" }
|
||||
CopyButton { value: advisory.id.clone(), small: true }
|
||||
if let Some(url) = advisory.required_backlink() {
|
||||
a {
|
||||
class: "vex-advisory-source",
|
||||
href: "{url}",
|
||||
target: "_blank",
|
||||
rel: "noopener noreferrer",
|
||||
{tx::SOURCE.get(lang)}
|
||||
}
|
||||
}
|
||||
if advisory.provider.starts_with(SUPPLIER_PROVIDER_PREFIX) {
|
||||
span { class: "vex-advisory-note", {tx::SUPPLIER_ADVISORY.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Who made an alert's statement: the person's name, "Prüfung" for a scan.
|
||||
fn stated_by(alert: &CveAlert, lang: Lang) -> String {
|
||||
match &alert.vex {
|
||||
@@ -473,13 +442,24 @@ fn CveTable(
|
||||
rsx! {
|
||||
tr { key: "{alert_id}", class: if open { "is-open" } else { "" },
|
||||
td {
|
||||
span { class: "vex-cve-id",
|
||||
code { "{alert.cve_id}" }
|
||||
CopyButton { value: alert.cve_id.clone(), small: true }
|
||||
}
|
||||
// The vendor advisories that name it (#515).
|
||||
code { "{alert.cve_id}" }
|
||||
// The vendor advisories that name it (#515), linked as
|
||||
// their terms ask; the remediation on hover.
|
||||
for adv in alert.advisories.iter() {
|
||||
AdvisoryLine { advisory: adv.clone() }
|
||||
div { class: "vex-advisory-line",
|
||||
a {
|
||||
class: "vex-advisory",
|
||||
href: adv.url.clone().unwrap_or_default(),
|
||||
target: "_blank",
|
||||
rel: "noopener noreferrer",
|
||||
title: adv.remediation.clone().unwrap_or_else(|| adv.title.clone()),
|
||||
"{adv.id}"
|
||||
}
|
||||
if adv.provider.starts_with(SUPPLIER_PROVIDER_PREFIX) {
|
||||
" "
|
||||
span { class: "vex-advisory-note", {tx::SUPPLIER_ADVISORY.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
td {
|
||||
|
||||
@@ -70,21 +70,6 @@ impl Text {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<compliance_core::cra_requirements::Words> for Text {
|
||||
fn from(words: compliance_core::cra_requirements::Words) -> Self {
|
||||
Self {
|
||||
de: words.de,
|
||||
en: words.en,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The name a customer reads for CRA requirement `id` (`cra-ai-8` is
|
||||
/// `Keine Standardpasswörter`); an id outside the 40 stays as it is.
|
||||
pub fn requirement_label(id: &str, lang: Lang) -> &str {
|
||||
compliance_core::cra_requirements::name(id).map_or(id, |words| Text::from(words).get(lang))
|
||||
}
|
||||
|
||||
/// The agent's refusal code in a server function's error message: the
|
||||
/// first word of `error` that is one of `codes`, as in
|
||||
/// `error running server function: label_taken (409) (details: None)`.
|
||||
|
||||
@@ -17,14 +17,6 @@ pub mod common {
|
||||
de: "Wird geladen …",
|
||||
en: "Loading...",
|
||||
};
|
||||
pub const COPY: Text = Text {
|
||||
de: "Kopieren",
|
||||
en: "Copy",
|
||||
};
|
||||
pub const COPIED: Text = Text {
|
||||
de: "Kopiert",
|
||||
en: "Copied",
|
||||
};
|
||||
pub const PREVIOUS: Text = Text {
|
||||
de: "Zurück",
|
||||
en: "Previous",
|
||||
@@ -3302,6 +3294,10 @@ pub mod sbom {
|
||||
de: "Keine",
|
||||
en: "None",
|
||||
};
|
||||
pub const VIEW_ADVISORY: Text = Text {
|
||||
de: "Hinweis ansehen →",
|
||||
en: "View advisory →",
|
||||
};
|
||||
pub const KEV_BADGE: Text = Text {
|
||||
de: "Aktiv ausgenutzt (KEV)",
|
||||
en: "Actively exploited (KEV)",
|
||||
@@ -3654,10 +3650,6 @@ pub mod vex {
|
||||
de: "Laut Lieferant",
|
||||
en: "Per the supplier",
|
||||
};
|
||||
pub const SOURCE: Text = Text {
|
||||
de: "Quelle",
|
||||
en: "Source",
|
||||
};
|
||||
pub const SUPPLIER_ADVISORY: Text = Text {
|
||||
de: "Hinweis des Zulieferers",
|
||||
en: "Supplier advisory",
|
||||
@@ -4153,26 +4145,26 @@ pub mod compliance {
|
||||
en: "Show CRA status",
|
||||
};
|
||||
pub const NOT_SATISFIED: Text = Text {
|
||||
de: "Offene Befunde",
|
||||
en: "Open findings",
|
||||
de: "Befunde zugeordnet",
|
||||
en: "Findings mapped",
|
||||
};
|
||||
pub const NO_VIOLATION: Text = Text {
|
||||
de: "Nichts gefunden",
|
||||
en: "Nothing found",
|
||||
de: "Geprüft, keine Befunde",
|
||||
en: "Checked, no findings",
|
||||
};
|
||||
pub const VIOLATED_COUNT: Text = Text {
|
||||
de: "mit Befunden",
|
||||
en: "with findings",
|
||||
};
|
||||
pub const NOT_ASSESSED: Text = Text {
|
||||
de: "Noch nicht geprüft",
|
||||
en: "Not checked yet",
|
||||
de: "Nicht geprüft",
|
||||
en: "Not checked",
|
||||
};
|
||||
/// A control checked on part of what it covers (a Yocto recipe
|
||||
/// inventory instead of the image's SBOM).
|
||||
pub const PARTIAL: Text = Text {
|
||||
de: "Nur teilweise geprüft",
|
||||
en: "Only partly checked",
|
||||
de: "Teilweise geprüft",
|
||||
en: "Partly checked",
|
||||
};
|
||||
pub const RECIPE_INVENTORY_ONLY: Text = Text {
|
||||
de: "Nur das Yocto-Rezeptinventar, nicht die SBOM des Images: geprüft sind die Rezepte im Layer-Baum, nicht was das Image enthält. Vollständig erst mit der SBOM aus dem Build.",
|
||||
@@ -4220,8 +4212,8 @@ pub mod compliance {
|
||||
en: "CVE lookup",
|
||||
};
|
||||
pub const NOT_CODE_CHECKABLE: Text = Text {
|
||||
de: "Nachweis per Dokument",
|
||||
en: "Proven by a document",
|
||||
de: "Nicht im Code prüfbar",
|
||||
en: "Not checkable in code",
|
||||
};
|
||||
pub const SHOW_REQUIREMENTS: Text = Text {
|
||||
de: "Anforderungen anzeigen",
|
||||
@@ -5783,42 +5775,6 @@ pub mod metering {
|
||||
}
|
||||
|
||||
/// "1 zusätzliches Prüfobjekt", or that every target is included.
|
||||
/// The plan's refusal of a new target (`target_limit`): its places are
|
||||
/// all taken.
|
||||
pub const TARGET_LIMIT: Text = Text {
|
||||
de: "Ihr Tarif enthält keine weiteren Prüfobjekte. Löschen Sie ein Prüfobjekt, \
|
||||
um ein neues anzulegen (seine Ergebnisse werden mit gelöscht), oder wechseln \
|
||||
Sie den Tarif.",
|
||||
en: "Your plan includes no further targets. Delete a target to add a new one \
|
||||
(its results are deleted with it), or change your plan.",
|
||||
};
|
||||
/// The plan's refusal to make a demo target the tenant's own
|
||||
/// (`target_limit`): other sources would make it count, and its places
|
||||
/// are all taken.
|
||||
pub const DEMO_LIMIT: Text = Text {
|
||||
de: "Mit eigenen Dateien oder Quellen zählt ein Demo-Prüfobjekt wie Ihre anderen, \
|
||||
und Ihr Tarif enthält keine weiteren Prüfobjekte. Löschen Sie ein anderes \
|
||||
Prüfobjekt (seine Ergebnisse werden mit gelöscht) oder wechseln Sie den Tarif.",
|
||||
en: "With your own files or sources a demo target counts like your other targets, \
|
||||
and your plan includes no further targets. Delete another target (its results \
|
||||
are deleted with it) or change your plan.",
|
||||
};
|
||||
/// A failed creation of a target in words: the plan's refusal as
|
||||
/// [`TARGET_LIMIT`], anything else as it came.
|
||||
pub fn target_refusal(error: &str, lang: Lang) -> String {
|
||||
plan_refusal(error, &TARGET_LIMIT, lang)
|
||||
}
|
||||
/// A failed change of a target's artifacts in words: the plan's refusal
|
||||
/// as [`DEMO_LIMIT`], anything else as it came.
|
||||
pub fn demo_refusal(error: &str, lang: Lang) -> String {
|
||||
plan_refusal(error, &DEMO_LIMIT, lang)
|
||||
}
|
||||
fn plan_refusal(error: &str, text: &Text, lang: Lang) -> String {
|
||||
match crate::i18n::agent_code(error, &["target_limit"]) {
|
||||
Some(_) => text.get(lang).to_string(),
|
||||
None => error.to_string(),
|
||||
}
|
||||
}
|
||||
pub fn extra_targets(extra: u32, lang: Lang) -> String {
|
||||
match (lang, extra) {
|
||||
(Lang::De, 0) => "Alle Prüfobjekte im Tarif enthalten".to_string(),
|
||||
@@ -7232,22 +7188,22 @@ pub mod cra_tiles {
|
||||
de: "CRA Annex I",
|
||||
en: "CRA Annex I",
|
||||
};
|
||||
pub const SELECTED: Text = Text {
|
||||
de: "Ausgewählte Anforderung",
|
||||
en: "Selected requirement",
|
||||
pub const BREADCRUMB: Text = Text {
|
||||
de: "Anforderung",
|
||||
en: "Requirement",
|
||||
};
|
||||
pub const PICK: Text = Text {
|
||||
de: "Klicken Sie auf eine Anforderung: Hier steht dann, was ihre Farbe bedeutet und worauf sie beruht.",
|
||||
en: "Click a requirement: this shows what its colour means and what it rests on.",
|
||||
pub const HINT: Text = Text {
|
||||
de: "Klick auf eine Kachel: die Anforderung mit den Befunden und Gründen dahinter.",
|
||||
en: "Click a tile: the requirement with the findings and reasons behind it.",
|
||||
};
|
||||
pub const BACK: Text = Text {
|
||||
de: "← Zurück zum Raster",
|
||||
en: "← Back to the grid",
|
||||
};
|
||||
pub const UNKNOWN: Text = Text {
|
||||
de: "Diese Anforderung gibt es für dieses Prüfobjekt nicht.",
|
||||
en: "This target has no such requirement.",
|
||||
};
|
||||
pub const CLOSE: Text = Text {
|
||||
de: "Schließen",
|
||||
en: "Close",
|
||||
};
|
||||
pub const ALL_REQUIREMENTS: Text = Text {
|
||||
de: "Alle Anforderungen als Liste",
|
||||
en: "All requirements as a list",
|
||||
@@ -7256,81 +7212,14 @@ pub mod cra_tiles {
|
||||
de: "Der CRA-Stand konnte nicht geladen werden.",
|
||||
en: "The CRA status could not be loaded.",
|
||||
};
|
||||
pub const OTHER_AREA: Text = Text {
|
||||
de: "Weitere Anforderungen",
|
||||
en: "Other requirements",
|
||||
};
|
||||
pub const MEANINGS: Text = Text {
|
||||
de: "Was die Farben hier bedeuten",
|
||||
en: "What the colours mean here",
|
||||
};
|
||||
pub const NOW: Text = Text {
|
||||
de: ": so ist es jetzt",
|
||||
en: ": this is how it is now",
|
||||
};
|
||||
pub const RED: Text = Text {
|
||||
de: "Rot",
|
||||
en: "Red",
|
||||
};
|
||||
pub const ORANGE: Text = Text {
|
||||
de: "Orange",
|
||||
en: "Orange",
|
||||
};
|
||||
pub const GREEN: Text = Text {
|
||||
de: "Grün",
|
||||
en: "Green",
|
||||
};
|
||||
pub const PROOF_TITLE: Text = Text {
|
||||
de: "Nachweis per Dokument",
|
||||
en: "Proven by a document",
|
||||
};
|
||||
pub const AGAINST_GENERIC: Text = Text {
|
||||
de: "Sie sprechen gegen diese Anforderung.",
|
||||
en: "They count against this requirement.",
|
||||
};
|
||||
pub const CLEAR_GENERIC: Text = Text {
|
||||
de: "Der Scan fand nichts, was dagegen spricht.",
|
||||
en: "The scan found nothing against it.",
|
||||
};
|
||||
pub const OPEN_GENERIC: Text = Text {
|
||||
de: "Noch nicht geprüft: Es ist noch kein Scan gelaufen, oder keine Regel deckt dieses Prüfobjekt ab.",
|
||||
en: "Not checked yet: no scan has run, or no rule covers this target.",
|
||||
};
|
||||
pub const PROCESS_GENERIC: Text = Text {
|
||||
de: "Diese Anforderung betrifft Ihre Abläufe und Ihren Entwurf, nicht einzelne Codezeilen.",
|
||||
en: "This requirement is about your processes and design, not single lines of code.",
|
||||
};
|
||||
|
||||
/// The map's heading: `CRA Annex I: 40 Anforderungen`.
|
||||
/// The grid's heading: `CRA Annex I: 40 Anforderungen`.
|
||||
pub fn title(count: usize, lang: Lang) -> String {
|
||||
match lang {
|
||||
Lang::De => format!("CRA Annex I: {count} Anforderungen"),
|
||||
Lang::En => format!("CRA Annex I: {count} requirements"),
|
||||
}
|
||||
}
|
||||
|
||||
/// How many open findings count against a requirement, as a sentence.
|
||||
pub fn against_count(count: usize, lang: Lang) -> String {
|
||||
match (lang, count) {
|
||||
(Lang::De, 1) => "Ein offener Befund spricht dagegen.".to_string(),
|
||||
(Lang::De, n) => format!("{n} offene Befunde sprechen dagegen."),
|
||||
(Lang::En, 1) => "One open finding counts against it.".to_string(),
|
||||
(Lang::En, n) => format!("{n} open findings count against it."),
|
||||
}
|
||||
}
|
||||
|
||||
/// The proof a requirement no scan decides asks for: `doc` is the
|
||||
/// document (`ein Rechtekonzept`).
|
||||
pub fn proof(doc: &str, lang: Lang) -> String {
|
||||
match lang {
|
||||
Lang::De => format!(
|
||||
"Ein Code-Scan kann diese Anforderung nicht entscheiden. Sie weisen sie mit einem Dokument nach: {doc}."
|
||||
),
|
||||
Lang::En => format!(
|
||||
"A code scan cannot decide this requirement. You prove it with a document: {doc}."
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The "Verlauf" of a target's views (#957): what each scan changed.
|
||||
@@ -8875,12 +8764,11 @@ pub mod offers {
|
||||
|
||||
/// The agent's refusal `error` in words; anything else as it came.
|
||||
pub fn refusal(error: &str, lang: Lang) -> String {
|
||||
const CODES: [&str; 5] = [
|
||||
const CODES: [&str; 4] = [
|
||||
"answered",
|
||||
"ended",
|
||||
"target_taken",
|
||||
"not_supplier_component",
|
||||
"target_limit",
|
||||
];
|
||||
let text = match crate::i18n::agent_code(error, &CODES) {
|
||||
Some("answered") => Text {
|
||||
@@ -8900,288 +8788,8 @@ pub mod offers {
|
||||
de: "Nur eine zugekaufte Komponente kann eine SBOM eines Zulieferers erhalten.",
|
||||
en: "Only a bought-in component can receive a supplier's SBOM.",
|
||||
},
|
||||
Some("target_limit") => super::metering::TARGET_LIMIT,
|
||||
_ => return error.to_string(),
|
||||
};
|
||||
text.get(lang).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// A target's Siemens controllers (SPS item 4a).
|
||||
pub mod devices {
|
||||
use super::Text;
|
||||
use crate::i18n::Lang;
|
||||
|
||||
pub const CRUMB: Text = Text {
|
||||
de: "Steuerungen",
|
||||
en: "Controllers",
|
||||
};
|
||||
pub fn title(name: &str, lang: Lang) -> String {
|
||||
match lang {
|
||||
Lang::De => format!("Auf welchen Siemens-Steuerungen läuft {name}?"),
|
||||
Lang::En => format!("Which Siemens controllers does {name} run on?"),
|
||||
}
|
||||
}
|
||||
pub const INTRO: Text = Text {
|
||||
de: "Mit Artikelnummer und Firmware gleicht Prüfwerk jeden Sicherheitshinweis von \
|
||||
Siemens mit Ihren Steuerungen ab, auch ohne Projektdatei.",
|
||||
en: "With the order number and firmware, Prüfwerk checks every Siemens security \
|
||||
advisory against your controllers, even without a project file.",
|
||||
};
|
||||
pub const LOADING: Text = Text {
|
||||
de: "Steuerungen werden geladen …",
|
||||
en: "Loading the controllers …",
|
||||
};
|
||||
pub const LOAD_FAILED: Text = Text {
|
||||
de: "Die Steuerungen lassen sich gerade nicht laden.",
|
||||
en: "The controllers cannot be loaded right now.",
|
||||
};
|
||||
pub const SAVE_FAILED: Text = Text {
|
||||
de: "Die Steuerungen ließen sich nicht speichern.",
|
||||
en: "The controllers could not be saved.",
|
||||
};
|
||||
pub const ADDED: Text = Text {
|
||||
de: "Steuerung hinzugefügt",
|
||||
en: "Controller added",
|
||||
};
|
||||
pub const REMOVED: Text = Text {
|
||||
de: "Steuerung entfernt",
|
||||
en: "Controller removed",
|
||||
};
|
||||
pub const FIRMWARE_SAVED: Text = Text {
|
||||
de: "Firmware gespeichert",
|
||||
en: "Firmware saved",
|
||||
};
|
||||
|
||||
// The rail.
|
||||
pub const RAIL: Text = Text {
|
||||
de: "Steuerungen auf der Schiene",
|
||||
en: "Controllers on the rail",
|
||||
};
|
||||
pub const LEGEND_AFFECTED: Text = Text {
|
||||
de: "Ein Hinweis betrifft die Firmware",
|
||||
en: "An advisory affects the firmware",
|
||||
};
|
||||
pub const LEGEND_NOT_AFFECTED: Text = Text {
|
||||
de: "Genannt, aber nicht betroffen",
|
||||
en: "Named, not affected",
|
||||
};
|
||||
pub const LEGEND_NOT_NAMED: Text = Text {
|
||||
de: "In keinem Hinweis genannt",
|
||||
en: "Named in no advisory",
|
||||
};
|
||||
pub const ADD: Text = Text {
|
||||
de: "Steuerung hinzufügen",
|
||||
en: "Add a controller",
|
||||
};
|
||||
pub const NO_LABEL: Text = Text {
|
||||
de: "Ohne Bezeichnung",
|
||||
en: "No name",
|
||||
};
|
||||
pub const EMPTY: Text = Text {
|
||||
de: "Noch keine Steuerung. Fügen Sie die erste mit Artikelnummer und Firmware hinzu.",
|
||||
en: "No controller yet. Add the first with its order number and firmware.",
|
||||
};
|
||||
pub const EMPTY_READ_ONLY: Text = Text {
|
||||
de: "Für dieses Prüfobjekt ist keine Steuerung eingetragen.",
|
||||
en: "No controller is entered for this target.",
|
||||
};
|
||||
/// What a screen reader says for a module on the rail.
|
||||
pub fn module(
|
||||
short: &str,
|
||||
firmware: &str,
|
||||
affecting: usize,
|
||||
named: bool,
|
||||
lang: Lang,
|
||||
) -> String {
|
||||
match (lang, affecting, named) {
|
||||
(Lang::De, 0, true) => {
|
||||
format!("{short}, Firmware {firmware}, kein Hinweis betrifft sie")
|
||||
}
|
||||
(Lang::De, 0, false) => {
|
||||
format!("{short}, Firmware {firmware}, in keinem Hinweis genannt")
|
||||
}
|
||||
(Lang::De, 1, _) => format!("{short}, Firmware {firmware}, ein Hinweis betrifft sie"),
|
||||
(Lang::De, n, _) => format!("{short}, Firmware {firmware}, {n} Hinweise betreffen sie"),
|
||||
(Lang::En, 0, true) => format!("{short}, firmware {firmware}, no advisory affects it"),
|
||||
(Lang::En, 0, false) => format!("{short}, firmware {firmware}, named in no advisory"),
|
||||
(Lang::En, 1, _) => format!("{short}, firmware {firmware}, one advisory affects it"),
|
||||
(Lang::En, n, _) => format!("{short}, firmware {firmware}, {n} advisories affect it"),
|
||||
}
|
||||
}
|
||||
|
||||
// The detail.
|
||||
pub const ORDER_NUMBER: Text = Text {
|
||||
de: "Artikelnummer",
|
||||
en: "Order number",
|
||||
};
|
||||
pub const FIRMWARE: Text = Text {
|
||||
de: "Firmware",
|
||||
en: "Firmware",
|
||||
};
|
||||
pub const CHANGE_FIRMWARE: Text = Text {
|
||||
de: "Firmware ändern",
|
||||
en: "Change firmware",
|
||||
};
|
||||
pub const SAVE_FIRMWARE: Text = Text {
|
||||
de: "Firmware speichern",
|
||||
en: "Save firmware",
|
||||
};
|
||||
pub const REMOVE: Text = Text {
|
||||
de: "Entfernen",
|
||||
en: "Remove",
|
||||
};
|
||||
pub const CANCEL: Text = Text {
|
||||
de: "Abbrechen",
|
||||
en: "Cancel",
|
||||
};
|
||||
/// The sentence under a device's figures.
|
||||
pub fn state(affecting: usize, named: usize, firmware: &str, lang: Lang) -> String {
|
||||
match (lang, affecting, named) {
|
||||
(Lang::De, 0, 0) => "Siemens nennt diese Artikelnummer bisher in keinem Hinweis. \
|
||||
Prüfwerk prüft sie bei jedem neuen."
|
||||
.to_string(),
|
||||
(Lang::De, 0, 1) => {
|
||||
format!("Siemens nennt diese Steuerung in einem Hinweis; er betrifft Firmware V{firmware} nicht.")
|
||||
}
|
||||
(Lang::De, 0, n) => {
|
||||
format!("Siemens nennt diese Steuerung in {n} Hinweisen; keiner betrifft Firmware V{firmware}.")
|
||||
}
|
||||
(Lang::De, 1, _) => format!("Ein Siemens-Hinweis betrifft Firmware V{firmware}."),
|
||||
(Lang::De, n, _) => format!("{n} Siemens-Hinweise betreffen Firmware V{firmware}."),
|
||||
(Lang::En, 0, 0) => "No Siemens advisory names this order number so far. Prüfwerk \
|
||||
checks it against every new one."
|
||||
.to_string(),
|
||||
(Lang::En, 0, 1) => {
|
||||
format!("Siemens names this controller in one advisory; it does not affect firmware V{firmware}.")
|
||||
}
|
||||
(Lang::En, 0, n) => {
|
||||
format!("Siemens names this controller in {n} advisories; none affects firmware V{firmware}.")
|
||||
}
|
||||
(Lang::En, 1, _) => format!("One Siemens advisory affects firmware V{firmware}."),
|
||||
(Lang::En, n, _) => format!("{n} Siemens advisories affect firmware V{firmware}."),
|
||||
}
|
||||
}
|
||||
pub const ADVISORIES: Text = Text {
|
||||
de: "Siemens-Hinweise zu dieser Steuerung",
|
||||
en: "Siemens advisories for this controller",
|
||||
};
|
||||
pub fn fixed_from(version: &str, lang: Lang) -> String {
|
||||
match lang {
|
||||
Lang::De => format!("Behoben ab V{version}"),
|
||||
Lang::En => format!("Fixed from V{version}"),
|
||||
}
|
||||
}
|
||||
pub const NO_FIX: Text = Text {
|
||||
de: "Noch keine behobene Firmware, Siemens nennt Gegenmaßnahmen",
|
||||
en: "No fixed firmware yet, Siemens names mitigations",
|
||||
};
|
||||
pub fn affects(firmware: &str, lang: Lang) -> String {
|
||||
match lang {
|
||||
Lang::De => format!("betrifft V{firmware}"),
|
||||
Lang::En => format!("affects V{firmware}"),
|
||||
}
|
||||
}
|
||||
pub const NOT_AFFECTED: Text = Text {
|
||||
de: "nicht betroffen",
|
||||
en: "not affected",
|
||||
};
|
||||
pub const SOURCE: Text = Text {
|
||||
de: "Quelle",
|
||||
en: "Source",
|
||||
};
|
||||
pub const TO_CVES: Text = Text {
|
||||
de: "Zu den Schwachstellen dieses Prüfobjekts",
|
||||
en: "To this target's vulnerabilities",
|
||||
};
|
||||
pub const NEXT_SCAN: Text = Text {
|
||||
de: "Die Schwachstellen des Prüfobjekts zeigen eine neue oder geänderte Steuerung nach \
|
||||
der nächsten Prüfung.",
|
||||
en: "The target's vulnerabilities show a new or changed controller after the next scan.",
|
||||
};
|
||||
|
||||
// Adding one.
|
||||
pub const LABEL: Text = Text {
|
||||
de: "Bezeichnung (optional)",
|
||||
en: "Name (optional)",
|
||||
};
|
||||
pub const LABEL_EXAMPLE: Text = Text {
|
||||
de: "Hauptsteuerung Zelle 2",
|
||||
en: "Main controller cell 2",
|
||||
};
|
||||
pub const BAD_ORDER_NUMBER: Text = Text {
|
||||
de: "Eine Artikelnummer hat drei Teile, etwa 6ES7511-1AK02-0AB0.",
|
||||
en: "An order number has three parts, such as 6ES7511-1AK02-0AB0.",
|
||||
};
|
||||
pub const BAD_FIRMWARE: Text = Text {
|
||||
de: "Die Firmware besteht aus Zahlen mit Punkten, etwa V3.1.4.",
|
||||
en: "Firmware is numbers with dots, such as V3.1.4.",
|
||||
};
|
||||
pub fn known(name: &str, lang: Lang) -> String {
|
||||
match lang {
|
||||
Lang::De => format!("Siemens führt diese Nummer als {name}."),
|
||||
Lang::En => format!("Siemens lists this number as {name}."),
|
||||
}
|
||||
}
|
||||
pub const UNKNOWN: Text = Text {
|
||||
de: "Gültige Artikelnummer. Siemens nennt sie bisher in keinem Hinweis; Prüfwerk prüft \
|
||||
sie bei jedem neuen.",
|
||||
en: "A valid order number. No Siemens advisory names it so far; Prüfwerk checks it \
|
||||
against every new one.",
|
||||
};
|
||||
pub const HELP: Text = Text {
|
||||
de: "Wo finde ich Artikelnummer und Firmware?",
|
||||
en: "Where do I find the order number and firmware?",
|
||||
};
|
||||
pub const HELP_PLATE: Text = Text {
|
||||
de: "Auf dem Typenschild vorn an der CPU, beginnend mit 6ES7, 6AG1 oder 6ED1.",
|
||||
en: "On the rating plate on the front of the CPU, starting with 6ES7, 6AG1 or 6ED1.",
|
||||
};
|
||||
pub const HELP_TIA: Text = Text {
|
||||
de: "In TIA Portal: die CPU in der Gerätekonfiguration markieren, dann Eigenschaften, \
|
||||
Allgemein, Katalog-Informationen.",
|
||||
en: "In TIA Portal: select the CPU in the device configuration, then Properties, \
|
||||
General, Catalog information.",
|
||||
};
|
||||
pub const HELP_WEB: Text = Text {
|
||||
de: "Die Firmware zeigt auch der Webserver der CPU auf der Startseite.",
|
||||
en: "The CPU's web server also shows the firmware on its start page.",
|
||||
};
|
||||
|
||||
// How it works.
|
||||
pub const HOW_TITLE: Text = Text {
|
||||
de: "So gleicht Prüfwerk ab",
|
||||
en: "How Prüfwerk checks",
|
||||
};
|
||||
pub const HOW_MATCH: Text = Text {
|
||||
de: "Siemens nennt in seinen Hinweisen jede betroffene CPU mit Artikelnummer und \
|
||||
Firmware-Stand. Prüfwerk liest die Hinweise täglich und vergleicht sie mit den \
|
||||
Steuerungen hier.",
|
||||
en: "Siemens names every affected CPU in its advisories by order number and firmware. \
|
||||
Prüfwerk reads the advisories daily and compares them with the controllers here.",
|
||||
};
|
||||
pub const HOW_FAMILIES: Text = Text {
|
||||
de: "Hinweise, die nur eine ganze Baureihe nennen (etwa „S7-1200 CPU family“), gleicht \
|
||||
Prüfwerk noch nicht ab.",
|
||||
en: "Advisories that name only a whole series (such as “S7-1200 CPU family”) are not \
|
||||
checked yet.",
|
||||
};
|
||||
|
||||
// The target page's card.
|
||||
pub const CARD_HINT: Text = Text {
|
||||
de: "Siemens-Steuerungen mit Artikelnummer und Firmware eintragen",
|
||||
en: "Enter Siemens controllers by order number and firmware",
|
||||
};
|
||||
pub fn card_figure(devices: usize, affected: usize, lang: Lang) -> String {
|
||||
match (lang, devices, affected) {
|
||||
(Lang::De, 1, 0) => "1 Steuerung, kein Hinweis betrifft sie".to_string(),
|
||||
(Lang::De, n, 0) => format!("{n} Steuerungen, kein Hinweis betrifft sie"),
|
||||
(Lang::De, 1, _) => "1 Steuerung, betroffen".to_string(),
|
||||
(Lang::De, n, a) => format!("{n} Steuerungen, {a} betroffen"),
|
||||
(Lang::En, 1, 0) => "1 controller, no advisory affects it".to_string(),
|
||||
(Lang::En, n, 0) => format!("{n} controllers, no advisory affects them"),
|
||||
(Lang::En, 1, _) => "1 controller, affected".to_string(),
|
||||
(Lang::En, n, a) => format!("{n} controllers, {a} affected"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
//! A target's Siemens controllers (SPS item 4a), read from the agent's
|
||||
//! `/api/v1/targets/{id}/devices` and changed with the target.
|
||||
|
||||
use compliance_core::device_check::{DeviceCheck, DeviceLookup};
|
||||
use compliance_core::models::PlcDevice;
|
||||
use dioxus::prelude::*;
|
||||
|
||||
/// Target `id`'s devices, each with the Siemens advisories naming it.
|
||||
#[server]
|
||||
pub async fn fetch_devices(id: String) -> Result<Vec<DeviceCheck>, ServerFnError> {
|
||||
super::agent_client::data(
|
||||
super::agent_client::agent_get(&format!("/api/v1/targets/{id}/devices")).await?,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// What Siemens' advisories know of `order_number`, as typed.
|
||||
#[server]
|
||||
pub async fn lookup_device(order_number: String) -> Result<DeviceLookup, ServerFnError> {
|
||||
super::agent_client::data(
|
||||
super::agent_client::agent_get("/api/v1/devices/lookup")
|
||||
.await?
|
||||
.query(&[("order_number", order_number)]),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Store `devices` as target `id`'s devices, replacing the ones it had.
|
||||
#[server]
|
||||
pub async fn save_devices(id: String, devices: Vec<PlcDevice>) -> Result<(), ServerFnError> {
|
||||
let resp = super::agent_client::agent_request(
|
||||
reqwest::Method::PATCH,
|
||||
&format!("/api/v1/targets/{id}"),
|
||||
)
|
||||
.await?
|
||||
.json(&serde_json::json!({ "devices": devices }))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
||||
super::agent_client::ok_or_error(resp).await
|
||||
}
|
||||
@@ -5,7 +5,6 @@ pub mod chat;
|
||||
pub mod cve_history;
|
||||
pub mod cve_matrix;
|
||||
pub mod dast;
|
||||
pub mod devices;
|
||||
pub mod download;
|
||||
pub mod evidence;
|
||||
pub mod finding_breakdown;
|
||||
|
||||
@@ -68,7 +68,7 @@ pub fn upload_problem(error: String, lang: Lang) -> String {
|
||||
} else if error.contains(UNSUPPORTED_ARCHIVE) {
|
||||
common::UNSUPPORTED_ARCHIVE.get(lang).to_string()
|
||||
} else {
|
||||
crate::i18n::texts::metering::demo_refusal(&error, lang)
|
||||
error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,8 +694,6 @@ pub async fn upload_target_artifact(
|
||||
413 if sbom => format!("{SBOM_REFUSED}too_large"),
|
||||
413 => "file is larger than the 512 MiB upload limit".to_string(),
|
||||
415 => UNSUPPORTED_ARCHIVE.to_string(),
|
||||
// A demo target the plan has no room for as the tenant's own.
|
||||
409 => refusal_code(resp).await,
|
||||
422 => format!("{SBOM_REFUSED}{}", refusal_code(resp).await),
|
||||
code => format!("upload rejected by the agent ({code})"),
|
||||
}));
|
||||
|
||||
@@ -18,8 +18,8 @@ use crate::infrastructure::evidence::{fetch_compliance, CraCounts};
|
||||
/// them: violated first, requirements evidenced outside the code last.
|
||||
pub(crate) const STATES: [(&str, Text, &str); 5] = [
|
||||
("not_satisfied", tx::NOT_SATISFIED, "badge badge-critical"),
|
||||
("not_assessed", tx::NOT_ASSESSED, "badge badge-open"),
|
||||
("partial", tx::PARTIAL, "badge badge-medium"),
|
||||
("not_assessed", tx::NOT_ASSESSED, "badge badge-medium"),
|
||||
("partial", tx::PARTIAL, "badge badge-info"),
|
||||
(
|
||||
"no_violation_found",
|
||||
tx::NO_VIOLATION,
|
||||
@@ -163,29 +163,11 @@ pub fn CompliancePage(id: String) -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
/// The name a customer reads for `control` (an entry of the compliance
|
||||
/// API's `controls`): the requirement's name, else the catalog's title for
|
||||
/// an id outside the 40, else the id.
|
||||
pub(crate) fn requirement_name(control: &serde_json::Value, lang: Lang) -> String {
|
||||
let id = control["control"].as_str().unwrap_or_default();
|
||||
match compliance_core::cra_requirements::name(id) {
|
||||
Some(words) => Text::from(words).get(lang).to_string(),
|
||||
None => control["title"].as_str().unwrap_or(id).to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// One requirement: its name, the catalog's rating, and what the state rests
|
||||
/// on (the findings against it, or why it was not assessed, unless
|
||||
/// `show_reason` is off because the group states it once). `headless` leaves
|
||||
/// the name line out where the requirement is already named above.
|
||||
/// One requirement: its id and title, the catalog's rating, and what the
|
||||
/// state rests on (the findings against it, or why it was not assessed,
|
||||
/// unless `show_reason` is off because the group states it once).
|
||||
#[component]
|
||||
pub(crate) fn ControlRow(
|
||||
control: serde_json::Value,
|
||||
lang: Lang,
|
||||
show_reason: bool,
|
||||
#[props(default)] headless: bool,
|
||||
) -> Element {
|
||||
let name = requirement_name(&control, lang);
|
||||
pub(crate) fn ControlRow(control: serde_json::Value, lang: Lang, show_reason: bool) -> Element {
|
||||
let findings = control["findings"].as_array().cloned().unwrap_or_default();
|
||||
// The control map's notes are engineering prose in English; in German
|
||||
// the group's hint says the same.
|
||||
@@ -204,9 +186,8 @@ pub(crate) fn ControlRow(
|
||||
rsx! {
|
||||
li { class: "cra-control",
|
||||
div { class: "cra-control-head",
|
||||
if !headless {
|
||||
span { class: "cra-control-title", "{name}" }
|
||||
}
|
||||
code { class: "cra-control-id", "{control[\"control\"].as_str().unwrap_or_default()}" }
|
||||
span { class: "cra-control-title", "{control[\"title\"].as_str().unwrap_or_default()}" }
|
||||
if let Some(label) = severity_label {
|
||||
span { class: "badge badge-{severity}", "{label}" }
|
||||
}
|
||||
|
||||
@@ -1,667 +0,0 @@
|
||||
//! A target's Siemens controllers (SPS item 4a): each one a module on a DIN
|
||||
//! rail whose light says whether a Siemens advisory affects its firmware,
|
||||
//! the chosen one's advisories beside it, and a form that recognises an
|
||||
//! order number while it is typed.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_free_icons::icons::bs_icons::{BsArrowRight, BsCheckLg, BsExclamationCircle, BsPlusLg};
|
||||
use dioxus_free_icons::Icon;
|
||||
|
||||
use compliance_core::device_check::{DeviceAdvisory, DeviceCheck, DeviceState};
|
||||
use compliance_core::models::{PlcDevice, PlcDeviceError};
|
||||
|
||||
use crate::app::Route;
|
||||
use crate::components::copy_button::CopyButton;
|
||||
use crate::components::no_access::use_can_write;
|
||||
use crate::components::severity_badge::SeverityBadge;
|
||||
use crate::components::toast::{ToastType, Toasts};
|
||||
use crate::i18n::texts::{devices as tx, repo_views as rv};
|
||||
use crate::i18n::{use_lang, Text};
|
||||
use crate::infrastructure::devices::{fetch_devices, lookup_device, save_devices};
|
||||
use crate::infrastructure::onboarding::fetch_target;
|
||||
use crate::pages::target_views::RepoView;
|
||||
|
||||
/// The CSS class of a state's light.
|
||||
fn light(state: DeviceState) -> &'static str {
|
||||
match state {
|
||||
DeviceState::Affected => "dev-led dev-led-affected",
|
||||
DeviceState::NotAffected => "dev-led dev-led-clear",
|
||||
DeviceState::NotNamed => "dev-led dev-led-unnamed",
|
||||
}
|
||||
}
|
||||
|
||||
/// How many of a device's advisories affect it.
|
||||
fn affecting(check: &DeviceCheck) -> usize {
|
||||
check.advisories.iter().filter(|a| a.affected).count()
|
||||
}
|
||||
|
||||
/// What the rail shows of a device: Siemens' short name for it (or its order
|
||||
/// number) and its series (or the vendor).
|
||||
fn module_names(check: &DeviceCheck) -> (String, String) {
|
||||
match &check.product {
|
||||
Some(p) => (
|
||||
p.short.clone(),
|
||||
p.family.clone().unwrap_or_else(|| "Siemens".to_string()),
|
||||
),
|
||||
None => (check.device.order_number.clone(), "Siemens".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
/// A change to a target's devices, for the toast it ends with.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
enum Change {
|
||||
Added,
|
||||
Removed,
|
||||
Firmware,
|
||||
}
|
||||
|
||||
impl Change {
|
||||
fn done(self) -> Text {
|
||||
match self {
|
||||
Self::Added => tx::ADDED,
|
||||
Self::Removed => tx::REMOVED,
|
||||
Self::Firmware => tx::FIRMWARE_SAVED,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Target `id`'s Siemens controllers.
|
||||
#[component]
|
||||
pub fn TargetDevicesPage(id: String) -> Element {
|
||||
let lang = use_lang()();
|
||||
let can_write = use_can_write();
|
||||
let mut toasts = use_context::<Toasts>();
|
||||
let target_id = use_signal(|| id.clone());
|
||||
let target = use_resource(move || async move { fetch_target(target_id()).await.ok() });
|
||||
let mut checks = use_resource(move || async move { fetch_devices(target_id()).await });
|
||||
let mut selected = use_signal(|| 0_usize);
|
||||
let mut adding = use_signal(|| false);
|
||||
let mut saving = use_signal(|| false);
|
||||
|
||||
let name = match &*target.read() {
|
||||
Some(Some(t)) => t
|
||||
.data
|
||||
.get("name")
|
||||
.and_then(|n| n.as_str())
|
||||
.unwrap_or_default()
|
||||
.to_string(),
|
||||
Some(None) => {
|
||||
return rsx! {
|
||||
div { class: "card target-missing",
|
||||
p { {crate::i18n::texts::targets::NOT_FOUND.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
None => return rsx! { div { class: "loading", {tx::LOADING.get(lang)} } },
|
||||
};
|
||||
let listed: Vec<DeviceCheck> = match &*checks.read() {
|
||||
Some(Ok(listed)) => listed.clone(),
|
||||
Some(Err(_)) => {
|
||||
return rsx! {
|
||||
DeviceCrumbs { id: id.clone(), name }
|
||||
div { class: "card", p { {tx::LOAD_FAILED.get(lang)} } }
|
||||
}
|
||||
}
|
||||
None => return rsx! { div { class: "loading", {tx::LOADING.get(lang)} } },
|
||||
};
|
||||
let devices: Vec<PlcDevice> = listed.iter().map(|c| c.device.clone()).collect();
|
||||
// A first device is added from the empty rail's form.
|
||||
let show_form = can_write && (adding() || listed.is_empty());
|
||||
let chosen = (!show_form)
|
||||
.then(|| listed.get(selected()))
|
||||
.flatten()
|
||||
.cloned();
|
||||
|
||||
let save = move |next: Vec<PlcDevice>, change: Change, then_select: usize| {
|
||||
spawn(async move {
|
||||
saving.set(true);
|
||||
match save_devices(target_id(), next).await {
|
||||
Ok(()) => {
|
||||
toasts.push(ToastType::Success, change.done().get(lang).to_string());
|
||||
selected.set(then_select);
|
||||
adding.set(false);
|
||||
checks.restart();
|
||||
}
|
||||
Err(e) => toasts.push(
|
||||
ToastType::Error,
|
||||
format!("{} {e}", tx::SAVE_FAILED.get(lang)),
|
||||
),
|
||||
}
|
||||
saving.set(false);
|
||||
});
|
||||
};
|
||||
|
||||
rsx! {
|
||||
div { class: "dev-page",
|
||||
DeviceCrumbs { id: id.clone(), name: name.clone() }
|
||||
header { class: "chain-head",
|
||||
h1 { {tx::title(&name, lang)} }
|
||||
p { {tx::INTRO.get(lang)} }
|
||||
}
|
||||
section { class: "card dev-rail-card", "aria-label": tx::RAIL.get(lang),
|
||||
ul { class: "dev-legend",
|
||||
li { span { class: light(DeviceState::Affected), "aria-hidden": "true" } {tx::LEGEND_AFFECTED.get(lang)} }
|
||||
li { span { class: light(DeviceState::NotAffected), "aria-hidden": "true" } {tx::LEGEND_NOT_AFFECTED.get(lang)} }
|
||||
li { span { class: light(DeviceState::NotNamed), "aria-hidden": "true" } {tx::LEGEND_NOT_NAMED.get(lang)} }
|
||||
}
|
||||
div { class: "dev-rail-scroll",
|
||||
div { class: "dev-rail",
|
||||
div { class: "dev-rail-bar", "aria-hidden": "true" }
|
||||
for (i , check) in listed.iter().enumerate() {
|
||||
DeviceModule {
|
||||
key: "{i}-{check.device.order_number}",
|
||||
check: check.clone(),
|
||||
pressed: chosen.is_some() && selected() == i,
|
||||
on_pick: move |_| {
|
||||
selected.set(i);
|
||||
adding.set(false);
|
||||
},
|
||||
}
|
||||
}
|
||||
if can_write {
|
||||
button {
|
||||
r#type: "button",
|
||||
class: if show_form { "dev-add dev-add-on" } else { "dev-add" },
|
||||
"aria-pressed": "{show_form}",
|
||||
onclick: move |_| adding.set(true),
|
||||
Icon { icon: BsPlusLg, width: 28, height: 28 }
|
||||
span { {tx::ADD.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if listed.is_empty() && !can_write {
|
||||
p { class: "dev-empty", {tx::EMPTY_READ_ONLY.get(lang)} }
|
||||
}
|
||||
}
|
||||
div { class: "dev-body",
|
||||
if show_form {
|
||||
AddDevice {
|
||||
first: listed.is_empty(),
|
||||
saving: saving(),
|
||||
on_cancel: move |_| adding.set(false),
|
||||
on_add: {
|
||||
let devices = devices.clone();
|
||||
move |device: PlcDevice| {
|
||||
let mut next = devices.clone();
|
||||
next.push(device);
|
||||
let last = next.len() - 1;
|
||||
save(next, Change::Added, last);
|
||||
}
|
||||
},
|
||||
}
|
||||
} else if let Some(check) = chosen {
|
||||
DeviceDetail {
|
||||
key: "{selected()}-{check.device.order_number}-{check.device.firmware}",
|
||||
target_id: id.clone(),
|
||||
check,
|
||||
can_write,
|
||||
saving: saving(),
|
||||
on_firmware: {
|
||||
let devices = devices.clone();
|
||||
move |firmware: String| {
|
||||
let at = selected();
|
||||
let mut next = devices.clone();
|
||||
if let Some(d) = next.get_mut(at) {
|
||||
d.firmware = firmware;
|
||||
}
|
||||
save(next, Change::Firmware, at);
|
||||
}
|
||||
},
|
||||
on_remove: {
|
||||
let devices = devices.clone();
|
||||
move |_| {
|
||||
let at = selected();
|
||||
let mut next = devices.clone();
|
||||
if at < next.len() {
|
||||
next.remove(at);
|
||||
}
|
||||
save(next, Change::Removed, at.saturating_sub(1));
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
aside { class: "dev-how", "aria-label": tx::HOW_TITLE.get(lang),
|
||||
h2 { {tx::HOW_TITLE.get(lang)} }
|
||||
p { {tx::HOW_MATCH.get(lang)} }
|
||||
p { {tx::HOW_FAMILIES.get(lang)} }
|
||||
p { {tx::NEXT_SCAN.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The target page's card: a light per device and the way to the page.
|
||||
#[component]
|
||||
pub fn DevicesCard(target_id: String) -> Element {
|
||||
let lang = use_lang()();
|
||||
let id = use_signal(|| target_id.clone());
|
||||
let checks = use_resource(move || async move { fetch_devices(id()).await.ok() });
|
||||
let listed = checks.read().clone().flatten().unwrap_or_default();
|
||||
let affected = listed
|
||||
.iter()
|
||||
.filter(|c| c.state() == DeviceState::Affected)
|
||||
.count();
|
||||
rsx! {
|
||||
section { class: "card target-devices",
|
||||
div { class: "target-card-head",
|
||||
h3 { {tx::CRUMB.get(lang)} }
|
||||
Link { to: Route::TargetDevicesPage { id: target_id.clone() }, class: "target-card-link",
|
||||
Icon { icon: BsArrowRight, width: 14, height: 14 }
|
||||
}
|
||||
}
|
||||
if listed.is_empty() {
|
||||
p { class: "target-graph-note", {tx::CARD_HINT.get(lang)} }
|
||||
} else {
|
||||
div { class: "dev-card-lights", "aria-hidden": "true",
|
||||
for check in listed.iter() {
|
||||
span { class: light(check.state()) }
|
||||
}
|
||||
}
|
||||
p { class: "target-graph-note", {tx::card_figure(listed.len(), affected, lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Overview › target › Controllers.
|
||||
#[component]
|
||||
fn DeviceCrumbs(id: String, name: String) -> Element {
|
||||
let lang = use_lang()();
|
||||
rsx! {
|
||||
nav { class: "repo-crumbs", "aria-label": rv::BREADCRUMB.get(lang),
|
||||
Link { to: Route::OverviewPage {}, {rv::OVERVIEW.get(lang)} }
|
||||
span { class: "repo-crumb-sep", "aria-hidden": "true", "›" }
|
||||
Link { class: "repo-crumb-name", to: Route::target(id.clone()), "{name}" }
|
||||
span { class: "repo-crumb-sep", "aria-hidden": "true", "›" }
|
||||
span { "aria-current": "page", {tx::CRUMB.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One device on the rail.
|
||||
#[component]
|
||||
fn DeviceModule(check: DeviceCheck, pressed: bool, on_pick: EventHandler<()>) -> Element {
|
||||
let lang = use_lang()();
|
||||
let (short, family) = module_names(&check);
|
||||
let label = check
|
||||
.device
|
||||
.label
|
||||
.clone()
|
||||
.unwrap_or_else(|| tx::NO_LABEL.get(lang).to_string());
|
||||
let aria = tx::module(
|
||||
&short,
|
||||
&check.device.firmware,
|
||||
affecting(&check),
|
||||
!check.advisories.is_empty(),
|
||||
lang,
|
||||
);
|
||||
rsx! {
|
||||
button {
|
||||
r#type: "button",
|
||||
class: if pressed { "dev-module dev-module-on" } else { "dev-module" },
|
||||
"aria-pressed": "{pressed}",
|
||||
"aria-label": "{aria}",
|
||||
onclick: move |_| on_pick.call(()),
|
||||
span { class: "dev-module-top",
|
||||
span { class: "dev-module-brand", "SIEMENS" }
|
||||
span { class: light(check.state()), "aria-hidden": "true" }
|
||||
}
|
||||
span { class: "dev-module-face", "aria-hidden": "true", "{family}" }
|
||||
span { class: "dev-module-names",
|
||||
span { class: "dev-module-short", "{short}" }
|
||||
span { class: "dev-module-label", "{label}" }
|
||||
}
|
||||
span { class: "dev-module-vents", "aria-hidden": "true", span {} span {} span {} }
|
||||
span { class: "dev-module-fw", "V{check.device.firmware}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The chosen device: its figures, its state and its advisories.
|
||||
#[component]
|
||||
fn DeviceDetail(
|
||||
target_id: String,
|
||||
check: DeviceCheck,
|
||||
can_write: bool,
|
||||
saving: bool,
|
||||
on_firmware: EventHandler<String>,
|
||||
on_remove: EventHandler<()>,
|
||||
) -> Element {
|
||||
let lang = use_lang()();
|
||||
let mut editing = use_signal(|| false);
|
||||
let mut draft = use_signal(|| check.device.firmware.clone());
|
||||
let state = check.state();
|
||||
let device = &check.device;
|
||||
let order_number = device.order_number.clone();
|
||||
let name = check.product.as_ref().map_or_else(
|
||||
|| format!("Siemens {}", device.order_number),
|
||||
|p| p.name.clone(),
|
||||
);
|
||||
let label = device
|
||||
.label
|
||||
.clone()
|
||||
.unwrap_or_else(|| tx::NO_LABEL.get(lang).to_string());
|
||||
let sentence = tx::state(
|
||||
affecting(&check),
|
||||
check.advisories.len(),
|
||||
&device.firmware,
|
||||
lang,
|
||||
);
|
||||
let firmware_error = PlcDevice::new(&device.order_number, &draft(), None).is_err();
|
||||
let tint = match state {
|
||||
DeviceState::Affected => "dev-state dev-state-affected",
|
||||
DeviceState::NotAffected => "dev-state dev-state-clear",
|
||||
DeviceState::NotNamed => "dev-state dev-state-unnamed",
|
||||
};
|
||||
|
||||
rsx! {
|
||||
section { class: "card dev-detail", "aria-label": "{name}",
|
||||
div { class: "dev-detail-head",
|
||||
div {
|
||||
h2 { "{name}" }
|
||||
span { class: "dev-detail-label", "{label}" }
|
||||
}
|
||||
if can_write {
|
||||
div { class: "dev-detail-actions",
|
||||
if !editing() {
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "btn btn-ghost",
|
||||
disabled: saving,
|
||||
onclick: move |_| editing.set(true),
|
||||
{tx::CHANGE_FIRMWARE.get(lang)}
|
||||
}
|
||||
}
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "btn btn-ghost btn-danger-ghost",
|
||||
disabled: saving,
|
||||
onclick: move |_| on_remove.call(()),
|
||||
{tx::REMOVE.get(lang)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dl { class: "dev-figures",
|
||||
div {
|
||||
dt { {tx::ORDER_NUMBER.get(lang)} }
|
||||
dd { "{device.order_number}" CopyButton { value: device.order_number.clone(), small: true } }
|
||||
}
|
||||
div {
|
||||
dt { {tx::FIRMWARE.get(lang)} }
|
||||
if editing() {
|
||||
dd { class: "dev-firmware-edit",
|
||||
input {
|
||||
r#type: "text",
|
||||
"aria-label": tx::FIRMWARE.get(lang),
|
||||
"aria-invalid": "{firmware_error}",
|
||||
value: "{draft}",
|
||||
autocomplete: "off",
|
||||
spellcheck: "false",
|
||||
oninput: move |e| draft.set(e.value()),
|
||||
}
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "btn btn-primary",
|
||||
disabled: firmware_error || saving,
|
||||
onclick: move |_| {
|
||||
if let Ok(d) = PlcDevice::new(&order_number, &draft(), None) {
|
||||
on_firmware.call(d.firmware);
|
||||
}
|
||||
},
|
||||
{tx::SAVE_FIRMWARE.get(lang)}
|
||||
}
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "btn btn-ghost",
|
||||
onclick: move |_| editing.set(false),
|
||||
{tx::CANCEL.get(lang)}
|
||||
}
|
||||
}
|
||||
if firmware_error && !draft().trim().is_empty() {
|
||||
p { class: "dev-field-note", role: "status", {tx::BAD_FIRMWARE.get(lang)} }
|
||||
}
|
||||
} else {
|
||||
dd { "V{device.firmware}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
div { class: tint,
|
||||
span { class: light(state), "aria-hidden": "true" }
|
||||
span { "{sentence}" }
|
||||
}
|
||||
if !check.advisories.is_empty() {
|
||||
div { class: "dev-advisories",
|
||||
h3 { {tx::ADVISORIES.get(lang)} }
|
||||
for advisory in check.advisories.iter() {
|
||||
AdvisoryRow { key: "{advisory.id}", advisory: advisory.clone(), firmware: device.firmware.clone() }
|
||||
}
|
||||
Link {
|
||||
class: "dev-to-cves",
|
||||
to: Route::target_view(target_id.clone(), RepoView::Cves),
|
||||
{tx::TO_CVES.get(lang)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One advisory naming the device.
|
||||
#[component]
|
||||
fn AdvisoryRow(advisory: DeviceAdvisory, firmware: String) -> Element {
|
||||
let lang = use_lang()();
|
||||
let fix = match &advisory.fixed_from {
|
||||
Some(version) => tx::fixed_from(version, lang),
|
||||
None => tx::NO_FIX.get(lang).to_string(),
|
||||
};
|
||||
let verdict = if advisory.affected {
|
||||
tx::affects(&firmware, lang)
|
||||
} else {
|
||||
tx::NOT_AFFECTED.get(lang).to_string()
|
||||
};
|
||||
rsx! {
|
||||
div { class: if advisory.affected { "dev-advisory" } else { "dev-advisory dev-advisory-clear" },
|
||||
SeverityBadge { severity: advisory.severity.clone().unwrap_or_default() }
|
||||
div { class: "dev-advisory-text",
|
||||
span { class: "dev-advisory-title", "{advisory.title}" }
|
||||
span { class: "dev-advisory-meta", "{advisory.id}. {fix}" }
|
||||
}
|
||||
span { class: if advisory.affected { "dev-verdict dev-verdict-affected" } else { "dev-verdict" }, "{verdict}" }
|
||||
// Every row is Siemens' (the agent reads no other provider for a
|
||||
// device), whose terms ask each use to link the advisory.
|
||||
if let Some(url) = &advisory.url {
|
||||
a { class: "dev-source", href: "{url}", target: "_blank", rel: "noopener noreferrer", {tx::SOURCE.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What the form says of the order number typed so far.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
enum Recognised {
|
||||
/// Too short to say anything yet.
|
||||
Nothing,
|
||||
/// Long enough, but not an order number's shape.
|
||||
BadShape,
|
||||
/// The shape is right; what Siemens' advisories know is being asked.
|
||||
Asking,
|
||||
/// Siemens' advisories name it, by this name.
|
||||
Known(String),
|
||||
/// The shape is right, but no advisory names it.
|
||||
Unknown,
|
||||
}
|
||||
|
||||
/// The shape of what has been typed: an order number, or not (yet).
|
||||
fn shape(order_number: &str) -> Option<bool> {
|
||||
match PlcDevice::new(order_number, "0", None) {
|
||||
Ok(_) => Some(true),
|
||||
Err(PlcDeviceError::OrderNumber(n)) if n.len() >= 6 => Some(false),
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The form for a new device.
|
||||
#[component]
|
||||
fn AddDevice(
|
||||
/// The target has no device yet: nothing to go back to.
|
||||
first: bool,
|
||||
saving: bool,
|
||||
on_cancel: EventHandler<()>,
|
||||
on_add: EventHandler<PlcDevice>,
|
||||
) -> Element {
|
||||
let lang = use_lang()();
|
||||
let mut order_number = use_signal(String::new);
|
||||
let mut firmware = use_signal(String::new);
|
||||
let mut label = use_signal(String::new);
|
||||
// Asked only once the typed number has an order number's shape.
|
||||
let known = use_resource(move || async move {
|
||||
let typed = order_number();
|
||||
if shape(&typed) != Some(true) {
|
||||
return None;
|
||||
}
|
||||
lookup_device(typed).await.ok()
|
||||
});
|
||||
let recognised = match shape(&order_number()) {
|
||||
None => Recognised::Nothing,
|
||||
Some(false) => Recognised::BadShape,
|
||||
Some(true) => match &*known.read() {
|
||||
Some(Some(found)) => match &found.product {
|
||||
Some(p) => Recognised::Known(p.name.clone()),
|
||||
None => Recognised::Unknown,
|
||||
},
|
||||
// Not answered, or the index cannot be read: the number is valid
|
||||
// either way and can be added.
|
||||
_ => Recognised::Asking,
|
||||
},
|
||||
};
|
||||
let device = PlcDevice::new(&order_number(), &firmware(), Some(&label()));
|
||||
let firmware_bad =
|
||||
!firmware().trim().is_empty() && matches!(device, Err(PlcDeviceError::Firmware(_)));
|
||||
|
||||
rsx! {
|
||||
section { class: "card dev-form", "aria-label": tx::ADD.get(lang),
|
||||
h2 { {tx::ADD.get(lang)} }
|
||||
div { class: "dev-form-fields",
|
||||
div { class: "form-group",
|
||||
label { r#for: "dev-on", {tx::ORDER_NUMBER.get(lang)} }
|
||||
input {
|
||||
id: "dev-on",
|
||||
r#type: "text",
|
||||
value: "{order_number}",
|
||||
placeholder: "6ES7511-1AK02-0AB0",
|
||||
autocomplete: "off",
|
||||
spellcheck: "false",
|
||||
oninput: move |e| order_number.set(e.value()),
|
||||
}
|
||||
}
|
||||
div { class: "form-group",
|
||||
label { r#for: "dev-fw", {tx::FIRMWARE.get(lang)} }
|
||||
input {
|
||||
id: "dev-fw",
|
||||
r#type: "text",
|
||||
value: "{firmware}",
|
||||
placeholder: "V3.1.4",
|
||||
autocomplete: "off",
|
||||
spellcheck: "false",
|
||||
"aria-invalid": "{firmware_bad}",
|
||||
oninput: move |e| firmware.set(e.value()),
|
||||
}
|
||||
}
|
||||
div { class: "form-group",
|
||||
label { r#for: "dev-label", {tx::LABEL.get(lang)} }
|
||||
input {
|
||||
id: "dev-label",
|
||||
r#type: "text",
|
||||
value: "{label}",
|
||||
placeholder: tx::LABEL_EXAMPLE.get(lang),
|
||||
autocomplete: "off",
|
||||
oninput: move |e| label.set(e.value()),
|
||||
}
|
||||
}
|
||||
}
|
||||
match recognised {
|
||||
Recognised::Nothing | Recognised::Asking => rsx! {},
|
||||
Recognised::BadShape => rsx! {
|
||||
div { class: "dev-recognised dev-recognised-bad", role: "status",
|
||||
Icon { icon: BsExclamationCircle, width: 16, height: 16 }
|
||||
span { {tx::BAD_ORDER_NUMBER.get(lang)} }
|
||||
}
|
||||
},
|
||||
Recognised::Known(name) => rsx! {
|
||||
div { class: "dev-recognised dev-recognised-known", role: "status",
|
||||
Icon { icon: BsCheckLg, width: 16, height: 16 }
|
||||
span { {tx::known(&name, lang)} }
|
||||
}
|
||||
},
|
||||
Recognised::Unknown => rsx! {
|
||||
div { class: "dev-recognised", role: "status",
|
||||
Icon { icon: BsExclamationCircle, width: 16, height: 16 }
|
||||
span { {tx::UNKNOWN.get(lang)} }
|
||||
}
|
||||
},
|
||||
}
|
||||
if firmware_bad {
|
||||
div { class: "dev-recognised dev-recognised-bad", role: "status",
|
||||
Icon { icon: BsExclamationCircle, width: 16, height: 16 }
|
||||
span { {tx::BAD_FIRMWARE.get(lang)} }
|
||||
}
|
||||
}
|
||||
details { class: "dev-help",
|
||||
summary { {tx::HELP.get(lang)} }
|
||||
ul {
|
||||
li { {tx::HELP_PLATE.get(lang)} }
|
||||
li { {tx::HELP_TIA.get(lang)} }
|
||||
li { {tx::HELP_WEB.get(lang)} }
|
||||
}
|
||||
}
|
||||
div { class: "dev-form-actions",
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "btn btn-primary",
|
||||
disabled: device.is_err() || saving,
|
||||
onclick: move |_| {
|
||||
if let Ok(d) = PlcDevice::new(&order_number(), &firmware(), Some(&label())) {
|
||||
on_add.call(d);
|
||||
}
|
||||
},
|
||||
{tx::ADD.get(lang)}
|
||||
}
|
||||
if !first {
|
||||
button {
|
||||
r#type: "button",
|
||||
class: "btn btn-ghost",
|
||||
onclick: move |_| on_cancel.call(()),
|
||||
{tx::CANCEL.get(lang)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn the_form_speaks_once_six_characters_are_typed() {
|
||||
assert_eq!(shape("6ES7"), None);
|
||||
assert_eq!(shape("6ES751"), Some(false));
|
||||
assert_eq!(shape("6es7511-1ak02-0ab0"), Some(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_module_shows_the_name_siemens_uses_or_the_order_number() {
|
||||
let device = PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.4", None).unwrap();
|
||||
let unnamed = DeviceCheck::new(device, &[]);
|
||||
assert_eq!(
|
||||
module_names(&unnamed),
|
||||
("6ES7511-1AK02-0AB0".to_string(), "Siemens".to_string())
|
||||
);
|
||||
assert_eq!(light(unnamed.state()), "dev-led dev-led-unnamed");
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,11 @@ use dioxus_free_icons::Icon;
|
||||
|
||||
use crate::app::Route;
|
||||
use crate::components::code_snippet::CodeSnippet;
|
||||
use crate::components::cra_tiles::{cra_tone, StateMark};
|
||||
use crate::components::markdown::render_markdown;
|
||||
use crate::components::page_header::PageHeader;
|
||||
use crate::components::severity_badge::SeverityBadge;
|
||||
use crate::i18n::texts::{common, finding_breakdown, findings as tx, graph as graph_tx};
|
||||
use crate::i18n::{format_count, format_time, requirement_label, use_lang, Lang};
|
||||
use crate::i18n::{format_count, format_time, use_lang, Lang};
|
||||
use crate::infrastructure::evidence::{fetch_catalog_controls, CatalogControl};
|
||||
use crate::infrastructure::findings::{location, mask_secrets, wire_name};
|
||||
use crate::infrastructure::graph::fetch_impact;
|
||||
@@ -128,12 +127,11 @@ pub fn FindingDetailPage(id: String) -> Element {
|
||||
.as_ref()
|
||||
.and_then(|d| d["target_name"].as_str())
|
||||
.map(String::from);
|
||||
// A requirement's state on the target, as the CRA map shows it.
|
||||
let control_state = |id: &str| -> Option<String> {
|
||||
let control_title = |id: &str| -> Option<String> {
|
||||
status_data.as_ref()?["controls"]
|
||||
.as_array()?
|
||||
.iter()
|
||||
.find(|c| c["control"].as_str() == Some(id))?["state"]
|
||||
.find(|c| c["control"].as_str() == Some(id))?["title"]
|
||||
.as_str()
|
||||
.map(String::from)
|
||||
};
|
||||
@@ -145,8 +143,8 @@ pub fn FindingDetailPage(id: String) -> Element {
|
||||
let cra_topics: Vec<(String, Option<String>)> = cra_refs
|
||||
.into_iter()
|
||||
.map(|c| {
|
||||
let state = control_state(&c);
|
||||
(c, state)
|
||||
let title = control_title(&c);
|
||||
(c, title)
|
||||
})
|
||||
.collect();
|
||||
// Offer Breakpilot Git only once the agent said the target opens
|
||||
@@ -311,22 +309,11 @@ pub fn FindingDetailPage(id: String) -> Element {
|
||||
if !f.control_refs.is_empty() {
|
||||
span { style: "opacity: 0.7;", {tx::CRA_REFS.get(lang)} }
|
||||
ul { class: "finding-refs",
|
||||
for (c, state) in cra_topics {
|
||||
for (c, title) in cra_topics {
|
||||
li {
|
||||
Link {
|
||||
class: "ct-chip {cra_tone(state.as_deref())}",
|
||||
to: Route::TargetViewsPage {
|
||||
id: f.repo_id.clone(),
|
||||
view: crate::pages::target_views::RepoView::Cra.slug().to_string(),
|
||||
cve_severity: None,
|
||||
cve_vex: None,
|
||||
control: Some(c.clone()),
|
||||
scan: None,
|
||||
},
|
||||
if let Some(state) = state.clone() {
|
||||
StateMark { state }
|
||||
}
|
||||
span { class: "ct-chip-name", {requirement_label(&c, lang)} }
|
||||
span { class: "badge badge-info", "{c}" }
|
||||
if let Some(title) = title {
|
||||
span { " {title}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -688,7 +675,7 @@ fn tracker_note(
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `finding` - the finding shown on the page
|
||||
/// * `cra_topics` - its CRA requirement ids, each with its state when known
|
||||
/// * `cra_topics` - its CRA control ids, each with its title when known
|
||||
/// * `link` - the finding's page in Prüfwerk
|
||||
/// * `lang` - the UI language, for the labels
|
||||
///
|
||||
@@ -733,8 +720,11 @@ fn ticket_markdown(
|
||||
}
|
||||
if !cra_topics.is_empty() {
|
||||
md.push_str(&format!("\n### {}\n\n", tx::CRA_TOPICS.get(lang)));
|
||||
for (id, _) in cra_topics {
|
||||
md.push_str(&format!("- {}\n", requirement_label(id, lang)));
|
||||
for (id, title) in cra_topics {
|
||||
match title {
|
||||
Some(title) => md.push_str(&format!("- `{id}` {title}\n")),
|
||||
None => md.push_str(&format!("- `{id}`\n")),
|
||||
}
|
||||
}
|
||||
}
|
||||
md.push_str(&format!(
|
||||
@@ -865,7 +855,10 @@ mod tests {
|
||||
#[test]
|
||||
fn the_ticket_text_holds_the_finding_and_a_link_back() {
|
||||
let topics = vec![
|
||||
("cra-ai-8".to_string(), Some("not_satisfied".to_string())),
|
||||
(
|
||||
"cra-ai-2c".to_string(),
|
||||
Some("Schutz vor unbefugtem Zugriff".to_string()),
|
||||
),
|
||||
("cra-ai-2f".to_string(), None),
|
||||
];
|
||||
let md = ticket_markdown(
|
||||
@@ -883,8 +876,8 @@ mod tests {
|
||||
\n### Beschreibung\n\nDie Abfrage setzt Benutzereingaben direkt ein.\n\
|
||||
\n### Einschätzung\n\nErreichbar über das Login-Formular.\n\
|
||||
\n### CRA-Themen\n\n\
|
||||
- Keine Standardpasswörter\n\
|
||||
- cra-ai-2f\n\
|
||||
- `cra-ai-2c` Schutz vor unbefugtem Zugriff\n\
|
||||
- `cra-ai-2f`\n\
|
||||
\n[Im Prüfwerk öffnen](https://pruefwerk.example/findings/abc)\n"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ use crate::components::toast::{ToastType, Toasts};
|
||||
use crate::i18n::texts::{
|
||||
common, finding_breakdown as breakdown_tx, finding_groups as gtx, findings as tx,
|
||||
};
|
||||
use crate::i18n::{requirement_label, use_lang};
|
||||
use crate::i18n::use_lang;
|
||||
use crate::infrastructure::findings::{has_control_refs, location, wire_name};
|
||||
use compliance_core::finding_breakdown::OPEN_STATUS_FILTER;
|
||||
|
||||
@@ -436,9 +436,9 @@ pub fn FindingsPage(
|
||||
if show_controls {
|
||||
td {
|
||||
{
|
||||
// CRA Annex I requirements by name; master
|
||||
// controls (`mc-…`) only as a count, their
|
||||
// detail is on the finding's page.
|
||||
// CRA Annex I refs by name; master controls
|
||||
// (`mc-…`) only as a count, their detail is on
|
||||
// the finding's page.
|
||||
let (cra, other): (Vec<&String>, Vec<&String>) = finding
|
||||
.control_refs
|
||||
.iter()
|
||||
@@ -446,9 +446,7 @@ pub fn FindingsPage(
|
||||
rsx! {
|
||||
div { class: "finding-controls",
|
||||
for c in cra {
|
||||
span { class: "finding-control", title: tx::CONTROLS_HINT.get(lang),
|
||||
{requirement_label(c, lang)}
|
||||
}
|
||||
span { class: "badge badge-info", title: tx::CONTROLS_HINT.get(lang), "{c}" }
|
||||
}
|
||||
if !other.is_empty() {
|
||||
span { class: "finding-controls-more",
|
||||
|
||||
@@ -12,11 +12,10 @@ use compliance_core::scan_changes::ComponentRowKind;
|
||||
use compliance_core::vex_docs::status_of;
|
||||
|
||||
use crate::app::Route;
|
||||
use crate::components::copy_button::CopyButton;
|
||||
use crate::components::severity_badge::SeverityBadge;
|
||||
use crate::components::toast::{ToastType, Toasts};
|
||||
use crate::components::vex_panel::{
|
||||
is_supplier_product, status_class, status_text, supplier_gist, AdvisoryLine,
|
||||
is_supplier_product, status_class, status_text, supplier_gist, SUPPLIER_PROVIDER_PREFIX,
|
||||
};
|
||||
use crate::i18n::texts::{common, cve_matrix, kinds, machine as tx, repo_views as rv};
|
||||
use crate::i18n::{format_ago, format_count, format_time, use_lang, Lang};
|
||||
@@ -478,12 +477,21 @@ fn MachineCveGroup(
|
||||
rsx! {
|
||||
tr { key: "{alert.repo_id}-{alert.cve_id}",
|
||||
td {
|
||||
span { class: "vex-cve-id",
|
||||
code { "{alert.cve_id}" }
|
||||
CopyButton { value: alert.cve_id.clone(), small: true }
|
||||
}
|
||||
code { "{alert.cve_id}" }
|
||||
for adv in alert.advisories.iter() {
|
||||
AdvisoryLine { advisory: adv.clone() }
|
||||
div { class: "vex-advisory-line",
|
||||
a {
|
||||
class: "vex-advisory",
|
||||
href: adv.url.clone().unwrap_or_default(),
|
||||
target: "_blank",
|
||||
rel: "noopener noreferrer",
|
||||
"{adv.id}"
|
||||
}
|
||||
if adv.provider.starts_with(SUPPLIER_PROVIDER_PREFIX) {
|
||||
" "
|
||||
span { class: "vex-advisory-note", {crate::i18n::texts::vex::SUPPLIER_ADVISORY.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
td {
|
||||
|
||||
@@ -5,7 +5,6 @@ pub mod dast_finding_detail;
|
||||
pub mod dast_findings;
|
||||
pub mod dast_overview;
|
||||
pub mod dast_targets;
|
||||
pub mod devices;
|
||||
pub mod finding_detail;
|
||||
pub mod findings;
|
||||
pub mod graph_explorer;
|
||||
@@ -35,7 +34,6 @@ pub use dast_finding_detail::DastFindingDetailPage;
|
||||
pub use dast_findings::DastFindingsPage;
|
||||
pub use dast_overview::DastOverviewPage;
|
||||
pub use dast_targets::DastTargetsPage;
|
||||
pub use devices::TargetDevicesPage;
|
||||
pub use finding_detail::FindingDetailPage;
|
||||
pub use findings::FindingsPage;
|
||||
pub use graph_explorer::GraphExplorerPage;
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::components::no_access::use_can_write;
|
||||
use crate::components::page_header::PageHeader;
|
||||
use crate::components::scan_coverage::ScanCoverage;
|
||||
use crate::components::scan_runs::ScanRunList;
|
||||
use crate::i18n::texts::{common, kinds, metering, onboarding as tx};
|
||||
use crate::i18n::texts::{common, kinds, onboarding as tx};
|
||||
use crate::i18n::{format_bytes, use_lang, Lang};
|
||||
use crate::infrastructure::onboarding::{
|
||||
check_supplier_sbom, create_target, detect_target, enable_target_scans, fetch_applicable_scans,
|
||||
@@ -232,7 +232,7 @@ pub fn OnboardingPage(origin: String) -> Element {
|
||||
if let Some(err) = error() {
|
||||
div { class: "card", style: "border-color: var(--danger, #d33); margin-bottom: 12px;",
|
||||
div { class: "card-header", {tx::ERROR.get(lang)} }
|
||||
div { style: "padding: 12px;", {metering::target_refusal(&err, lang)} }
|
||||
div { style: "padding: 12px;", "{err}" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -993,34 +993,6 @@ fn type_label_of(value: &str, lang: Lang) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_target_the_plan_has_no_room_for_reads_in_words() {
|
||||
let error = "error running server function: target_limit (409) (details: None)";
|
||||
assert_eq!(
|
||||
metering::target_refusal(error, Lang::En),
|
||||
"Your plan includes no further targets. Delete a target to add a new one \
|
||||
(its results are deleted with it), or change your plan."
|
||||
);
|
||||
assert_eq!(metering::target_refusal("x (500)", Lang::De), "x (500)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_demo_target_the_plan_has_no_room_for_reads_in_words() {
|
||||
let error = "error running server function: target_limit (409) (details: None)";
|
||||
assert_eq!(
|
||||
metering::demo_refusal(error, Lang::En),
|
||||
metering::DEMO_LIMIT.get(Lang::En)
|
||||
);
|
||||
assert_eq!(
|
||||
upload_problem(
|
||||
"error running server function: target_limit".into(),
|
||||
Lang::De
|
||||
),
|
||||
metering::DEMO_LIMIT.get(Lang::De)
|
||||
);
|
||||
assert_eq!(metering::demo_refusal("x (500)", Lang::De), "x (500)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_refused_supplier_sbom_upload_reads_in_the_readers_language() {
|
||||
let error = "error running server function: supplier_sbom_refused:empty (details: None)";
|
||||
|
||||
@@ -4,7 +4,6 @@ use dioxus::prelude::*;
|
||||
|
||||
use crate::app::Route;
|
||||
use crate::components::component_overview::ComponentOverview;
|
||||
use crate::components::copy_button::CopyButton;
|
||||
use crate::components::license_editor::{category_class, confirmed_title, LicenseEditor};
|
||||
use crate::components::license_review::{
|
||||
action_class, reasons_text, review_title, LicenseCheckPanel,
|
||||
@@ -546,9 +545,7 @@ pub fn SbomPage(target: String, #[props(default)] ecosystem: String) -> Element
|
||||
for vuln in &entry.known_vulnerabilities {
|
||||
div { class: "sbom-vuln-card",
|
||||
div { class: "sbom-vuln-card-header",
|
||||
// The id to copy, never a link off-site.
|
||||
span { class: "sbom-vuln-id", "{vuln.id}" }
|
||||
CopyButton { value: vuln.id.clone(), small: true }
|
||||
span { class: "sbom-vuln-source", "{vuln.source}" }
|
||||
if let Some(sev) = &vuln.severity {
|
||||
span {
|
||||
@@ -576,6 +573,14 @@ pub fn SbomPage(target: String, #[props(default)] ecosystem: String) -> Element
|
||||
"{tx::SSVC_EXPLOITATION.get(lang)}: {ssvc}"
|
||||
}
|
||||
}
|
||||
if let Some(url) = &vuln.url {
|
||||
a {
|
||||
href: "{url}",
|
||||
target: "_blank",
|
||||
class: "sbom-vuln-link",
|
||||
{tx::VIEW_ADVISORY.get(lang)}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if entry.known_vulnerabilities.iter().any(|v| v.exploitation.as_ref().is_some_and(|e| e.epss.is_some())) {
|
||||
|
||||
@@ -39,7 +39,6 @@ use crate::infrastructure::platform::{use_source_only, SourceOnlyNote};
|
||||
use crate::infrastructure::projects::{
|
||||
fetch_projects, project_ids_of, projects_named, set_target_projects,
|
||||
};
|
||||
use crate::pages::devices::DevicesCard;
|
||||
use crate::pages::target_views::{RepoCrumbs, RepoView, TodayLink};
|
||||
|
||||
/// Open findings listed on the page; the rest are one click away.
|
||||
@@ -318,12 +317,6 @@ pub fn TargetPage(id: String) -> Element {
|
||||
}
|
||||
}
|
||||
}
|
||||
// A control application's Siemens controllers (SPS item 4a).
|
||||
if str_at(&t, "target_type") == "plc_sps"
|
||||
|| t.get("devices").and_then(|d| d.as_array()).is_some_and(|d| !d.is_empty())
|
||||
{
|
||||
DevicesCard { target_id: id.clone() }
|
||||
}
|
||||
if let Some(graph) = graph {
|
||||
section { class: "card target-graph",
|
||||
div { class: "target-card-head",
|
||||
@@ -911,10 +904,7 @@ fn TargetEditor(
|
||||
toasts.push(ToastType::Success, tx::UPDATED.get(lang));
|
||||
on_saved.call(());
|
||||
}
|
||||
Err(e) => toasts.push(
|
||||
ToastType::Error,
|
||||
crate::i18n::texts::metering::demo_refusal(&e.to_string(), lang),
|
||||
),
|
||||
Err(e) => toasts.push(ToastType::Error, e.to_string()),
|
||||
}
|
||||
edit_saving.set(false);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "compliance-dast"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "compliance-graph"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "compliance-mcp"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "compliance-smoke"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
description = "Tiny Axum service exercising compliance-core M7.1 tenant gating. Run smoke.sh against it before merging anything that touches the auth/tenant path."
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "control-map"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -13,8 +13,7 @@ What Prüfwerk keeps about a target, where, and when it is removed.
|
||||
|
||||
Deleting a target (`DELETE /api/v1/targets/{id}`, or **Delete** on the
|
||||
targets page) removes its records and its files. Erasing a tenant
|
||||
(`DELETE /api/v1/platform/tenants/{id}/data` with `{"confirm": "<tenant id>"}`,
|
||||
the same id as in the path) drops its database
|
||||
(`DELETE /api/v1/platform/tenants/{id}/data`, confirmed) drops its database
|
||||
and removes every file listed above; the response says how many paths were
|
||||
removed and how many could not be. Only paths inside the two configured base
|
||||
directories are ever removed.
|
||||
|
||||
+4
-47
@@ -196,53 +196,10 @@ CERT@VDE): the alert links the advisory (e.g. `VDE-2026-094`) and carries the
|
||||
vendor's remediation and the fixed version.
|
||||
|
||||
A CVE alert a later scan no longer finds (the project now references a fixed
|
||||
runtime or library version) is marked resolved, as for code targets; this needs
|
||||
both lookups (OSV and NVD) to have covered every component. The scan does not
|
||||
state VEX `fixed` for it: that is a person's statement. For a PLC project in a
|
||||
managed Git repository, its CVE issue stays open with a note that the CVE is no
|
||||
longer found, and a person closes it.
|
||||
|
||||
## Siemens controllers by order number
|
||||
|
||||
A Siemens CPU is matched by what is printed on it, without a project file. On the
|
||||
target's page, the **Steuerungen** card opens the target's controllers. Each
|
||||
controller is entered with:
|
||||
|
||||
- its **order number** (Artikelnummer, MLFB), such as `6ES7511-1AK02-0AB0`, from
|
||||
the rating plate or from TIA Portal (device configuration, Properties,
|
||||
General, Catalog information);
|
||||
- its **firmware**, such as `V3.1.4`, also shown on the CPU web server's start
|
||||
page;
|
||||
- optionally a name (`Hauptsteuerung Zelle 2`).
|
||||
|
||||
The form recognises the order number while it is typed, by the name Siemens
|
||||
uses for it. A valid number that no advisory names yet is accepted: Prüfwerk
|
||||
checks it against every new advisory.
|
||||
|
||||
Siemens ProductCERT names every affected CPU in its CSAF advisories by order
|
||||
number and firmware range. Prüfwerk reads them daily and shows each controller
|
||||
as a module on a DIN rail, with a light:
|
||||
|
||||
| Light | Meaning |
|
||||
| --- | --- |
|
||||
| red | an advisory affects the installed firmware |
|
||||
| green | advisories name the controller, none affects this firmware |
|
||||
| grey | no advisory names the order number |
|
||||
|
||||
The controller's panel lists the advisories with their severity, the firmware
|
||||
that fixes them (`Behoben ab V3.1.5`, read from Siemens' remediation) and a
|
||||
**Quelle** link to the advisory, which Siemens' terms require. The page shows
|
||||
the current advisories at once. The target's CVE alerts and issues follow at
|
||||
its next scan.
|
||||
|
||||
Not matched yet: advisories that name only a whole series ("S7-1200 CPU
|
||||
family") instead of order numbers.
|
||||
|
||||
The API takes `devices` on `POST /api/v1/targets` and `PATCH
|
||||
/api/v1/targets/{id}` (`order_number`, `firmware`, `label`).
|
||||
`GET /api/v1/targets/{id}/devices` returns each device with the advisories
|
||||
naming it, and `GET /api/v1/devices/lookup?order_number=` what the advisories
|
||||
know of an order number.
|
||||
runtime or library version) is marked resolved, and its VEX status becomes
|
||||
`fixed`, as for code targets; this needs both lookups (OSV and NVD) to have
|
||||
covered every component. For a PLC project in a managed Git repository, the CVE
|
||||
issues in the repository follow, as for code.
|
||||
|
||||
## Dynamic testing — ICS protocol probe
|
||||
|
||||
|
||||
@@ -247,19 +247,14 @@ runs. Scans never fetch; they match the target's components against the index:
|
||||
- a CODESYS runtime or library (from a `.projectarchive`) by its name and
|
||||
version against CODESYS's advisories, including the range forms CERT@VDE's
|
||||
vendors write besides proper `vers` (`4.15.0.0<4.21.0.0`, `<4.17.0.0`);
|
||||
- a Siemens device the target runs on (its `devices`: order number and
|
||||
firmware, entered with the target) against Siemens' advisories, by the
|
||||
product's order number (MLFB, `6ES7511-1AK02-0AB0`) and firmware range
|
||||
(`vers:intdot/<3.1.5`, `vers:all/*`); a device is matched only against
|
||||
Siemens', and is a `device` component in the CycloneDX export;
|
||||
- any component with a purl against an advisory product with the same purl.
|
||||
|
||||
A match raises a CVE alert with source `csaf`, or, where OSV or NVD reported
|
||||
the same CVE, is added to that alert. Either way the alert names the advisory
|
||||
(id, title, link) with the vendor's remediation and the fixed versions, and
|
||||
the component lists the CVE with the advisory's link. A Siemens advisory that
|
||||
names a whole family (`S7-1200 CPU family`) and no order number is not matched
|
||||
to a device yet.
|
||||
the component lists the CVE with the advisory's link. Siemens order numbers
|
||||
(MLFB) are indexed but not matched yet: no component carries one until TIA
|
||||
exports are read.
|
||||
|
||||
`PW_CSAF_PROVIDERS` chooses the providers: unset or `default` (CERT@VDE's
|
||||
vendors and Siemens), `off`, or a comma list of `default`, `siemens`, `cisa`
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "werkbank-exec"
|
||||
version = "0.4.19"
|
||||
version = "0.4.17"
|
||||
edition = "2021"
|
||||
description = "Shared dynamic-execution logic: soft-PLC provisioning + industrial-protocol probing, used by the compliance agent and the Werkbank runner."
|
||||
|
||||
|
||||
Reference in new issue
Block a user