From b7e51360e47f36855d414d719d9fbd988f36040d Mon Sep 17 00:00:00 2001 From: Steve Spiller Date: Tue, 22 Oct 2024 10:20:47 -0700 Subject: [PATCH] Add menu option to export root certificate to the deskop and have cert avaialbe as a CER file and in PEM format --- .../WebServiceProxy/Logic/Proxy/CertificateManager.cs | 8 ++++++++ .../WebServiceProxy/Logic/Proxy/WebServiceProxy.cs | 2 ++ XMAT/Langs/en-us.json | 2 ++ XMAT/Logic/AppCommands.cs | 6 ++++-- XMAT/Logic/PublicUtilities.cs | 8 ++++++++ XMAT/Windows/MainWindow.xaml | 5 ++++- XMAT/Windows/MainWindow.xaml.cs | 6 ++++++ 7 files changed, 34 insertions(+), 3 deletions(-) diff --git a/XMAT/Engines/WebServiceProxy/Logic/Proxy/CertificateManager.cs b/XMAT/Engines/WebServiceProxy/Logic/Proxy/CertificateManager.cs index 74d764f..e695445 100644 --- a/XMAT/Engines/WebServiceProxy/Logic/Proxy/CertificateManager.cs +++ b/XMAT/Engines/WebServiceProxy/Logic/Proxy/CertificateManager.cs @@ -17,6 +17,8 @@ internal partial class CertificateManager : IDisposable, ICertificateManager private readonly string CertFileName = "XMATRoot.cer"; private readonly string CertFileNameFiddler = "FiddlerRoot.cer"; + private readonly string CertFileNamePem = "XMATRoot.pem"; + private readonly string CertFileNameFiddlerPem = "FiddlerRoot.pem"; private readonly string CertPassword = string.Empty; private readonly X509Store _rootStore; @@ -219,6 +221,12 @@ public void ExportRootCertificate(string path) // For back compat with our own tools File.WriteAllBytes(Path.Combine(path, CertFileNameFiddler), buff); + + // write it out to the path specified in PEM format + string pem = "-----BEGIN CERTIFICATE-----\n" + Convert.ToBase64String(buff) + "\n-----END CERTIFICATE-----\n"; + File.WriteAllText(Path.Combine(path, CertFileNamePem), pem); + File.WriteAllText(Path.Combine(path, CertFileNameFiddlerPem), pem); + } public void RemoveRootCertificate() diff --git a/XMAT/Engines/WebServiceProxy/Logic/Proxy/WebServiceProxy.cs b/XMAT/Engines/WebServiceProxy/Logic/Proxy/WebServiceProxy.cs index e341922..c76e610 100644 --- a/XMAT/Engines/WebServiceProxy/Logic/Proxy/WebServiceProxy.cs +++ b/XMAT/Engines/WebServiceProxy/Logic/Proxy/WebServiceProxy.cs @@ -76,6 +76,8 @@ public void Reset() _availableRequestId = 0; } + internal static CertificateManager CertManager { get { return _certManager; } } + internal static WebServiceProxy CreateProxy() { if (!_isInitialized) diff --git a/XMAT/Langs/en-us.json b/XMAT/Langs/en-us.json index a5e69f1..80cc4db 100644 --- a/XMAT/Langs/en-us.json +++ b/XMAT/Langs/en-us.json @@ -10,6 +10,8 @@ "VIEW_CLEAR_CAPTURES": "Clear Captures", "EDIT_PREFERENCES": "Preferences", "ANALYSIS_MENU": "Analysis", + "ACTIONS_MENU": "Actions", + "EXPORT_ROOT_CERT": "Export Root Certificate to Desktop", "VIEW_ANALYZE_CAPTURES": "Analyze Captures", "HELP_MENU": "Help", "COLLECT_LOGS": "Collect Logs", diff --git a/XMAT/Logic/AppCommands.cs b/XMAT/Logic/AppCommands.cs index b006ae1..7208c95 100644 --- a/XMAT/Logic/AppCommands.cs +++ b/XMAT/Logic/AppCommands.cs @@ -29,7 +29,9 @@ public static class AppCommands new RoutedUICommand("Collect Debug _Logs", "Collect Debug Logs", typeof(AppCommands)); public static readonly RoutedUICommand ViewGDKXInfo = - new RoutedUICommand("View _GDK Extensions for Xbox details", "View GDK Extensions for Xbox details", typeof(AppCommands)); - + new RoutedUICommand("View _GDK Extensions for Xbox details", "View GDK Extensions for Xbox details", typeof(AppCommands)); + + public static readonly RoutedUICommand ExportRootCert = + new RoutedUICommand("Export Root Certificate", "ExportRootCert", typeof(AppCommands)); } } diff --git a/XMAT/Logic/PublicUtilities.cs b/XMAT/Logic/PublicUtilities.cs index 33c3cea..7b7fbac 100644 --- a/XMAT/Logic/PublicUtilities.cs +++ b/XMAT/Logic/PublicUtilities.cs @@ -53,6 +53,14 @@ public static string StorageDirectoryPath } } + public static string DesktopDirectoryPath + { + get + { + return Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + } + } + public static void RestartAsAdmin() { ProcessStartInfo psi = new ProcessStartInfo() diff --git a/XMAT/Windows/MainWindow.xaml b/XMAT/Windows/MainWindow.xaml index 55f5205..2c84e80 100644 --- a/XMAT/Windows/MainWindow.xaml +++ b/XMAT/Windows/MainWindow.xaml @@ -23,6 +23,7 @@ + @@ -50,11 +51,13 @@ - + + + diff --git a/XMAT/Windows/MainWindow.xaml.cs b/XMAT/Windows/MainWindow.xaml.cs index 95a76b7..bafdae7 100644 --- a/XMAT/Windows/MainWindow.xaml.cs +++ b/XMAT/Windows/MainWindow.xaml.cs @@ -46,6 +46,8 @@ public MainWindow() HelpMenu.Header = Localization.GetLocalizedString("HELP_MENU"); CollectLogs.Header = Localization.GetLocalizedString("COLLECT_LOGS"); ViewGDKXInfo.Header = Localization.GetLocalizedString("GDKX_INFO"); + ActionsMenu.Header = Localization.GetLocalizedString("ACTIONS_MENU"); + ExportRootCert.Header = Localization.GetLocalizedString("EXPORT_ROOT_CERT"); } private void Window_Loaded(object sender, RoutedEventArgs e) @@ -365,5 +367,9 @@ private void Window_Drop(object sender, DragEventArgs e) } } } + private void ExportRootCert_Executed(object sender, ExecutedRoutedEventArgs e) + { + XMAT.WebServiceCapture.Proxy.WebServiceProxy.CertManager.ExportRootCertificate(PublicUtilities.DesktopDirectoryPath); + } } }