private static RenewResult Renew(ScheduledRenewal renewal)
 {
     using (var scope = AutofacBuilder.Renewal(_container, renewal, false))
     {
         return(Renew(scope, renewal));
     }
 }
        private static void CancelRenewal()
        {
            var tempRenewal = CreateRenewal(_options);

            using (var scope = AutofacBuilder.Renewal(_container, tempRenewal, false))
            {
                // Choose target plugin
                var targetPluginFactory = scope.Resolve <ITargetPluginFactory>();
                if (targetPluginFactory is INull)
                {
                    return; // User cancelled or unable to resolve
                }

                // Aquire target
                var targetPlugin = scope.Resolve <ITargetPlugin>();
                var target       = targetPlugin.Default(_optionsService);
                if (target == null)
                {
                    _log.Error("Plugin {name} was unable to generate a target", targetPluginFactory.Name);
                    return;
                }

                // Find renewal
                var renewal = _renewalService.Find(target);
                if (renewal == null)
                {
                    _log.Warning("No renewal scheduled for {target}, this run has no effect", target);
                    return;
                }

                // Cancel renewal
                _renewalService.Cancel(renewal);
            }
        }
示例#3
0
 private static RenewResult Renew(ScheduledRenewal renewal, RunLevel runLevel)
 {
     using (var scope = AutofacBuilder.Renewal(_container, renewal, runLevel))
     {
         return Renew(scope, renewal);
     }
 }
示例#4
0
        /// <summary>
        /// Revoke certificate
        /// </summary>
        private static void RevokeCertificate()
        {
            var target = _input.ChooseFromList("Which certificate would you like to revoke?",
                                               _renewalService.Renewals,
                                               x => Choice.Create(x),
                                               true);

            if (target != null)
            {
                if (_input.PromptYesNo($"Are you sure you want to revoke the most recently issued certificate for {target.Binding}?"))
                {
                    using (var scope = AutofacBuilder.Renewal(_container, target, RunLevel.Unattended))
                    {
                        var cs = scope.Resolve <CertificateService>();
                        try
                        {
                            cs.RevokeCertificate(target.Binding);
                            target.History.Add(new RenewResult(new Exception($"Certificate revoked")));
                        }
                        catch (Exception ex)
                        {
                            HandleException(ex);
                        }
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// Show certificate details
        /// </summary>
        private static void ShowCertificates()
        {
            var target = _input.ChooseFromList("Show details for renewal?",
                                               _renewalService.Renewals.OrderBy(x => x.Date),
                                               x => Choice.Create(x),
                                               true);

            if (target != null)
            {
                try
                {
                    using (var scope = AutofacBuilder.Renewal(_container, target, RunLevel.Unattended))
                    {
                        var resolver = scope.Resolve <UnattendedResolver>();
                        _input.Show("Name", target.Binding.Host, true);
                        _input.Show("AlternativeNames", string.Join(", ", target.Binding.AlternativeNames));
                        _input.Show("ExcludeBindings", target.Binding.ExcludeBindings);
                        _input.Show("Target plugin", resolver.GetTargetPlugin(scope).Description);
                        _input.Show("Validation plugin", resolver.GetValidationPlugin(scope).Description);
                        _input.Show("Store plugin", resolver.GetStorePlugin(scope).Description);
                        _input.Show("Install plugin(s)", string.Join(", ", resolver.GetInstallationPlugins(scope).Select(x => x.Description)));
                        _input.Show("Renewal due", target.Date.ToUserString());
                        _input.Show("Script", target.Script);
                        _input.Show("ScriptParameters", target.ScriptParameters);
                        _input.Show("CentralSslStore", target.CentralSslStore);
                        _input.Show("KeepExisting", target.KeepExisting.ToString());
                        _input.Show("Warmup", target.Warmup.ToString());
                        _input.Show("Renewed", $"{target.History.Count} times");
                        _input.WritePagedList(target.History.Select(x => Choice.Create(x)));
                    }
                }
                catch (Exception ex)
                {
                    _log.Error(ex, "Unable to list details for target");
                }
            }
        }
        private static void CreateNewCertificate(bool unattended)
        {
            if (unattended)
            {
                _log.Information(true, "Running in unattended mode.");
            }
            var tempRenewal = CreateRenewal(_options);

            using (var scope = AutofacBuilder.Renewal(_container, tempRenewal, !unattended))
            {
                // Choose target plugin
                var targetPluginFactory = scope.Resolve <ITargetPluginFactory>();
                if (targetPluginFactory is INull)
                {
                    return; // User cancelled or unable to resolve
                }

                // Aquire target
                var targetPlugin   = scope.Resolve <ITargetPlugin>();
                var target         = unattended ? targetPlugin.Default(_optionsService) : targetPlugin.Aquire(_optionsService, _input);
                var originalTarget = tempRenewal.Binding;
                tempRenewal.Binding = target;
                if (target == null)
                {
                    _log.Error("Plugin {name} was unable to generate a target", targetPluginFactory.Name);
                    return;
                }
                tempRenewal.Binding.TargetPluginName     = targetPluginFactory.Name;
                tempRenewal.Binding.SSLPort              = _options.SSLPort;
                tempRenewal.Binding.ValidationPluginName = originalTarget.ValidationPluginName;
                _log.Information("Plugin {name} generated target {target}", targetPluginFactory.Name, tempRenewal.Binding);

                // Choose validation plugin
                var validationPluginFactory = scope.Resolve <IValidationPluginFactory>();
                if (validationPluginFactory is INull)
                {
                    return; // User cancelled
                }
                else if (!validationPluginFactory.CanValidate(target))
                {
                    // Might happen in unattended mode
                    _log.Error("Validation plugin {name} is unable to validate target", validationPluginFactory.Name);
                    return;
                }

                // Configure validation
                try
                {
                    if (unattended)
                    {
                        validationPluginFactory.Default(target, _optionsService);
                    }
                    else
                    {
                        validationPluginFactory.Aquire(target, _optionsService, _input);
                    }
                    tempRenewal.Binding.ValidationPluginName = $"{validationPluginFactory.ChallengeType}.{validationPluginFactory.Name}";
                }
                catch (Exception ex)
                {
                    _log.Error(ex, "Invalid validation input");
                    return;
                }

                // Choose and configure installation plugins
                try
                {
                    var installFactories = scope.Resolve <List <IInstallationPluginFactory> >();
                    if (installFactories.Count == 0)
                    {
                        // User cancelled, otherwise we would at least have the Null-installer
                        return;
                    }
                    foreach (var installFactory in installFactories)
                    {
                        if (unattended)
                        {
                            installFactory.Default(tempRenewal, _optionsService);
                        }
                        else
                        {
                            installFactory.Aquire(tempRenewal, _optionsService, _input);
                        }
                    }
                    tempRenewal.InstallationPluginNames = installFactories.Select(f => f.Name).ToList();
                }
                catch (Exception ex)
                {
                    _log.Error(ex, "Invalid installation input");
                    return;
                }

                var result = Renew(scope, CreateRenewal(tempRenewal));
                if (!result.Success)
                {
                    _log.Error("Create certificate failed");
                }
            }
        }