Programmation RMI Sécurisée 5 janvier 2012 D après http ://blogs.oracle.com/lmalventosa/entry/using_the_ssl_tls_based. A Code RMI de Base A.1 Les fichiers Hello.java public i n t e r f a c e Hello extends Remote { public S t r i n g sayhello ( ) throws RemoteException ; super ( ) ; Registry = LocateRegistry. g e t R e g i s t r y ( null, 3000) ;. bind ( " HelloServer ", obj ) ; System. out. p r i n t l n ( " " ) ; HelloClient.java public c l a s s HelloClient { Registry = LocateRegistry. g e t R e g i s t r y ( null, 3000) ; / / Lookup t h e r e m o t e r e f e r e n c e bound t o t h e name " H e l l o S e r v e r " Hello obj = ( Hello ). lookup ( " HelloServer " ) ; S t r i n g message = obj. sayhello ( ) ; System. out. p r i n t l n ( message ) ;
RmiRegistry.java public c l a s s RmiRegistry { public s t a t i c void main ( S t r i n g [ ] args ) throws Exception { / / S t a r t RMI on p o r t 3000 LocateRegistry. c r e a t e R e g i s t r y ( 3 0 0 0 ) ; System. out. p r i n t l n ( "RMI running on port 3000 " ) ; / / S l e e p f o r e v e r Thread. sleep ( Long.MAX\_VALUE) ; A.2 Les commandes $ java RmiRegistry & RMI running on port 3000 $ java HelloImpl & $ java HelloClient B Utilisation de SSLRMI*SocketFactory B.3 Nouveau code pour HelloImpl super(0, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory()) ; Registry = LocateRegistry. g e t R e g i s t r y ( null, 3000) ;. bind ( " HelloServer ", obj ) ; System. out. p r i n t l n ( " " ) ; B.4 Commandes $ j a v a -Djavax.net.ssl.trustStore=truststore -Djavax.net.ssl.trustStorePassword=trustword RmiRegistry &
RMI running on port 3000 $ j a v a -Djavax.net.ssl.keyStore=keystore -Djavax.net.ssl.keyStorePassword=password HelloImpl & $ j a v a -Djavax.net.ssl.trustStore=truststore -Djavax.net.ssl.trustStorePassword=trustword HelloClient C Avec Authentification du Client C.5 Nouveau code super ( 0, new SslRMIClientSocketFactory ( ), new SslRMIServerSocketFactory(null, null, true) ) ; Registry = LocateRegistry. g e t R e g i s t r y ( null, 3000) ;. bind ( " HelloServer ", obj ) ; System. out. p r i n t l n ( " " ) ; C.6 commandes $ j a v a -Djavax.net.ssl.keyStore=keystore -Djavax.net.ssl.keyStorePassword=password Djavax. net. s s l. t r u s t S t o r e = t r u s t s t o r e Djavax. net. s s l. truststorepassword=trustword RmiRegistry & RMI running on port 3000 keystorepassword=password -Djavax.net.ssl.trustStore=truststore -Djavax.net.ssl.trustStorePassword=trustword HelloImpl &
$ j a v a -Djavax.net.ssl.keyStore=keystore -Djavax.net.ssl.keyStorePassword=password Djavax. net. s s l. t r u s t S t o r e = t r u s t s t o r e Djavax. net. s s l. truststorepassword=trustword HelloClient D Avec une Suite Cryptographique Précise D.7 Nouveau code super ( 0, new SslRMIClientSocketFactory ( ), new SslRMIServerSocketFactory(new String[] "SSL_RSA_WITH_RC4_128_MD5", new String[] "TLSv1",true) ) ; Registry = LocateRegistry. g e t R e g i s t r y ( null, 3000) ;. bind ( " HelloServer ", obj ) ; System. out. p r i n t l n ( " " ) ; D.8 Commandes Associées Djavax. net. s s l. truststorepassword=trustword -Djavax.rmi.ssl.client.enabledCipherSuites=SSL_RSA_WITH_RC4_128_MD5 -Djavax.rmi.ssl.client.enabledProtocols=TLSv1 RMI running on port 3000 RmiRegistry & Djavax. net. s s l. truststorepassword=trustword HelloImpl &
Djavax. net. s s l. truststorepassword=trustword -Djavax.rmi.ssl.client.enabledCipherSuites=SSL_RSA_WITH_RC4_128_MD5 -Djavax.rmi.ssl.client.enabledProtocols=TLSv1 HelloClient E Protection du Registry E.9 Nouveau code super ( 0, new SslRMIClientSocketFactory ( ), new SslRMIServerSocketFactory ( null, null, true ) ) ; Registry registry = LocateRegistry.getRegistry(null, 3000, new SslRMIClientSocketFactory()) ;. bind ( " HelloServer ", obj ) ; System. out. p r i n t l n ( " " ) ; HelloClient.java public c l a s s HelloClient { Registry registry = LocateRegistry.getRegistry(null, 3000, new SslRMIClientSocketFactory()) ; / / Lookup t h e r e m o t e r e f e r e n c e bound t o t h e name " H e l l o S e r v e r " Hello obj = ( Hello ). lookup ( " HelloServer " ) ; S t r i n g message = obj. sayhello ( ) ; System. out. p r i n t l n ( message ) ;
RmiRegistry.java public c l a s s RmiRegistry { public s t a t i c void main ( S t r i n g [ ] args ) throws Exception { / / S t a r t RMI on p o r t 3000 LocateRegistry.createRegistry(3000, new SslRMIClientSocketFactory(),new SslRMIServerSocketFactory(null, null, true)) ; System. out. p r i n t l n ( "RMI running on port 3000 " ) ; / / S l e e p f o r e v e r Thread. sleep ( Long.MAX_VALUE) ; E.10 Commandes Associées Djavax. net. s s l. truststorepassword=trustword RmiRegistry & RMI running on port 3000 Djavax. net. s s l. truststorepassword=trustword HelloImpl & Djavax. net. s s l. truststorepassword=trustword HelloClient