From 70c918e5d4e099e1acab875b67e75da57ad8e501 Mon Sep 17 00:00:00 2001 From: 5B96790E3664F40075A67E6ADF737EDB15B4408DBC91A81228B31537B0CE3E26 <33426478+iadgovuser29@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:33:57 -0500 Subject: [PATCH] Add Component Class Registries to the Provisioner (#892) * Adds PCIe and Storage Component Class capability to the provisioner * Add SMBIOS Component Class to the provisioner --- .../hirs/Directory.Build.targets | 5 +++- .../hirs/HIRS_Provisioner.NET.csproj | 22 ++++++++++------- HIRS_Provisioner.NET/hirs/appsettings.json | 2 +- .../hirs/src/config/Settings.cs | 24 +++++++++---------- .../hirs/src/provisioner/Provisioner.cs | 1 + .../hirs/src/tpm/CommandTpm.cs | 4 ++-- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/HIRS_Provisioner.NET/hirs/Directory.Build.targets b/HIRS_Provisioner.NET/hirs/Directory.Build.targets index 71c6d238c..c3cf55e97 100644 --- a/HIRS_Provisioner.NET/hirs/Directory.Build.targets +++ b/HIRS_Provisioner.NET/hirs/Directory.Build.targets @@ -35,9 +35,12 @@ + + + diff --git a/HIRS_Provisioner.NET/hirs/HIRS_Provisioner.NET.csproj b/HIRS_Provisioner.NET/hirs/HIRS_Provisioner.NET.csproj index 6e5f5e9d1..d5b46767d 100644 --- a/HIRS_Provisioner.NET/hirs/HIRS_Provisioner.NET.csproj +++ b/HIRS_Provisioner.NET/hirs/HIRS_Provisioner.NET.csproj @@ -6,9 +6,10 @@ linux-x64;win-x64 hirs.Program true + true enable enable - 3.0.1 + 3.0.5 @@ -24,26 +25,29 @@ - - + + all - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + all @@ -81,7 +85,7 @@ - + diff --git a/HIRS_Provisioner.NET/hirs/appsettings.json b/HIRS_Provisioner.NET/hirs/appsettings.json index bbc2324e3..32ebdeff1 100644 --- a/HIRS_Provisioner.NET/hirs/appsettings.json +++ b/HIRS_Provisioner.NET/hirs/appsettings.json @@ -5,7 +5,7 @@ "certificate_output_directory": "", "paccor_output_file": "", "event_log_file": "", - "hardware_manifest_collectors": "paccor_scripts", + "hardware_manifest_collectors": "paccor_scripts,paccor.pcie,paccor.smbios,paccor.storage", "Serilog": { "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ], diff --git a/HIRS_Provisioner.NET/hirs/src/config/Settings.cs b/HIRS_Provisioner.NET/hirs/src/config/Settings.cs index 637692b0a..17bba4272 100644 --- a/HIRS_Provisioner.NET/hirs/src/config/Settings.cs +++ b/HIRS_Provisioner.NET/hirs/src/config/Settings.cs @@ -77,7 +77,7 @@ public virtual string linux_product_serial { public virtual string certificate_output_directory { get; private set; } - private List hardwareManifests = new(); + private List hardwareManifests = new(); private Dictionary hardware_manifest_collectors_with_args = new(); private bool hardware_manifest_collection_swid_enforced = false; @@ -163,7 +163,7 @@ private void ConfigureHardwareManifestManagement() { List names = hardware_manifest_collectors_with_args.Keys.ToList(); if (!string.IsNullOrWhiteSpace(configFromSettingsFile[Options.hardware_manifest_collection_swid_enforced.ToString()])) { string hardware_manifest_collection_swid_enforced_str = $"{ configFromSettingsFile[Options.hardware_manifest_collection_swid_enforced.ToString()] }"; - hardware_manifest_collection_swid_enforced = Boolean.Parse(hardware_manifest_collection_swid_enforced_str); + hardware_manifest_collection_swid_enforced = bool.Parse(hardware_manifest_collection_swid_enforced_str); Log.Debug("SWID enforcement of Hardware Manifest Plugins are " + (hardware_manifest_collection_swid_enforced ? "en" : "dis") + "abled in settings."); } hardwareManifests = HardwareManifestPluginManagerUtils.LoadPlugins(names, hardware_manifest_collection_swid_enforced); @@ -196,23 +196,21 @@ private void CleanHardwareManifestCollectors() { public virtual string RunHardwareManifestCollectors() { Log.Debug("Gathering data from loaded hardware manifest collectors."); - string manifestJson = ""; - foreach (IHardwareManifest manifest in hardwareManifests) { + HardwareManifestProto.ManifestV2 manifestJson = new(); + foreach (IHardwareManifestPlugin manifest in hardwareManifests) { try { Log.Debug(" Configuring " + manifest.Name); - if (hardware_manifest_collectors_with_args.ContainsKey(manifest.Name)) { - manifest.Configure(CLI.SplitArgs(hardware_manifest_collectors_with_args[manifest.Name])); - } - // TODO: Combine JSON Better - // OR Return proto objects Log.Debug(" Gathering from " + manifest.Name); - manifestJson = string.Join(manifestJson, manifest.GatherHardwareManifestAsJsonString()); + if (manifest.GatherHardwareIdentifiers()) { + manifestJson.MergeFrom(manifest.ManifestV2); + } } catch (Exception e) { Log.Debug($"Problem retrieving hardware manifest from {manifest.Name}.", e.InnerException); } } - //TODO: Verify JSON? - return manifestJson; + + string manifestString = manifestJson.ToString(); + return manifestString; } #endregion @@ -262,7 +260,7 @@ private void CheckAutoDetectTpm() { Log.Debug("Checking Auto Detect TPM setting."); string auto_detect_tpm_str = $"{ configFromSettingsFile[Options.auto_detect_tpm.ToString()] }"; try { - auto_detect_tpm = Boolean.Parse(auto_detect_tpm_str); + auto_detect_tpm = bool.Parse(auto_detect_tpm_str); Log.Debug(" Auto Detect TPM is " + (auto_detect_tpm ? "en" : "dis") + "abled."); } catch (FormatException) { auto_detect_tpm = false; diff --git a/HIRS_Provisioner.NET/hirs/src/provisioner/Provisioner.cs b/HIRS_Provisioner.NET/hirs/src/provisioner/Provisioner.cs index 1aba17d85..3ee7451de 100644 --- a/HIRS_Provisioner.NET/hirs/src/provisioner/Provisioner.cs +++ b/HIRS_Provisioner.NET/hirs/src/provisioner/Provisioner.cs @@ -3,6 +3,7 @@ using Serilog; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; diff --git a/HIRS_Provisioner.NET/hirs/src/tpm/CommandTpm.cs b/HIRS_Provisioner.NET/hirs/src/tpm/CommandTpm.cs index b8d5679cd..5f7a73fec 100644 --- a/HIRS_Provisioner.NET/hirs/src/tpm/CommandTpm.cs +++ b/HIRS_Provisioner.NET/hirs/src/tpm/CommandTpm.cs @@ -30,14 +30,14 @@ public enum Devices { private readonly Tpm2 tpm; - private readonly Boolean simulator; + private readonly bool simulator; private List sessionTracking = new List(); /** * For TCP TpmDevices */ - public CommandTpm(Boolean sim, string ip, int port) { + public CommandTpm(bool sim, string ip, int port) { simulator = sim; Tpm2Device tpmDevice = new TcpTpmDevice(ip, port); tpm = TpmSetupByType(tpmDevice);