public static KestrelServerOptions UseLetsEncrypt(this KestrelServerOptions options,
                                                          LetsEncryptCertificateFetcher fetcher, HttpsConnectionAdapterOptions httpsOptions = null, int port = 443)
        {
            if (port == 80)
            {
                throw new ArgumentOutOfRangeException(nameof(port), "The value 80 is reserved for Let's Encrypt checks");
            }

            options.Listen(fetcher.Address, port, listenOptions =>
            {
                var loggerFactory = listenOptions.KestrelServerOptions.ApplicationServices
                                    .GetRequiredService <ILoggerFactory>();
                listenOptions.ConnectionAdapters.Add(
                    new HttpsConnectionAdapter(httpsOptions ?? new HttpsConnectionAdapterOptions(),
                                               loggerFactory,
                                               fetcher));
            });

            return(options);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            using (var fetcher = new LetsEncryptCertificateFetcher("ayende.hopto.org", "*****@*****.**", IPAddress.Any,
                                                                   // will read & write it from the current directory
                                                                   // read impl will probably use a vault or provide a password
                                                                   // when persisting
                                                                   File.ReadAllBytes,
                                                                   File.WriteAllBytes
                                                                   ))
            {
                fetcher.InitializeAsync().Wait();

                var host = new WebHostBuilder()
                           .UseKestrel(options =>
                {
                    options.UseLetsEncrypt(fetcher, new HttpsConnectionAdapterOptions());
                })
                           .UseStartup <Startup>()
                           .Build();

                host.Run();
            }
        }