work
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled

This commit is contained in:
StellaOps Bot
2025-11-25 08:01:23 +02:00
parent d92973d6fd
commit 6bee1fdcf5
207 changed files with 12816 additions and 2295 deletions

View File

@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using StellaOps.Concelier.Models;
using StellaOps.Concelier.Storage.Mongo.Documents;
using StellaOps.Concelier.Normalization.SemVer;
namespace StellaOps.Concelier.Connector.CertBund.Internal;
@@ -116,23 +118,9 @@ internal static class CertBundMapper
recordedAt,
new[] { ProvenanceFieldMasks.AffectedPackages });
var ranges = string.IsNullOrWhiteSpace(product.Versions)
? Array.Empty<AffectedVersionRange>()
: new[]
{
new AffectedVersionRange(
rangeKind: "string",
introducedVersion: null,
fixedVersion: null,
lastAffectedVersion: null,
rangeExpression: product.Versions,
provenance: new AdvisoryProvenance(
CertBundConnectorPlugin.SourceName,
"package-range",
product.Versions,
recordedAt,
new[] { ProvenanceFieldMasks.VersionRanges }))
};
var anchor = $"certbund:{dto.AdvisoryId}:{vendor.ToLowerInvariant().Replace(' ', '-')}";
var ranges = BuildVersionRanges(product.Versions, anchor, recordedAt);
var normalized = BuildNormalizedVersions(ranges, anchor);
packages.Add(new AffectedPackage(
AffectedPackageTypes.Vendor,
@@ -141,7 +129,7 @@ internal static class CertBundMapper
versionRanges: ranges,
statuses: Array.Empty<AffectedPackageStatus>(),
provenance: new[] { provenance },
normalizedVersions: Array.Empty<NormalizedVersionRule>()));
normalizedVersions: normalized));
}
return packages
@@ -150,6 +138,87 @@ internal static class CertBundMapper
.ToArray();
}
private static IReadOnlyList<AffectedVersionRange> BuildVersionRanges(string? versions, string anchor, DateTimeOffset recordedAt)
{
if (string.IsNullOrWhiteSpace(versions)
|| string.Equals(versions.Trim(), "alle", StringComparison.OrdinalIgnoreCase))
{
return Array.Empty<AffectedVersionRange>();
}
var tokens = Regex.Matches(versions, @"\d+(?:\.\d+){0,3}(?:[A-Za-z0-9\-_]*)?")
.Select(match => match.Value)
.Where(value => !string.IsNullOrWhiteSpace(value))
.ToList();
if (tokens.Count == 0)
{
return Array.Empty<AffectedVersionRange>();
}
var introduced = tokens.First();
var fixedVersion = tokens.Count > 1 ? tokens.Last() : null;
var vendorExtensions = new Dictionary<string, string>
{
["certbund.version.raw"] = versions!,
["certbund.anchor"] = anchor,
};
var semVer = new SemVerPrimitive(
Introduced: introduced,
IntroducedInclusive: true,
Fixed: fixedVersion,
FixedInclusive: true,
LastAffected: null,
LastAffectedInclusive: true,
ConstraintExpression: null,
ExactValue: tokens.Count == 1 ? introduced : null);
var rangeProvenance = new AdvisoryProvenance(
CertBundConnectorPlugin.SourceName,
"package-range",
anchor,
recordedAt,
new[] { ProvenanceFieldMasks.VersionRanges });
var primitives = new RangePrimitives(semVer, Nevra: null, Evr: null, VendorExtensions: vendorExtensions);
return new[]
{
new AffectedVersionRange(
rangeKind: NormalizedVersionSchemes.SemVer,
introducedVersion: introduced,
fixedVersion: fixedVersion,
lastAffectedVersion: null,
rangeExpression: versions!,
provenance: rangeProvenance,
primitives: primitives),
};
}
private static IReadOnlyList<NormalizedVersionRule> BuildNormalizedVersions(
IReadOnlyList<AffectedVersionRange> ranges,
string anchor)
{
if (ranges.Count == 0)
{
return Array.Empty<NormalizedVersionRule>();
}
var rules = new List<NormalizedVersionRule>(ranges.Count);
foreach (var range in ranges)
{
var rule = range.ToNormalizedVersionRule(anchor);
if (rule is not null)
{
rules.Add(rule);
}
}
return rules.Count == 0 ? Array.Empty<NormalizedVersionRule>() : rules.ToArray();
}
private static string? MapSeverity(string? severity)
{
if (string.IsNullOrWhiteSpace(severity))