private ServerTreeNode(IServiceProvider serviceProvider, string name, string hostName, string credentials, string hash, ServerManager server, bool isLocalhost, WorkingMode mode, bool ignoreInCache) : base(GetNodeName(name, credentials, isLocalhost), serviceProvider) { Tag = server; ServerManager = server; DisplayName = name; HostName = hostName; Credentials = credentials; Mode = mode; if (Mode == WorkingMode.Iis) { ImageIndex = 8; SelectedImageIndex = 8; } else { ImageIndex = 1; SelectedImageIndex = 1; } IsLocalhost = isLocalhost; CertificateHash = hash; IgnoreInCache = ignoreInCache; Handler = (sender1, certificate, chain, sslPolicyErrors) => { var remoteHash = certificate.GetCertHashString(); if (remoteHash == CertificateHash) { return(true); } var dialog = new CertificateErrorsDialog(certificate); var result = dialog.ShowDialog(); if (result == DialogResult.OK) { MainForm.SaveMenuItem.Enabled = true; } if (result != DialogResult.OK) { return(false); } CertificateHash = remoteHash; return(true); }; }
private async Task <bool> OpenConnection(SynchronizationContext context) { string accepted = null; var handler = ServicePointManager.ServerCertificateValidationCallback; ServicePointManager.ServerCertificateValidationCallback = (sender1, certificate, chain, sslPolicyErrors) => { var hash = certificate.GetCertHashString(); if (accepted == hash) { return(true); } if (sslPolicyErrors == SslPolicyErrors.None) { accepted = hash; return(true); } var dialog = new CertificateErrorsDialog(certificate); var result = dialog.ShowDialog(); if (result != DialogResult.OK) { return(false); } accepted = hash; return(true); }; var service = (IManagementUIService)GetService(typeof(IManagementUIService)); try { var data = (ConnectionWizardData)WizardData; var server = new JexusServerManager(data.HostName, data.UserName + "|" + data.Password); data.Server = server; var version = await server.GetVersionAsync(); if (version == null) { service.ShowMessage("Authentication failed.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (version < JexusServerManager.MinimumServerVersion) { var toContinue = service.ShowMessage( string.Format( "The server version is {0}, while minimum compatible version is {1}. Making changes might corrupt server configuration. Do you want to continue?", version, JexusServerManager.MinimumServerVersion), Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (toContinue != DialogResult.Yes) { return(false); } } var conflict = await server.HelloAsync(); if (Environment.MachineName != conflict) { service.ShowMessage(string.Format("The server is also connected to {0}. Making changes on multiple clients might corrupt server configuration.", conflict), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } data.CertificateHash = accepted; return(true); } catch (Exception ex) { File.WriteAllText(DialogHelper.DebugLog, ex.ToString()); var last = ex; while (last is AggregateException) { last = last.InnerException; } var message = new StringBuilder(); message.AppendLine("Could not connect to the specified computer.") .AppendLine() .AppendFormat("Details: {0}", last.Message); service.ShowMessage(message.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } finally { ServicePointManager.ServerCertificateValidationCallback = handler; } }
private ServerTreeNode(IServiceProvider serviceProvider, string name, string hostName, string credentials, string hash, ServerManager server, bool isLocalhost, WorkingMode mode, bool ignoreInCache) : base(GetNodeName(name, credentials, isLocalhost), serviceProvider) { Tag = server; ServerManager = server; DisplayName = name; HostName = hostName; Credentials = credentials; Mode = mode; var elevated = PublicNativeMethods.IsProcessElevated; if (Mode == WorkingMode.Iis) { if (elevated) { ImageIndex = 8; SelectedImageIndex = 8; } else { ImageIndex = 12; SelectedImageIndex = 12; readOnly = true; } } else { var restricted = false; foreach (var restrictedPath in RestrictedPaths) { if (hostName.StartsWith(restrictedPath, StringComparison.OrdinalIgnoreCase)) { restricted = true; break; } } if (restricted && !elevated) { ImageIndex = 11; SelectedImageIndex = 11; readOnly = true; } else { ImageIndex = 1; SelectedImageIndex = 1; } } IsLocalhost = isLocalhost; CertificateHash = hash; IgnoreInCache = ignoreInCache; if (mode == WorkingMode.Jexus) { ((JexusServerManager)server).ServerCertificateValidationCallback = (sender1, certificate, chain, sslPolicyErrors) => { var remoteHash = certificate.GetCertHashString(); if (remoteHash == CertificateHash) { return(true); } using (var dialog = new CertificateErrorsDialog(certificate)) { var result = dialog.ShowDialog(); if (result == DialogResult.OK) { MainForm.SaveMenuItem.Enabled = true; } if (result != DialogResult.OK) { return(false); } } CertificateHash = remoteHash; return(true); }; } }