Skip to content

Commit

Permalink
Add menu option to export root certificate to the deskop and have cer…
Browse files Browse the repository at this point in the history
…t avaialbe as a CER file and in PEM format
  • Loading branch information
sspiller-atg committed Oct 22, 2024
1 parent 5c7129e commit b7e5136
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions XMAT/Engines/WebServiceProxy/Logic/Proxy/WebServiceProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public void Reset()
_availableRequestId = 0;
}

internal static CertificateManager CertManager { get { return _certManager; } }

internal static WebServiceProxy CreateProxy()
{
if (!_isInitialized)
Expand Down
2 changes: 2 additions & 0 deletions XMAT/Langs/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions XMAT/Logic/AppCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
8 changes: 8 additions & 0 deletions XMAT/Logic/PublicUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion XMAT/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<CommandBinding Command="{x:Static local:AppCommands.AnalyzeCaptures}" Executed="AnalyzeCaptures_Executed" CanExecute="AnalyzeCaptures_CanExecute"/>
<CommandBinding Command="{x:Static local:AppCommands.CollectLogs}" Executed="CollectLogs_Executed"/>
<CommandBinding Command="{x:Static local:AppCommands.ViewGDKXInfo}" Executed="ViewGDKXInfo_Executed"/>
<CommandBinding Command="{x:Static local:AppCommands.ExportRootCert}" Executed="ExportRootCert_Executed"/>
</Window.CommandBindings>
<Grid>
<Grid.RowDefinitions>
Expand Down Expand Up @@ -50,11 +51,13 @@
<MenuItem x:Name="ViewClearCaptures" Command="{x:Static local:AppCommands.ClearAllCaptures}" />
<Separator />
<MenuItem x:Name="EditPreferences" Command="{x:Static local:AppCommands.Preferences}"/>

</MenuItem>
<MenuItem x:Name="AnalysisMenu" HorizontalAlignment="Left" Header="_Analysis">
<MenuItem x:Name="ViewAnalyzeCaptures" Command="{x:Static local:AppCommands.AnalyzeCaptures}" />
</MenuItem>
<MenuItem x:Name="ActionsMenu" HorizontalAlignment="Left" Header="_Actions">
<MenuItem x:Name="ExportRootCert" Header="_Export Root Certificate to Desktop" Command="{x:Static local:AppCommands.ExportRootCert}" />
</MenuItem>
<MenuItem x:Name="HelpMenu" HorizontalAlignment="Left" Header="_Help">
<MenuItem x:Name="CollectLogs" Command="{x:Static local:AppCommands.CollectLogs}" />
<MenuItem x:Name="ViewGDKXInfo" Command="{x:Static local:AppCommands.ViewGDKXInfo}" />
Expand Down
6 changes: 6 additions & 0 deletions XMAT/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit b7e5136

Please sign in to comment.