无法使用带有HTTPS的Kestrel进行相互握手(双向SSL)

时间:2017-07-10 15:30:59

标签: ssl https asp.net-core asp.net-core-mvc kestrel-http-server

主要方法:

 public static void InitHttpServer(ServerInitiatorParam sip)
    {   
            var host = new WebHostBuilder()
                     //.UseKestrel(options => { options.UseHttps(cert); })
                     .UseKestrel(options =>
                     {
                         var cert = new X509Certificate2("C:/cert/Test.pfx", "password");
                         HttpsConnectionFilterOptions httpsOptions = new HttpsConnectionFilterOptions();
                         httpsOptions.ServerCertificate = cert;
                         httpsOptions.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
                         options.UseHttps(httpsOptions);
                     })
                    .UseStartup<Startup>()
                    .UseUrls($"https://localhost:{port}/")
                    .Build();
            host.Run();

启动文件:

public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();
        services.Configure<MvcOptions>(options =>
            {
                options.Filters.Add(new RequireHttpsAttribute());
            });
    }

错误:

System.Security.Authentication.AuthenticationException:根据验证程序,远程证书无效。

对&#34; C:\ Windows \ System32 \ drivers \ etc \ hosts&#34; 进行了更改 补充道:

127.0.0.1测试 localhost测试

确保证书名称即 &#34;试验&#34;与主机名相同。

错误堆栈跟踪:

2017-07-10T10:12:05.6963689-05:00 [ERR] ConnectionFilter.OnConnection(e77fccc9) System.AggregateException:发生一个或多个错误。 ---&GT; System.Security.Authentication.AuthenticationException:根据验证过程,远程证书无效。    在System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)    在System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult结果)    在System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)    在System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic(IAsyncResult iar, Func 2 endFunction,Action 1 endAction, Task 1 promise,Boolean requiresSynchronization) ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter.d__6.MoveNext()    ---内部异常堆栈跟踪结束--- ---&GT; (内部异常#0)System.Security.Authentication.AuthenticationException:根据验证过程,远程证书无效。    在System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)    在System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult结果)    在System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)    在System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic(IAsyncResult iar, Func 2 endFunction,Action 1 endAction, Task 1 promise,Boolean requiresSynchronization) ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter.d__6.MoveNext()&lt; ---

2017-07-10T10:12:05.7203861-05:00 [ERR] ConnectionFilter.OnConnection(e77fccc9) System.AggregateException:发生一个或多个错误。 ---&GT; System.Security.Authentication.AuthenticationException:根据验证过程,远程证书无效。    在System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)    在System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult结果)    在System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)    在System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic(IAsyncResult iar, Func 2 endFunction,Action 1 endAction, Task 1 promise,Boolean requiresSynchronization) ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter.d__6.MoveNext()    ---内部异常堆栈跟踪结束--- ---&GT; (内部异常#0)System.Security.Authentication.AuthenticationException:根据验证过程,远程证书无效。    在System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)    在System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult结果)    在System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)    在System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic(IAsyncResult iar, Func 2 endFunction,Action 1 endAction, Task 1 promise,Boolean requiresSynchronization) ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter.d__6.MoveNext()&lt; ---

0 个答案:

没有答案