javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate
I am trying to connect to a server process using SSL socket. However, during handshake it fails with the exception.Any ideas why would this happen? I know that the server process works, because we have a TCL client that connects to it without any problem (tls::socket -cipher EDH-RSA-DES-CBC3-SHA).
The java code and the exception is below.
publicclass SecureChannel{
privatestatic SecureChannel instance=null;
private SSLContext ctx=null;
privatestaticfinal String keystore ="keystore";
privatestaticfinal String[] cipherSuites ={
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA"
};
publicstatic SecureChannel getInstance()throws Exception{
if(instance==null)
instance=new SecureChannel();
return instance;
}
private SecureChannel()throws Exception{
InputStream is=new FileInputStream(keystore);
TrustManagerFactory tmf=TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
KeyStore ks=KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(is,null);
is.close();
tmf.init(ks);
ctx = SSLContext.getInstance("TLS");//"SSLv3");
ctx.init(null, tmf.getTrustManagers(),null);
}
public SSLSocket getSocket(String ip,int port)throws Exception{
SSLSocketFactory sf = ctx.getSocketFactory();
String ciphers[]=sf.getSupportedCipherSuites();
for(int i=0; i<ciphers.length; i++){
System.out.println(ciphers[i]);
}
SSLSocket sslSock = (SSLSocket)sf.createSocket(ip, port);
sslSock.setEnabledCipherSuites(cipherSuites);
return sslSock;
}
}
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.AppInputStream.read(AppInputStream.java:86)
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:411)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:453)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:183)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.read(BufferedReader.java:157)
at clitest.CliParse.makeList(CliParse.java:30)
at clitest.CliParse.parseInput(CliParse.java:12)
at clitest.CliTest.connect(CliTest.java:45)
at clitest.CliTest.main(CliTest.java:160)
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:125)
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.readDataRecord(SSLSocketImpl.java:675)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
... 10 more
Caused by: java.security.InvalidAlgorithmParameterException: Exponent value must be less than (modulus value -1)
at com.sun.crypto.provider.DHKeyPairGenerator.initialize(DashoA12275)
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)
... 19 more
>

