Exemplo n.º 1
0
        /// <summary>
        /// Revoke certificate
        /// </summary>
        private static void RevokeCertificate()
        {
            var target = _input.ChooseFromList("Which certificate would you like to revoke?",
                                               _renewalService.Renewals.OrderBy(x => x.Date),
                                               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);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 private static RenewResult Renew(ScheduledRenewal renewal, RunLevel runLevel)
 {
     using (var scope = AutofacBuilder.Renewal(_container, renewal, runLevel))
     {
         return(Renew(scope, renewal));
     }
 }
Exemplo n.º 3
0
        private static void CancelRenewal()
        {
            var tempRenewal = CreateRenewal(_options);

            using (var scope = AutofacBuilder.Renewal(_container, tempRenewal, RunLevel.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       = 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);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Cancel all renewals
 /// </summary>
 private static void CreateScheduledTask()
 {
     using (var scope = AutofacBuilder.Renewal(_container, null, RunLevel.Advanced))
     {
         var taskScheduler = scope.Resolve <TaskSchedulerService>();
         taskScheduler.EnsureTaskScheduler();
     }
 }
Exemplo n.º 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("CommonName", target.Binding.CommonName ?? "<not set>");
                        _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);
                        if (!string.IsNullOrEmpty(target.CertificateStore))
                        {
                            _input.Show("Certificate store", target.CertificateStore);
                        }
                        _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");
                }
            }
        }
Exemplo n.º 6
0
        private static void CreateNewCertificate(RunLevel runLevel)
        {
            _log.Information(true, "Running in {runLevel} mode", runLevel);
            var tempRenewal = CreateRenewal(_options);

            using (var scope = AutofacBuilder.Renewal(_container, tempRenewal, runLevel))
            {
                // 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         = runLevel == RunLevel.Unattended ? targetPlugin.Default(_optionsService) : targetPlugin.Aquire(_optionsService, _input, runLevel);
                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.ValidationPort       = _options.ValidationPort;
                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 (runLevel == RunLevel.Unattended)
                    {
                        validationPluginFactory.Default(target, _optionsService);
                    }
                    else
                    {
                        validationPluginFactory.Aquire(target, _optionsService, _input, runLevel);
                    }
                    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 (runLevel == RunLevel.Unattended)
                        {
                            installFactory.Default(tempRenewal, _optionsService);
                        }
                        else
                        {
                            installFactory.Aquire(tempRenewal, _optionsService, _input, runLevel);
                        }
                    }
                    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");
                }
            }
        }