title: XMPPFramework - Connect via SSL on Openfire
body: <p>I'm trying to connect my users via <strong>SSL</strong> from my iOS XMPP chat client to Openfire server.</p>
  
  <p>In my <strong>iOS</strong> client:</p>
  
  <pre><code>- (void)setupStream 
  {
      ...
      // BOOL values for security settings
      customCertEvaluation = NO;
      allowSelfSignedCertificates = YES;
      allowSSLHostNameMismatch = NO;
  }
  </code></pre>
  
  <p>In my <strong>Openfire</strong> server's <strong>Security Settings</strong> > <strong>Client Connection Security</strong>, I've set:</p>
  
  <p><code>Required - Clients can only connect to the server using secured connections.</code></p>
  
  <p>Thus, the following delegate method will be called:</p>
  
  <pre><code>- (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];
  }
  </code></pre>
  
  <p>I attempted this solution from this thread: <a href="https://stackoverflow.com/questions/17876421/xmppframework-tls-ssl-connection-with-openfire">XMPPFramework TLS/SSL connection with Openfire</a></p>
  
  <p>However, when I run my application and attempt to connect to the server, I'd receive this error:</p>
  
  <p><code>Security option unavailable - kCFStreamSSLAllowsAnyRoot - You must use manual trust evaluation</code></p>
  
  <p>I looked through the <code>GCDAsyncSocket</code> class and realized <code>kCFStreamSSLAllowsAnyRoot</code> is stated as deprecated. An NSAssert was implemented to deliberately throw the error.</p>
  
  <p>Next, I decided to change my BOOL values as such:</p>
  
  <pre><code>- (void)setupStream 
  {
      ...
      // BOOL values for security settings
      // Manually evaluate trust
      customCertEvaluation = YES;
      allowSelfSignedCertificates = NO;
      allowSSLHostNameMismatch = NO;
  }
  </code></pre>
  
  <p>This time, again, no connection could be made to the server but, no error was prompted.</p>
  
  <p>I could connect to Openfire fine if I changed the Client Connection Security back to the original setting > <strong>Optional</strong>. But, I wouldn't be connected via SSL as indicated by a <em>lock</em> icon beside every user's status in Client Sessions.</p>
  
  <p>My Android client (using Smack API for XMPP) connects to Openfire via SSL without issues. So I'm wondering if there's workaround I have to implement for my iOS client using XMPPFramework.</p>
  
  <p>I would greatly appreciate any advices.</p>