Which class should be used to create TLS connection in java. Socket class or SSLSocket class? -


i trying create simple java client connect port 5223 of presence server(openfire). presence server docs tell me port supports secure tls connections.

so try connect 5223 port using below code.

sslsocketfactory factory=(sslsocketfactory)sslsocketfactory.getdefault(); sslsocket socket= (sslsocket)factory.createsocket("host",5223); bufferedreader reader=new bufferedreader(new inputstreamreader(socket.getinputstream(),"utf-8")); bufferedwriter writer =new bufferedwriter(new outputstreamwriter(socket.getoutputstream(),"utf-8")); writer.write("some data"); writer.flush(); char r0[]= new char[600]; reader.read(r0); system.out.println(r0); 

this worked fine , see that(in wireshark) data sent responce received encrypted.

next tried below code

socket socket=new socket("host", 5223); bufferedreader reader=new bufferedreader(new inputstreamreader(socket.getinputstream(),"utf-8")); bufferedwriter writer =new bufferedwriter(new outputstreamwriter(socket.getoutputstream(),"utf-8")); writer.write("some data"); writer.flush(); char r0[]= new char[600]; reader.read(r0); system.out.println(r0); 

surpisingly(for me) works. issue being got 7 byte unexpected response in begining. when skipped response, other responses seem work fine , saw data encrypted(using wireshark).

i confused. if socket class able provide secured communication why should user sslsocket class.

any appreciated.

  • clearly documentation of server wrong in saying supports tls via port, and
  • clearly using starttls feature start plaintext connection , can upgrade tls issuing starttls command.

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -