Exemple #1
0
        public async Task <bool> DeleteManagedCertificate(ManagedCertificate selectedItem)
        {
            var existing = ManagedCertificates.FirstOrDefault(s => s.Id == selectedItem.Id);

            if (existing != null)
            {
                if (MessageBox.Show(SR.ManagedCertificateSettings_ConfirmDelete, SR.ConfirmDelete, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                {
                    existing.Deleted = true;
                    var deletedOK = await CertifyClient.DeleteManagedCertificate(selectedItem.Id);

                    if (deletedOK)
                    {
                        ManagedCertificates.Remove(existing);
                    }
                    return(deletedOK);
                }
            }
            return(false);
        }
Exemple #2
0
 /// <summary>
 /// Request deletion of a managed certificate by Id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public async Task <ActionResult> DeleteManagedCertificate(string id)
 {
     try
     {
         if (await _client.DeleteManagedCertificate(id))
         {
             return(new ActionResult("OK", true));
         }
         else
         {
             return(new ActionResult("Not Found", false));
         }
     }
     catch (Exception exp)
     {
         return(new ActionResult {
             IsSuccess = false, Message = "Failed to perform delete operation: " + exp.ToString()
         });
     }
 }
Exemple #3
0
        /// <summary>
        /// Remove identifiers from a managed cert e.g. certify remove 89ccaf11-d7c4-427a-b491-9d3582835c48 test1.test.com;test2.test.com (optionally with --perform-request)
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        internal async Task RemoveIdentifiers(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Not enough arguments");
                return;
            }

            var managedCertId = args[1];
            var domains       = args[2]?.Split(";, ".ToCharArray());

            var performRequestNow = false;

            if (args.Contains("--perform-request"))
            {
                performRequestNow = true;
            }
            var managedCert = await _certifyClient.GetManagedCertificate(managedCertId);

            if (domains != null && domains.Any())
            {
                foreach (var d in domains.Where(i => !string.IsNullOrEmpty(i)).Select(i => i.Trim().ToLower()))
                {
                    var domainOption = managedCert.DomainOptions.FirstOrDefault(o => o.Domain == d);

                    if (domainOption != null)
                    {
                        managedCert.DomainOptions.Remove(domainOption);
                    }

                    if (managedCert.RequestConfig.SubjectAlternativeNames.Contains(d))
                    {
                        // remove domain from list of subject alternative names
                        managedCert.RequestConfig.SubjectAlternativeNames = managedCert.RequestConfig.SubjectAlternativeNames.Where(i => i != d).ToArray();
                    }
                }

                // check we still have a primary domain, if not selected a default one
                if (!managedCert.DomainOptions.Any(o => o.IsPrimaryDomain))
                {
                    var defaultIdentifier = managedCert.DomainOptions.FirstOrDefault(o => o.IsSelected);
                    if (defaultIdentifier != null)
                    {
                        defaultIdentifier.IsPrimaryDomain       = true;
                        managedCert.RequestConfig.PrimaryDomain = defaultIdentifier.Domain;
                    }
                }

                if (managedCert.GetCertificateDomains().Count() == 0)
                {
                    // this managed certificate has no domains anymore. Delete it.
                    await _certifyClient.DeleteManagedCertificate(managedCert.Id);

                    Console.WriteLine("Managed certificate has no more domains, deleted.");
                }
                else
                {
                    // update managed cert and optionally begin the request
                    var updatedManagedCert = await _certifyClient.UpdateManagedCertificate(managedCert);

                    if (updatedManagedCert != null && performRequestNow)
                    {
                        await _certifyClient.BeginCertificateRequest(updatedManagedCert.Id, true, true);
                    }
                }
            }
        }