dcsimg
RMI/SSL not all messages encrypted
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Federico_Martinez
Posted On:   Tuesday, January 4, 2011 09:47 AM

Hello, Well months ago I finished an implementation of RMI over SSL but now my course assistant tells me that the messages from the server to the client are not encrypted. When creating the server I'm sure that I use SslRMIServerSocketFactory so I don't understand why the messages aren't encrypted. 1. How can I assure that the messages (Client->Server AND Server->Client) will be encrypted? 2. On wireshark how can I see the traffic generated from my application? My code is the following: CLIENT CODE import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; import javax.rmi.ssl.SslRMIClientSocketFactory; import java.io.Serializable;    More>>

Hello,

Well months ago I finished an implementation of RMI over SSL but now my course assistant tells me that the messages from the server to the client are not encrypted. When creating the server I'm sure that I use SslRMIServerSocketFactory so I don't understand why the messages aren't encrypted.

1. How can I assure that the messages (Client->Server AND Server->Client) will be encrypted?
2. On wireshark how can I see the traffic generated from my application?
My code is the following:

CLIENT CODE

			
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import java.io.Serializable;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Scanner;
import java.rmi.RemoteException;

/**
* Implementation of the IRC server
* @author elr, brabbit (fhml)
*/
public class Client implements IRCClient, Serializable{

/** Serial version UID */
private static final long serialVersionUID = -7462568329203430064L;

/** Name for the RMI registry */
private static final String RMIRegistryName = "IRCServer";

/** User Name */
private String userName;
/** IRC Server */
private IRCServer server;
/** IRC Message flag*/
private boolean receiverOK;

/**
* Main method of the IRC client
* @param args Command line arguments
*/
public static void main(String[] args) throws Exception{
System.setProperty("javax.net.ssl.keyStore", "keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "XXX");
System.setProperty("javax.net.ssl.trustStore", "truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "YYY");

String hostname = args[0];
String nickname = args[1];

Registry registry = LocateRegistry.getRegistry(hostname, 3000, new SslRMIClientSocketFactory());

IRCServer server = (IRCServer) registry.lookup(RMIRegistryName);

Client c = new Client(server, nickname);
UnicastRemoteObject.exportObject(c,0);
c.run();

}



/**
* Create a new IRC server
* @throws RemoteException
*/
protected Client(IRCServer server, String userName) throws RemoteException{
super();
this.userName = userName;
this.server = server;
}

private void doWho() throws RemoteException, IRCException{
for (String userName : server.getClientNames(this)) {
System.out.println(userName);
}
}

private void doQuit() throws RemoteException, IRCException{
server.disconnect(this);
}

private void doMsg(String receiverName, String message) throws RemoteException, IRCException{
server.sendMessageTo(this, receiverName, message);
}

public void run(){
try{
this.server.connect(this);
System.out.println("
Welcome to the IRC Channel

");
Scanner scanner = new Scanner(System.in);
while (true) {
String cmd;

System.out.print("#");
cmd = scanner.nextLine().trim();

if (cmd.equals("")) {
continue;
}

if (cmd.equals("who")) {
this.doWho();
} else if (cmd.equals("msg")) {
String receiverName, message;
receiverOK = true;
do {
System.out.print("To whom? ");
receiverName = scanner.nextLine().trim();
if (receiverName.equals(this.userName)) {
System.out.println("Can't send a message to yourself.");
receiverOK = false;
break;
}
} while (receiverName.equals(""));

if (receiverOK == true){
do {
System.out.print("message: ");
message = scanner.nextLine().trim();
} while (message.equals(""));
this.doMsg(receiverName, message);
}
} else if (cmd.equals("quit")) {
this.doQuit();
break;
} else {
System.out.println("Unknown command");
System.out.println("Available commands are: who, msg and quit");
}
}
System.exit(0);
}
catch (Exception error)
{
System.err.println("IRClient exception:");
error.printStackTrace();
}


}

/**
* Get this client's name
*

This method must always reply with the same name for a given instance.
* @return This client's name
*/
public String getName() throws RemoteException{
return this.userName;
}

/**
* Receive a message from another user
* @param senderName Sender's name
* @param message Message to be delivered
*/
public void receive(String senderName, String message) throws RemoteException, IRCException{
System.out.println("Message from " + senderName + ": " + message);
}

/**
* Notify that another user connected to the server
* @param userName Name of the new user
*/
public void notifyConnection(String userName) throws RemoteException, IRCException{
System.out.println(userName + " joined the room");
}

/**
* Notify that another user disconnected from the server
* @param userName Name of the disconnected user
*/
public void notifyDisconnection(String userName) throws RemoteException, IRCException{
System.out.println(userName + " left");
}
}




SERVER CODE

			
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.RemoteException;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

/**
* Implementation of the IRC server
* @author sjrd, brabbit (fhml)
*/
public class Server extends UnicastRemoteObject implements IRCServer
{
/** Serial version UID */
private static final long serialVersionUID = -3495888953276051388L;

/** Name for the RMI registry */
private static final String RMIRegistryName = "IRCServer";

/** Connected clients */
private final Map clients = new HashMap ();

/**
* Constructor of class Server
*/
public Server() throws RemoteException {
super(0, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory(null, null, true));
}

/**
* Main method of the IRC server
* @param args Command line arguments
*/
public static void main(String[] args) throws Exception{

System.setProperty("javax.net.ssl.keyStore", "keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "XXX");
System.setProperty("javax.net.ssl.trustStore", "truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "YYY");

Registry registry = LocateRegistry.createRegistry(3000,
new SslRMIClientSocketFactory(),
new SslRMIServerSocketFactory(null, null, true));
System.out.println("RMI registry running on port 3000");

Server obj = new Server();
registry.bind(RMIRegistryName, obj);
System.out.println("IRCServer bound in registry");
}

/**
* {@inheritDoc}
*/
@Override
public void connect(IRCClient sender) throws RemoteException, IRCException
{
final String userName = sender.getName();

if (clients.containsKey(userName)){
throw new IRCException("User name already exists");
}

clients.put(userName, sender);

for (final IRCClient client: clients.values())
{
if (client != sender)
{
client.notifyConnection(userName);
}
}
}

/**
* {@inheritDoc}
*/
@Override
public void disconnect(IRCClient sender)
throws RemoteException, IRCException
{
assertClientExists(sender);

final String userName = sender.getName();

clients.remove(userName);

for (final IRCClient client: clients.values())
{
client.notifyDisconnection(userName);
}
}

/**
* {@inheritDoc}
*/
@Override
public List getClientNames(IRCClient sender) throws RemoteException, IRCException{
assertClientExists(sender);
return new ArrayList (clients.keySet());
}

/**
* {@inheritDoc}
*/
@Override
public void sendMessageTo(IRCClient sender, String receiverName,
String message) throws RemoteException, IRCException
{
assertClientExists(sender);

IRCClient receiver = clients.get(receiverName);

if (receiver == null)
throw new IRCException(String.format(
"Client %s is not connected", receiverName));

receiver.receive(sender.getName(), message);
}

/**
* Make sure that a sender client is indeed connected to this server
* @param client Client to check
* @throws RemoteException
* @throws IRCException
*/
private void assertClientExists(IRCClient client) throws RemoteException, IRCException{

final String userName = client.getName();
if (!clients.get(userName).equals(client))
throw new IRCException(String.format("Client %s is not connected", userName));
}
}
   <<Less
About | Sitemap | Contact