Ejemplo n.º 1
0
        /// <summary>
        /// If renewal is already Scheduled, replace it with the new options
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        private static ScheduledRenewal CreateRenewal(ScheduledRenewal temp)
        {
            var renewal = _renewalService.Find(temp.Binding);

            if (renewal == null)
            {
                renewal = temp;
            }
            renewal.New              = true;
            renewal.Test             = temp.Test;
            renewal.Binding          = temp.Binding;
            renewal.CentralSslStore  = temp.CentralSslStore;
            renewal.KeepExisting     = temp.KeepExisting;
            renewal.Script           = temp.Script;
            renewal.ScriptParameters = temp.ScriptParameters;
            renewal.Warmup           = temp.Warmup;
            return(renewal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Steps to take on succesful (re)authorization
        /// </summary>
        /// <param name="binding"></param>
        public static RenewResult OnAutoSuccess(Target binding)
        {
            RenewResult result = new RenewResult(new Exception("Unknown error after validation"));

            try
            {
                var scheduled         = _renewalService.Find(binding);
                var oldCertificate    = FindCertificate(scheduled);
                var newCertificate    = _certificateService.RequestCertificate(binding);
                var newCertificatePfx = new FileInfo(_certificateService.PfxFilePath(binding));
                result = new RenewResult(newCertificate);

                if (_options.Test &&
                    !_options.Renew &&
                    !_input.PromptYesNo($"Do you want to install the certificate?"))
                {
                    return(result);
                }

                SaveCertificate(binding.GetHosts(true), newCertificate, newCertificatePfx);

                if (_options.Renew ||
                    !_options.Test ||
                    _input.PromptYesNo($"Do you want to add/update the certificate to your server software?"))
                {
                    _log.Information("Installing SSL certificate in server software");
                    if (_options.CentralSsl)
                    {
                        binding.Plugin.Install(binding);
                    }
                    else
                    {
                        binding.Plugin.Install(binding, newCertificatePfx.FullName, _certificateStoreService.DefaultStore, newCertificate, oldCertificate);
                    }

                    if (!_options.KeepExisting && oldCertificate != null)
                    {
                        DeleteCertificate(oldCertificate.Thumbprint);
                    }
                }

                if (!_options.Renew &&
                    (scheduled != null ||
                     !_options.Test ||
                     _input.PromptYesNo($"Do you want to automatically renew this certificate in {_renewalService.RenewalPeriod} days? This will add a task scheduler task.")))
                {
                    _renewalService.CreateOrUpdate(binding, result);
                }
                return(result);
            }
            catch (Exception ex)
            {
                // Result might still contain the Thumbprint of the certificate
                // that was requested and (partially? installed, which might help
                // with debugging
                HandleException(ex);
                result.Success      = false;
                result.ErrorMessage = ex.Message;
            }
            return(result);
        }