title: SSL handshake hang
body: <p>I have seen this question around the forums but couldn't find any appropriate fix. Also all those questions are missing some info, so thought to put all what i have learned here. connecting the dots.</p>
  
  <p>I am working with SSL/TLS in <strong>openfire</strong> with 2 way authentication. Got a self signed wildcard certificate. which means i have my CA in both client and server. Now this works but sometimes, SSL handshake stucks at some particular line. Logs from server side: </p>
  
  <pre><code>org.apache.mina.filter.ssl.SslFilter  - Session Server[40](ssl...): Processing the SSL Data
  </code></pre>
  
  <p>On client side, I am using <strong>SMACK</strong> so building the configuration i gave around 2 min reply timeout just to check the behaviour; I also set hostNameVerifier. </p>
  
  <p>So when ever it hangs, following logs i can see:</p>
  
  <pre><code>05-07 17:35:45.705 D/SMACK: SENT (1): &lt;stream:stream xmlns='jabber:client' to='mydomain.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'&gt;
  05-07 17:35:45.712 D/SMACK: RECV (1): &lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="mydomain.com" id="9haislljp2" xml:lang="en" version="1.0"&gt;
  05-07 17:35:45.721 D/SMACK: RECV (1): &lt;stream:features&gt;&lt;starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"&gt;&lt;required/&gt;&lt;/starttls&gt;&lt;mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"&gt;&lt;mechanism&gt;PLAIN&lt;/mechanism&gt;&lt;mechanism&gt;EXTERNAL&lt;/mechanism&gt;&lt;/mechanisms&gt;&lt;/stream:features&gt;
  05-07 17:35:45.723 D/SMACK: SENT (1): &lt;starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'&gt;&lt;/starttls&gt;
  05-07 17:35:45.730 D/SMACK: RECV (1): &lt;proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/&gt;
  </code></pre>
  
  <p>And here it hangs for undefined time, sometimes its around 20 seconds, sometimes a minute or more.</p>
  
  <p>But right after that the very first log i see is:</p>
  
  <pre><code>05-07 17:36:15.151 : HostNameVerifier callback verify: hostname:mydomain.com SessionID:[B@3cedf14
                                               CipherSuite:TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
                                               Protocol:TLSv1.2
  05-07 17:36:15.153 D/SMACK: SENT (1): &lt;stream:stream xmlns='jabber:client' to='mydomain' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'&gt;
  05-07 17:36:15.161 D/SMACK: RECV (1): &lt;?xml version='1.0' encoding='UTF-8'?&gt;&lt;stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="mydomain.com" id="9haislljp2" xml:lang="en" version="1.0"&gt;&lt;stream:features&gt;&lt;mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"&gt;&lt;mechanism&gt;PLAIN&lt;/mechanism&gt;&lt;mechanism&gt;EXTERNAL&lt;/mechanism&gt;&lt;/mechanisms&gt;&lt;compression xmlns="http://jabber.org/features/compress"&gt;&lt;method&gt;zlib&lt;/method&gt;&lt;/compression&gt;&lt;register xmlns="http://jabber.org/features/iq-register"/&gt;&lt;/stream:features&gt;
  </code></pre>
  
  <p>and <strong>XMPP</strong> is connected.</p>
  
  <p>So I looked into this hostname verifier functionality from jdk and other source, I am not sure but quite came to idea that it was doing some dns lookup. I also put my domain with ip in etc/hosts. so that should avoid dns lookups but still. Anyhow, would appreciate if anyone can point to something concrete. </p>
  
  <p>Links I followed:</p>
  
  <p><a href="https://stackoverflow.com/questions/42531225/apache-mina-stuck-on-ssl-connection">Apache MINA - stuck on SSL connection</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3193936/how-to-disable-javas-ssl-reverse-dns-lookup">How to disable Java&#39;s SSL Reverse DNS Lookup</a></p>
  
  <p><a href="https://stackoverflow.com/questions/27228623/android-4-2-slow-ssl-tls">Android 4.2 slow SSL/TLS</a></p>
  
  <p>If anyone needs anymore info, will be more than happy to share. </p>
  
  <p>Openfire Version: 4.1.3</p>
  
  <p>Smack Version: 4.2.0</p>
  
  <p>Ubuntu running openfire: 16.04</p>
  
  <p>JDK installed: openjdk 7,8 (tried with both)</p>