In this post I will demonstrate how a Java Remote Method Invocation (RMI) application can make remote invocations over Secure Socket Layer (SSL) connections.
Environment
Microsoft Windows 7
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)
Before we actually start coding the RMI Client and Server, we have to do following:
- Create a KeyStore and Generate a Public-Private Key
- Export a X.509 Certificate against above Key into a file
- Create a TrustStore and Import X.509 Certificate as a Trusted Certificate
Define RMI Remote Interface
Implement RMI Remote Interface
Create RMI Client which will consume/invoke RMI method remotely
Finally, create RMI Registry
Copy ‘test-keystore’ created here and ‘test-truststore’ created here to the folder where your compiled classes reside.
Now, open up a console/command prompt and ‘cd’ to the directory where your compiled class files are, and:
Run RMIRegistry
java -Djavax.net.ssl.keyStore=test-keystore -Djavax.net.ssl.keyStorePassword=test-keystore-pwd -Djavax.net.ssl.trustStore=test-truststore -Djavax.net.ssl.trustStorePassword=test-truststore-pwd smhumayun.codeoftheday.RmiOverSslTest.RmiRegistry
Run CentralTimeServiceImpl
java -Djavax.net.ssl.keyStore=test-keystore -Djavax.net.ssl.keyStorePassword=test-keystore-pwd -Djavax.net.ssl.trustStore=test-truststore -Djavax.net.ssl.trustStorePassword=test-truststore-pwd smhumayun.codeoftheday.RmiOverSslTest.CentralTimeServiceImpl
Run CentralTimeServiceClient
java -Djavax.net.ssl.keyStore=test-keystore -Djavax.net.ssl.keyStorePassword=test-keystore-pwd -Djavax.net.ssl.trustStore=test-truststore -Djavax.net.ssl.trustStorePassword=test-truststore-pwd smhumayun.codeoftheday.RmiOverSslTest.CentralTimeServiceClient
No comments:
Post a Comment