3

I am writing a prototype of cryptographic system using RMI.

I have a problem, because when I launch two clients, they got a response from one object in the server from OneTimePad class.

So client A recives key that was reserved for client b, because of specific algorithm, this situation could not happen.

Server send to the clients only E and N variable (like in RSA) so i can't serialize OneTimePad object and send it through the network (because it will have all keys in it).

How can I make for each client one object of OneTimePad class?

tshepang
  • 12,111
  • 21
  • 91
  • 136
user2263192
  • 65
  • 1
  • 5

1 Answers1

4

I called this the Remote Session pattern in my 2001 book. The remote object in the Registry is a kind of login server exporting only a login() method. The login() method, if successful, returns a new remote object per call, which is basically a per-client remote session object. This session object can export a logout() method, which unexports itself, and it can also implement Unreferenced, such that the unreferenced() method also unexports itself (or you can rely on DGC which des the same thing anyway: using Unreferenced gives you a chance to log it). This remote session object exports all the remote methods that a logged in client should have access to, and because it is per-client it can hold client state, hence it is a session.

public interface RemoteLogin extends Remote
{
    RemoteSession login() throws RemoteException;
}

public interface RemoteSession extends Remote
{
    void logout() throws RemoteException;
    void myMethod(...) throws RemoteException; // whatever you need
}

public class RemoteLoginImpl extends UnicastRemoteObject implements RemoteLogin
{
  // ...
  public RemoteSession login()
  {
    // ...
    return new RemoteSessionImpl(); // whatever arguments you need
  }
}

public class RemoteSessionImpl extends UnicastRemoteObject implements RemoteSession, Unreferenced
{
  // ...
}
user207421
  • 305,947
  • 44
  • 307
  • 483
  • Sounded complex. Where can I find your book? Thanks. – Paulo Pedroso Apr 09 '13 at 22:09
  • It's not complex, it's just a second remote object really. The book is Pitt & McNiff, *java.rmi: the Guide to Remote Method Invocation,* Addison Wesley 2001, but a google for 'Remote Session pattern' should find something useful too. – user207421 Apr 09 '13 at 22:24
  • Out of curiosity, I was having problems in my latest project to reconnect a client when this one changed IP address (when using wifi instead of cable when leaving for a meeting). In this case I was never able to reconnect. Is this simple or should I open a thread on this? – Paulo Pedroso Apr 09 '13 at 22:31
  • That's a new question, and I don't know what 'this one' means. – user207421 Apr 09 '13 at 23:07
  • 1
    @EJB Thank you! It worked flawlessly. I don't even have to make many changes in the code. Thank you very much, kind sir. (; – user2263192 Apr 11 '13 at 10:47