162 lines
6.2 KiB
C#
162 lines
6.2 KiB
C#
// SPDX-License-Identifier: BUSL-1.1
|
|
// Sprint: SPRINT_6000_0004_0001 - Scanner Worker Integration
|
|
// Task: T5 - Add Configuration and DI Registration
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using StellaOps.BinaryIndex.Core.Services;
|
|
using StellaOps.BinaryIndex.Persistence.Services;
|
|
using StellaOps.Scanner.Worker.Processing;
|
|
|
|
namespace StellaOps.Scanner.Worker.Extensions;
|
|
|
|
/// <summary>
|
|
/// Extension methods for registering BinaryIndex integration services.
|
|
/// </summary>
|
|
public static class BinaryIndexServiceExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds BinaryIndex integration services to the service collection.
|
|
/// </summary>
|
|
public static IServiceCollection AddBinaryIndexIntegration(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
var options = configuration
|
|
.GetSection("BinaryIndex")
|
|
.Get<BinaryIndexOptions>() ?? new BinaryIndexOptions();
|
|
|
|
if (!options.Enabled)
|
|
{
|
|
services.AddSingleton<IBinaryVulnerabilityService, NullBinaryVulnerabilityService>();
|
|
return services;
|
|
}
|
|
|
|
services.AddSingleton(options);
|
|
services.AddScoped<IBinaryVulnerabilityService, BinaryVulnerabilityService>();
|
|
services.AddScoped<IBinaryFeatureExtractor, ElfFeatureExtractor>();
|
|
services.AddScoped<BinaryVulnerabilityAnalyzer>();
|
|
services.AddScoped<Processing.BinaryFindingMapper>();
|
|
|
|
return services;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Configuration options for BinaryIndex integration.
|
|
/// </summary>
|
|
public sealed class BinaryIndexOptions
|
|
{
|
|
/// <summary>
|
|
/// Whether binary vulnerability analysis is enabled.
|
|
/// </summary>
|
|
public bool Enabled { get; init; } = true;
|
|
|
|
/// <summary>
|
|
/// Batch size for binary lookups.
|
|
/// </summary>
|
|
public int BatchSize { get; init; } = 100;
|
|
|
|
/// <summary>
|
|
/// Timeout in milliseconds for binary lookups.
|
|
/// </summary>
|
|
public int TimeoutMs { get; init; } = 5000;
|
|
|
|
/// <summary>
|
|
/// Minimum confidence threshold for reporting matches.
|
|
/// </summary>
|
|
public decimal MinConfidence { get; init; } = 0.7m;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Null implementation of IBinaryVulnerabilityService for when binary analysis is disabled.
|
|
/// </summary>
|
|
internal sealed class NullBinaryVulnerabilityService : IBinaryVulnerabilityService
|
|
{
|
|
public Task<System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>> LookupByIdentityAsync(
|
|
StellaOps.BinaryIndex.Core.Models.BinaryIdentity identity,
|
|
LookupOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>.Empty);
|
|
}
|
|
|
|
public Task<System.Collections.Immutable.ImmutableDictionary<string, System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>>> LookupBatchAsync(
|
|
IEnumerable<StellaOps.BinaryIndex.Core.Models.BinaryIdentity> identities,
|
|
LookupOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableDictionary<string, System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>>.Empty);
|
|
}
|
|
|
|
public Task<FixStatusResult?> GetFixStatusAsync(
|
|
string distro,
|
|
string release,
|
|
string sourcePkg,
|
|
string cveId,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult<FixStatusResult?>(null);
|
|
}
|
|
|
|
public Task<System.Collections.Immutable.ImmutableDictionary<string, FixStatusResult>> GetFixStatusBatchAsync(
|
|
string distro,
|
|
string release,
|
|
string sourcePkg,
|
|
IEnumerable<string> cveIds,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableDictionary<string, FixStatusResult>.Empty);
|
|
}
|
|
|
|
public Task<System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>> LookupByFingerprintAsync(
|
|
byte[] fingerprint,
|
|
FingerprintLookupOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>.Empty);
|
|
}
|
|
|
|
public Task<System.Collections.Immutable.ImmutableDictionary<string, System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>>> LookupByFingerprintBatchAsync(
|
|
IEnumerable<(string Key, byte[] Fingerprint)> fingerprints,
|
|
FingerprintLookupOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableDictionary<string, System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>>.Empty);
|
|
}
|
|
|
|
public Task<System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>> LookupByDeltaSignatureAsync(
|
|
Stream binaryStream,
|
|
DeltaSigLookupOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>.Empty);
|
|
}
|
|
|
|
public Task<System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>> LookupBySymbolHashAsync(
|
|
string symbolHash,
|
|
string symbolName,
|
|
DeltaSigLookupOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableArray<BinaryVulnMatch>.Empty);
|
|
}
|
|
|
|
public Task<System.Collections.Immutable.ImmutableArray<CorpusFunctionMatch>> IdentifyFunctionFromCorpusAsync(
|
|
FunctionFingerprintSet fingerprints,
|
|
CorpusLookupOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableArray<CorpusFunctionMatch>.Empty);
|
|
}
|
|
|
|
public Task<System.Collections.Immutable.ImmutableDictionary<string, System.Collections.Immutable.ImmutableArray<CorpusFunctionMatch>>> IdentifyFunctionsFromCorpusBatchAsync(
|
|
IEnumerable<(string Key, FunctionFingerprintSet Fingerprints)> functions,
|
|
CorpusLookupOptions? options = null,
|
|
CancellationToken ct = default)
|
|
{
|
|
return Task.FromResult(System.Collections.Immutable.ImmutableDictionary<string, System.Collections.Immutable.ImmutableArray<CorpusFunctionMatch>>.Empty);
|
|
}
|
|
}
|