我们使用了带有 SSL 配置的 AWS iOS IoT 开发工具包。我们遵循 https://github.com/awslabs/aws-sdk-ios-samples/tree/master/IoT-Sample/Swift 作为参考。 在这里,我们的服务器端点将是格式
https://xxxxxxxxxx.iot..amazonaws.com
我们将 pkcs12 文件导入到捆绑包中,并能够连接、发布、订阅服务器。
后来我们想到在我们的组织内有本地网络解决方案,我们为 serverhttps://www.rabbitmq.com/ssl.html#keys-and-certs 的MQTT代理设置了rabbitmq。目前,我们正在尝试使用 ec2 实例,后者将设置本地服务器。终点是
ssl://ec2-..compute.amazonaws.com:8883
现在我无法使用 aws iot ios sdk 连接到 rabbitmq 服务器。
但是,如果我使用 https://github.com/emqtt/CocoaMQTT 示例,我能够连接到两个 aws IoT 服务器终端节点,即 rabbitmq 服务器端点。
我现在应该怎么做才能使用 aws iot ios 开发工具包 https://github.com/aws/aws-sdk-ios/tree/master/AWSIoT 连接到 rabbitmq 服务器端点。我应该在 sdk 中进行哪些编辑?
以下是尝试使用 AWS IoT ios 开发工具包连接到 rabbitmq 服务器时的日志。
2017-07-27 12:56:55:860 sample[2124:1004208] hostName: ec2-<ip>.<region>.compute.amazonaws.com
2017-07-27 12:56:55:861 sample[2124:1004208] URL: ssl://ec2-<ip>.<region>.compute.amazonaws.com
2017-07-27 12:56:55:875 sample[2124:1004208] -[MQTTSession initWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetainFlag:runLoop:forMode:] [Line 169], Thread:<NSThread: 0x170068000>{number = 1, name = main}
2017-07-27 12:56:55:875 sample[2124:1004208] +[MQTTMessage connectMessageWithClientId:userName:password:keepAlive:cleanSession:willTopic:willMsg:willQoS:willRetain:] [Line 68], Thread:<NSThread: 0x170068000>{number = 1, name = main}
2017-07-27 12:56:55:875 sample[2124:1004208] Creating MQTTMessage with raw data >>>>> <00044d51 54540406 003c0004 696f732d 0017746f 7069632f 77726974 652f736f 75726365 2f757365 7200787b 22636c69 5f657665 6e745f69 64223a22 636c695f 6576656e 745f7573 65725f31 35303131 34303431 352e3832 37393422 2c22736f 75726365 223a2273 6f757263 65222c22 73656e64 65725f69 64223a22 75736572 222c2265 76656e74 5f747970 65223a22 4c415354 5f57494c 4c5f4d45 53534147 45227d> <<<<<
2017-07-27 12:56:55:879 sample[2124:1004208] Initializing MQTTEncoder and MQTTDecoder streams
2017-07-27 12:56:55.882561+0530 sample[2124:1004208] ChatViewController: connection status = Connecting 1
2017-07-27 12:56:55:880 sample[2124:1004208] opening encoder stream.
2017-07-27 12:56:55:880 sample[2124:1004208] opening decoder stream.
2017-07-27 12:56:55:946 sample[2124:1004208] -[MQTTDecoder stream:handleEvent:] [Line 64] EventCode:1, stream: <__NSCFInputStream: 0x170112870>, Thread: <NSThread: 0x170068000>{number = 1, name = main}
2017-07-27 12:56:55:947 sample[2124:1004208] -[MQTTEncoder stream:handleEvent:] [Line 71] EventCode:1, Thread: <NSThread: 0x170068000>{number = 1, name = main}
2017-07-27 12:56:56.002911+0530 sample[2124:1004208] CFNetwork SSLHandshake failed (-9807)
2017-07-27 12:56:56:003 sample[2124:1004208] -[MQTTDecoder stream:handleEvent:] [Line 64] EventCode:8, stream: <__NSCFInputStream: 0x170112870>, Thread: <NSThread: 0x170068000>{number = 1, name = main}
2017-07-27 12:56:56:003 sample[2124:1004208] -[MQTTSession decoder:handleEvent:] [Line 471] eventCode:2
2017-07-27 12:56:56:004 sample[2124:1004208] MQTT session error, code: 3
2017-07-27 12:56:56:004 sample[2124:1004208] closing encoder stream.
2017-07-27 12:56:56:005 sample[2124:1004208] closing decoder stream.
2017-07-27 12:56:57:008 sample[2124:1004208] MQTTSessionDelegate handleEvent: 3
2017-07-27 12:56:57:008 sample[2124:1004208] MQTT session connection error
2017-07-27 12:56:57.010082+0530 sample[2124:1004287] Chat :Alive service stop
2017-07-27 12:56:57.010521+0530 sample[2124:1004208] ChatViewController: connection status = Disconnected 5
2017-07-27 12:56:57.016899+0530 sample[2124:1004208] Chat :viewDidDisappear
2017-07-27 12:56:57:009 sample[2124:1004208] setting up reconnectTimer.
2017-07-27 12:56:58:010 sample[2124:1004208] Trying to reconnect to session.
2017-07-27 12:56:58:011 sample[2124:1004208] Initializing MQTTEncoder and MQTTDecoder streams
2017-07-27 12:56:58:011 sample[2124:1004208] opening encoder stream.
2017-07-27 12:56:58:011 sample[2124:1004208] opening decoder stream.
2017-07-27 12:56:58:075 sample[2124:1004208] -[MQTTDecoder stream:handleEvent:] [Line 64] EventCode:1, stream: <__NSCFInputStream: 0x170112bd0>, Thread: <NSThread: 0x170068000>{number = 1, name = main}
2017-07-27 12:56:58:075 sample[2124:1004208] -[MQTTEncoder stream:handleEvent:] [Line 71] EventCode:1, Thread: <NSThread: 0x170068000>{number = 1, name = main}
2017-07-27 12:56:58.127802+0530 sample[2124:1004208] CFNetwork SSLHandshake failed (-9807)
2017-07-27 12:56:58:128 sample[2124:1004208] -[MQTTDecoder stream:handleEvent:] [Line 64] EventCode:8, stream: <__NSCFInputStream: 0x170112bd0>, Thread: <NSThread: 0x170068000>{number = 1, name = main}
2017-07-27 12:56:58:128 sample[2124:1004208] -[MQTTSession decoder:handleEvent:] [Line 471] eventCode:2
2017-07-27 12:56:58:128 sample[2124:1004208] MQTT session error, code: 3
2017-07-27 12:56:58:128 sample[2124:1004208] closing encoder stream.
2017-07-27 12:56:58:128 sample[2124:1004208] closing decoder stream.
2017-07-27 12:56:59:129 sample[2124:1004208] MQTTSessionDelegate handleEvent: 3
2017-07-27 12:56:59:130 sample[2124:1004208] MQTT session connection error
2017-07-27 12:56:59.131627+0530 sample[2124:1004299] Chat :Alive service stop
2017-07-27 12:56:59.132071+0530 sample[2124:1004208] ChatViewController: connection status = Disconnected 5
你的目标是什么? 您是希望本地 MQTT 代理进行测试,还是希望运行自己的 MQTT 代理并使用 AWS iOS IoT 开发工具包连接到它?
如果你想经营自己的经纪人,我建议你仔细考虑一下,因为它在规模上变得困难。 我尚未尝试对本地代理使用 AWS IoT 开发工具包,但您的日志显示 SSL 握手失败。 我猜这是因为您的应用程序和 RabbitMQ 之间的相互身份验证由于服务器证书不匹配而失败。
AWS IoT 使用相互身份验证而不仅仅是客户端身份验证来建立信任:http://docs.aws.amazon.com/iot/latest/developerguide/managing-device-certs.html
你需要做两件事 1(在 iOS 开发工具包中标识设置 AWS IoT 服务器 CA 的位置 (https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem(,并将其替换为 RabbitMQ 代理的 CA,2( 配置 RabbitMQ 以进行相互身份验证(如果支持(。
祝你好运。