Skip to content

Remove Bouncy Castle dependency usage from PemUtils #1318

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

exceptionfactory
Copy link

This pull request removes use of the Bouncy Castle Provider library for the PemUtils class for parsing public and private key files.

The Bouncy Castle library includes a large number of cryptographic capabilities, some of which are duplicative of current capabilities in recent versions of Java. Parsing PEM-encoded files is the only direct use of Bouncy Castle in Polaris based on imported classes, so replacing this usage with an alternative solution removes the need for a significant direct dependency.

The PemUtils class already uses standard Java Security components for parsing decoded public keys and private key material, so the changes are scoped to replacing the initial PEM content parsing and Base64 decoding.

The changes include a new PemUtilsTest class that exercises parsing RSA public key and private key files.

The PemUtils class usage is limited to JWT asymmetric token support, narrowing the scope of changes to this specific token signing implementation.

- Added PEM format parsing in PemUtils
- Added unit test for PemUtils
- Removed Bouncy Castle Provider dependency from service common module
- Removed Bouncy Castle Provider dependency from quarkus service module
- Removed Bouncy Castle references from LICENSE and NOTICE files
adutra
adutra previously approved these changes Apr 7, 2025
@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Apr 7, 2025
@@ -46,9 +45,38 @@ private static byte[] parsePEMFile(Path pemPath) throws IOException {
throw new FileNotFoundException(
String.format("The file '%s' doesn't exist.", pemPath.toAbsolutePath()));
}
try (PemReader reader = new PemReader(Files.newBufferedReader(pemPath, UTF_8))) {
PemObject pemObject = reader.readPemObject();
Copy link
Contributor

Choose a reason for hiding this comment

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

One general remark: the original readPemObject() method, in principle, only reads the first object in the PEM file:

https://downloads.bouncycastle.org/java/docs/bcprov-jdk18on-javadoc/org/bouncycastle/util/io/pem/PemReader.html#readPemObject()

With your changes, what happens when the PEM file contains more than one object? And what if it doesn't contain any? It might be good to add tests for these cases as well.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback and noting the behavior of readPemObject(). I adjusted the new implementation to stop reading when finding a footer line, and added unit tests for that scenario, as well as an empty file, which throws an IOException.

Copy link
Member

@snazy snazy left a comment

Choose a reason for hiding this comment

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

The LICENSE/NOTICE changes need to be corrected.

@@ -2050,12 +2050,6 @@ License (from POM): Apache License 2.0 - https://www.apache.org/licenses/LICENSE

--------------------------------------------------------------------------------

Group: org.bouncycastle Name: bcprov-jdk18on Version: 1.80
Copy link
Member

Choose a reason for hiding this comment

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

bouncycastle/bc-prov is still a dependency of polaris-quarkus-server (see dependencies of the runtimeClasspath Gradle configuration), so the removals in LICENSE/NOTICE are wrong.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for noting the runtime transitive dependency on bcprov-jdk18on, I reverted the license and notice changes.

@github-project-automation github-project-automation bot moved this from Ready to merge to PRs In Progress in Basic Kanban Board Apr 7, 2025
@exceptionfactory
Copy link
Author

Thanks for the feedback @adutra and @snazy, I pushed updates to address your comments thus far.

Copy link
Contributor

@dimas-b dimas-b left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thanks, @exceptionfactory !

@exceptionfactory
Copy link
Author

Thanks for the feedback @dimas-b!

Do you have any additional comments @snazy or @adutra following the updates?

@adutra
Copy link
Contributor

adutra commented Apr 18, 2025

I'm good here; @snazy do you have further remarks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants