title: ssl socket write gives connection reset exception
body: <p>I am trying to send ios push notification using javapns library . the code is working fine on java 6 but not working on java 7 . I am trying to write on a ssl socket by java code 
    this.socket.getOutputStream().write(bytes);
  but getting following exception : - </p>
  
  <blockquote>
    <p>2015-09-24 02:01:17,330 [JavaPNS grouped notification thread in LIST
    mode] ERROR javapns.notification.PushNotificationManager
    (PushNotificationManager.java:496) - Delivery error
        java.net.SocketException: Connection reset
          at java.net.SocketInputStream.read(SocketInputStream.java:196) ~[?:1.7.0_79]
          at java.net.SocketInputStream.read(SocketInputStream.java:122) ~[?:1.7.0_79]
          at sun.security.ssl.InputRecord.readFully(InputRecord.java:442) ~[?:1.7.0_79]
          at sun.security.ssl.InputRecord.read(InputRecord.java:480) ~[?:1.7.0_79]
          at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
    ~[?:1.7.0_79]
          at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
    ~[?:1.7.0_79]
          at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:709)
    ~[?:1.7.0_79]
          at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
    ~[?:1.7.0_79]
          at java.io.OutputStream.write(OutputStream.java:75) ~[?:1.7.0_79]
          at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:464)
    [utils-1.0.jar:?]
          at javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:409)
    [utils-1.0.jar:?]
          at javapns.notification.transmission.NotificationThread.runList(NotificationThread.java:283)
    [utils-1.0.jar:?]
          at javapns.notification.transmission.NotificationThread.run(NotificationThread.java:254)
    [utils-1.0.jar:?]
          at java.lang.Thread.run(Thread.java:745) [?:1.7.0_79]</p>
  </blockquote>
  
  <p>Following are my ssl debug log : -</p>
  
  <pre><code>*** Certificate chain
  
  chain [0] = [
  [
    Version: V3
    Subject: ........
    Signature Algorithm: SHA256withRSA, OID = 1.2.840.113549.1.1.11
  
    Key:  Sun RSA public key, 2048 bits
    modulus: 22222491044564264786925450301128660800404037455402211937155693765439451266775814064935111308236503917661658380453607223444671197507922227372310694498331784203397249559620562506847738658137494429967865235154139927237328515659798669693649542833648664525838898423359833650942229563615420055801398510282090750116916759108752545159033267269553610447830532132801594757535863574777003658295660123855620269370519852284530709335738820289388013418673721050782042119531816409879900413319632795054390149130447840278225455201462347192736907867086706041266601675705875530393925455170420669674672723643704537136254104782678046353641
    public exponent: 65537
    Validity: [From: Thu Jul 16 12:10:32 IST 2015,
                 To: Fri Jul 15 12:10:32 IST 2016]
    Issuer: CN=Apple Worldwide Developer Relations Certification Authority, OU=Apple Worldwide Developer Relations, O=Apple Inc., C=US
    SerialNumber: [    25dea3f4 f4f072b3]
  
  Certificate Extensions: 8
  [1]: ObjectId: 1.2.840.113635.100.6.1.2 Criticality=true
  Extension unknown: DER encoded OCTET string =
  0000: 04 02 05 00                                        ....
  
  
  [2]: ObjectId: 1.3.6.1.5.5.7.1.1 Criticality=false
  AuthorityInfoAccess [
    [
     accessMethod: ocsp
     accessLocation: URIName: http://ocsp.apple.com/ocsp03-wwdr01
  ]
  ]
  
  [3]: ObjectId: 2.5.29.35 Criticality=false
  AuthorityKeyIdentifier [
  KeyIdentifier [
  0000: 88 27 17 09 A9 B6 18 60   8B EC EB BA F6 47 59 C5  .'.....`.....GY.
  0010: 52 54 A3 B7                                        RT..
  ]
  ]
  
  [4]: ObjectId: 2.5.29.19 Criticality=true
  BasicConstraints:[
    CA:false
    PathLen: undefined
  ]
  
  [5]: ObjectId: 2.5.29.32 Criticality=false
  CertificatePolicies [
    [CertificatePolicyId: [1.2.840.113635.100.5.1]
  [PolicyQualifierInfo: [
    qualifierID: 1.3.6.1.5.5.7.2.2
    qualifier: 0000: 30 81 B6 0C 81 B3 52 65   6C 69 61 6E 63 65 20 6F  0.....Reliance o
  0010: 6E 20 74 68 69 73 20 63   65 72 74 69 66 69 63 61  n this certifica
  0020: 74 65 20 62 79 20 61 6E   79 20 70 61 72 74 79 20  te by any party 
  0030: 61 73 73 75 6D 65 73 20   61 63 63 65 70 74 61 6E  assumes acceptan
  0040: 63 65 20 6F 66 20 74 68   65 20 74 68 65 6E 20 61  ce of the then a
  0050: 70 70 6C 69 63 61 62 6C   65 20 73 74 61 6E 64 61  pplicable standa
  0060: 72 64 20 74 65 72 6D 73   20 61 6E 64 20 63 6F 6E  rd terms and con
  0070: 64 69 74 69 6F 6E 73 20   6F 66 20 75 73 65 2C 20  ditions of use, 
  0080: 63 65 72 74 69 66 69 63   61 74 65 20 70 6F 6C 69  certificate poli
  0090: 63 79 20 61 6E 64 20 63   65 72 74 69 66 69 63 61  cy and certifica
  00A0: 74 69 6F 6E 20 70 72 61   63 74 69 63 65 20 73 74  tion practice st
  00B0: 61 74 65 6D 65 6E 74 73   2E                       atements.
  
  ], PolicyQualifierInfo: [
    qualifierID: 1.3.6.1.5.5.7.2.1
    qualifier: 0000: 16 2A 68 74 74 70 3A 2F   2F 77 77 77 2E 61 70 70  .*http://www.app
  0010: 6C 65 2E 63 6F 6D 2F 63   65 72 74 69 66 69 63 61  le.com/certifica
  0020: 74 65 61 75 74 68 6F 72   69 74 79 2F              teauthority/
  
  ]]  ]
  ]
  
  [6]: ObjectId: 2.5.29.37 Criticality=true
  ExtendedKeyUsages [
    codeSigning
  ]
  
  [7]: ObjectId: 2.5.29.15 Criticality=true
  KeyUsage [
    DigitalSignature
  ]
  
  [8]: ObjectId: 2.5.29.14 Criticality=false
  SubjectKeyIdentifier [
  KeyIdentifier [
  0000: 6F FB BD 5A 59 70 1C 2E   77 32 9A 97 69 C3 23 0E  o..ZYp..w2..i.#.
  0010: EF D8 E9 D0                                        ....
  ]
  ]
  
  ]
    Algorithm: [SHA256withRSA]
    Signature:
  0000: 90 BE B9 5B E7 66 C1 B4   C1 C8 60 90 69 5F 01 04  ...[.f....`.i_..
  0010: 2B C4 E6 9E 8D 13 8C A7   3F 81 55 6C CD D1 47 48  +.......?.Ul..GH
  0020: 3C D7 D8 3E F5 C2 69 A7   A2 21 CE 15 08 F7 D9 8C  &lt;..&gt;..i..!......
  0030: 2D FE 37 29 AD DC E3 CA   27 27 83 2C 15 95 4D 40  -.7)....''.,..M@
  0040: EA 2C AD EF 99 7C 9B 84   59 3F 6C E6 BA 07 F4 EC  .,......Y?l.....
  0050: 05 36 E4 58 EA B0 DF 00   AB 54 F2 FF 6B AE C2 C1  .6.X.....T..k...
  0060: E4 3C D3 23 79 61 D1 67   DD 0C 0D 2B 77 E0 8E 6F  .&lt;.#ya.g...+w..o
  0070: A2 7B 21 13 D2 4F D7 8B   98 A7 E0 22 E9 95 D7 1A  ..!..O....."....
  0080: C5 71 0A 15 35 77 38 37   EC F9 CC 60 79 2D A5 E0  .q..5w87...`y-..
  0090: DA C2 78 AD 59 88 7B 92   93 66 9A 44 F7 58 8C 0D  ..x.Y....f.D.X..
  00A0: 28 E3 42 D0 79 DC F5 23   C7 36 D0 61 0A 34 61 F3  (.B.y..#.6.a.4a.
  00B0: 16 AE 7B D8 8B BC B8 6B   D6 05 C4 E4 EF B0 BF 4B  .......k.......K
  00C0: 66 E1 6F 59 EC 67 F6 A3   C0 49 7A 83 8A 7B FC 7B  f.oY.g...Iz.....
  00D0: 26 3C 42 16 F7 DE DB 74   4D 1A A5 7F AE C2 36 C4  &amp;&lt;B....tM.....6.
  00E0: 8E 5A F9 75 05 3A A5 13   70 0C 69 96 00 CB FD 77  .Z.u.:..p.i....w
  00F0: 4A 9E C8 E4 AA 39 75 7D   6D C9 79 04 BC DF 59 EF  J....9u.m.y...Y.
  
  ]
  ***
  *** ClientKeyExchange, RSA PreMasterSecret, TLSv1
  JavaPNS grouped notification thread in LIST mode, WRITE: TLSv1 Handshake, length = 1729
  SESSION KEYGEN:
  PreMaster Secret:
  0000: 03 01 00 2E C1 C7 9F 24   B2 E9 02 59 7B D2 8A A7  .......$...Y....
  0010: 22 D3 72 B2 16 55 5F 5C   E1 30 7D 4A 56 F1 3C 32  ".r..U_\.0.JV.&lt;2
  0020: 5D 77 8F 13 BD B0 E9 6A   84 9E 81 0D 0B 38 D5 0E  ]w.....j.....8..
  CONNECTION KEYGEN:
  Client Nonce:
  0000: 56 03 10 94 63 A2 8C A1   6D 75 2F F0 38 EC CD 4F  V...c...mu/.8..O
  0010: 3A D6 46 C7 C4 2D 5F 76   4B 38 3F FC 28 59 6B 04  :.F..-_vK8?.(Yk.
  Server Nonce:
  0000: B2 1F 50 60 42 F5 94 7A   5B 7C FE 50 60 3E 84 BC  ..P`B..z[..P`&gt;..
  0010: CB 18 B7 B1 E8 50 56 6E   F9 DD 6E E2 B9 34 25 01  .....PVn..n..4%.
  Master Secret:
  0000: 03 87 6A 7D 0E 69 76 FA   5F 2E 48 BB B7 77 79 0F  ..j..iv._.H..wy.
  0010: 5E 59 CF 32 BA B5 D7 2E   0F 9D 43 F2 4F F1 CD 52  ^Y.2......C.O..R
  0020: DF A7 05 EB 47 BF FD 18   48 F0 DD F1 78 10 47 FF  ....G...H...x.G.
  Client MAC write Secret:
  0000: ED B5 4A 85 1D CC 96 D2   D0 94 29 40 AE 8F C3 10  ..J.......)@....
  0010: 74 52 24 8D                                        tR$.
  Server MAC write Secret:
  0000: B9 ED CD B7 30 52 1F 74   9E 47 71 41 2A 1B 90 C7  ....0R.t.GqA*...
  0010: AF 2F 93 4E                                        ./.N
  Client write key:
  0000: A0 B0 7C 23 2F C7 A3 5D   24 03 B4 1F F9 2B B2 97  ...#/..]$....+..
  Server write key:
  0000: 29 4C 64 FB 39 02 96 43   7A 5B F5 1D D4 2A 51 B7  )Ld.9..Cz[...*Q.
  Client write IV:
  0000: 85 3C C4 38 B4 9F 41 92   B6 88 7A 47 F6 B9 82 C1  .&lt;.8..A...zG....
  Server write IV:
  0000: FA 04 7C A8 D7 29 A3 0D   5F 20 BF 3C 4C C8 52 9A  .....).._ .&lt;L.R.
  *** CertificateVerify
  JavaPNS grouped notification thread in LIST mode, WRITE: TLSv1 Handshake, length = 262
  JavaPNS grouped notification thread in LIST mode, WRITE: TLSv1 Change Cipher Spec, length = 1
  *** Finished
  verify_data:  { 221, 26, 21, 239, 125, 223, 149, 73, 149, 170, 46, 218 }
  ***
  JavaPNS grouped notification thread in LIST mode, WRITE: TLSv1 Handshake, length = 48
  JavaPNS grouped notification thread in LIST mode, handling exception: java.net.SocketException: Connection reset
  %% Invalidated:  [Session-2, TLS_RSA_WITH_AES_128_CBC_SHA]
  JavaPNS grouped notification thread in LIST mode, SEND TLSv1 ALERT:  fatal, description = unexpected_message
  JavaPNS grouped notification thread in LIST mode, WRITE: TLSv1 Alert, length = 32
  JavaPNS grouped notification thread in LIST mode, Exception sending alert: java.net.SocketException: Broken pipe
  JavaPNS grouped notification thread in LIST mode, called closeSocket()
  JavaPNS grouped notification thread in LIST mode, called close()
  JavaPNS grouped notification thread in LIST mode, called closeInternal(true)
  
  
  abhishek$ which openssl
  /usr/bin/openssl
  abhishek$ openssl version
  OpenSSL 1.0.2d 9 Jul 2015
  
  abhishek$ java -version
  java version "1.7.0_79"
  Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
  Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
  </code></pre>
  
  <p>Edit : When I printed this SSLSession </p>
  
  <pre><code>    SSLSession session = socket.getSession();
  //I got [Session-1, SSL_NULL_WITH_NULL_NULL] 
  </code></pre>
  
  <p>// Returns the SSL Session in use by this connection. These can be long lived, and frequently correspond to an entire login session for some user. The session specifies a particular cipher suite which is being actively used by all connections in that session, as well as the identities of the session's client and server.
  This method will initiate the initial handshake if necessary and then block until the handshake has been established.
  If an error occurs during the initial handshake, this method returns an invalid session object which reports an invalid cipher suite of "SSL_NULL_WITH_NULL_NULL".</p>
  
  <p>System.out.println(session.getLocalCertificates());
      // I got null
      While Using same certificates in java 6 I did not get null .</p>