0
안녕 난 그냥 SSL로 시작 그리고 난 아주 간단한 예를 만들고 싶어, 여기에 코드입니다.는 RMI SSL을 통해 :</p> <p>인터페이스 : 핸드 셰이크 실패
package tpfinal;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface CentralTimeService extends Remote {
int PORT = 8844;
long getTime() throws RemoteException;
}
클라이언트 :
package tpfinal;
import java.rmi.AccessException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.rmi.ssl.SslRMIClientSocketFactory;
public class CentralTimeServiceClient {
public static void main(String[] args) {
try {
System.setProperty("javax.net.ssl.keyStore","C:\\Users\\luciano\\workspace\\Distribuida\\bin\\keystore");
System.setProperty("javax.net.ssl.keyStorePassword","123456");
System.setProperty("javax.net.ssl.trustStore","C:\\Users\\luciano\\workspace\\Distribuida\\bin\\truststore");
System.setProperty("javax.net.ssl.trustStorePassword","123456");
Registry registry = LocateRegistry.getRegistry(null, CentralTimeService.PORT, new SslRMIClientSocketFactory());
CentralTimeService cts = (CentralTimeService) registry.lookup("CentralTimeService");
//Invocamos llamada RMI
long serverTime = cts.getTime();
System.out.println(serverTime);
System.out.println("Central server time is: " + SimpleDateFormat.getDateInstance().format(new Date(serverTime)));
} catch (AccessException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NotBoundException e) {
e.printStackTrace();
}
}
}
서버 :
패키지 tpfinal;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
public class CentralTimeServiceImpl extends UnicastRemoteObject implements CentralTimeService {
protected CentralTimeServiceImpl() throws RemoteException{
super(0, new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory(null, null, true));
System.setProperty("javax.net.ssl.keyStore","C:\\Users\\luciano\\workspace\\Distribuida\\bin\\keystore");
System.setProperty("javax.net.ssl.keyStorePassword","123456");
System.setProperty("javax.net.ssl.trustStore","C:\\Users\\luciano\\workspace\\Distribuida\\bin\\truststore");
System.setProperty("javax.net.ssl.trustStorePassword","123456");
}
@Override
public long getTime() throws RemoteException {
return System.currentTimeMillis();
}
public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry(null, CentralTimeService.PORT, new SslRMIClientSocketFactory());
CentralTimeServiceImpl ctsi = new CentralTimeServiceImpl();
registry.bind("CentralTimeService", ctsi);
System.out.println("Central time service bound in registry");
} catch (Exception e) {
System.out.println("Central time error: " + e.getMessage());
e.printStackTrace();
}
}
}
그리고 마지막으로 rmiregistry에
:package tpfinal;
import java.rmi.registry.LocateRegistry;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
public class RmiRegistry {
public static void main(String[] args) throws Exception {
LocateRegistry.createRegistry(CentralTimeService.PORT,new SslRMIClientSocketFactory(), new SslRMIServerSocketFactory(null, null, true));
System.out.println("Rmi Registry running on port " + CentralTimeService.PORT);
System.setProperty("javax.net.ssl.keyStore","C:\\Users\\luciano\\workspace\\Distribuida\\bin\\keystore");
System.setProperty("javax.net.ssl.keyStorePassword","123456");
System.setProperty("javax.net.ssl.trustStore","C:\\Users\\luciano\\workspace\\Distribuida\\bin\\truststore");
System.setProperty("javax.net.ssl.trustStorePassword","123456");
//Sleep
Thread.sleep(Long.MAX_VALUE);
}
}
내가 레지스트리가 잘 작동 실행하지만 서버를 실행할 때 날이 오류를주고 내가 이유를 알아낼 수 없습니다.
Central time error: error during JRMP connection establishment; nested exception is:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at tpfinal.CentralTimeServiceImpl.main(CentralTimeServiceImpl.java:31)
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.writeRecord(Unknown Source)
at sun.security.ssl.AppOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
at java.io.DataOutputStream.flush(Unknown Source)
감사합니다. 사전에 감사드립니다.
감사합니다. @EJP는 어리석은 실수였습니다. 매우 유용한 정보 –