【发布时间】:2014-08-09 12:54:45
【问题描述】:
我正在尝试通过 SSL 从我的 iOS XMPP 聊天客户端将我的用户连接到 Openfire 服务器。
在我的 iOS 客户端中:
- (void)setupStream
{
...
// BOOL values for security settings
customCertEvaluation = NO;
allowSelfSignedCertificates = YES;
allowSSLHostNameMismatch = NO;
}
在我的 Openfire 服务器的 Security Settings > Client Connection Security 中,我设置了:
Required - Clients can only connect to the server using secured connections.
因此,将调用以下委托方法:
- (void)xmppStream:(XMPPStream *)sender willSecureWithSettings:(NSMutableDictionary *)settings
{
NSString *expectedCertName = [xmppStream.myJID domain];
if (customCertEvaluation)
[settings setObject:@(YES) forKey:GCDAsyncSocketManuallyEvaluateTrust];
if (allowSelfSignedCertificates)
[settings setObject:[NSNumber numberWithBool:YES] forKey:(NSString *)kCFStreamSSLAllowsAnyRoot];
if (allowSSLHostNameMismatch)
[settings setObject:[NSNull null] forKey:(NSString *)kCFStreamSSLPeerName];
else
if (expectedCertName)
[settings setObject:expectedCertName forKey:(NSString *)kCFStreamSSLPeerName];
}
我从这个帖子尝试了这个解决方案:XMPPFramework TLS/SSL connection with Openfire
但是,当我运行我的应用程序并尝试连接到服务器时,我会收到以下错误:
Security option unavailable - kCFStreamSSLAllowsAnyRoot - You must use manual trust evaluation
我查看了GCDAsyncSocket 类并意识到kCFStreamSSLAllowsAnyRoot 被声明为已弃用。实施了一个 NSAssert 来故意抛出错误。
接下来,我决定更改我的 BOOL 值:
- (void)setupStream
{
...
// BOOL values for security settings
// Manually evaluate trust
customCertEvaluation = YES;
allowSelfSignedCertificates = NO;
allowSSLHostNameMismatch = NO;
}
这一次,再次无法与服务器建立连接,但没有提示错误。
如果我将客户端连接安全更改回原始设置,我可以很好地连接到 Openfire > 可选。但是,我不会通过 SSL 连接,如客户端会话中每个用户状态旁边的 lock 图标所示。
我的 Android 客户端(使用 Smack API for XMPP)通过 SSL 连接到 Openfire 没有问题。所以我想知道是否有我必须使用 XMPPFramework 为我的 iOS 客户端实现的解决方法。
如果有任何建议,我将不胜感激。
【问题讨论】:
标签: ios ssl xmpp openfire xmppframework