示例#1
0
文件: Program.cs 项目: oocx/acme.net
        private void Execute(Options options)
        {
            try
            {
                Log.Level = options.Verbosity;

                var configuration = new ContainerConfiguration();
                var container = configuration.Configure(options);
                if (container == null)
                {
                    return;
                }

                var process = container.Resolve<IAcmeProcess>(new NamedParameter("options",  options));
                process.StartAsync().GetAwaiter().GetResult();
            }
            catch (AggregateException ex)
            {
                var acmeEx = ex.InnerExceptions.OfType<AcmeException>().FirstOrDefault();
                if (acmeEx != null)
                {
                    PrintError(acmeEx);
                }
                else
                {
                    throw;
                }
            }
            catch (AcmeException ex)
            {
                PrintError(ex);
            }
        }
示例#2
0
 public AcmeProcess(Options options, IChallengeProvider challengeProvider, IServerConfigurationProvider serverConfiguration, IAcmeClient client, IPkcs12 pkcs12, ICertificateRequestAsn1DEREncoder certificateRequestEncoder)
 {
     this.options = options;
     this.challengeProvider = challengeProvider;
     this.serverConfiguration = serverConfiguration;
     this.client = client;
     this.pkcs12 = pkcs12;            
     this.certificateRequestEncoder = certificateRequestEncoder;
 }
        public IContainer Configure(Options options)
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<AcmeProcess>().As<IAcmeProcess>();
            builder.RegisterType<AcmeClient>().As<IAcmeClient>()
                .WithParameter("baseAddress", options.AcmeServer)
                .WithParameter("keyName", options.AccountKeyName )
                .SingleInstance();

            if ("user".Equals(options.AccountKeyContainerLocation) || "machine".Equals(options.AccountKeyContainerLocation))
            {
                builder.RegisterType<KeyContainerStore>().As<IKeyStore>().WithParameter("storeType", options.AccountKeyContainerLocation);
            }
            else
            {
                builder.RegisterType<FileKeyStore>().As<IKeyStore>().WithParameter("basePath", options.AccountKeyContainerLocation ?? Environment.CurrentDirectory);
            }

            if ("manual-http-01".Equals(options.ChallengeProvider, StringComparison.OrdinalIgnoreCase))
            {
                builder.RegisterType<ManualChallengeProvider>().As<IChallengeProvider>();                
            }
            else if ("iis-http-01".Equals(options.ChallengeProvider, StringComparison.OrdinalIgnoreCase))
            {
                builder.RegisterType<IISChallengeProvider>().As<IChallengeProvider>();             
            }
            else
            {
                Error($"unsupported challenge provider: {options.ChallengeProvider}");
                return null;
            }

            if ("iis".Equals(options.ServerConfigurationProvider))
            {
                builder.RegisterType<IISServerConfigurationProvider>().As<IServerConfigurationProvider>();
            }
            else
            {
                builder.RegisterType<ManualServerConfigurationProvider>().As<IServerConfigurationProvider>();
            }

            builder.RegisterType<Pkcs12>().As<IPkcs12>();
            builder.RegisterType<Asn1Serializer>().As<IAsn1Serializer>();
            builder.RegisterType<CertificateRequestAsn1DEREncoder>().As<ICertificateRequestAsn1DEREncoder>();

            return builder.Build();
        }