title: SSL Handshake failed 9801 - TCP connection - Xcode 7
body: <p>In the app , built on Xcode 7 (beta) , TCP socket connection (NSStream) fails with below error.</p>
  
  <pre><code>**CFNetwork SSLHandshake failed (-9801)
  
  Stream Error -9801: The operation couldn’t be completed. (OSStatus error -9801.)**   
  </code></pre>
  
  <p>In the Info.plist I have also included the ATS following related exceptions.</p>
  
  <pre><code>&lt;key&gt;NSAppTransportSecurity&lt;/key&gt;
    &lt;dict&gt;
    &lt;key&gt;NSAllowsArbitraryLoads&lt;/key&gt;
      &lt;true/&gt;
            &lt;key&gt;XXdomain&lt;/key&gt;
  
            &lt;dict&gt;
                    &lt;key&gt;NSExceptionAllowsInsecureHTTPLoads&lt;/key&gt;
                    &lt;true/&gt;
                    &lt;key&gt;NSExceptionRequiresForwardSecrecy&lt;/key&gt;
                    &lt;false/&gt;
            &lt;/dict&gt;
    &lt;/dict&gt;
  </code></pre>
  
  <p>But in the below delegate</p>
  
  <p>-(void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode</p>
  
  <p>I got the event code as 8 indicating errorOccured. With the above mentioned description.</p>
  
  <p><strong>Connection established properly through openSSL</strong></p>
  
  <p>openssl s_client -showcerts -connect XXX:ZZZ-ssl3</p>
  
  <p>CONNECTED(00000003)</p>
  
  <p>depth=3 /C=US/O=XXX, Inc./OU=XXXX</p>
  
  <p>verify error:num=19:self signed certificate in certificate chain</p>
  
  <p>verify return:0</p>
  
  <p>Certificate chain</p>
  
  <p>0 s:/C=US/ST=New York/L=New York/O=XXX/OU=XXX/CN=XXX
    i:/C=US/O=Symantec Corporation/OU=Symantec Trust Network/CN=Symantec Class 3 Secure Server CA - G4</p>
  
  <p>-----BEGIN CERTIFICATE</p>
  
  <p>MIIFGTCCBAGgAwIBAgIQbfM51mUYqjtW9jExlV1z6zANBgkqhkiG9w0BAQsFADB+
  ....
  VXDdeaPZWHp/cTAlAQ==</p>
  
  <p>-----END CERTIFICATE</p>
  
  <p>1 s:/C=US/O=Symantec Corporation/OU=Symantec Trust Network/CN=Symantec Class 3 Secure Server CA - G4
    i:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=(c) 2006 VeriSign, Inc. - For authorized use only/CN=VeriSign Class 3 Public Primary Certification Authority - G5
  -----BEGIN CERTIFICATE</p>
  
  <p>MIIFODCCBCCgAwIBAgIQUT+5dDhwtzRAQY0wkwaZ/zANBgkqhkiG9w0BAQsFADCB</p>
  
  <p>...
  Kvi4Os7X1g8RvmurFPW9QaAiY4nxug9vKWNmLT+sjHLF+8fk1A/yO0+MKcc=</p>
  
  <p>-----END CERTIFICATE</p>
  
  <p>2 s:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=(c) 2006 VeriSign, Inc. - For authorized use only/CN=VeriSign Class 3 Public Primary Certification Authority - G5
    i:/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
  -----BEGIN CERTIFICATE-----
  MIIE0DCCBDmgAwIBAgIQJQzo4DBhLp8rifcFTXz4/TANBgkqhkiG9w0BAQUFADBf
  ...
  tOxFNfeKW/9mz1Cvxm1XjRl4t7mi0VfqH5pLr7rJjhJ+xr3/
  -----END CERTIFICATE-----
  3 s:/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
    i:/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
  -----BEGIN CERTIFICATE</p>
  
  <p>MIICPDCCAaUCEDyRMcsf9tAbDpq40ES/Er4wDQYJKoZIhvcNAQEFBQAwXzELMAkG
  ...
  2HUw19JlYD1n1khVdWk/kfVIC0dpImmClr7JyDiGSnoscxlIaU5rfGW/D/xwzoiQ</p>
  
  <p>--END CERTIFICATE</p>
  
  <hr>
  
  <p>Server certificate</p>
  
  <p>subject=/C=US/ST=New York/L=New York/O=XXXX/OU=XXXe/CN=XXX</p>
  
  <p>issuer=/C=US/O=Symantec Corporation/OU=Symantec Trust Network/CN=Symantec Class 3 Secure Server CA - G4</p>
  
  <pre><code>No client certificate CA names sent
  
  SSL handshake has read 4655 bytes and written 434 bytes
  
  
  New, TLSv1/SSLv3, Cipher is AES256-SHA
  
  Server public key is 2048 bit
  Secure Renegotiation IS supported
  Compression: NONE
  Expansion: NONE
  SSL-Session:
  
  Protocol  : SSLv3
  
  Cipher    : AES256-SHA
  
  Session-ID: A159CA3FAFF5A23E7CE47C2C1DD21C91310A3820F5A5D1EDE38D451613CAE704
  
  Session-ID-ctx:
  
  Master-Key: XXXXX
  
  Key-Arg  : None
  
  Start Time: 1439320578
  
  Timeout  : 7200 (sec)
  </code></pre>
  
  <p>Verify return code: 0 (ok)</p>