public async Task <ActionResult> RemoveCertificateAuthority(string id) { var customCAs = SettingsManager.GetCustomCertificateAuthorities(); var customCa = customCAs.FirstOrDefault(c => c.Id == id); if (customCa != null) { customCAs.Remove(customCa); if (SettingsManager.SaveCustomCertificateAuthorities(customCAs)) { return(new ActionResult("OK", true)); } } return(await Task.FromResult(new ActionResult("An error occurred saving the updated Certificate Authorities list.", false))); }
public async Task <ActionResult> UpdateCertificateAuthority(CertificateAuthority certificateAuthority) { try { if (_certificateAuthorities.Any(c => c.Key == certificateAuthority.Id && c.Value.IsCustom == false)) { // can't modify built in CAs return(new ActionResult("Default Certificate Authorities cannot be modified.", false)); } var customCAs = SettingsManager.GetCustomCertificateAuthorities(); var customCa = customCAs.FirstOrDefault(c => c.Id == certificateAuthority.Id); if (customCa != null) { // replace customCAs.Remove(customCa); customCAs.Add(certificateAuthority); _certificateAuthorities.TryUpdate(certificateAuthority.Id, certificateAuthority, customCa); } else { // add customCAs.Add(certificateAuthority); _certificateAuthorities.TryAdd(certificateAuthority.Id, certificateAuthority); } //store updated CAs if (SettingsManager.SaveCustomCertificateAuthorities(customCAs)) { return(new ActionResult("OK", true)); } } catch (Exception exp) { // failed to load custom CAs _serviceLog.Error(exp.Message); } return(await Task.FromResult(new ActionResult("An error occurred saving the updated Certificate Authorities list.", false))); }