Skip to content

TLS: Load Android system CA store when default root pool is empty - #7098

Closed
Raycc-lang wants to merge 3 commits into
XTLS:mainfrom
Raycc-lang:android-system-cert-pool
Closed

Raycc-lang wants to merge 3 commits into
XTLS:mainfrom
Raycc-lang:android-system-cert-pool

Conversation

@Raycc-lang

@Raycc-lang Raycc-lang commented Oct 7, 2026 •

Copy link
Copy Markdown

Problem

Official Linux ARM binaries can run on rooted Android, but Go's default Linux certificate locations do not include Android's CA store. On the affected device, x509.SystemCertPool() was empty and verified outbound TLS connections failed with:

tls: failed to verify certificate: x509: certificate signed by unknown authority

The original reproduction used the official linux-arm64 release:

$ xray tls ping -ip 223.5.5.5 dns.alidns.com
Pinging with SNI
Handshake failure: tls: failed to verify certificate: x509: certificate signed by unknown authority

$ SSL_CERT_DIR=/system/etc/security/cacerts xray tls ping -ip 223.5.5.5 dns.alidns.com
Pinging with SNI
Handshake succeeded

Fix

Replace the initial Android directory-loading implementation with golang.org/x/crypto/x509roots/fallback, imported by main/distro/all under linux && (arm || arm64).

  • Registers bundled Mozilla/NSS roots through Go's fallback mechanism for use when system roots are unavailable.
  • Restores transport/internet/tls/config_other.go to its original implementation; existing SystemCertPool() calls obtain the fallback pool.
  • Keeps fallback registration in the executable assembly package.
  • Uses the bundled root snapshot rather than Android's CA store. The dependency must be kept updated.
  • Pins the fallback module to v0.0.0-20261005185213-c3db4df58582.

Validation of the current revision

Using Go 1.27.1:

  • Linux arm64 and Linux arm (GOARM=7) builds passed; both contain the fallback dependency.
  • Linux amd64 excludes the new import file.
  • Targeted TLS tests passed: certificate issuance, expired certificate replacement, and insecure-certificate configuration.
  • Local smoke checks with system certificate paths pointed at nonexistent locations produced 120 fallback roots and confirmed Xray receives that pool.
  • A separate process with a configured CA file retained its one-root pool. Additional configured CAs remained trusted.
  • disableSystemRoot retained a custom-only pool, or an empty pool when no certificates were configured.
  • Repository formatting checks and go mod verify passed.

The current fallback implementation has not yet been tested on the Android device: the cloud development environment has no ADB/device connection. The earlier on-device success reported for this PR applied to the original Android directory-loading patch, not this replacement. The full test suite was not run for this revision.

Official releases are built with GOOS=linux. Go only searches
/etc/ssl/certs and /etc/pki/tls/certs for system roots on GOOS=linux;
/system/etc/security/cacerts is only added for GOOS=android builds.
Neither default path exists on Android, so Xray ends up with an empty
root pool there and every outbound TLS handshake fails with
x509: certificate signed by unknown authority. This is a common
deployment (rooted devices running the linux/arm64 binary via
Magisk/KernelSU modules such as box_for_root).

When the system pool comes back empty on linux, fall back to loading
the Android system CA store directly.
@Fangliding

Copy link
Copy Markdown
Member

maybe

//go:build linux && (arm || arm64)

package tls

import _ "golang.org/x/crypto/x509roots/fallback"

@Raycc-lang

Copy link
Copy Markdown
Author

Thanks, this looks like a simpler way to address the empty root pool. The trade-off is that it would use the bundled Mozilla/NSS roots rather than Android’s system CA store, so the dependency would need to stay updated.

Would you prefer that approach?

@RPRX

RPRX commented Oct 8, 2026

Copy link
Copy Markdown
Member

之前说过计划是 Xray 内置 CA 库然后不再 load 操作系统内置的根证书来着

@Fangliding

Copy link
Copy Markdown
Member

Thanks, this looks like a simpler way to address the empty root pool. The trade-off is that it would use the bundled Mozilla/NSS roots rather than Android’s system CA store, so the dependency would need to stay updated.

Would you prefer that approach?

机器人会更新它的 而且它的本质只是给不标准的设备追加一个后备证书库 不是主要机制 应该不会有人服务端使用非常新的根证书还在安卓上跑xray的Linux build还用几年前的旧版本xray

Added a comment explaining the purpose of the file for Linux ARM builds on Android.
@RPRX

RPRX commented Oct 8, 2026

Copy link
Copy Markdown
Member

@Fangliding 话说 Golang 这个 CA 库有哪些根证书?

@Raycc-lang 这个 PR 改成 @Fangliding 说的然后默认不 load 系统 CA 库,TLS 加个选项才使用系统 CA 库吧

@Fangliding

Copy link
Copy Markdown
Member

那算了还是我弄吧

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.

3 participants