Skip to content

Support user added CAs in android client - #224

Open
prixeus wants to merge 1 commit into
netbirdio:mainfrom
prixeus:fix-android-ca
Open

Support user added CAs in android client#224
prixeus wants to merge 1 commit into
netbirdio:mainfrom
prixeus:fix-android-ca

Conversation

@prixeus

@prixeus prixeus commented Jul 28, 2026

Copy link
Copy Markdown

The android stores the Certificate Authorities separately which are installed by the user. The Golang ecosystem does not care about them by default, so there was no possibility to use them in self-hosted environment on android clients with user supplied CA. As my understanding to fix that the android code should collect the Certificates Authorities with java API, supply them to go code, and consume it combined with the system provided CAs.
By default the system CAs will be used in Golang.

  • Bump netbird submodule to include updated golang code

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features

    • Added automatic integration of Android system and user certificates with the secure network connection during app startup.
    • Certificates are extracted and converted to PEM, then supplied to the secure networking core before theme initialization.
  • Bug Fixes

    • Added error handling and logging for certificate extraction and handoff failures.
  • Chores

    • Updated the bundled networking core to a newer revision.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f2754f7f-6765-4ca7-85d4-54c4347cdb4e

📥 Commits

Reviewing files that changed from the base of the PR and between ada3051 and 5147dec.

📒 Files selected for processing (3)
  • app/src/main/java/io/netbird/client/MyApplication.java
  • app/src/main/java/io/netbird/client/PlatformUtils.java
  • netbird
🚧 Files skipped from review as they are similar to previous changes (3)
  • netbird
  • app/src/main/java/io/netbird/client/MyApplication.java
  • app/src/main/java/io/netbird/client/PlatformUtils.java

📝 Walkthrough

Walkthrough

Android startup retrieves user CA certificates, formats them as PEM bytes, and sends them to the Go-mobile Android bridge. The bundled netbird reference is updated to a newer commit.

Changes

Certificate integration

Layer / File(s) Summary
Certificate extraction and PEM formatting
app/src/main/java/io/netbird/client/PlatformUtils.java
Adds Android CA keystore access, X.509 certificate extraction for user: aliases, Base64 PEM formatting, and UTF-8 byte output.
Startup certificate handoff
app/src/main/java/io/netbird/client/MyApplication.java, netbird
Initializes certificates during application startup, logs success or errors, and updates the netbird subproject reference.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MyApplication
  participant PlatformUtils
  participant Android
  MyApplication->>PlatformUtils: Extract user certificates
  PlatformUtils-->>MyApplication: Return PEM bytes
  MyApplication->>Android: Set Android certificates
  Android-->>MyApplication: Complete certificate initialization
Loading

Poem

A bunny hops through CAStore bright,
Wrapping certs in PEM just right.
To Go they’re sent at startup’s call,
With logs to catch a stumble or fall.
The Android burrow trusts them all!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: Android client support for user-added certificate authorities.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
app/src/main/java/io/netbird/client/PlatformUtils.java (1)

45-47: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Pass only user-installed roots to the Go bridge.

AndroidCAStore exposes both user: and system: aliases, so this serializes the complete Android trust store. The PR contract says Go merges user-provided roots with its system roots; filter to user: aliases before encoding to avoid duplicating or mixing the two trust-store sources. (android.googlesource.com)

Proposed fix
 while (aliases.hasMoreElements()) {
     String alias = aliases.nextElement();
+    if (!alias.startsWith("user:")) {
+        continue;
+    }
     X509Certificate cert = (X509Certificate) keyStore.getCertificate(alias);

Based on the PR objective, Go is expected to merge user-provided roots with system roots.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/io/netbird/client/PlatformUtils.java` around lines 45 - 47,
Filter aliases in the AndroidCAStore iteration before retrieving certificates so
only aliases beginning with “user:” are serialized for the Go bridge. Update the
loop around aliases.hasMoreElements() and preserve the existing certificate
encoding behavior for matching user-installed roots.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@app/src/main/java/io/netbird/client/PlatformUtils.java`:
- Around line 45-47: Filter aliases in the AndroidCAStore iteration before
retrieving certificates so only aliases beginning with “user:” are serialized
for the Go bridge. Update the loop around aliases.hasMoreElements() and preserve
the existing certificate encoding behavior for matching user-installed roots.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8a4fc7ba-b0f3-4ef9-92f7-a7552a8db970

📥 Commits

Reviewing files that changed from the base of the PR and between 99e998e and c22c627.

📒 Files selected for processing (3)
  • app/src/main/java/io/netbird/client/MyApplication.java
  • app/src/main/java/io/netbird/client/PlatformUtils.java
  • netbird

The android stores the Certificate Authorities separately which are
installed by the user. The Golang ecosystem does not care about them by
default, so there was no possibility to use them in self-hosted
environment on android clients with user supplied CA.
As my understanding to fix that the android code should collect the
Certificates Authorities with java API, supply them to go code, and
consume it combined with the system provided CAs.
By default the system CAs will be used in Golang.

* Bump netbird submodule to include updated golang code
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.

1 participant