Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bouncy Castle fips incompatible issue #2740

Merged
merged 5 commits into from
Jul 5, 2021

Conversation

jiazhai
Copy link
Member

@jiazhai jiazhai commented Jun 16, 2021

Descriptions of the changes in this PR:

Motivation

More details are provided in Pulsar # 10937.

In #2631, the default BouncyCastle was changed from non-fips into fips version. But the default version of BouncyCastle in Pulsar is the non-fips one(aimed to make it compatible with the old version of Pulsar).

Bouncy Castle provides both FIPS and non-FIPS versions, but in a JVM, it can not include both of the 2 versions(non-Fips and Fips), and we have to exclude the current version before including the other. This makes the backward compatible a little hard, and that's why Pulsar has to involve an individual module for Bouncy Castle.

And if we want to start BookKeeper with TLS enabled through Pulsar's binary, it will meet the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jcajce/provider/BouncyCastleFipsProvider
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at org.apache.bookkeeper.common.util.ReflectionUtils.forName(ReflectionUtils.java:49)
	at org.apache.bookkeeper.tls.SecurityProviderFactoryFactory.getSecurityProviderFactory(SecurityProviderFactoryFactory.java:39)
	at org.apache.bookkeeper.proto.BookieServer.<init>(BookieServer.java:129)
	at org.apache.bookkeeper.server.service.BookieService.<init>(BookieService.java:52)
	at org.apache.bookkeeper.server.Main.buildBookieServer(Main.java:304)
	at org.apache.bookkeeper.server.Main.doMain(Main.java:226)
	at org.apache.bookkeeper.server.Main.main(Main.java:208)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 9 more

This fix is to use the reflection to get the loaded bc version to avoid the hard-coded bc version.

Changes

Use the reflection to get the loaded bc version to avoid the hard-coded bc version
Add backward compatible test for bc-non-fips version

@jiazhai
Copy link
Member Author

jiazhai commented Jun 16, 2021

@zymap @codelipenghui FYI.

@eolivelli
Copy link
Contributor

@Ghatage PTAL

@eolivelli
Copy link
Contributor

@jiazhai TLS tests are failing, PTAL

@sijie
Copy link
Member

sijie commented Jun 18, 2021

@jiazhai overall looks good to me. Can you check why TLS tests are failing?

Copy link
Contributor

@Ghatage Ghatage left a comment

Choose a reason for hiding this comment

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

Thanks for doing this @jiazhai, I understand this is a WIP, comments added below.

Thanks for the tag @eolivelli!

@Ghatage
Copy link
Contributor

Ghatage commented Jun 28, 2021

Thanks for the context @jiazhai. That helps a lot. And also thanks for doing this!.
Wouldn't an easy fix be to allow imports of BK's bouncy castle which were disallowed in @eolivelli's changes here?
I guess I may be over looking the reasons why they were made in the first place.
Your changes look good otherwise 👍
Will you be using maven or gradle for your builds?

Side note:
@pkumar-singh Could you please help us understand how build.gradle is pulling in the dependencies here?
In these lines I see bouncycastle 1.56 and bc-fips 1.0.2, both deps being pulled in. AFAIK, it's recommended to have only one or to avoid classpath conflicts and runtime errors based on which one gets loaded.
I don't see the same in the base level maven pom.xml.

@jiazhai jiazhai force-pushed the bc_fips_compatible branch from c4e81ea to 1095181 Compare June 29, 2021 03:02
@jiazhai jiazhai changed the title [WIP] Fix Bouncy Castle fips incompatible issue Fix Bouncy Castle fips incompatible issue Jun 29, 2021
@jiazhai
Copy link
Member Author

jiazhai commented Jun 29, 2021

Thanks for the comments @Ghatage .
From my view, @eolivelli's changes are reasonable, because the bc versions(fips/non-fips) are in conflict, we could only include one of them into the package. Usually it uses include/exclude to solve the issue.
It would help a lot if we could find a way to support both of the versions.

currently, the changes and tests are included in this PR. And by this change, we could have a choice in Pulsar.

Thanks for the context @jiazhai. That helps a lot. And also thanks for doing this!.
Wouldn't an easy fix be to allow imports of BK's bouncy castle which were disallowed in @eolivelli's changes here?
I guess I may be over looking the reasons why they were made in the first place.
Your changes look good otherwise 👍
Will you be using maven or gradle for your builds?

Side note:
@pkumar-singh Could you please help us understand how build.gradle is pulling in the dependencies here?
In these lines I see bouncycastle 1.56 and bc-fips 1.0.2, both deps being pulled in. AFAIK, it's recommended to have only one or to avoid classpath conflicts and runtime errors based on which one gets loaded.
I don't see the same in the base level maven pom.xml.

Copy link
Contributor

@Ghatage Ghatage left a comment

Choose a reason for hiding this comment

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

LGTM +1 @jiazhai
PTAL at the tests, other than that the changes are good and thanks for doing this!

@jiazhai
Copy link
Member Author

jiazhai commented Jun 29, 2021

@zymap Would you please also help take a look?

Copy link
Member

@zymap zymap left a comment

Choose a reason for hiding this comment

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

LGTM

@jiazhai
Copy link
Member Author

jiazhai commented Jun 30, 2021

@sijie to take a look

@jiazhai jiazhai merged commit d03b046 into apache:master Jul 5, 2021
jiazhai added a commit to jiazhai/bookkeeper-1 that referenced this pull request Jul 5, 2021
### Motivation

More details are provided in [Pulsar # 10937](apache/pulsar#10937).

In apache#2631, the default BouncyCastle was changed from non-fips into fips version. But the default version of BouncyCastle in Pulsar is the [non-fips](https://github.com/apache/pulsar/blob/v2.8.0/pulsar-client/pom.xml#L56) one(aimed to make it compatible with the old version of Pulsar).

Bouncy Castle provides both FIPS and non-FIPS versions, but in a JVM, it can not include both of the 2 versions(non-Fips and Fips), and we have to exclude the current version before including the other. This makes the backward compatible a little hard, and that's why Pulsar has to involve an individual module for [Bouncy Castle](https://pulsar.apache.org/docs/en/security-bouncy-castle).

And if we want to start BookKeeper with TLS enabled through Pulsar's binary, it will meet the following error:
```
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jcajce/provider/BouncyCastleFipsProvider
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at org.apache.bookkeeper.common.util.ReflectionUtils.forName(ReflectionUtils.java:49)
	at org.apache.bookkeeper.tls.SecurityProviderFactoryFactory.getSecurityProviderFactory(SecurityProviderFactoryFactory.java:39)
	at org.apache.bookkeeper.proto.BookieServer.<init>(BookieServer.java:129)
	at org.apache.bookkeeper.server.service.BookieService.<init>(BookieService.java:52)
	at org.apache.bookkeeper.server.Main.buildBookieServer(Main.java:304)
	at org.apache.bookkeeper.server.Main.doMain(Main.java:226)
	at org.apache.bookkeeper.server.Main.main(Main.java:208)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 9 more
```

This fix is to use the reflection to get the loaded bc version to avoid the hard-coded bc version.

### Changes

Use the reflection to get the loaded bc version to avoid the hard-coded bc version
Add backward compatible test for bc-non-fips version
(cherry picked from commit d03b046)
@jiazhai
Copy link
Member Author

jiazhai commented Jul 5, 2021

cherry-picked into branch-4.14

eolivelli pushed a commit to datastax/bookkeeper that referenced this pull request Jul 5, 2021
More details are provided in [Pulsar # 10937](apache/pulsar#10937).

In apache#2631, the default BouncyCastle was changed from non-fips into fips version. But the default version of BouncyCastle in Pulsar is the [non-fips](https://github.com/apache/pulsar/blob/v2.8.0/pulsar-client/pom.xml#L56) one(aimed to make it compatible with the old version of Pulsar).

Bouncy Castle provides both FIPS and non-FIPS versions, but in a JVM, it can not include both of the 2 versions(non-Fips and Fips), and we have to exclude the current version before including the other. This makes the backward compatible a little hard, and that's why Pulsar has to involve an individual module for [Bouncy Castle](https://pulsar.apache.org/docs/en/security-bouncy-castle).

And if we want to start BookKeeper with TLS enabled through Pulsar's binary, it will meet the following error:
```
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jcajce/provider/BouncyCastleFipsProvider
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at org.apache.bookkeeper.common.util.ReflectionUtils.forName(ReflectionUtils.java:49)
	at org.apache.bookkeeper.tls.SecurityProviderFactoryFactory.getSecurityProviderFactory(SecurityProviderFactoryFactory.java:39)
	at org.apache.bookkeeper.proto.BookieServer.<init>(BookieServer.java:129)
	at org.apache.bookkeeper.server.service.BookieService.<init>(BookieService.java:52)
	at org.apache.bookkeeper.server.Main.buildBookieServer(Main.java:304)
	at org.apache.bookkeeper.server.Main.doMain(Main.java:226)
	at org.apache.bookkeeper.server.Main.main(Main.java:208)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 9 more
```

This fix is to use the reflection to get the loaded bc version to avoid the hard-coded bc version.

Use the reflection to get the loaded bc version to avoid the hard-coded bc version
Add backward compatible test for bc-non-fips version
(cherry picked from commit d03b046)
(cherry picked from commit e54be34)
@eolivelli
Copy link
Contributor

@jiazhai I have fixed branch-4.14 because this patch included a new pom.xml, that needed to be amended to set the version to 4.14.1-SNAPSHOT in branch-4.14.

cc @sijie @merlimat

@eolivelli
Copy link
Contributor

see 69360e1

@diegosalvi
Copy link
Contributor

+1 to have this released ^_^ I failed to cannot upgrade to 4.14.x due to non fips libs already in my classpath and widely used

@jiazhai
Copy link
Member Author

jiazhai commented Aug 13, 2021

@diegosalvi Would you please also help verify this change in your environment?

fpj pushed a commit that referenced this pull request Aug 13, 2021
…port to branch-4.14)

### Motivation

backport #2695 to branch-4.14

Reviewers: Enrico Olivelli <eolivelli@gmail.com>, Flavio Junqueira <None>

This closes #2762 from lhotari/lh-upgrade-libthrift-4.14 and squashes the following commits:

79b78b6 [Lari Hotari] [SECURITY] Upgrade libthrift to 0.14.2 to address multiple CVEs
69360e1 [Enrico Olivelli] Fix tests pom, set version to 4.14.1-SNAPSHOT
e54be34 [Jia Zhai] Fix Bouncy Castle fips incompatible issue (#2740)
4c078bb [Matteo Merli] [maven-release-plugin] rollback changes from release preparation of v4.14.1-rc0
f7a9442 [Matteo Merli] [maven-release-plugin] prepare release v4.14.1-rc0
4292db8 [hangc0276] fix prometheus metric provider bug and add test to cover label scope …
12f0f5f [Matteo Merli] Version 4.14.1-SNAPSHOT
4acca53 [Andrey Yegorov] Include gradle files into the source artifact for releases, exclude site2/**
f24bef6 [Andrey Yegorov] [maven-release-plugin] rollback changes from release preparation of v4.14.0-rc0
4729682 [Andrey Yegorov] [maven-release-plugin] prepare release v4.14.0-rc0
@diegosalvi
Copy link
Contributor

@jiazhai I can check with this commit next week :)

@eolivelli
Copy link
Contributor

@diegosalvi we are going to cut a release soon

@zymap already started a discussion on dev@bookkeeper.apache.org

@eolivelli
Copy link
Contributor

Please take time to vote on the release candidate when it will be prepared

Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024


### Motivation

More details are provided in [Pulsar # 10937](apache/pulsar#10937).

In apache#2631, the default BouncyCastle was changed from non-fips into fips version. But the default version of BouncyCastle in Pulsar is the [non-fips](https://github.com/apache/pulsar/blob/v2.8.0/pulsar-client/pom.xml#L56) one(aimed to make it compatible with the old version of Pulsar). 

Bouncy Castle provides both FIPS and non-FIPS versions, but in a JVM, it can not include both of the 2 versions(non-Fips and Fips), and we have to exclude the current version before including the other. This makes the backward compatible a little hard, and that's why Pulsar has to involve an individual module for [Bouncy Castle](https://pulsar.apache.org/docs/en/security-bouncy-castle).

And if we want to start BookKeeper with TLS enabled through Pulsar's binary, it will meet the following error:
```
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jcajce/provider/BouncyCastleFipsProvider
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at org.apache.bookkeeper.common.util.ReflectionUtils.forName(ReflectionUtils.java:49)
	at org.apache.bookkeeper.tls.SecurityProviderFactoryFactory.getSecurityProviderFactory(SecurityProviderFactoryFactory.java:39)
	at org.apache.bookkeeper.proto.BookieServer.<init>(BookieServer.java:129)
	at org.apache.bookkeeper.server.service.BookieService.<init>(BookieService.java:52)
	at org.apache.bookkeeper.server.Main.buildBookieServer(Main.java:304)
	at org.apache.bookkeeper.server.Main.doMain(Main.java:226)
	at org.apache.bookkeeper.server.Main.main(Main.java:208)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 9 more
```

This fix is to use the reflection to get the loaded bc version to avoid the hard-coded bc version.

### Changes

Use the reflection to get the loaded bc version to avoid the hard-coded bc version
Add backward compatible test for bc-non-fips version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants