Problems trying to retro fit SSL to server

Hi all, im trying put SSL sockets into my server, but am encountering a few problems, mainly with the following two lines

SSLSocket sslsocket = (SSLSocket) sslserversocket.accept();

in my Accept function (null pointer exception - trying to cast a Socket to an SSLSocket?)

and

//sslserversocket = new SSLServerSocket( port );

in my Listen function

Apologies for the full code listing and the fact that it is littered with older element of the server, but they may be the sources of the problem :-)

Thanks in advance

Full Code listing

import java.io.*;

import java.net.*;

import javax.net.ssl.*;

public class NetInterface

{

private SSLSocket sslsocket;

private ServerSocket connection;

private SSLServerSocket sslserversocket;

private SSLServerSocketFactory sslserversocketfactory;

private DataInputStream dinput;

private DataOutputStream doutput;

public final static int DEFAULT_SERVER_PORT = 5000;

public NetInterface()

{

sslserversocket = null;

}

public NetInterface( SSLSocket socket ) throws IOException

{

this();

SSLServerSocketFactory sslserversocketfactory =

(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();

SSLServerSocket sslserversocket =

(SSLServerSocket) sslserversocketfactory.createServerSocket(DEFAULT_SERVER_PORT);

//SSLSocket sslsocket = (SSLSocket) sslserversocket.accept();

dinput = new DataInputStream( sslsocket.getInputStream() );

doutput = new DataOutputStream( sslsocket.getOutputStream() );

}

public boolean Connect( String ip, int port )

{

try

{

dinput = new DataInputStream(sslsocket.getInputStream());

doutput = new DataOutputStream(sslsocket.getOutputStream());

return true;

}

catch( Exception ex )

{

return false;

}

}

public boolean Disconnect()

{

try

{

dinput.close();

doutput.close();

sslsocket.close();

if( sslserversocket != null )

sslserversocket.close();

return true;

}

catch( Exception ex )

{

return false;

}

}

public boolean Listen( int port )

{

try

{

sslserversocket = new SSLServerSocket( port );

}

catch( Exception ex )

{

return false;

}

return true;

}

public NetInterface Accept()

{

NetInterface netio;

try {

//SSLServerSocket needs to call an accept method!

SSLSocket sslsocket = (SSLSocket) sslserversocket.accept();

//Socket s = connection.accept();

netio = new NetInterface( sslsocket );

}catch( IOException ex )

{

return null;

}

return netio;

}

}

[2885 byte] By [eljackstera] at [2007-10-1 9:36:21]
# 1
Help anyone? anything I can do to elicit more help?Please and Thank you in advance.
eljackstera at 2007-7-10 2:02:10 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2

> Hi all, im trying put SSL sockets into my server, but

> am encountering a few problems, mainly with the

> following two lines

>

> SSLSocket sslsocket = (SSLSocket)

> sslserversocket.accept();

> in my Accept function (null pointer exception -

> trying to cast a Socket to an SSLSocket?)

> and

> //sslserversocket = new SSLServerSocket( port );

> in my Listen function

Looks to me like you never actually set up your sslserversocket. So, it's still null. So, sslserversocket.accept() throws an NPE.

Uncomment out that line in your Listen function.

Grant

(PS - and please use the [ code ] tags when you post code...)

ggaineya at 2007-7-10 2:02:10 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 3

>public boolean Listen( int port )

>{

>try

>{

>sslserversocket = new SSLServerSocket( port );

The last line above doesn't even compile. No wonder it doesn't run.

This code is so confused ... you need to go back to your original and start again.

ejpa at 2007-7-10 2:02:10 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...