Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Created CycloneDX and SPDX SBOM files for both reachable and unreachable images. - Added symbols.json detailing function entry and sink points in the WordPress code. - Included runtime traces for function calls in both reachable and unreachable scenarios. - Developed OpenVEX files indicating vulnerability status and justification for both cases. - Updated README for evaluator harness to guide integration with scanner output.
102 lines
3.0 KiB
C#
102 lines
3.0 KiB
C#
using System;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.Extensions.Options;
|
|
using StellaOps.Cryptography;
|
|
using StellaOps.Cryptography.DependencyInjection;
|
|
using StellaOps.Cryptography.Plugin.CryptoPro;
|
|
using StellaOps.Cryptography.Plugin.Pkcs11Gost;
|
|
|
|
namespace StellaOps.Configuration;
|
|
|
|
public static class StellaOpsCryptoServiceCollectionExtensions
|
|
{
|
|
public static IServiceCollection AddStellaOpsCrypto(
|
|
this IServiceCollection services,
|
|
StellaOpsCryptoOptions? options)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
|
|
var resolved = options ?? new StellaOpsCryptoOptions();
|
|
|
|
services.AddStellaOpsCrypto(registryOptions =>
|
|
{
|
|
ApplyRegistry(registryOptions, resolved.Registry);
|
|
});
|
|
|
|
services.AddPkcs11GostProvider();
|
|
services.Configure<Pkcs11GostProviderOptions>(target =>
|
|
{
|
|
CopyPkcs11Options(target, resolved.Pkcs11);
|
|
});
|
|
|
|
services.AddCryptoProGostProvider();
|
|
services.Configure<CryptoProGostProviderOptions>(target =>
|
|
{
|
|
CopyCryptoProOptions(target, resolved.CryptoPro);
|
|
});
|
|
|
|
services.Configure<CryptoHashOptions>(hash =>
|
|
{
|
|
hash.DefaultAlgorithm = string.IsNullOrWhiteSpace(resolved.DefaultHashAlgorithm)
|
|
? HashAlgorithms.Sha256
|
|
: resolved.DefaultHashAlgorithm.Trim();
|
|
});
|
|
|
|
return services;
|
|
}
|
|
|
|
private static void ApplyRegistry(
|
|
CryptoProviderRegistryOptions target,
|
|
CryptoProviderRegistryOptions source)
|
|
{
|
|
target.ActiveProfile = source.ActiveProfile;
|
|
target.PreferredProviders.Clear();
|
|
foreach (var provider in source.PreferredProviders)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(provider))
|
|
{
|
|
target.PreferredProviders.Add(provider.Trim());
|
|
}
|
|
}
|
|
|
|
target.Profiles.Clear();
|
|
foreach (var kvp in source.Profiles)
|
|
{
|
|
if (kvp.Value is null)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var profile = new CryptoProviderProfileOptions();
|
|
foreach (var provider in kvp.Value.PreferredProviders)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(provider))
|
|
{
|
|
profile.PreferredProviders.Add(provider.Trim());
|
|
}
|
|
}
|
|
|
|
target.Profiles[kvp.Key] = profile;
|
|
}
|
|
}
|
|
|
|
private static void CopyPkcs11Options(Pkcs11GostProviderOptions target, Pkcs11GostProviderOptions source)
|
|
{
|
|
target.Keys.Clear();
|
|
foreach (var key in source.Keys)
|
|
{
|
|
target.Keys.Add(key.Clone());
|
|
}
|
|
}
|
|
|
|
private static void CopyCryptoProOptions(CryptoProGostProviderOptions target, CryptoProGostProviderOptions source)
|
|
{
|
|
target.Keys.Clear();
|
|
foreach (var key in source.Keys)
|
|
{
|
|
target.Keys.Add(key.Clone());
|
|
}
|
|
}
|
|
}
|