serialization - Sending Crypto Objects via Java RMI -
i'm using java rmi send objects client -> server. primitive objects works fine(e.g. string etc.) java objects crypto library, throws exception. need these java objects settle on secret key in diffiehellman key exchange exception here:
exception in thread "main" java.rmi.marshalexception: error marshalling arguments; nested exception is: java.io.notserializableexception: javax.crypto.spec.dhparameterspec @ sun.rmi.server.unicastref.invoke(unknown source) @ java.rmi.server.remoteobjectinvocationhandler.invokeremotemethod(unknown source) @ java.rmi.server.remoteobjectinvocationhandler.invoke(unknown source) @ com.sun.proxy.$proxy0.diffieexchange(unknown source) @ rmihello.client.main(client.java:51) caused by: java.io.notserializableexception: javax.crypto.spec.dhparameterspec @ java.io.objectoutputstream.writeobject0(unknown source) @ java.io.objectoutputstream.writeobject(unknown source) @ sun.rmi.server.unicastref.marshalvalue(unknown source) ... 5 more
code
//the client public class client { public static void main(string[] args) throws exception { helloservice lookup = (helloservice) naming.lookup("rmi://localhost:5099/hello"); //some crypto stuff string username = console.next(); biginteger p1024 = biginteger.probableprime(1024, new securerandom()); biginteger g = biginteger.valueof(2); dhparameterspec dhparams = new dhparameterspec(p1024,g); //a module have generates keypairs keypair kp = diffiehellmanmodule.gendhkeypair(dhparams); publickey clientpubkey = kp.getpublic(); //@@@@@@@--fails--@@@@@@@ publickey serverpubkey = lookup.diffieexchange(clientpubkey,dhparams,username); } } //the interface rmi public interface helloservice extends remote{ public publickey diffieexchange(publickey clientpublickey, dhparameterspec dhparams,string username) throws remoteexception; } //the server servant implementing interface rmi public class helloservant extends unicastremoteobject implements helloservice{ protected helloservant() throws remoteexception { super(); } @override public publickey diffieexchange(publickey clientpublickey, dhparameterspec dhparams, string username) throws remoteexception { keypair key = diffiehellmanmodule.gendhkeypair(dhparams); publickey serverpubkey = key.getpublic(); homecoming serverpubkey; } } //the application server public class applicationserver { public static void main(string[] args) throws remoteexception, alreadyboundexception { registry registry = locateregistry.createregistry(5099); registry.rebind("hello", new helloservant()); } }
if they're not serializable,
can't utilize them in remote methods.
you may able them bytes, send bytes, , reconstitute them bytes @ receiver. have @ apis crypto objects of interest. crypto objects in java have getencoded()
methods, , factories or constructors can build them byte arrays.
java serialization cryptography rmi object-serialization
No comments:
Post a Comment