【发布时间】:2022-11-11 02:59:55
【问题描述】:
我试图通过 SSL/TLS 找出 ASP.NET Core 6 和 RabbitMQ 通信的问题。
当我使用相同的代码与控制台应用程序进行 RabbitMQ 通信时,它正在工作。
当我尝试在与 F5 的 VS2022 相同的机器上运行 ASP.NET Core 中的相同代码时,它也可以正常工作。
但是当我在 IIS 机器上运行它时,您可能会在下面找到错误。
- 证书位于
wwwroot文件夹中 - 文件夹具有“所有人”权限
- 证书是自签名的私有证书
ConnectionFactory factory = new ConnectionFactory();
factory.HostName = "129001-01";
factory.RequestedHeartbeat = heartbeat;
factory.AutomaticRecoveryEnabled = true;
factory.UserName = "";
factory.Password = "";
factory.VirtualHost = "/";
factory.AuthMechanisms = new IAuthMechanismFactory[] { new ExternalMechanismFactory() };
System.Diagnostics.Debug.WriteLine("2 ");
// SSL Certification
X509Certificate2Collection certCollection = new X509Certificate2Collection();
string certificateName = "CART1290213.A000.pfx";
X509Certificate2 certificate = new X509Certificate2(certificatePath + certificateName, certificatePassword);
certCollection.Add(certificate);
factory.Ssl.Certs = certCollection;
factory.Ssl.Enabled = true;
factory.Ssl.ServerName = "129001-01";
factory.Ssl.Version = SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13;
factory.Ssl.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateNotAvailable | SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors;
System.Diagnostics.Debug.WriteLine("4 Connection will start");
IConnection connection = factory.CreateConnection();
IModel channel = connection.CreateModel();
抛出异常:
RabbitMQ.Client.dll 中的“RabbitMQ.Client.Exceptions.BrokerUnreachableException”
EXCEPTIONRabbitMQ.Client.Exceptions.BrokerUnreachableException:指定的端点均不可访问System.AggregateException:发生一个或多个错误。 (身份验证失败,请参阅内部异常。)
System.Security.Authentication.AuthenticationException:身份验证失败,请参阅内部异常。
System.ComponentModel.Win32Exception (0x8009030D):无法识别提供给包的凭据
在 System.Net.SSPIWrapper.AcquireCredentialsHandle(ISSPIInterface secModule,字符串包,CredentialUse 意图,SCH_CREDENTIALS* scc)
在 System.Net.Security.SslStreamPal.AcquireCredentialsHandle(CredentialUse credUsage,SCH_CREDENTIALS*secureCredential)
在 System.Net.Security.SslStreamPal.AcquireCredentialsHandleSchCredentials(SslStreamCertificateContext certificateContext,SslProtocols 协议,EncryptionPolicy 策略,布尔 isServer)
在 System.Net.Security.SslStreamPal.AcquireCredentialsHandle(SslStreamCertificateContext certificateContext,SslProtocols 协议,EncryptionPolicy 策略,布尔 isServer)
--- 内部异常堆栈跟踪结束 ---
在 System.Net.Security.SslStreamPal.AcquireCredentialsHandle(SslStreamCertificateContext certificateContext,SslProtocols 协议,EncryptionPolicy 策略,布尔 isServer)
在 System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]& thumbPrint)
在 System.Net.Security.SecureChannel.GenerateToken(ReadOnlySpan1 inputBuffer, Byte[]& output) at System.Net.Security.SecureChannel.NextMessage(ReadOnlySpan1 incomingBuffer)
在 System.Net.Security.SslStream.ProcessBlob(Int32 帧大小)
在 System.Net.Security.SslStream.ReceiveBlobAsync[TIOAdapter](TIOAdapter 适配器)
在 System.Net.Security.SslStream.ForceAuthenticationAsync [TIOAdapter](TIOAdapter 适配器,布尔接收第一,字节 [] reAuthenticationData,布尔 isApm)
在 RabbitMQ.Client.Impl.SslHelper.<>c__DisplayClass2_0.b__0(SslOption opts)
在 RabbitMQ.Client.Impl.SslHelper.TcpUpgrade(流 tcpStream,SslOption 选项)
在 RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint 端点,Func2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout) at RabbitMQ.Client.Framing.Impl.IProtocolExtensions.CreateFrameHandler(IProtocol protocol, AmqpTcpEndpoint endpoint, ArrayPool1 池,Func2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout) at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint) at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func2 选择器)
--- 内部异常堆栈跟踪结束 ---
在 RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver 解析器,Func`2 选择器)
在 RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IEndpointResolver 端点)
在 RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
--- 内部异常堆栈跟踪结束 ---
在 RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
在 RabbitMQ.Client.ConnectionFactory.CreateConnection(String clientProvidedName)
在 RabbitMQ.Client.ConnectionFactory.CreateConnection()
在 C:\Bordel\AdvancedConnector.NET\AdvancedConnector.MVC\Models\AdvancedConnector.cs:line 62 中的 AdvancedConnector.MVC.Models.AdvancedConnector.ConnectRabbitMQ()Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:错误:未找到视图“StartRabbitMq”。
搜索位置:/Views/Home/StartRabbitMq.cshtml、/Views/Shared/StartRabbitMq.cshtmlMicrosoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware:错误:执行请求时发生未处理的异常。
System.InvalidOperationException:未找到视图“StartRabbitMq”。
搜索了以下位置:
/Views/Home/StartRabbitMq.cshtml
/Views/Shared/StartRabbitMq.cshtml在 Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
在 Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext 上下文,ViewResult 结果)
在 Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext 上下文)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker 调用者,任务 lastTask,下一个状态,作用域范围,对象状态,布尔 isCompleted)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed 上下文)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- 上一个位置的堆栈跟踪结束 ---
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker 调用者,任务 lastTask,下一个状态,作用域范围,对象状态,布尔 isCompleted)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed 上下文)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(状态&下一个,范围&范围,对象&状态,布尔& isCompleted)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- 上一个位置的堆栈跟踪结束 ---
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker 调用程序,任务任务,IDisposable 范围)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker 调用程序,任务任务,IDisposable 范围)
在 Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(端点端点,任务 requestTask,ILogger 记录器)
在 Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext 上下文)
在 Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware 中间件,HttpContext 上下文,任务任务)我更改了权限,尝试更改不同的路径、凭据、不同的 IIS 服务器。
【问题讨论】:
标签: asp.net-core openssl rabbitmq