Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app)
        {
            //app.UseIISPlatformHandler();

            RemoteCertificateValidationCallback validationCallback = (sender, cert, chain, sslPolicyErrors) => true;
            ServicePointManager.ServerCertificateValidationCallback += validationCallback;

            var connectionFilterOptions =
                new HttpsConnectionFilterOptions
                {
                    ServerCertificate = GetCertificateFromStore(),
                    ClientCertificateMode = ClientCertificateMode.RequireCertificate,
                    ClientCertificateValidation = (certificate, chain, sslPolicyErrors) => true
                };

            app.UseKestrelHttps(connectionFilterOptions);


            app.UseStaticFiles();

            app.UseMvc();

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        }
        public static IApplicationBuilder UseKestrelHttps(this IApplicationBuilder app, HttpsConnectionFilterOptions options)
        {
            var serverInfo = app.ServerFeatures.Get<IKestrelServerInformation>();

            if (serverInfo == null)
            {
                return app;
            }

            var prevFilter = serverInfo.ConnectionFilter ?? new NoOpConnectionFilter();

            serverInfo.ConnectionFilter = new HttpsConnectionFilter(options, prevFilter);

            return app;
        }
        public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (previous == null)
            {
                throw new ArgumentNullException(nameof(previous));
            }
            if (options.ServerCertificate == null)
            {
                throw new ArgumentException("The server certificate parameter is required.");
            }

            _options = options;
            _previous = previous;
        }
Ejemplo n.º 4
0
        public HttpsConnectionFilter(HttpsConnectionFilterOptions options, IConnectionFilter previous)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (previous == null)
            {
                throw new ArgumentNullException(nameof(previous));
            }
            if (options.ServerCertificate == null)
            {
                throw new ArgumentException("The server certificate parameter is required.");
            }

            _options  = options;
            _previous = previous;
        }