常见的Java套接字中没有密码套件 [英] No cipher suites in common java sockets
问题描述
我最近一直在为邮件系统使用SSL套接字。
I have been using SSL sockets for a messaging system recently.
我终于开始使用CA颁发的证书了。我将它导入我的密钥库,设置了密钥库属性,并启动了我的客户端,但是当我尝试发送数据时,我一直收到握手异常。
I finally started using a CA issued certificate. I imported it into my keystore, set the keystore property, and started up my client, but I keep getting handshake exceptions when I try to send data.
我启用了调试模式我发现这是由于没有支持密码套件
。对此有何看法?
I enabled debug mode and I found that it is due to no cipher suites supported
. Any thoughts on this?
如果有帮助,它还说它忽略了TLSV1和TLSV1.1的10个密码套件。
If it helps, It also says that it is ignoring about 10 cipher suites from TLSV1 and TLSV1.1.
我还安装了无限强度加密政策。
I also installed Unlimited Strength Cryptographic Policy.
客户代码
public static void Message(String args){
System.setProperty("https.protocols", "TLSv1");
System.setProperty("javax.net.debug", "all");
try
{
String host = "localhost";
int port = 3498;
InetAddress address = InetAddress.getByName(host);
socket = (SSLSocket)SSLSocketFactory.getDefault().createSocket(address, port);
//Send the message to the server
OutputStream os = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
String number = "Hello from the other side!";
String sendMessage = number + "\n";
bw.write(args);
bw.flush();
System.out.println("Message sent to the server : "+sendMessage);
//Get the return message from the server
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
//Closing the socket
try
{
socket.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
服务器代码
private void initListen() {
System.setProperty("javax.net.ssl.keyStore", "/Users/181095/server.jks");
try {
SSLServerSocketFactory sf = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket serverSocket = (SSLServerSocket)sf.createServerSocket(Ting.port);
System.out.println("Server Started and listening to the port "
+ Ting.port);
// Server is running always. This is done using this while(true)
// loop
while (true) {
// Reading the message from the client
socket = (SSLSocket)serverSocket.accept();
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String input = br.readLine();
System.out.println("Message received from client is " + input);
/*if(PacketReader.isPacket(input)){
if(PacketReader.shouldSendDataBack(input)){
}
}*/
/*
*
* if client has data waiting or client has new data
* request new data.
* else, wait 5 seconds and repeat
*
*
*/
// Sending the response back to the client.
/*OutputStream os = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
bw.write("");*/
//TODO Implement method to send this data to client storage data.
//bw.flush();
}
//Check for exceptions and try to close the socket.
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
socket.close();
} catch (Exception e) {
}
}
}
编辑:
我刚刚添加了密码,但我的输入/证书没有密钥,这是否会导致错误?我该如何解决?
I have just added the password, but my entry/certificate does not have a key, could this be contributing to the error? How can I fix it?
推荐答案
令人惊讶的是,这可能意味着服务器无法找到私钥/证书对。在这种情况下,这是因为您没有通过 javax.net.ssl.keyStorePassword
指定密钥库密码。
Surprisingly, this can mean that the server couldn't find a private key/certificate pair. In this case it is because you haven't specified the keystore password via javax.net.ssl.keyStorePassword
.
这篇关于常见的Java套接字中没有密码套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!