Skip to content

feat(sdk): replace ayza libraries with TrustProvider on JCA#366

Draft
mkleene wants to merge 3 commits into
remove-bouncycastlefrom
remove-ayza
Draft

feat(sdk): replace ayza libraries with TrustProvider on JCA#366
mkleene wants to merge 3 commits into
remove-bouncycastlefrom
remove-ayza

Conversation

@mkleene
Copy link
Copy Markdown
Contributor

@mkleene mkleene commented May 11, 2026

Remove the three io.github.hakky54:ayza* dependencies and replace their TLS trust-material role with an SDK-owned TrustProvider built on provider-agnostic JCA APIs (CertificateFactory, KeyStore, TrustManagerFactory, SSLContext). This works under any registered crypto provider, including BC-FIPS, and avoids hardcoded provider names.

  • Add TrustProvider and package-private CompositeX509ExtendedTrustManager for combining JVM default + custom trust material.
  • SDKBuilder: replace SSLFactory field with SSLSocketFactory + X509TrustManager. sslFactory(SSLFactory) becomes sslFactory(SSLSocketFactory); add sslFactory(SSLSocketFactory, X509TrustManager) for callers that have a matching trust manager. sslFactoryFromDirectory / sslFactoryFromKeyStore signatures and semantics are preserved, now backed by TrustProvider internally.
  • TokenSource takes SSLSocketFactory directly.
  • Command.java --insecure path uses TrustProvider.insecure().
  • SDKBuilderTest reworked to drop nl.altindag imports and use TrustProvider + standard JCA.

Remove the three io.github.hakky54:ayza* dependencies and replace their
TLS trust-material role with an SDK-owned TrustProvider built on
provider-agnostic JCA APIs (CertificateFactory, KeyStore,
TrustManagerFactory, SSLContext). This works under any registered crypto
provider, including BC-FIPS, and avoids hardcoded provider names.

- Add TrustProvider and package-private CompositeX509ExtendedTrustManager
  for combining JVM default + custom trust material.
- SDKBuilder: replace SSLFactory field with SSLSocketFactory +
  X509TrustManager. sslFactory(SSLFactory) becomes
  sslFactory(SSLSocketFactory); add sslFactory(SSLSocketFactory,
  X509TrustManager) for callers that have a matching trust manager.
  sslFactoryFromDirectory / sslFactoryFromKeyStore signatures and
  semantics are preserved, now backed by TrustProvider internally.
- TokenSource takes SSLSocketFactory directly.
- Command.java --insecure path uses TrustProvider.insecure().
- SDKBuilderTest reworked to drop nl.altindag imports and use
  TrustProvider + standard JCA.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 50a0f14a-897d-4008-8604-b96080f52a84

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch remove-ayza

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the external SSLFactory dependency with a native JCA-based implementation using the new TrustProvider and CompositeX509ExtendedTrustManager classes. The SDKBuilder, TokenSource, and associated tests have been updated to work with standard SSLSocketFactory and X509TrustManager objects. Reviewers suggested using InputStream.readAllBytes() for better performance, deduplicating keystore types during loading, and ensuring that X509TrustManager instances are provided alongside socket factories to avoid deprecated OkHttp methods and potential validation issues.

Comment on lines +145 to +153
private static byte[] readAll(InputStream in) throws IOException {
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
byte[] buf = new byte[8192];
int n;
while ((n = in.read(buf)) >= 0) {
out.write(buf, 0, n);
}
return out.toByteArray();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The readAll method is redundant as InputStream.readAllBytes() is available since Java 9. Since the project targets Java 11, it's better to use the built-in method for better performance and readability.

    private static byte[] readAll(InputStream in) throws IOException {
        return in.readAllBytes();
    }

// registered fulfills the request.
byte[] bytes = readAll(in);
KeyStoreException last = null;
for (String type : new String[]{KeyStore.getDefaultType(), "JKS", "PKCS12"}) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The loop iterates over a fixed array that likely contains duplicate values (e.g., KeyStore.getDefaultType() is often "PKCS12" on modern JVMs). This leads to redundant attempts to load the keystore if the first attempt fails.

Suggested change
for (String type : new String[]{KeyStore.getDefaultType(), "JKS", "PKCS12"}) {
for (String type : new java.util.LinkedHashSet<>(java.util.Arrays.asList(KeyStore.getDefaultType(), "JKS", "PKCS12"))) {

Comment on lines +410 to 414
// Caller supplied an SSLSocketFactory without a matching trust manager (e.g. via
// sslFactory(SSLSocketFactory)). Falls back to OkHttp's reflection-based platform
// default trust manager — only the SSLSocketFactory governs the actual handshake.
httpClient.sslSocketFactory(sslSocketFactory);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The httpClient.sslSocketFactory(SSLSocketFactory) method is deprecated in OkHttp 4.x. It relies on reflection to find a matching X509TrustManager, which can fail on modern JVMs with strict encapsulation or on Android. Since the SDK now provides a TrustProvider that returns both the socket factory and the trust manager, it's highly recommended to always provide both to OkHttp. For the sslFactory(SSLSocketFactory) overload, consider documenting that it may fail on some platforms or require a matching trust manager.

* @param sslSocketFactory Optional SSLSocketFactory for token endpoint requests
*/
public TokenSource(ClientAuthentication clientAuth, RSAKey rsaKey, URI tokenEndpointURI, AuthorizationGrant authzGrant, SSLFactory sslFactory) {
public TokenSource(ClientAuthentication clientAuth, RSAKey rsaKey, URI tokenEndpointURI, AuthorizationGrant authzGrant, SSLSocketFactory sslSocketFactory) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The TokenSource constructor now takes an SSLSocketFactory but not the matching X509TrustManager. Similar to the OkHttp client in SDKBuilder, the underlying HTTP client used by the Nimbus OAuth2 SDK may require the trust manager for proper certificate validation and platform compatibility. Consider passing the X509TrustManager to TokenSource as well.

try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509ExtendedTrustManager trustAll = new InsecureTrustManager();
ctx.init(new KeyManager[0], new TrustManager[]{trustAll}, new SecureRandom());
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.

2 participants