【问题标题】:How to use SSL Certificate in xmpp IOS?如何在 xmpp IOS 中使用 SSL 证书?
【发布时间】:2016-04-07 11:44:12
【问题描述】:

您好,我正在使用 XMPP 框架,一切正常。现在由于安全原因,我需要使用 ssl 证书。但我不知道如何在我的应用程序中实现,即使我不知道 SSL 证书的基本知识,所以任何人都可以帮助我如何创建 SSL。以及如何在 ios 中的 xmpp 中实现,我正在使用 openfire 服务器。

【问题讨论】:

标签: ios ssl-certificate chat openfire xmppframework


【解决方案1】:

嘿,我在 XMPP 中成功实现了 SSL,请按照以下步骤操作:

第 1 步:

-(BOOL) connect {

    [self setupStream];

    [xmppStream setHostName:xxx];
    [xmppStream setHostPort:zzz];
    [xmppStream setMyJID:yyy];

    NSError *error = nil;

    if (![xmppStream oldSchoolSecureConnectWithTimeout:XMPPStreamTimeoutNone error:&error]) {

    nslog(@"Error %@",error)

        return NO;
    }

    return YES;

}

第 2 步:

- (void)setupStream {

    customCertEvaluation = NO;
    allowSelfSignedCertificates = NO;
    allowSSLHostNameMismatch = NO;


    xmppStream = [[XMPPStream alloc] init];
    [xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];

    xmppStream.startTLSPolicy = XMPPStreamStartTLSPolicyPreferred;
    // or
    // xmppStream.startTLSPolicy = XMPPStreamStartTLSPolicyRequired;

}

第 3 步:根据您的服务器需要设置标志

 - (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];
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-18
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    相关资源
    最近更新 更多