/// <summary> /// UpgradeServersConfig method implementation (Client) /// </summary> private void UpgradeServersConfig(NamedPipeRegistryRecord reg) { NamedPipeRegistryRecord rec = FarmUtilities.InitServerNodeConfiguration(reg); MFAConfig cfg = CFGUtilities.ReadConfiguration(null); ADFSServerHost svr = null; if (cfg.Hosts.ADFSFarm.Servers.Exists(s => s.FQDN.ToLower().Equals(rec.FQDN.ToLower()))) { svr = cfg.Hosts.ADFSFarm.Servers.Find(s => s.FQDN.ToLower().Equals(rec.FQDN.ToLower())); cfg.Hosts.ADFSFarm.Servers.Remove(svr); } svr = new ADFSServerHost(); svr.FQDN = rec.FQDN; svr.CurrentVersion = rec.CurrentVersion; svr.CurrentBuild = rec.CurrentBuild; svr.CurrentMajorVersionNumber = rec.CurrentMajorVersionNumber; svr.CurrentMinorVersionNumber = rec.CurrentMinorVersionNumber; svr.InstallationType = rec.InstallationType; svr.ProductName = rec.ProductName; svr.NodeType = rec.NodeType; svr.BehaviorLevel = rec.BehaviorLevel; svr.HeartbeatTmeStamp = rec.HeartbeatTimestamp; cfg.Hosts.ADFSFarm.Servers.Add(svr); CFGUtilities.WriteConfiguration(null, cfg); using (MailSlotClient mailslot = new MailSlotClient()) { mailslot.Text = Environment.MachineName; mailslot.SendNotification(NotificationsKind.ConfigurationReload); } }
/// <summary> /// ReadConfigurationForCache method implementation /// </summary> private byte[] ReadConfigurationForCache() { MFAConfig config = CFGUtilities.ReadConfiguration(); XmlConfigSerializer xmlserializer = new XmlConfigSerializer(typeof(MFAConfig)); MemoryStream stm = new MemoryStream(); using (StreamReader reader = new StreamReader(stm)) { xmlserializer.Serialize(stm, config); stm.Position = 0; return(XORUtilities.XOREncryptOrDecrypt(stm.ToArray(), XORUtilities.XORKey)); } }
/// <summary> /// DoOnRequestServerConfiguration method implementation (Client) /// </summary> private void DoOnRequestServerConfiguration(string servername) { if (CFGUtilities.IsPrimaryComputer()) { List <string> lst = new List <string>() { servername }; PipeClient pipe = new PipeClient(XORUtilities.XORKey, lst); string req = Environment.MachineName; NamedPipeRegistryRecord reg = pipe.DoRequestServerConfiguration(req); UpgradeServersConfig(reg); } return; }
/// <summary> /// ExportMFAMailTemplates method implementation /// </summary> internal static void ExportMFAMailTemplates(PSHost host, int lcid) { MFAConfig config = CFGUtilities.ReadConfiguration(host); Dictionary <string, string> data = new Dictionary <string, string>(); ResourcesLocale Resources = new ResourcesLocale(lcid); data.Add("MailOTPContent.html", Resources.GetString(ResourcesLocaleKind.CommonMail, "MailOTPContent")); data.Add("MailKeyContent.html", Resources.GetString(ResourcesLocaleKind.CommonMail, "MailKeyContent")); data.Add("MailAdminContent.html", Resources.GetString(ResourcesLocaleKind.CommonMail, "MailAdminContent")); data.Add("MailNotifications.html", Resources.GetString(ResourcesLocaleKind.CommonMail, "MailNotifications")); if (WebAdminManagerClient.ExportMailTemplates(config, lcid, data)) { CFGUtilities.WriteConfiguration(host, config); CFGUtilities.BroadcastNotification(config, NotificationsKind.ConfigurationReload, Environment.MachineName, true, true); } }
/// <summary> /// DoOnCreateConfiguration method implementation (Client) /// </summary> private void DoOnClearConfiguration() { if (CFGUtilities.IsPrimaryComputer()) { if (_adfsservers.Count == 0) { BuildADFSServersList(); } PipeClient pipe = new PipeClient(XORUtilities.XORKey, ADFSServers, true); string req = Environment.MachineName; if (!pipe.DoClearConfigurationCache(req)) { this.EventLog.WriteEntry("Configuration cahe cannot be cleared !", EventLogEntryType.Warning, 10000); } } }
/// <summary> /// ReloadData method implementation /// </summary> internal void ReloadData() { this.SuspendLayout(); this.Cursor = Cursors.WaitCursor; _notifenabled = false; try { ComponentResourceManager resources = new ComponentResourceManager(typeof(ServiceViewControl)); this.label1.Text = resources.GetString("label1.Text"); this.label2.Text = resources.GetString("label2.Text"); this.label3.Text = resources.GetString("label3.Text"); this.label4.Text = resources.GetString("label4.Text"); ((IMMCRefreshData)ControlInstance).DoRefreshData(); bool isconfigured = ManagementService.ADFSManager.IsFarmConfigured(); if (isconfigured) { foreach (ADFSServerControl srv in _lst) { this.tableLayoutPanel.Controls.Remove(srv); } _lst.Clear(); int i = 3; MFAConfig cfg = CFGUtilities.ReadConfiguration(null); foreach (ADFSServerHost srv in cfg.Hosts.ADFSFarm.Servers) { bool isok = ManagementService.ADFSManager.IsRunning(srv.FQDN); ADFSServerControl crt = new ADFSServerControl(this, srv, isok); _lst.Add(crt); this.tableLayoutPanel.Invoke((MethodInvoker) delegate { this.tableLayoutPanel.Controls.Add(crt, 0, i); }); i++; } } } finally { _notifenabled = true; this.Cursor = Cursors.Default; this.ResumeLayout(); } }
/// <summary> /// DoOnSendConfiguration method implementation (Client) /// </summary> private void DoOnSendConfiguration() { if (CFGUtilities.IsPrimaryComputer()) { if (_adfsservers.Count == 0) { BuildADFSServersList(); } PipeClient pipe = new PipeClient(XORUtilities.XORKey, ADFSServers, true); byte[] byt = ReadConfigurationForCache(); string msg = Convert.ToBase64String(byt, 0, byt.Length); string req = Environment.MachineName; if (!pipe.DoReloadConfiguration(req, msg)) { this.EventLog.WriteEntry("Some Servers configuration where not updated ! Wait for WID synchro !", EventLogEntryType.Warning, 10000); } } }
/// <summary> /// ResetWebThemesList method implementation /// </summary> internal static void ResetWebThemesList(PSHost host) { MFAConfig config = CFGUtilities.ReadConfiguration(host); WebThemeManagerClient.ResetThemesList(config); }
/// <summary> /// InstallMFASample method implementation /// </summary> internal static void InstallMFASample(PSHost host, FlatSampleKind kind, bool reset = false) { MFAConfig config = CFGUtilities.ReadConfiguration(host); switch (kind) { case FlatSampleKind.QuizProvider: if (!reset) { config.ExternalProvider.FullQualifiedImplementation = "Neos.IdentityServer.MultiFactor.Samples.QuizProviderSample, Neos.IdentityServer.MultiFactor.Samples, Version = 3.0.0.0, Culture = neutral, " + Utilities.GetAssemblyPublicKey(); } else { config.ExternalProvider.FullQualifiedImplementation = ""; } break; case FlatSampleKind.CaesarEnryption: if (!reset) { config.KeysConfig.CustomFullyQualifiedImplementation = "Neos.IdentityServer.MultiFactor.Samples.CaesarKeyManagerActivator, Neos.IdentityServer.MultiFactor.Samples, Version=3.0.0.0, Culture=neutral, " + Utilities.GetAssemblyPublicKey(); config.KeysConfig.KeyFormat = SecretKeyFormat.CUSTOM; } else { config.KeysConfig.CustomFullyQualifiedImplementation = ""; config.KeysConfig.KeyFormat = SecretKeyFormat.RNG; } break; case FlatSampleKind.InMemoryStorage: if (!reset) { config.Hosts.CustomStoreHost.KeysRepositoryFullyQualifiedImplementation = "Neos.IdentityServer.MultiFactor.Samples.InMemoryKeys2RepositoryService, Neos.IdentityServer.MultiFactor.Samples, Version=3.0.0.0, Culture=neutral, " + Utilities.GetAssemblyPublicKey(); config.Hosts.CustomStoreHost.DataRepositoryFullyQualifiedImplementation = "Neos.IdentityServer.MultiFactor.Samples.InMemoryDataRepositoryService, Neos.IdentityServer.MultiFactor.Samples, Version=3.0.0.0, Culture=neutral, " + Utilities.GetAssemblyPublicKey(); config.StoreMode = DataRepositoryKind.Custom; } else { config.Hosts.CustomStoreHost.KeysRepositoryFullyQualifiedImplementation = ""; config.Hosts.CustomStoreHost.DataRepositoryFullyQualifiedImplementation = ""; config.StoreMode = DataRepositoryKind.ADDS; } break; case FlatSampleKind.SMSProvider: if (!reset) { config.ExternalProvider.FullQualifiedImplementation = "Neos.IdentityServer.MultiFactor.Samples.NeosSMSProvider, Neos.IdentityServer.MultiFactor.Samples, Version=3.0.0.0, Culture=neutral, " + Utilities.GetAssemblyPublicKey(); } else { config.ExternalProvider.FullQualifiedImplementation = ""; } break; case FlatSampleKind.TOTPProvider: if (!reset) { config.OTPProvider.FullQualifiedImplementation = "Neos.IdentityServer.MultiFactor.Samples.NeosOTPProvider430, Neos.IdentityServer.MultiFactor.Samples, Version=3.0.0.0, Culture=neutral, " + Utilities.GetAssemblyPublicKey(); } else { config.OTPProvider.FullQualifiedImplementation = ""; } break; case FlatSampleKind.CustomPresentation: if (!reset) { config.CustomAdapterPresentation = "Neos.IdentityServer.MultiFactor.Samples.AdapterPresentationCustom, Neos.IdentityServer.MultiFactor.PresentationSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken = 711047a08ea8edb3"; } else { config.CustomAdapterPresentation = ""; } break; } CFGUtilities.WriteConfiguration(host, config); CFGUtilities.BroadcastNotification(config, NotificationsKind.ConfigurationReload, Environment.MachineName, true, true); }
/// <summary> /// SetMFACredentials method implementation /// </summary> internal static void SetMFACredentials(PSHost host, byte kind, string value, bool clearvalue = false) { MFAConfig config = CFGUtilities.ReadConfigurationFromADFSStore(host); if (config == null) { return; } switch (kind) { case 0x00: using (SystemEncryption MSIS = new SystemEncryption()) { if (clearvalue) { config.Hosts.ActiveDirectoryHost.Password = string.Empty; config.Hosts.ActiveDirectoryHost.Account = string.Empty; config.Hosts.ActiveDirectoryHost.DomainAddress = string.Empty; config.Hosts.SQLServerHost.SQLAccount = string.Empty; config.Hosts.SQLServerHost.SQLPassword = string.Empty; config.MailProvider.Password = string.Empty; config.MailProvider.UserName = string.Empty; config.MailProvider.Anonymous = true; config.KeysConfig.XORSecret = XORUtilities.DefaultKey; } else { config.KeysConfig.XORSecret = MSIS.Encrypt(config.KeysConfig.XORSecret, "Pass Phrase Encryption"); config.Hosts.ActiveDirectoryHost.Password = MSIS.Encrypt(config.Hosts.ActiveDirectoryHost.Password, "ADDS Super Account Password"); config.Hosts.SQLServerHost.SQLPassword = MSIS.Encrypt(config.Hosts.SQLServerHost.SQLPassword, "SQL Super Account Password"); config.MailProvider.Password = MSIS.Encrypt(config.MailProvider.Password, "Mail Provider Account Password"); config.DefaultPin = MSIS.Encrypt(config.DefaultPin, "Default Users Pin"); config.AdministrationPin = MSIS.Encrypt(config.AdministrationPin, "Administration Pin"); if (!string.IsNullOrEmpty(value)) { host.UI.WriteWarningLine("Block Updates not allowed, values where only encrypted !"); } } } break; case 0x01: using (SystemEncryption MSIS = new SystemEncryption()) { if (clearvalue) { config.Hosts.ActiveDirectoryHost.Password = string.Empty; config.Hosts.ActiveDirectoryHost.Account = string.Empty; config.Hosts.ActiveDirectoryHost.DomainAddress = string.Empty; } else { if (string.IsNullOrEmpty(value)) { config.Hosts.ActiveDirectoryHost.Password = MSIS.Encrypt(config.Hosts.ActiveDirectoryHost.Password, "ADDS Super Account Password"); host.UI.WriteWarningLine("Empty value not allowed, value was only encrypted !"); } else { config.Hosts.ActiveDirectoryHost.Password = MSIS.Encrypt(value, "ADDS Super Account Password"); } } } break; case 0x02: using (SystemEncryption MSIS = new SystemEncryption()) { if (clearvalue) { config.MailProvider.Password = string.Empty; config.MailProvider.UserName = string.Empty; config.MailProvider.Anonymous = true; } else { if (string.IsNullOrEmpty(value)) { config.MailProvider.Password = MSIS.Encrypt(config.MailProvider.Password, "Mail Provider Account Password"); host.UI.WriteWarningLine("Empty value not allowed, value was only encrypted !"); } else { config.MailProvider.Password = MSIS.Encrypt(value, "Mail Provider Account Password"); } } } break; case 0x03: using (SystemEncryption MSIS = new SystemEncryption()) { if (clearvalue) { config.KeysConfig.XORSecret = XORUtilities.DefaultKey; } else { if (string.IsNullOrEmpty(value)) { config.KeysConfig.XORSecret = MSIS.Encrypt(config.KeysConfig.XORSecret, "Pass Phrase Encryption"); config.DefaultPin = MSIS.Encrypt(config.DefaultPin, "Default Users Pin"); config.AdministrationPin = MSIS.Encrypt(config.AdministrationPin, "Administration Pin"); host.UI.WriteWarningLine("Empty value not allowed, value was only encrypted !"); } else { config.KeysConfig.XORSecret = MSIS.Encrypt(value, "Pass Phrase Encryption"); } } } break; case 0x04: using (SystemEncryption MSIS = new SystemEncryption()) { if (clearvalue) { config.Hosts.SQLServerHost.SQLAccount = string.Empty; config.Hosts.SQLServerHost.SQLPassword = string.Empty; } else { if (string.IsNullOrEmpty(value)) { config.Hosts.SQLServerHost.SQLPassword = MSIS.Encrypt(config.Hosts.SQLServerHost.SQLPassword, "SQL Super Account Password"); host.UI.WriteWarningLine("Empty value not allowed, value was only encrypted !"); } else { config.Hosts.SQLServerHost.SQLPassword = MSIS.Encrypt(value, "SQL Super Account Password"); } } } break; } CFGUtilities.WriteConfigurationToDatabase(host, config, false); CFGUtilities.BroadcastNotification(config, NotificationsKind.ConfigurationCreated, Environment.MachineName, true, true); }
/// <summary> /// BroadcastNotification method implmentation /// </summary> internal static void BroadcastNotification(MFAConfig config, NotificationsKind kind, string message, bool local = true, bool dispatch = true) { CFGUtilities.BroadcastNotification(config, kind, message, local, dispatch); }