fix: set CA certificate path for CGO_ENABLED=0 Android builds

The pure-Go TLS stack cannot find CA certificates on Android because
they are at /system/etc/security/cacerts instead of standard Linux
paths. Set SSL_CERT_DIR when no cert env vars are configured.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
KoheiYamashita 2026-03-01 04:18:58 +09:00
parent c0babbc643
commit 314b84808c

View file

@ -123,6 +123,15 @@ func init() {
net.DefaultResolver.Dial = func(ctx context.Context, network, address string) (net.Conn, error) {
return (&net.Dialer{}).DialContext(ctx, "udp", "8.8.8.8:53")
}
// Set CA certificate location for CGO_ENABLED=0 builds (Android APK).
// The pure-Go TLS stack cannot find Android's CA certs at their
// non-standard path. Only set if not already configured.
if os.Getenv("SSL_CERT_FILE") == "" && os.Getenv("SSL_CERT_DIR") == "" {
if _, err := os.Stat("/system/etc/security/cacerts"); err == nil {
os.Setenv("SSL_CERT_DIR", "/system/etc/security/cacerts")
}
}
}
func main() {