Why does SSL handshake give 'Could not generate DH keypair' exception?

前端 未结 21 777
梦如初夏
梦如初夏 2020-11-22 07:46

When I make an SSL connection with some IRC servers (but not others - presumably due to the server\'s preferred encryption method) I get the following exception:

<         


        
相关标签:
21条回答
  • 2020-11-22 08:51

    I used to get a similar error accessing svn.apache.org with java SVN clients using an IBM JDK. Currently, svn.apache.org users the clients cipher preferences.

    After running just once with a packet capture / javax.net.debug=ALL I was able to blacklist just a single DHE cipher and things work for me (ECDHE is negotiated instead).

    .../java/jre/lib/security/java.security:
        jdk.tls.disabledAlgorithms=SSL_DHE_RSA_WITH_AES_256_CBC_SHA
    

    A nice quick fix when it is not easy to change the client.

    0 讨论(0)
  • 2020-11-22 08:52

    The "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files" answer did not work for me but The BouncyCastle's JCE provider suggestion did.

    Here are the steps I took using Java 1.6.0_65-b14-462 on Mac OSC 10.7.5

    1) Download these jars:

    • bcprov-jdk15on-154.jar

    • bcprov-ext-jdk15on-154.jar

    2) move these jars to $JAVA_HOME/lib/ext

    3) edit $JAVA_HOME/lib/security/java.security as follows: security.provider.1=org.bouncycastle.jce.provider.BouncyCastleProvider

    restart app using JRE and give it a try

    0 讨论(0)
  • 2020-11-22 08:52

    The answer above is correct, but in terms of the workaround, I had problems with the BouncyCastle implementation when I set it as preferred provider:

    java.lang.ArrayIndexOutOfBoundsException: 64
        at com.sun.crypto.provider.TlsPrfGenerator.expand(DashoA13*..)
    

    This is also discussed in one forum thread I found, which doesn't mention a solution. http://www.javakb.com/Uwe/Forum.aspx/java-programmer/47512/TLS-problems

    I found an alternative solution which works for my case, although I'm not at all happy with it. The solution is to set it so that the Diffie-Hellman algorithm is not available at all. Then, supposing the server supports an alternative algorithm, it will be selecting during normal negotiation. Obviously the downside of this is that if somebody somehow manages to find a server that only supports Diffie-Hellman at 1024 bits or less then this actually means it will not work where it used to work before.

    Here is code which works given an SSLSocket (before you connect it):

    List<String> limited = new LinkedList<String>();
    for(String suite : ((SSLSocket)s).getEnabledCipherSuites())
    {
        if(!suite.contains("_DHE_"))
        {
            limited.add(suite);
        }
    }
    ((SSLSocket)s).setEnabledCipherSuites(limited.toArray(
        new String[limited.size()]));
    

    Nasty.

    0 讨论(0)
提交回复
热议问题