From 28a8eb8f985d3c92b3b8a11ec5f8525caeb587ab Mon Sep 17 00:00:00 2001 From: jarno9981 <53493418+jarno9981@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:25:51 +0200 Subject: [PATCH 1/2] Code Improvements & Aligments And Added Pcr Values Api --- TrustedPlatform/MainWindow.xaml | 2 +- TrustedPlatform/Models/TpmManager.cs | 109 ++++++++++------ .../Rebound - Backup.TrustedPlatform.csproj | 117 ++++++++++++++++++ .../Rebound.TrustedPlatform.csproj | 8 +- TrustedPlatform/Views/MainPage.xaml | 3 +- TrustedPlatform/Views/MainPage.xaml.cs | 72 +++++------ 6 files changed, 231 insertions(+), 80 deletions(-) create mode 100644 TrustedPlatform/Rebound - Backup.TrustedPlatform.csproj diff --git a/TrustedPlatform/MainWindow.xaml b/TrustedPlatform/MainWindow.xaml index 79c9fa3..fb672e7 100644 --- a/TrustedPlatform/MainWindow.xaml +++ b/TrustedPlatform/MainWindow.xaml @@ -283,7 +283,7 @@ FontWeight="Normal" Foreground="{Binding Foreground, ElementName=WindowTitle}" Opacity="0.5" - Text=" v0.0.3" + Text=" v0.0.4" TextTrimming="CharacterEllipsis" /> GetTpmInfo() + private void GetTpmInfo() { try { @@ -101,24 +109,14 @@ public List GetTpmInfo() { foreach (ManagementObject queryObj in searcher.Get()) { - return new List - { - queryObj["ManufacturerID"] != null ? ConvertManufacturerIdToName((uint)queryObj["ManufacturerID"]) : "Unknown", - queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown", - queryObj["SpecVersion"]?.ToString() ?? "Unknown", - queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown", - queryObj["SpecVersion"]?.ToString() ?? "Unknown", - GetPcrValues(), - queryObj["IsActivated_InitialValue"] != null && (bool)queryObj["IsActivated_InitialValue"] ? "Ready" : "Not Ready" - }; - /*ManufacturerName = queryObj["ManufacturerID"] != null ? ConvertManufacturerIdToName((uint)queryObj["ManufacturerID"]) : "Unknown"; + ManufacturerName = queryObj["ManufacturerID"] != null ? ConvertManufacturerIdToName((uint)queryObj["ManufacturerID"]) : "Unknown"; ManufacturerVersion = queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown"; SpecificationVersion = queryObj["SpecVersion"]?.ToString() ?? "Unknown"; TpmSubVersion = queryObj["ManufacturerVersion"]?.ToString() ?? "Unknown"; PcClientSpecVersion = queryObj["SpecVersion"]?.ToString() ?? "Unknown"; PcrValues = GetPcrValues(); - Status = queryObj["IsActivated_InitialValue"] != null && (bool)queryObj["IsActivated_InitialValue"] ? "Ready" : "Not Ready";*/ + Status = queryObj["IsActivated_InitialValue"] != null && (bool)queryObj["IsActivated_InitialValue"] ? "Ready" : "Not Ready"; } } } @@ -133,21 +131,9 @@ public List GetTpmInfo() Status = "Error communicating with TPM"; Console.WriteLine($"An error occurred while getting TPM information: {ex.Message}"); } - - return new List() - { - ManufacturerName, - ManufacturerVersion, - SpecificationVersion, - TpmSubVersion, - PcClientSpecVersion, - PcrValues, - - Status, - }; } - private string ConvertManufacturerIdToName(uint manufacturerId) + public string ConvertManufacturerIdToName(uint manufacturerId) { var manufacturerStr = string.Empty; manufacturerStr += (char)((manufacturerId >> 24) & 0xFF); @@ -157,11 +143,54 @@ private string ConvertManufacturerIdToName(uint manufacturerId) return manufacturerStr; } - private string GetPcrValues() + public Tpm2Device tpmDevice; + public Tpm2 tpm; + public string GetPcrValues() { - // Placeholder for PCR retrieval logic. This should query TPM for PCR values. - // Requires advanced access via TBS API or TPM library. - return "PCR values are not directly accessible via WMI. Requires advanced TPM API."; + try + { + // Specify PCR selection for reading (e.g., PCR 0, 1, 2) + PcrSelection[] pcrSelectionIn = { new PcrSelection(TpmAlgId.Sha256, new uint[] { 0, 1, 2 }) }; + PcrSelection[] pcrSelectionOut; + Tpm2bDigest[] pcrValues; + + // Read PCR values + tpm.PcrRead(pcrSelectionIn, out pcrSelectionOut, out pcrValues); + + // Build a string to display PCR values + StringBuilder pcrStringBuilder = new StringBuilder(); + + // Check if pcrValues has entries + if (pcrValues.Length == 0) + { + return "No PCR values available."; + } + + for (int i = 0; i < pcrSelectionOut.Length; i++) + { + pcrStringBuilder.AppendLine($"PCR {i}: {BitConverter.ToString(pcrValues[i].buffer)}"); + } + + return pcrStringBuilder.ToString(); + } + catch (TpmException tpmEx) + { + // Log specific TPM-related errors + Debug.WriteLine($"TPM Error retrieving PCR values: {tpmEx.Message} (Error Code:)"); + return $"TPM Error: {tpmEx.Message} (Error Code:)"; + } + catch (Exception ex) + { + // Log general errors with stack trace + Debug.WriteLine($"General Error retrieving PCR values: {ex.Message}\n{ex.StackTrace}"); + return $"Error retrieving PCR values: {ex.Message}"; + } + finally + { + // Ensure resources are cleaned up + tpm?.Dispose(); + tpmDevice?.Dispose(); + } } protected virtual void OnPropertyChanged(string propertyName) diff --git a/TrustedPlatform/Rebound - Backup.TrustedPlatform.csproj b/TrustedPlatform/Rebound - Backup.TrustedPlatform.csproj new file mode 100644 index 0000000..3fb43c4 --- /dev/null +++ b/TrustedPlatform/Rebound - Backup.TrustedPlatform.csproj @@ -0,0 +1,117 @@ + + + WinExe + net8.0-windows10.0.22621.0 + 10.0.17763.0 + 10.0.22621.35-preview + Rebound.TrustedPlatform + app.manifest + x64;x86 + win-x86;win-x64 + win10-x86;win10-x64 + win-$(Platform).pubxml + true + true + 0.0.3 + true + Latest + Assets\icon.ico + false + true + MSIX + False + True + SHA256 + False + False + True + Never + 0 + Rebound.TrustedPlatform_TemporaryKey.pfx + + + + + Always + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MSBuild:Compile + + + + + + true + + + + + True + \ + + + + + + + + + + + True + Riverside, ErrorTek,TheDevil, Lamparter + https://ivirius.vercel.app + TPM Management + Riverside.Rebound.TrustedPlatform + Copyright (c) 2024-present Ivirius Community + Windows 11 done right. + Rebound11Icon.png + true + snupkg + MIT + README.md + Rebound TPM Management + + diff --git a/TrustedPlatform/Rebound.TrustedPlatform.csproj b/TrustedPlatform/Rebound.TrustedPlatform.csproj index be585d0..c2eeb8e 100644 --- a/TrustedPlatform/Rebound.TrustedPlatform.csproj +++ b/TrustedPlatform/Rebound.TrustedPlatform.csproj @@ -12,7 +12,7 @@ win-$(Platform).pubxml true true - 0.0.3 + 0.0.4 true Latest Assets\icon.ico @@ -98,10 +98,14 @@ + + + 10.0.22621.38 + True - Riverside, ErrorTek, Lamparter + Riverside, ErrorTek,TheDevil, Lamparter https://ivirius.vercel.app TPM Management Riverside.Rebound.TrustedPlatform diff --git a/TrustedPlatform/Views/MainPage.xaml b/TrustedPlatform/Views/MainPage.xaml index 82783ed..4d579bc 100644 --- a/TrustedPlatform/Views/MainPage.xaml +++ b/TrustedPlatform/Views/MainPage.xaml @@ -167,9 +167,10 @@ Date: Mon, 14 Oct 2024 14:30:52 +0000 Subject: [PATCH 2/2] Bump WinUIEx and Microsoft.WindowsAppSDK Bumps [WinUIEx](https://github.com/dotMorten/WinUIEx) and [Microsoft.WindowsAppSDK](https://github.com/microsoft/windowsappsdk). These dependencies needed to be updated together. Updates `WinUIEx` from 2.3.4 to 2.4.2 - [Release notes](https://github.com/dotMorten/WinUIEx/releases) - [Commits](https://github.com/dotMorten/WinUIEx/compare/v2.3.4...v2.4.2) Updates `Microsoft.WindowsAppSDK` from 1.6.240701003-experimental2 to 1.6.240829007 - [Release notes](https://github.com/microsoft/windowsappsdk/releases) - [Commits](https://github.com/microsoft/windowsappsdk/commits) --- updated-dependencies: - dependency-name: WinUIEx dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: Microsoft.WindowsAppSDK dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- About/Rebound.About.csproj | 4 ++-- Cleanup/Rebound.Cleanup.csproj | 4 ++-- Defrag/Rebound.Defrag.csproj | 4 ++-- .../Rebound.ExplorerPhotoPrintingDialog.csproj | 4 ++-- Helpers/Rebound.Helpers.csproj | 4 ++-- Rebound/Rebound.csproj | 4 ++-- Run/Rebound.Run.csproj | 4 ++-- SysInfo/Rebound.SysInfo.csproj | 4 ++-- TrustedPlatform/Rebound.TrustedPlatform.csproj | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/About/Rebound.About.csproj b/About/Rebound.About.csproj index 10cdcd2..2a0d647 100644 --- a/About/Rebound.About.csproj +++ b/About/Rebound.About.csproj @@ -63,9 +63,9 @@ - + - + diff --git a/Cleanup/Rebound.Cleanup.csproj b/Cleanup/Rebound.Cleanup.csproj index 311852e..33a04f7 100644 --- a/Cleanup/Rebound.Cleanup.csproj +++ b/Cleanup/Rebound.Cleanup.csproj @@ -51,8 +51,8 @@ - - + + diff --git a/Defrag/Rebound.Defrag.csproj b/Defrag/Rebound.Defrag.csproj index 12af031..7e9443c 100644 --- a/Defrag/Rebound.Defrag.csproj +++ b/Defrag/Rebound.Defrag.csproj @@ -58,12 +58,12 @@ - + - + diff --git a/ExplorerPhotoPrintingDialog/Rebound.ExplorerPhotoPrintingDialog.csproj b/ExplorerPhotoPrintingDialog/Rebound.ExplorerPhotoPrintingDialog.csproj index d2d5cf1..ddf5e40 100644 --- a/ExplorerPhotoPrintingDialog/Rebound.ExplorerPhotoPrintingDialog.csproj +++ b/ExplorerPhotoPrintingDialog/Rebound.ExplorerPhotoPrintingDialog.csproj @@ -27,9 +27,9 @@ - + - + diff --git a/Helpers/Rebound.Helpers.csproj b/Helpers/Rebound.Helpers.csproj index 79a45f6..0ffdd8d 100644 --- a/Helpers/Rebound.Helpers.csproj +++ b/Helpers/Rebound.Helpers.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/Rebound/Rebound.csproj b/Rebound/Rebound.csproj index 32f2dee..41ee06b 100644 --- a/Rebound/Rebound.csproj +++ b/Rebound/Rebound.csproj @@ -92,10 +92,10 @@ - + - + diff --git a/Run/Rebound.Run.csproj b/Run/Rebound.Run.csproj index b9e2aa4..6aa4939 100644 --- a/Run/Rebound.Run.csproj +++ b/Run/Rebound.Run.csproj @@ -55,10 +55,10 @@ - + - + diff --git a/SysInfo/Rebound.SysInfo.csproj b/SysInfo/Rebound.SysInfo.csproj index c453135..151f5f3 100644 --- a/SysInfo/Rebound.SysInfo.csproj +++ b/SysInfo/Rebound.SysInfo.csproj @@ -41,7 +41,7 @@ - + @@ -52,7 +52,7 @@ - +