0
誰かが私がこのコードで間違っていることを教えてください。サーバー側が動作しているようです。サーバー側のコードを実行すると、サーバーはクライアントが接続を要求するのを待ちます。私は、クライアントのコードを実行すると、それはクライアント側で次の例外がスローされます。SSLHandshakeException:共通の暗号スイートがない(JAVA)
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.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at LoginDialog.doConnectToServer(LoginDialog.java:208)
at LoginDialog.<init>(LoginDialog.java:67)
at ClientSideMain.main(ClientSideMain.java:5)
Press any key to continue . . .
とサーバ側で以下の例外:
javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLHandshakeException: no cipher suites in common
at sun.security.ssl.SSLSocketImpl.checkEOF(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at Talker.recieve(Talker.java:78)
at CTC.run(CTC.java:49)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.net.ssl.SSLHandshakeException: no cipher suites in common
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ServerHandshaker.chooseCipherSuite(Unknown Source)
at sun.security.ssl.ServerHandshaker.clientHello(Unknown Source)
at sun.security.ssl.ServerHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(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 sun.security.ssl.AppOutputStream.write(Unknown Source)
at java.io.DataOutputStream.writeBytes(Unknown Source)
at Talker.send(Talker.java:58)
at CTC.send(CTC.java:344)
at CTC.<init>(CTC.java:31)
at ServerSide.<init>(ServerSide.java:73)
at ServerSideMain.main(ServerSideMain.java:5)
サーバーサイドコード
public class ServerSide
{
ServerSocket serverSocket;
Socket regSocket;
Hashtable<String,User> userList;
CTC tempCTC;
File f;
DataInputStream in;
BufferedReader br;
SSLContext sslContext;
KeyManagerFactory keyManagerFactory;
KeyStore keyStore;
char[] keyStorePassphrase;
SSLServerSocketFactory sslServerSocketFactory;
SSLServerSocket sslServerSocket;
SSLSocket sslNormalSocket;
ServerSide()
{
f = new File("userlist.txt");
userList = new Hashtable<String, User>();
loadUsers(f);
try
{
sslContext = SSLContext.getInstance("SSL");
keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyStore = KeyStore.getInstance("JKS");
keyStorePassphrase = "passphrase".toCharArray();
keyStore.load(new FileInputStream("testkeys"), keyStorePassphrase);
keyManagerFactory.init(keyStore, keyStorePassphrase);
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
sslServerSocketFactory = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
sslServerSocket = (SSLServerSocket)sslServerSocketFactory.createServerSocket(12345);
try{Thread.sleep(1000);}catch(Exception e){}
while(true)
{
sslNormalSocket = (SSLSocket)sslServerSocket.accept();
tempCTC = new CTC(sslNormalSocket, userList, f);
}
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch(NoSuchAlgorithmException nsae)
{
nsae.printStackTrace();
}
catch(KeyStoreException kse)
{
kse.printStackTrace();
}
catch(CertificateException ce)
{
ce.printStackTrace();
}
catch(UnrecoverableKeyException uke)
{
uke.printStackTrace();
}
catch(KeyManagementException kme)
{
kme.printStackTrace();
}
}
クライアントサイドコード(例外が発生した場合)
private void doConnectToServer()
{
SSLSocketFactory sslSocketFactory;
KeyManagerFactory keyManagerFactory;
SSLContext sslContext;
KeyStore keyStore;
char[] keyStorePassphrase;
SSLSocket sslSocket;
try
{
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
System.setProperty("javax.net.ssl.trustStore", "samplecacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
sslContext = SSLContext.getInstance("SSL");
keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
keyStore = KeyStore.getInstance("JKS");
keyStorePassphrase = "passphrase".toCharArray();
keyStore.load(new FileInputStream("testkeys"), keyStorePassphrase);
keyManagerFactory.init(keyStore, keyStorePassphrase);
sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
sslSocketFactory = sslContext.getSocketFactory();
sslSocketFactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
sslSocket = (SSLSocket)sslSocketFactory.createSocket("127.0.0.1", 12345);
sslSocket.startHandshake(); //line that throws the exception
cts = new CTS(sslSocket, this);
}
catch(Exception e)
{
e.printStackTrace();
}
}