首页 > 其他分享 >【Azure 服务总线】使用Azure Service Bus 时,出现证书错误: 所使用的证书具有无法验证的信任链

【Azure 服务总线】使用Azure Service Bus 时,出现证书错误: 所使用的证书具有无法验证的信任链

时间:2022-12-05 20:25:07浏览次数:72  
标签:Service 证书 Bus Shanghai client Azure

问题描述

在Azure中连接 Service Bus 服务发送消息时发生证书错误,抛出证书异常消息:

The X.509 certificate CN=servicebus.chinacloudapi.cn, OU=Azure, O=Shanghai Blue Cloud Technology Co Ltd, L=Shanghai, S=Shanghai, C=CN is not in the trusted people store. 
The X.509 certificate CN=servicebus.chinacloudapi.cn, OU=Azure, O=Shanghai Blue Cloud Technology Co Ltd, L=Shanghai, S=Shanghai, C=CN chain building failed. 
The certificate that was used has a trust chain that cannot be verified. 
Replace the certificate or change the certificateValidationMode. 
A certificate chain could not be built to a trusted root authority.

 

 

问题解答

如果在连接Service Bus的代码中不对 ConnectivityMode 做预先设置,Service Bus SDK默认使用了 AutoDetect 模式 连接 Service Bus 服务。 

AutoDetect 会优先使用 TCP 连接模式,由于 TCP 连接模式也是加密的,所以客户端需要首先验证 service bus 服务器证书 CN = servicebus.chinacloudapi.cn 的有效性,证书链信息在 SSL 协议的 server hello 消息中返回。

如果证书链中的某些中间证书没有安装在 web 应用实例上,web 应用需要发起额外的请求到 CA 服务器上下载中间证书并安装。当下面任何一种情况发生时,web 应用无法对 service bus 服务器证书建立信任的证书链,随后会报告上述的证书错误:

  1. 运行Service Bus客户端代码的实例和 CA 服务器之间存在网络问题,导致无法下载证书.
  2. 运行Service Bus客户端代码的实例无法成功安装证书,如权限问题等。

推荐在代码中强制使用 HTTPS 模式连接 Service Bus 服务,HTTPS 模式有不同的设计,因此会很大程度上避免上述错误发生。

示例代码如下:

string connectionString = "servicebus connection string";

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Https

var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

if (!namespaceManager.TopicExists("TestTopic"))
{
    namespaceManager.CreateTopic("TestTopic");
}

TopicClient client = TopicClient.CreateFromConnectionString(connectionString, "TestTopic");

BrokeredMessage testMessage = new BrokeredMessage("test message");
testMessage.MessageId = "message id";

client.Send(testMessage);

另外,以上代码代码使用很旧的Service Bus SDK,强烈建议升级SDK代码,使用新的AMQP协议连接Service Bus

using Azure.Messaging.ServiceBus;

// the client that owns the connection and can be used to create senders and receivers
ServiceBusClient client;
// The Service Bus client types are safe to cache and use as a singleton for the lifetime
// of the application, which is best practice when messages are being published or read
// regularly.
//
// set the transport type to AmqpWebSockets so that the ServiceBusClient uses the port 443. 
// If you use the default AmqpTcp, you will need to make sure that the ports 5671 and 5672 are open

// TODO: Replace the <NAMESPACE-CONNECTION-STRING> and <QUEUE-NAME> placeholders
var clientOptions = new ServiceBusClientOptions()
{ 
    TransportType = ServiceBusTransportType.AmqpWebSockets
};
client = new ServiceBusClient("<NAMESPACE-CONNECTION-STRING>", clientOptions); 

 

 

参考文档

添加将消息发送到队列的代码  : https://learn.microsoft.com/zh-cn/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues?tabs=passwordless#add-code-to-send-messages-to-the-queue 

 

标签:Service,证书,Bus,Shanghai,client,Azure
From: https://www.cnblogs.com/lulight/p/16953387.html

相关文章

  • java对接webservice服务实现推送
    【背景】  前不久接到一个任务需要将我们平台的内容推送到第三方的一个webService服务中,我们平台接口使用java来做的,所以需要通过java调用webService服务实现推送效果,不......
  • webservice接口调用OA方法
    【背景】  最近一直在做这样一个需求,在OA中写一个webservice接口,通过调用OA中更新的方法来同步上级主管,我们公司的OA系统是买的产品,一无所知的我就这样开启了无悔......
  • Android中的intentservice
    在Android的应用中,往往需要在执行主界面的操作时,如果要执行耗时的操作,那么应该是另外开线程的,或者是用async或者handler,今天发现其实也可以用android中的一个Intents......
  • htts证书申请
    ​​https://freessl.cn/​​教程:​​​https://www.bilibili.com/video/BV1Ug411673P/?spm_id_from=333.337.search-card.all.click&vd_source=a68414cd60fe26e829ce1cdd4d......
  • 群辉 synology 开启NFS 服务 service ,debian ubuntu 挂载 mount 群辉 synology NFS
    目录1.群辉synology开启NFS服务2.共享文件夹的设置中设置NFS服务权限3.Debianubuntu中设置挂载目录1.群辉synology开启NFS服务群辉的控制面板>>文件服务......
  • 关于sqlservice 2019的安装
    目录一、安装SQLServer。下载地址:https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads二、安装SSMS。 下载地址:https://learn.microsoft.com/zh-cn/sql/......
  • Service详解
    Service详解Service介绍在kubernetes中,pod是应用程序的载体,我们可以通过pod的ip来访问应用程序,但是pod的ip地址不是固定的,这也就意味着不方便直接采用pod的ip对服务进行......
  • CompletionService 使用小结
    本文为博主原创,转载请注明出处:实现异步任务时,经常使用 FutureTask来实现;一个简单的示例代码如下:publicstaticvoidmain(String[]args)throwsExecutionExcept......
  • 【Azure 服务总线】查看Service Bus中消息多次发送的日志信息,消息是否被重复消费
    问题描述使用ServiceBus,发现消息被重复消费。如果要查看某一条消息的具体消费情况,需要那些消息的属性呢? 问题解答使用AzureServiceBus,当消费发送到服务端后,就会生......
  • K8S-service介绍
    Service介绍在kubernetes中,pod是应用程序的载体,我们可以通过pod的ip来访问应用程序,但是pod的ip地址不是固定的,这也就意味着不方便直接采用pod的ip对服务进行访问。为了解......