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

前端 未结 21 1230
梦如初夏
梦如初夏 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: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 limited = new LinkedList();
    for(String suite : ((SSLSocket)s).getEnabledCipherSuites())
    {
        if(!suite.contains("_DHE_"))
        {
            limited.add(suite);
        }
    }
    ((SSLSocket)s).setEnabledCipherSuites(limited.toArray(
        new String[limited.size()]));
    

    Nasty.

提交回复
热议问题