Skip to content

Commit 2aaec6d

Browse files
committed
Add support for managing Trusted Signing endpoints
Enhanced configurability by introducing support for managing "Trusted Signing" endpoints alongside timestamp servers. Updated UI elements dynamically based on the context (timestamp servers vs. endpoints). Added methods to load and save certificate type configurations, with improved error handling and logging for better user feedback. Refactored `TimestampServerManagementForm` to include an `isTrustedSigning` flag, updating titles, messaging, and reset behavior accordingly. Minor UI adjustments include reordering menu items, resizing menu options, and disabling the timestamp provider ComboBox. Removed unused namespaces and improved code readability and maintainability.
1 parent 5940d93 commit 2aaec6d

3 files changed

Lines changed: 133 additions & 15 deletions

File tree

src/SignToolGUI/Forms/MainForm.Designer.cs

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SignToolGUI/Forms/MainForm.cs

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,20 @@ private void MainForm_Load(object sender, EventArgs e)
878878

879879
toolTip.SetToolTip(checkBoxTimestamp, "Check this box to timestamp the signed file(s).");
880880

881+
// Load type of certificate configuration
882+
try
883+
{
884+
// Load timestamp server configuration FIRST
885+
LoadTimestampConfiguration();
886+
887+
// Load certificate type configuration
888+
LoadCertificateTypeConfiguration();
889+
}
890+
catch (Exception ex)
891+
{
892+
Message($"Error loading timestamp configuration: {ex.Message}", EventType.Error, 3012);
893+
}
894+
881895
// Set the Text property of the form to the application's name and version
882896
try
883897
{
@@ -1246,6 +1260,16 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
12461260
Message($"Error saving timestamp configuration: {ex.Message}", EventType.Error, 3013);
12471261
}
12481262

1263+
// Save certificate type configuration
1264+
try
1265+
{
1266+
SaveCertificateTypeConfiguration();
1267+
}
1268+
catch (Exception ex)
1269+
{
1270+
Message($"Error saving certificate type configuration: {ex.Message}", EventType.Error, 3030);
1271+
}
1272+
12491273
// Log application closed message
12501274
Message("Application " + Application.ProductName + @" v." + Application.ProductVersion + " is closed",
12511275
EventType.Information, 1057);
@@ -2600,20 +2624,89 @@ private void manageTimestampServersToolStripMenuItem_Click(object sender, EventA
26002624
{
26012625
try
26022626
{
2603-
using (var timestampForm = new TimestampServerManagementForm(_timestampManager, ConfigIniPath))
2627+
// Determine if we're currently in Trusted Signing mode
2628+
bool isTrustedSigning = radioButtonTrustedSigning.Checked;
2629+
2630+
using (var timestampForm = new TimestampServerManagementForm(_timestampManager, ConfigIniPath, isTrustedSigning))
26042631
{
26052632
if (timestampForm.ShowDialog(this) == DialogResult.OK)
26062633
{
26072634
// Refresh the ComboBox to reflect any changes
26082635
PopulateComboBox();
2609-
Message("Timestamp server management completed", EventType.Information, 3015);
2636+
Message($"{(isTrustedSigning ? "Endpoint" : "Timestamp server")} management completed", EventType.Information, 3015);
26102637
}
26112638
}
26122639
}
26132640
catch (Exception ex)
26142641
{
2615-
MessageBox.Show($"Error opening timestamp server management: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
2616-
Message($"Error opening timestamp server management: {ex.Message}", EventType.Error, 3016); // Changed 'message' to 'Message'
2642+
MessageBox.Show($"Error opening {(radioButtonTrustedSigning.Checked ? "endpoint" : "timestamp server")} management: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
2643+
Message($"Error opening {(radioButtonTrustedSigning.Checked ? "endpoint" : "timestamp server")} management: {ex.Message}", EventType.Error, 3016);
2644+
}
2645+
}
2646+
2647+
private void SaveCertificateTypeConfiguration()
2648+
{
2649+
try
2650+
{
2651+
var iniFile = new IniFile(ConfigIniPath);
2652+
2653+
// Determine and save the certificate type
2654+
string certificateType = "WindowsCertificateStore"; // Default
2655+
if (radioButtonPFXCertificate.Checked)
2656+
{
2657+
certificateType = "PFXCertificate";
2658+
}
2659+
else if (radioButtonTrustedSigning.Checked)
2660+
{
2661+
certificateType = "TrustedSigning";
2662+
}
2663+
2664+
iniFile.WriteValue("Program", "CertificateType", certificateType);
2665+
Message($"Certificate type configuration saved: {certificateType}", EventType.Information, 3026);
2666+
}
2667+
catch (Exception ex)
2668+
{
2669+
Message($"Error saving certificate type configuration: {ex.Message}", EventType.Error, 3027);
2670+
}
2671+
}
2672+
2673+
private void LoadCertificateTypeConfiguration()
2674+
{
2675+
try
2676+
{
2677+
var iniFile = new IniFile(ConfigIniPath);
2678+
var certificateType = iniFile.GetString("Program", "CertificateType", "WindowsCertificateStore");
2679+
2680+
// Set the appropriate radio button based on saved configuration
2681+
switch (certificateType)
2682+
{
2683+
case "PFXCertificate":
2684+
radioButtonPFXCertificate.Checked = true;
2685+
radioButtonWindowsCertificateStore.Checked = false;
2686+
radioButtonTrustedSigning.Checked = false;
2687+
break;
2688+
case "TrustedSigning":
2689+
radioButtonTrustedSigning.Checked = true;
2690+
radioButtonWindowsCertificateStore.Checked = false;
2691+
radioButtonPFXCertificate.Checked = false;
2692+
break;
2693+
case "WindowsCertificateStore":
2694+
default:
2695+
radioButtonWindowsCertificateStore.Checked = true;
2696+
radioButtonPFXCertificate.Checked = false;
2697+
radioButtonTrustedSigning.Checked = false;
2698+
break;
2699+
}
2700+
2701+
Message($"Certificate type configuration loaded: {certificateType}", EventType.Information, 3028);
2702+
}
2703+
catch (Exception ex)
2704+
{
2705+
Message($"Error loading certificate type configuration: {ex.Message}", EventType.Error, 3029);
2706+
// Default to Windows Certificate Store if loading fails
2707+
radioButtonWindowsCertificateStore.Checked = true;
2708+
radioButtonPFXCertificate.Checked = false;
2709+
radioButtonTrustedSigning.Checked = false;
26172710
}
26182711
}
26192712
}

src/SignToolGUI/Forms/TimestampServerManagementForm.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Drawing;
44
using System.Linq;
5-
using System.Threading.Tasks;
65
using System.Windows.Forms;
76
using SignToolGUI.Class;
87
using static SignToolGUI.Class.FileLogger;
@@ -15,16 +14,33 @@ public partial class TimestampServerManagementForm : Form
1514
private List<TimestampServer> _currentServers;
1615
private bool _isModified = false;
1716
private string _configIniPath;
17+
private bool _isTrustedSigning;
1818

19-
public TimestampServerManagementForm(TimestampManager timestampManager, string configIniPath)
19+
public TimestampServerManagementForm(TimestampManager timestampManager, string configIniPath, bool isTrustedSigning = false)
2020
{
2121
_timestampManager = timestampManager;
2222
_configIniPath = configIniPath; // Store the config path
23+
_isTrustedSigning = isTrustedSigning;
2324
_currentServers = new List<TimestampServer>();
2425
InitializeComponent();
26+
UpdateGroupBoxTitle();
2527
LoadServers();
2628
}
2729

30+
private void UpdateGroupBoxTitle()
31+
{
32+
if (_isTrustedSigning)
33+
{
34+
groupBoxServers.Text = "Endpoints";
35+
this.Text = "Trusted Signing Endpoint Management";
36+
}
37+
else
38+
{
39+
groupBoxServers.Text = "Timestamp Servers";
40+
this.Text = "Timestamp Server Management";
41+
}
42+
}
43+
2844
private void LoadServers()
2945
{
3046
_currentServers = _timestampManager.GetServers().ToList();
@@ -229,7 +245,7 @@ private async void ButtonTestAll_Click(object sender, EventArgs e)
229245
private void ButtonReset_Click(object sender, EventArgs e)
230246
{
231247
var result = MessageBox.Show(
232-
"This will reset all timestamp servers to default settings. Continue?",
248+
$"This will reset all {(_isTrustedSigning ? "endpoints" : "timestamp servers")} to default settings. Continue?",
233249
"Reset to Defaults",
234250
MessageBoxButtons.YesNo,
235251
MessageBoxIcon.Question);
@@ -238,6 +254,14 @@ private void ButtonReset_Click(object sender, EventArgs e)
238254
{
239255
// Create a temporary manager to get default servers
240256
var tempManager = new TimestampManager();
257+
if (_isTrustedSigning)
258+
{
259+
tempManager.InitializeTrustedSigningServers();
260+
}
261+
else
262+
{
263+
tempManager.SetDefaultServers();
264+
}
241265
_currentServers = tempManager.GetServers().ToList();
242266
RefreshServerList();
243267
_isModified = true;
@@ -269,15 +293,15 @@ private void ApplyChanges()
269293

270294
_isModified = false;
271295
UpdateButtonStates(); // This will disable the Apply button
272-
Message("Timestamp server configuration applied and saved", EventType.Information, 3014);
296+
Message($"{(_isTrustedSigning ? "Endpoint" : "Timestamp server")} configuration applied and saved", EventType.Information, 3014);
273297

274298
MessageBox.Show("Changes have been applied and saved successfully.", "Configuration Applied",
275299
MessageBoxButtons.OK, MessageBoxIcon.Information);
276300
}
277301
catch (Exception ex)
278302
{
279303
MessageBox.Show($"Error applying changes: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
280-
Message($"Error applying timestamp server changes: {ex.Message}", EventType.Error, 3017);
304+
Message($"Error applying {(_isTrustedSigning ? "endpoint" : "timestamp server")} changes: {ex.Message}", EventType.Error, 3017);
281305
}
282306
}
283307

@@ -292,11 +316,11 @@ private void SaveTimestampConfigurationToFile()
292316
var jsonString = System.Text.Json.JsonSerializer.Serialize(timestampConfig);
293317
iniFile.WriteValue("Timestamp", "ServerConfiguration", jsonString);
294318

295-
Message("Timestamp server configuration saved to file", EventType.Information, 3018);
319+
Message($"{(_isTrustedSigning ? "Endpoint" : "Timestamp server")} configuration saved to file", EventType.Information, 3018);
296320
}
297321
catch (Exception ex)
298322
{
299-
Message($"Error saving timestamp configuration to file: {ex.Message}", EventType.Error, 3019);
323+
Message($"Error saving {(_isTrustedSigning ? "endpoint" : "timestamp")} configuration to file: {ex.Message}", EventType.Error, 3019);
300324
throw; // Re-throw to let the calling method handle it
301325
}
302326
}

0 commit comments

Comments
 (0)