Connection to an SSL socket server

M

max

I try to establish a connection to a SSL socket server , by using ssl
socket client (code below) and I got an exception, can you help me pls?
The server is ok I did a connection with sslopen client.
thanks

public class ClientSSL {
static int port = 1111;

static String hostname = "myIP";

public static void main(String[] arstring) {
try {
SSLSocketFactory sslsocketfactory =(SSLSocketFactory) SSLSocketFactory
.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(
hostname, port);
String[] prot = new String[1];
prot[0]="SSLv3";
sslsocket.setEnabledProtocols(prot);

String[] newcipher = new String[1];
newcipher[0]="TLS_DH_anon_WITH_AES_128_CBC_SHA";

sslsocket.setEnabledCipherSuites(newcipher);

String[] cipher = sslsocket.getEnabledCipherSuites();
for(int i=0;i<cipher.length;i++){
System.out.println(cipher);
}

OutputStream outputstream = sslsocket.getOutputStream();
BufferedOutputStream outbuff = new BufferedOutputStream (outputstream);


byte[] test = new byte[4];
test[0]=8;
test[1]=1;
test[2]=3;
test[3]=6;

outbuff.write(test);
outbuff.flush();
sslsocket.close();
} catch (Exception exception) {
exception.printStackTrace();
}
}

}






output:
TLS_DH_anon_WITH_AES_128_CBC_SHA



javax.net.ssl.SSLException: java.lang.RuntimeException: Could not
generate DH keypair
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:166)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal
(SSLSocketImpl.java:1476)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal
(SSLSocketImpl.java:1443)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.handleException
(SSLSocketImpl.java:1426)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write
(AppOutputStream.java:64)
at java.io.BufferedOutputStream.flushBuffer
(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at ClientSSL.main(ClientSSL.java:58)
Caused by: java.lang.RuntimeException: Could not generate DH keypair
at com.sun.net.ssl.internal.ssl.DHKeyExchange.generateKeyPair
(DHKeyExchange.java:137)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.getDHephemeral
(ClientHandshaker.java:370)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverKeyExchange
(ClientHandshaker.java:385)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage
(ClientHandshaker.java:121)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop
(Handshaker.java:495)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record
(Handshaker.java:433)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord
(SSLSocketImpl.java:815)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake
(SSLSocketImpl.java:1025)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord
(SSLSocketImpl.java:619)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write
(AppOutputStream.java:59)
... 3 more
Caused by: java.security.InvalidAlgorithmParameterException: Prime size
must be multiple of 64, and can only range from 512 to 1024 (inclusive)
at com.sun.crypto.provider.DHKeyPairGenerator.initialize(DashoA6275)
at java.security.KeyPairGenerator$Delegate.initialize
(KeyPairGenerator.java:609)
at java.security.KeyPairGenerator.initialize(KeyPairGenerator.java:351)
at com.sun.net.ssl.internal.ssl.DHKeyExchange.generateKeyPair
(DHKeyExchange.java:123)
... 12 more
 
R

Rogan Dawes

I try to establish a connection to a SSL socket server , by using ssl
socket client (code below) and I got an exception, can you help me pls?
The server is ok I did a connection with sslopen client.
thanks
newcipher[0]="TLS_DH_anon_WITH_AES_128_CBC_SHA";


output:
TLS_DH_anon_WITH_AES_128_CBC_SHA



javax.net.ssl.SSLException: java.lang.RuntimeException: Could not
generate DH keypair
Caused by: java.security.InvalidAlgorithmParameterException: Prime size
must be multiple of 64, and can only range from 512 to 1024 (inclusive)

Looks like there is some problem with the size of the prime you are
using. Do you HAVE to use "DH_anon"? Could you not allow the SSL/TLS
suite to negotiate a shared algorithm?

You may also want to look at http://dawes.za.net/rogan/PKCS11Test.java,
which shows a whole bunch of client-side SSL-related techniques in a
simple example. Some may be of use to you.

Regards,

Rogan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top