Skip to content

Commit

Permalink
Fix issue #30 : rework registry instanciation path and make non=stati…
Browse files Browse the repository at this point in the history
…c variables not static.

Fix incomplete reset bug
  • Loading branch information
aloopkin committed Sep 30, 2020
1 parent 27ba445 commit e19d42a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions MSIPackaging/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.4.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")]
2 changes: 1 addition & 1 deletion MSIPackaging/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static public void Main(string[] args)
}
);
project.GUID = new Guid("bb0a8e11-24a8-4d7e-a7d6-6fc5bd8166d2");
project.Version = Version.Parse("1.4.1");
project.Version = Version.Parse("1.4.2");
project.LicenceFile = path + @"\MSIPackaging\Resources\gpl-3.0.rtf";
project.BannerImage = path + @"\MSIPackaging\Resources\banner.png";
project.BackgroundImage = path + @"\MSIPackaging\Resources\background.png";
Expand Down
4 changes: 2 additions & 2 deletions WinCertes/CertesWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ private void InitCertes()
/// </summary>
/// <param name="serviceUri">The ACME service URI (endin in /directory). If null, defaults to Let's encrypt</param>
/// <param name="accountEmail">The email address to be registered within the ACME account. If null, no email will be used</param>
public CertesWrapper(int extra = -1, string serviceUri = null, string accountEmail = null)
public CertesWrapper(IConfig config, string serviceUri = null, string accountEmail = null)
{
_settings = new CertesSettings();
_config = new RegistryConfig(extra);
_config = config;

// Let's initialize the password
PfxPassword = Guid.NewGuid().ToString("N").Substring(0, 16);
Expand Down
2 changes: 1 addition & 1 deletion WinCertes/Config/IConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Interface to Configuration Engine
/// </summary>
interface IConfig
public interface IConfig
{
/// <summary>
/// Deletes parameter from configuration
Expand Down
11 changes: 8 additions & 3 deletions WinCertes/Config/RegistryConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace WinCertes
/// <summary>
/// Configuration class, managing WinCertes configuration into Windows Registry
/// </summary>
class RegistryConfig : IConfig
public class RegistryConfig : IConfig
{
private static readonly ILogger _logger = LogManager.GetLogger("WinCertes.WinCertesOptions");

private static string _registryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\WinCertes";
private static string _subKey = @"Software\WinCertes";
private string _registryKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\WinCertes";
private string _subKey = @"Software\WinCertes";

/// <summary>
/// Class constructor. if extra = false, builds the base config. if extra = true, builds the extra certificate config.
Expand Down Expand Up @@ -225,6 +225,11 @@ public void DeleteAllParameters()
{
Registry.LocalMachine.OpenSubKey(_subKey, true).DeleteSubKeyTree("extra");
}
for (int i = 2; i < 10; i++)
{
if (Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("WinCertes").OpenSubKey("extra" + i) != null)
Registry.LocalMachine.OpenSubKey(_subKey, true).DeleteSubKeyTree("extra" + i);
}
foreach (string key in Registry.LocalMachine.OpenSubKey(_subKey).GetValueNames())
{
DeleteParameter(key);
Expand Down
6 changes: 3 additions & 3 deletions WinCertes/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,10 @@ private static void RegisterCertificateIntoConfiguration(X509Certificate2 certif
/// </summary>
/// <param name="serviceUri">the ACME service URI</param>
/// <param name="email">the email account used to register</param>
private static void InitCertesWrapper(int extra, string serviceUri, string email)
private static void InitCertesWrapper(IConfig config, string serviceUri, string email)
{
// We get the CertesWrapper object, that will do most of the job.
_certesWrapper = new CertesWrapper(extra, serviceUri, email);
_certesWrapper = new CertesWrapper(config, serviceUri, email);

// If local computer's account isn't registered on the ACME service, we'll do it.
if (!_certesWrapper.IsAccountRegistered())
Expand Down Expand Up @@ -354,7 +354,7 @@ static int Main(string[] args)
// Initialization and renewal/revocation handling
try
{
InitCertesWrapper(_extra, _winCertesOptions.ServiceUri, _winCertesOptions.Email);
InitCertesWrapper(_config, _winCertesOptions.ServiceUri, _winCertesOptions.Email);
}
catch (Exception e) { _logger.Error(e.Message); return ERROR; }
if (_winCertesOptions.Revoke > -1) { RevokeCert(_domains, _winCertesOptions.Revoke); return 0; }
Expand Down
4 changes: 2 additions & 2 deletions WinCertes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.4.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")]

0 comments on commit e19d42a

Please sign in to comment.