?
Solved

Implementing SSL Sockets onto an Existing Java Application Server

Posted on 2005-03-31
6
Medium Priority
?
280 Views
Last Modified: 2010-04-11
I have been trying, unsuccessfully, to change my sockets over to SSL sockets.
My various attempts have ended in failure and I was hoping for some pointers in the right direction
My functions are called elsewhere, so i would like to keep the structure as close to its current state as possible

Below is the original code

[ code ]

import java.io.*;
import java.net.*;

public class NetInterface
{
  private Socket socket;
  private ServerSocket connection;
  private DataInputStream dinput;
  private DataOutputStream doutput;

  public final static int DEFAULT_SERVER_PORT = 5000;

  public NetInterface()
  {
    connection = null;
  }

  public NetInterface( Socket socket ) throws IOException
  {
    this();
    dinput = new DataInputStream( socket.getInputStream() );
    doutput = new DataOutputStream( socket.getOutputStream() );
  }

  public boolean Connect( String ip, int port )
  {
    try
    {
      socket = new Socket( ip, port );
      dinput = new DataInputStream(socket.getInputStream());
      doutput = new DataOutputStream(socket.getOutputStream());
      return true;
    }
    catch( Exception ex )
    {
      return false;
    }
  }

  public boolean Disconnect()
  {
    try
    {
      dinput.close();
      doutput.close();
      socket.close();
      if( connection != null )
        connection.close();
      return true;
    }
    catch( Exception ex )
    {
      return false;
    }
  }


  public boolean Listen( int port )
  {
    try
    {
      connection = new ServerSocket( port );
    }
    catch( Exception ex )
    {
      return false;
    }
    return true;
  }

  public NetInterface Accept()
  {
    NetInterface netio;
    try
    {
      Socket s = connection.accept();
      netio = new NetInterface( s );
    }
    catch( IOException ex )
    {
      return null;
    }
    return netio;
  }

}

[ /code ]
0
Comment
Question by:Dcom4CIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13675971
where is your call to Connect() and Listen() ?
where did you specify to use HTTPS/SSL?
0
 

Author Comment

by:Dcom4CIT
ID: 13679146
The Connect() and Listen() methods are called separately from my Server class, but im beginning to believe this could be part of the problem...

[quote]
where did you specify to use HTTPS/SSL?
[\quote]

Not quite sure if this answers this question but:

-Djavax.net.ssl.keyStore=SSLStore -Djavax.net.ssl.keyStorePassword=***** Server
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 1000 total points
ID: 13679325
> Not quite sure if this answers this question but:
hmm, no.
You need to tell the socket somehow that the protocol is SSL. Then your java class (javax.net.ssl) uses the given credentials.

BTW, you set the credentials to javax.* but you include java.*
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 

Author Comment

by:Dcom4CIT
ID: 13679572
The above code is the original code for the server.
At the moment I have an SSL socket version that doesn't have any (apparent!) bugs or errors.

The socket server runs ok, but the client appears to hang.

Shall i post the new version?

Thanks for your help so far,
J.
0
 

Author Comment

by:Dcom4CIT
ID: 13680016
Thank for all your help, but have resolved the problems myself after some painful trial and error :)

below is the SSL Socket enabled version of the above code

the only changes being
connection = new ServerSocket( port );
becomes
connection = SecureServerSocketFactory.getDefault().createServerSocket(port);
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13680480
hmm, I'm not that deep in all java classes, but sounds that this s exactly what I said in http:#13679325 : you need to tell the socket which protocol to use
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question