Skip to content

Java 13 (I know...) Compatibility - XDH Key Generation (Works on Java 12) #589

@brcolow

Description

@brcolow

I am not sure if this has anything to do with Bouncycastle. Java 13 has JEP 353 which rewrites (parts) of the legacy socket API. I am using Bouncycastle 1.62.

When I try to connect to Amazon AWS DynamoDB on Java 13, I get the following (partial) stack trace:

Caused by: java.lang.RuntimeException: Could not generate XDH keypair
at java.base/sun.security.ssl.XDHKeyExchange$XDHEPossession.<init>(XDHKeyExchange.java:110)
at java.base/sun.security.ssl.NamedGroup$XDHFunctions.createPossession(NamedGroup.java:750)
at java.base/sun.security.ssl.NamedGroup.createPossession(NamedGroup.java:390)
at java.base/sun.security.ssl.SSLKeyExchange$T13KeyAgreement.createPossession(SSLKeyExchange.java:568)
at java.base/sun.security.ssl.SSLKeyExchange.createPossessions(SSLKeyExchange.java:84)
at java.base/sun.security.ssl.KeyShareExtension$CHKeyShareProducer.produce(KeyShareExtension.java:255)
at java.base/sun.security.ssl.SSLExtension.produce(SSLExtension.java:571)
at java.base/sun.security.ssl.SSLExtensions.produce(SSLExtensions.java:250)
at java.base/sun.security.ssl.ClientHello$ClientHelloKickstartProducer.produce(ClientHello.java:649)
at java.base/sun.security.ssl.SSLHandshake.kickstart(SSLHandshake.java:519)
at java.base/sun.security.ssl.ClientHandshakeContext.kickstart(ClientHandshakeContext.java:107)
at java.base/sun.security.ssl.TransportContext.kickstart(TransportContext.java:231)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:430)
... 61 more
Caused by: java.security.InvalidAlgorithmParameterException: invalid parameterSpec: java.security.spec.NamedParameterSpec@15e0fe05
at org.bouncycastle.jcajce.provider.asymmetric.edec.KeyPairGeneratorSpi.initialize(Unknown Source)
at java.base/java.security.KeyPairGenerator$Delegate.initialize(KeyPairGenerator.java:699)
at java.base/sun.security.ssl.XDHKeyExchange$XDHEPossession.<init>(XDHKeyExchange.java:105)
... 73 more

Downgrading to the latest nightly build of the Java 12 repository makes the error go away.

The actual chain of events here is that the Amazon AWS SDK is calling Apache's HTTP client which is trying to make an SSL connection. I am not 100% sure how Bouncycastle comes into it unless the only XDH provider accessible is Bouncycastle? I tried to put the provider at position 2, but it made no difference.

I believe the full stack trace where a custom AWS Lambda runtime calls a Lambda request handler, calls DynamoDB, calls Apache, calls, etc. etc. is essentially obfuscation. I think this would show up trying to make an SSL connection to Amazon's DynamoDB server that happens to use XDH key exchange. I see some changes to the sun.security.ssl.SSLSocketImpl classes (as well as other classes in the stack trace) new to Java 13 (most likely related to the aforementioned JEP).

This could very well be a bug in the new Java socket implementation and if so I will certainly open this upstream.

Thanks for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions