我们希望在运行在Kestrel服务器上的IIS Web服务器(作为代理)上实现ASP.NET Core API(1.0.1)。 运行API的客户端应该使用我们公司CA提供的证书来执行此操作。 用户应通过" Active Directory客户端证书身份验证"。
进行身份验证我们正在开发人员客户端(而不是Web服务器)上使用Visual Studio 2015(Update 3)进行开发。
在阅读了试图理解机制之后,我在代码中尝试了一下。 可悲的是,尝试和错误没有多大帮助:))
之后我试图在互联网上找到一些教程,但其中大多数只是覆盖部分解决方案,而且大多数都是针对ASP.NET 5。
那么我的问题是什么?
客户 - (SSL证书) - > https://API(IIS - > Kestrel)
当我只想通过AD验证客户端证书并读取我的API中的证书以获取UPN时,Kestrel是否需要使用"Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1"
?
我尝试了什么?
首先我将"Microsoft.AspNetCore.Server.Kestrel.Https": "1.0.1",
添加到project.json文件中。
在Startup.cs文件中,我将以下代码添加到ConfigureServices
函数中:
services.Configure<KestrelServerOptions>(options =>
{
options.ThreadCount = 4;
options.UseConnectionLogging();
HttpsConnectionFilterOptions https = new HttpsConnectionFilterOptions();
https.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
https.ServerCertificate = GetCetificate();
https.CheckCertificateRevocation = false;
options.UseHttps(https);
});
GetCetificate()
从本地商店检索证书(我想我需要一个带私钥的真实服务器证书?)
我正在收听以下端口:
"server.urls": "http://localhost:6000;https://localhost:6001;"
我让默认的ValuesController不受影响进行测试。
当我运行API-Profile(非IIS Express)http://localhost:6000/api/values
时,返回json数据。当我请求https://localhost:6001/api/values
时,我收到以下错误:
失败:Microsoft.AspNetCore.Server.Kestrel [0] ConnectionFilter.OnConnection System.AggregateException:发生一个或多个错误。 (服务器模式SSL必须使用证书 相关的私钥。)---&gt; System.NotSupportedException:The 服务器模式SSL必须使用具有关联私有的证书 键。在 System.Net.Security.SecureChannel.AcquireServerCredentials(字节[]&安培; thumbPrint)at System.Net.Security.SecureChannel.GenerateToken(Byte []输入,Int32 offset,Int32 count,Byte []&amp;输出)at System.Net.Security.SecureChannel.NextMessage(字节[]传入,Int32 offset,Int32 count)at System.Net.Security.SslState.StartSendBlob(Byte [] incoming,Int32 count,AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.ProcessReceivedBlob(Byte []缓冲区,Int32 count,AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest) ---从抛出异常的先前位置开始的堆栈跟踪结束--- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult的 结果)在 System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult的 asyncResult)at System.Threading.Tasks.TaskFactory
1.FromAsyncCoreLogic(IAsyncResult iar, Func
2 endFunction,Action1 endAction, Task
1 promise,Boolean requiresSynchronization) ---从抛出异常的先前位置开始的堆栈跟踪结束--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务) Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter.d__3.MoveNext() ---内部异常堆栈跟踪结束--- ---&GT; (内部异常#0)System.NotSupportedException:服务器模式SSL必须使用具有关联私钥的证书。在 System.Net.Security.SecureChannel.AcquireServerCredentials(字节[]&安培; thumbPrint)at System.Net.Security.SecureChannel.GenerateToken(Byte []输入,Int32 offset,Int32 count,Byte []&amp;输出)at System.Net.Security.SecureChannel.NextMessage(字节[]传入,Int32 offset,Int32 count)at System.Net.Security.SslState.StartSendBlob(Byte [] incoming,Int32 count,AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.ProcessReceivedBlob(Byte []缓冲区,Int32 count,AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest) ---从抛出异常的先前位置开始的堆栈跟踪结束--- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult的 结果)在 System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult的 asyncResult)at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func
2 endFunction,Action1 endAction, Task
1 promise,Boolean requiresSynchronization) ---从抛出异常的先前位置开始的堆栈跟踪结束--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务) System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务) Microsoft.AspNetCore.Server.Kestrel.Https.HttpsConnectionFilter.d__3.MoveNext()&LT; ---
运行IIS Express似乎可以工作(通过在launchSettings.json中配置的http://localhost:31943/和https://localhost:44317/ 但是,我仍然无法获得ClientCertificate。