diff --git a/setup/Program.cs b/setup/Program.cs index f4a7943..55a85e3 100644 --- a/setup/Program.cs +++ b/setup/Program.cs @@ -49,9 +49,19 @@ namespace setup string result = ""; string arch = is64 ? "amd64" : "386"; string url = "https://server-0.sercretcore.cn/api/download?arch=" + arch + "&platform=windows"; - HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); - HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); - Stream stream = resp.GetResponseStream(); + Stream stream; + try + { + HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); + HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); + stream = resp.GetResponseStream(); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + return ""; + } + try { //获取内容 @@ -247,7 +257,7 @@ namespace setup } } - catch (Exception ex) // 异常处理 + catch (Exception) // 异常处理 { // Console.WriteLine(ex.Message.ToString());// 异常信息 } @@ -257,6 +267,51 @@ namespace setup { if (IsAdministrator()) { + int systemVersion = Environment.OSVersion.Version.Major; + if (systemVersion < 6) + { + // ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; + // ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; + // print initial status + Console.WriteLine("Runtime: " + System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(int).Assembly.Location).ProductVersion); + Console.WriteLine("Enabled protocols: " + ServicePointManager.SecurityProtocol); + Console.WriteLine("Available protocols: "); + Boolean platformSupportsTls12 = false; + foreach (SecurityProtocolType protocol in Enum.GetValues(typeof(SecurityProtocolType))) + { + Console.WriteLine(protocol.GetHashCode()); + if (protocol.GetHashCode() == 3072) + { + platformSupportsTls12 = true; + } + } + Console.WriteLine("Is Tls12 enabled: " + ServicePointManager.SecurityProtocol.HasFlag((SecurityProtocolType)3072)); + + + // enable Tls12, if possible + if (!ServicePointManager.SecurityProtocol.HasFlag((SecurityProtocolType)3072)) + { + if (platformSupportsTls12) + { + Console.WriteLine("Platform supports Tls12, but it is not enabled. Enabling it now."); + ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072; + } + else + { + Console.WriteLine("Platform does not supports Tls12."); + } + } + + // disable ssl3 + if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Ssl3)) + { + Console.WriteLine("Ssl3SSL3 is enabled. Disabling it now."); + // disable SSL3. Has no negative impact if SSL3 is already disabled. The enclosing "if" if just for illustration. + System.Net.ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3; + } + Console.WriteLine("Enabled protocols: " + ServicePointManager.SecurityProtocol); + } + Console.Write(@" DC-Agent @@ -287,7 +342,7 @@ SOFTWARE."); Console.WriteLine(""); Console.WriteLine(""); - string cmd = ""; + string cmd; if (args.Length > 0 && (args[0] == "--install" || args[0] == "/install")) { @@ -310,13 +365,21 @@ SOFTWARE."); if (cmd == "1") { string res = GetDownloadURL(); + if (res == "") + { + Console.WriteLine("Server connection failed, please check your network connection and try again."); + Console.ReadLine(); + Environment.Exit(0); + return; + } + string patternStatus = "\"status\":."; string patternDownloadURL = "\"downloadURL\":\".*?[^\\\\]\","; string status = Regex.Matches(res, patternStatus)[0].Value.Replace("\"status\":", ""); if (status != "1") { - Console.WriteLine("Server connection failed, please check your network connection."); + Console.WriteLine("Install Failed. Please check your network connection and try again."); Console.ReadLine(); Environment.Exit(0); return;