diff --git a/MSIPackaging/Properties/AssemblyInfo.cs b/MSIPackaging/Properties/AssemblyInfo.cs
index 2071313..bc664c8 100644
--- a/MSIPackaging/Properties/AssemblyInfo.cs
+++ b/MSIPackaging/Properties/AssemblyInfo.cs
@@ -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.1.3.0")]
-[assembly: AssemblyFileVersion("1.1.3.0")]
+[assembly: AssemblyVersion("1.1.4.0")]
+[assembly: AssemblyFileVersion("1.1.4.0")]
diff --git a/MSIPackaging/Script.cs b/MSIPackaging/Script.cs
index dc38c0c..a6241f4 100644
--- a/MSIPackaging/Script.cs
+++ b/MSIPackaging/Script.cs
@@ -37,7 +37,7 @@ static public void Main(string[] args)
}
);
project.GUID = new Guid("bb0a8e11-24a8-4d7e-a7d6-6fc5bd8166d2");
- project.Version = Version.Parse("1.1.3");
+ project.Version = Version.Parse("1.1.4");
project.LicenceFile = path + @"\MSIPackaging\Resources\gpl-3.0.rtf";
project.BannerImage = path + @"\MSIPackaging\Resources\banner.png";
project.BackgroundImage = path + @"\MSIPackaging\Resources\background.png";
diff --git a/WinCertes/ChallengeValidator/HTTPChallengeValidatorFactory.cs b/WinCertes/ChallengeValidator/HTTPChallengeValidatorFactory.cs
index 1988eaf..1932a00 100644
--- a/WinCertes/ChallengeValidator/HTTPChallengeValidatorFactory.cs
+++ b/WinCertes/ChallengeValidator/HTTPChallengeValidatorFactory.cs
@@ -14,12 +14,12 @@ public class HTTPChallengeValidatorFactory
/// true if we use the built-in webserver, false otherwise
/// the full path to the web server root, when not using built-in
/// the HTTP challenge Validator
- public static IHTTPChallengeValidator GetHTTPChallengeValidator(bool standalone, string webRoot = null)
+ public static IHTTPChallengeValidator GetHTTPChallengeValidator(bool standalone, int httpPort, string webRoot = null)
{
IHTTPChallengeValidator challengeValidator = null;
if (standalone) {
if (!CheckAvailableServerPort(80)) return null;
- challengeValidator = new HTTPChallengeWebServerValidator();
+ challengeValidator = new HTTPChallengeWebServerValidator(httpPort);
} else if (webRoot != null) {
challengeValidator = new HTTPChallengeFileValidator(webRoot);
}
diff --git a/WinCertes/ChallengeValidator/HTTPChallengeWebServerValidator.cs b/WinCertes/ChallengeValidator/HTTPChallengeWebServerValidator.cs
index 29e2500..a83ea65 100644
--- a/WinCertes/ChallengeValidator/HTTPChallengeWebServerValidator.cs
+++ b/WinCertes/ChallengeValidator/HTTPChallengeWebServerValidator.cs
@@ -12,14 +12,15 @@ class HTTPChallengeWebServerValidator : IHTTPChallengeValidator
private Thread _serverThread;
private HttpListener _listener;
private string _tokenContents;
+ private int httpPort;
private void Listen()
{
try {
_listener = new HttpListener();
- _listener.Prefixes.Add("http://*:80/");
+ _listener.Prefixes.Add("http://*:"+this.httpPort+"/");
_listener.Start();
- logger.Debug("Started Listener on port 80");
+ logger.Debug("Started Listener on port "+this.httpPort);
while (true) {
try {
HttpListenerContext context = _listener.GetContext();
@@ -55,8 +56,9 @@ private void Process(HttpListenerContext context)
/// Class constructor. Starts the simple web server on port 80.
/// HTTPChallengeWebServerValidator.Stop() MUST be called after use.
///
- public HTTPChallengeWebServerValidator()
+ public HTTPChallengeWebServerValidator(int httpPort)
{
+ this.httpPort = httpPort;
try {
_serverThread = new Thread(this.Listen) {
IsBackground = true
diff --git a/WinCertes/Config/IConfig.cs b/WinCertes/Config/IConfig.cs
index 6189ce7..9181551 100644
--- a/WinCertes/Config/IConfig.cs
+++ b/WinCertes/Config/IConfig.cs
@@ -19,6 +19,14 @@ interface IConfig
///
int ReadIntParameter(string parameter, int defaultValue = 0);
+ ///
+ /// Tries to read parameter value from configuration. If it does not exist, uses provided value instead, and writes it to configuration
+ ///
+ /// the configuration parameter to manage
+ /// the default value is parameter does not exist in configuration
+ /// the value of the configuration parameter
+ int ReadOrWriteIntParameter(string parameter, int value);
+
///
/// Tries to read parameter value from configuration. If it does not exist, uses provided value instead, and writes it to configuration
///
diff --git a/WinCertes/Config/RegistryConfig.cs b/WinCertes/Config/RegistryConfig.cs
index 90a3a93..a699f9e 100644
--- a/WinCertes/Config/RegistryConfig.cs
+++ b/WinCertes/Config/RegistryConfig.cs
@@ -88,6 +88,22 @@ public int ReadIntParameter(string parameter, int defaultValue = 0)
return (int)Registry.GetValue(_registryKey, parameter, defaultValue);
}
+ ///
+ /// Tries to read parameter value from configuration. If it does not exist, uses provided value instead, and writes it to configuration
+ ///
+ /// the configuration parameter to manage
+ /// the default value is parameter does not exist in configuration
+ /// the value of the configuration parameter
+ public int ReadOrWriteIntParameter(string parameter, int value)
+ {
+ int myValue = ReadIntParameter(parameter, 0);
+ if (myValue == 0)
+ {
+ WriteIntParameter(parameter, value);
+ }
+ return ReadIntParameter(parameter);
+ }
+
///
/// Writes integer parameter into configuration
///
diff --git a/WinCertes/Program.cs b/WinCertes/Program.cs
index 04c6112..a8e22d0 100644
--- a/WinCertes/Program.cs
+++ b/WinCertes/Program.cs
@@ -29,6 +29,7 @@ public WinCertesOptions()
Revoke = -1;
Csp = null;
RenewalDelay = 30;
+ HttpPort = 80;
}
public string ServiceUri { get; set; }
public string Email { get; set; }
@@ -39,6 +40,7 @@ public WinCertesOptions()
public int Revoke { get; set; }
public string Csp { get; set; }
public int RenewalDelay { get; set; }
+ public int HttpPort { get; set; }
///
/// Writes command line parameters into the specified config
@@ -61,6 +63,8 @@ public void WriteOptionsIntoConfiguration(IConfig config)
ScriptFile = config.WriteAndReadStringParameter("scriptFile", ScriptFile);
// Writing renewal delay to conf
config.WriteIntParameter("renewalDays", RenewalDelay);
+ // Writing HTTP listening Port in conf
+ HttpPort = config.ReadOrWriteIntParameter("httpPort", HttpPort);
} catch (Exception e) {
_logger.Error($"Could not Read/Write command line parameters to configuration: {e.Message}");
}
@@ -100,7 +104,8 @@ private static bool HandleOptions(string[] args)
{ "a|standalone", "should WinCertes create its own WebServer for validation. Activates HTTP validation mode. WARNING: it will use port 80", v => _winCertesOptions.Standalone = (v != null) },
{ "r|revoke:", "should WinCertes revoke the certificate identified by its domains (to be used only with -d). {REASON} is an optional integer between 0 and 5.", (int v) => _winCertesOptions.Revoke = v },
{ "k|csp=", "import the certificate into specified csp. By default WinCertes imports in the default CSP.", v => _winCertesOptions.Csp = v },
- { "t|renewal=", "trigger certificate renewal {N} days before expiration", (int v) => _winCertesOptions.RenewalDelay = v }
+ { "t|renewal=", "trigger certificate renewal {N} days before expiration", (int v) => _winCertesOptions.RenewalDelay = v },
+ { "l|listenport=", "listen on port {N} in standalone mode (for use with -a switch, default 80)", (int v) => _winCertesOptions.HttpPort = v }
};
// and the handling of these options
@@ -256,7 +261,7 @@ static void Main(string[] args)
if (!IsThereCertificateAndIsItToBeRenewed(_domains)) { Utils.CreateScheduledTask(taskName, _domains); return; }
// Now the real stuff: we register the order for the domains, and have them validated by the ACME service
- IHTTPChallengeValidator httpChallengeValidator = HTTPChallengeValidatorFactory.GetHTTPChallengeValidator(_winCertesOptions.Standalone, _winCertesOptions.WebRoot);
+ IHTTPChallengeValidator httpChallengeValidator = HTTPChallengeValidatorFactory.GetHTTPChallengeValidator(_winCertesOptions.Standalone, _winCertesOptions.HttpPort, _winCertesOptions.WebRoot);
IDNSChallengeValidator dnsChallengeValidator = DNSChallengeValidatorFactory.GetDNSChallengeValidator(_config);
if ((httpChallengeValidator == null) && (dnsChallengeValidator == null)) { WriteErrorMessageWithUsage(_options, "Specify either an HTTP or a DNS validation method."); return; }
if (!(Task.Run(() => _certesWrapper.RegisterNewOrderAndVerify(_domains, httpChallengeValidator, dnsChallengeValidator)).GetAwaiter().GetResult())) { if (httpChallengeValidator != null) httpChallengeValidator.EndAllChallengeValidations(); return; }
diff --git a/WinCertes/Properties/AssemblyInfo.cs b/WinCertes/Properties/AssemblyInfo.cs
index 6b35f59..a0e85b9 100644
--- a/WinCertes/Properties/AssemblyInfo.cs
+++ b/WinCertes/Properties/AssemblyInfo.cs
@@ -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.1.3.0")]
-[assembly: AssemblyFileVersion("1.1.3.0")]
+[assembly: AssemblyVersion("1.1.4.0")]
+[assembly: AssemblyFileVersion("1.1.4.0")]