Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Implementing SSL Sockets onto an Existing Java Application Server

Posted on 2005-03-31
6
Medium Priority
?
282 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
  • 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
Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

 

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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

When you put your credit card number into a website for an online transaction, surely you know to look for signs of a secure website such as the padlock icon in the web browser or the green address bar.  This is one way to protect yourself from oth…
Spectre and Meltdown, how it affects me and my clients?
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Suggested Courses

572 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