private static int StartHttpChallengeServer(string[] args) { System.Console.WriteLine("Starting Certify Http Challenge Server"); //syntax: certify httpchallenge keys=CONTROLKEY,CHECKKEY var keys = args[1].Replace("keys=", "").Split(','); var task = Task.Run(async() => { // start an http challenge server var challengeServer = new Core.Management.Challenges.HttpChallengeServer(); var config = SharedUtils.ServiceConfigManager.GetAppServiceConfig(); if (!challengeServer.Start(config.HttpChallengeServerPort, controlKey: keys[0], checkKey: keys[1])) { // failed to start http challenge server return(-1); } // wait for server to stop while (challengeServer.IsRunning()) { await Task.Delay(500); } return(0); }); return(task.Result); }
private static int StartHttpChallengeServer(string[] args) { System.Console.WriteLine("Starting Certify Http Challenge Server"); if (args.Length < 2) { System.Console.WriteLine("Error: control key arguments required e.g. certify httpchallenge keys=CONTROLKEY,CHECKKEY"); return(-1); } //syntax: certify httpchallenge keys=CONTROLKEY,CHECKKEY var keys = args[1].Replace("keys=", "").Split(','); var task = Task.Run(async() => { // start an http challenge server var challengeServer = new Core.Management.Challenges.HttpChallengeServer(); var config = SharedUtils.ServiceConfigManager.GetAppServiceConfig(); if (!challengeServer.Start(config.HttpChallengeServerPort, controlKey: keys[0], checkKey: keys[1])) { // failed to start http challenge server return(-1); } // wait for server to stop var stopwatch = System.Diagnostics.Stopwatch.StartNew(); while (challengeServer.IsRunning() && stopwatch.ElapsedMilliseconds < MAX_CHALLENGE_SERVER_RUNTIME) { await Task.Delay(500); } // if we exceeded the allowed time for challenge server to run, ensure it is closed and quit if (challengeServer.IsRunning()) { challengeServer.Stop(); } return(0); }); return(task.Result); }