【发布时间】:2015-05-14 17:58:31
【问题描述】:
几天来,我一直在尝试使用与最新的 Eclipse 等效的工具与 IBM MessageSight 虚拟设备 建立安全 (SSL/TLS) 连接Paho C Client 库,即 IBM WebSphere MQ Client Pack MA9B for Mobile V1.0.0.4。
客户端:
Objective-C 代码:
...
client = [client initWithHosts:hosts ports:ports clientId:clientId];
ConnectOptions *opts = [[ConnectOptions alloc] init];
opts.timeout = 3600;
/*
opts.userName = @"******";
opts.password = @"******";
*/
opts.cleanSession = cleanSession;
opts.willMessage = nil;
NSBundle *mainBundle = [NSBundle mainBundle];
NSString *ksFile = [mainBundle pathForResource: @"ClientKeyStore" ofType: @"pem"];
NSString *pkFile = [mainBundle pathForResource: @"ClientKey" ofType: @"pem"];
NSString *tsFile = [mainBundle pathForResource: @"RootCAKey" ofType: @"pem"];
if (DEBUG) {
NSLog(@"Bundle ==> %@", mainBundle);
NSLog(@"ClientKeyStore ==> %@", ksFile);
NSLog(@"ClientKey ==> %@", pkFile);
NSLog(@"TrustStore ==> %@", tsFile);
}
SSLOptions *ssl = [[SSLOptions alloc] init];
ssl.enableServerCertAuth = NO;
// ssl.enabledCipherSuites = @"SHA2";
ssl.keyStore = ksFile;
ssl.privateKey = pkFile;
ssl.privateKeyPassword = @"******";
ssl.trustStore = tsFile;
opts.sslProperties = ssl;
[client connectWithOptions:opts invocationContext:self onCompletion:callback];
这是我用来通过其包装器 (MqttOCClient.h/m) 与 C 库交互的 Objective-C 代码。
现在是规格:
- iOS 7.1 以上,Xcode 6.3.1(模拟器)。
- iOS 8.3,Xcode 6.3.1 (iPhone 5S)。
- MQTT iOS 客户端:IBM WebSphere MQ Client Pack MA9B for Mobile V1.0.0.4 (http://www-01.ibm.com/support/knowledgecenter/?lang=en#!/SSFKSJ_7.5.0/com.ibm.mm.tc.doc/tc10120_.htm)。
跟踪:
我已经通过 2 个环境变量在库上启用了跟踪模式:
MQTT_C_CLIENT_TRACE_LEVEL = MAXIMUM
MQTT_C_CLIENT_TRACE = ON
这是输出:
D] >>MessagingClient::connectWithOptions
I] first serverURI is ssl://example.com:1884
=========================================================
Trace Output
Product name: Paho Asynchronous MQTT C Client Library
Version: ##MQTTCLIENT_VERSION_TAG##
Build level: ##MQTTCLIENT_BUILD_TAG##
OpenSSL version: OpenSSL 1.0.1h 5 Jun 2014
OpenSSL flags: compiler: /Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -miphoneos-version-min=7.1 -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -O3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -fomit-frame-pointer -fno-common
OpenSSL build timestamp: built on: Thu Jun 5 14:59:07 BST 2014
OpenSSL platform: platform: iphoneos-cross
OpenSSL directory: OPENSSLDIR: "/tmp/openssl-1.0.1h-iOS-i386"
=========================================================
19691231 200000.000 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x7a068df0
19691231 200000.000 (42856916) (1)> Socket_outInitialize:124
19691231 200000.000 (42856916) (2)> SocketBuffer_initialize:85
19691231 200000.000 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/SocketBuffer.c line 73 ptr 0x79f75480
19691231 200000.000 Allocating 1008 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/SocketBuffer.c line 75 ptr 0x7a917000
19691231 200000.000 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x79f791c0
19691231 200000.000 (42856916) (2)< SocketBuffer_initialize:89
19691231 200000.000 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x79f792a0
19691231 200000.000 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x79f786f0
19691231 200000.000 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x7a26ba90
19691231 200000.000 (42856916) (1)< Socket_outInitialize:137
19691231 200000.000 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x7a26bcb0
19691231 200000.000 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x7a26ba20
19691231 200000.000 (42856916) (1)> SSLSocket_initialize:398
19691231 200000.000 Allocating 1808 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/SSLSocket.c line 414 ptr 0x7b8fd600
...
20150514 130126.866 (42856916) (2)< SSL_create_mutex:313 (0)
20150514 130126.866 (42856916) (2)> SSL_create_mutex:307
...
20150514 130126.867 (42856916) (1)< SSLSocket_initialize:438 (1)
20150514 130126.867 Allocating 144 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/MQTTAsync.c line 374 ptr 0x79f75f10
20150514 130126.867 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/MQTTAsync.c line 386 ptr 0x79f75fb0
20150514 130126.867 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x79ec7160
20150514 130126.867 Allocating 16 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 93 ptr 0x79e78970
20150514 130126.867 Allocating 96 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/MQTTAsync.c line 391 ptr 0x79ec1840
20150514 130126.867 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x79ec1780
20150514 130126.867 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x79ed00c0
20150514 130126.867 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 56 ptr 0x79ec9090
20150514 130126.867 Allocating 32 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/MQTTAsync.c line 397 ptr 0x79ec2110
20150514 130126.867 (42856916) (1)> MQTTPersistence_create:47
20150514 130126.867 (42856916) (1)< MQTTPersistence_create:93 (0)
20150514 130126.867 (42856916) (1)> MQTTPersistence_initialize:108
20150514 130126.867 (42856916) (1)< MQTTPersistence_initialize:116 (0)
20150514 130126.867 (42856916) (1)> MQTTAsync_restoreCommands:666
20150514 130126.867 0 commands restored for client 32c94ab93d29fda895b02f6
20150514 130126.867 (42856916) (1)< MQTTAsync_restoreCommands:698 (0)
20150514 130126.867 (42856916) (1)> MQTTAsync_restoreMessageQueue:1872
20150514 130126.867 0 queued messages restored for client 32c94ab93d29fda895b02f6
20150514 130126.867 (42856916) (1)< MQTTAsync_restoreMessageQueue:1903 (0)
20150514 130126.867 Allocating 16 bytes in heap at file /Users/asm/workspace/Client/client_ios/iosMQTT/iosMQTT/mqttCClient/LinkedList.c line 93 ptr 0x79e7cef0
20150514 130126.867 (42856916) (0)< MQTTAsync_create:416 (0)
2015-05-14 13:01:26.867 SmartBanking[2616:607] D] C Client created
20150514 130126.867 (42856916) (0)> MQTTAsync_setCallbacks:1658
20150514 130126.867 (42856916) (0)< MQTTAsync_setCallbacks:1672 (0)
2015-05-14 13:01:26.868 SmartBanking[2616:607] D] Calling C client to make connection
20150514 130126.867 (42856916) (0)> MQTTAsync_connect:1990
20150514 130126.867 (42856916) (0)< MQTTAsync_connect:2177 (-8)
E] C client connect failed
Connection Error: ErrorCode=8 ErrorMessage=Unable to connect
D] <<MessagingClient::connectWithOptions
服务器端:
- IBM MessageSight v1.1.0
- 服务器证书:2048 位自签名。
- 安全已启用且端点已启动。
- 已启用用户和通行证。
旁注:
- 如果我使用浏览器,我可以查看证书,这意味着它可以连接到服务器。
- 如果我使用 Java 版 Eclipse Paho,则可以使用相同的 TrustStore(包含自签名 CA)验证服务器证书。
如果有人使用此库从 iOS 与 MQTT 建立 SSL 连接,我将不胜感激。
问候,
【问题讨论】:
标签: ios eclipse xcode ssl mqtt