Skip to content

Commit

Permalink
[openpgp] Do not put the BouncyCastleProvider at first position
Browse files Browse the repository at this point in the history
This causes

java.security.InvalidKeyException: cannot identify XDH private key

on Java 11 or higher.

See also
- bcgit/bc-java#620
- bcgit/bc-java#589
- corretto/corretto-11#168
- https://bugs.openjdk.java.net/browse/JDK-8171279
  • Loading branch information
Flowdalic committed Feb 14, 2021
1 parent 86b48fb commit 9261d64
Showing 1 changed file with 1 addition and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,15 @@
package org.jivesoftware.smackx.ox.util;

import org.jivesoftware.smack.initializer.UrlInitializer;
import org.jivesoftware.smack.util.SecurityUtil;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

/**
* Initializer class which registers ExtensionElementProviders on startup.
*/
public class OpenPgpInitializer extends UrlInitializer {

static {
// Remove any BC providers and add a fresh one.
// This is done, since older Android versions ship with a crippled BC provider.
SecurityUtil.ensureProviderAtFirstPosition(BouncyCastleProvider.class);
}

@Override
protected String getProvidersUri() {
return "classpath:org.jivesoftware.smackx.ox/openpgp.providers";
}

}

2 comments on commit 9261d64

@alvdavi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I just wanted to mention that this issue was fixed in Bouncy Castle 1.66, which is older than the version of JDK11 that added support for x448 and x25519. As long as people keep BC up to date, there is no problem with JDK11

@Flowdalic
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I ran into it also with bc 1.68 on Java 11. But hat doesn't matter: Smack as library should not modify the SecurityProvider in that way. Hence this commit.

Please sign in to comment.