---
title: "修復 Mac 上 Rust（cargo/rustup）與 Go 的 x509 SSL 憑證錯誤 — SWG bar"
description: "在 Zscaler、Cloudflare WARP 或 Netskope 企業 SWG 環境下，修復 macOS 上 Rust（cargo/rustup）與 Go 的 x509 憑證驗證失敗錯誤，無需關閉 TLS 驗證。"
image: "https://swgbar.com/brand/swgbar-og-1200x630.png"
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://swgbar.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

Source: https://swgbar.com/zh-TW/guides/fix-rust-cargo-rustup-go-ssl-x509-error-mac/
Language: zh-TW

# 修復 Mac 上 Rust（cargo/rustup）與 Go 的 x509 SSL 憑證錯誤

在 Zscaler、Cloudflare WARP 或 Netskope 企業 SWG 環境下，修復 macOS 上 Rust（cargo/rustup）與 Go 的 x509 憑證驗證失敗錯誤，無需關閉 TLS 驗證。

SWG bar · 更新日期 2026年12月2日

在安裝了 Zscaler、Cloudflare WARP、Netskope、Cisco Umbrella、Palo Alto GlobalProtect 或 Fortinet 的工作用 Mac 上執行 `cargo build`、`cargo add`、`rustup update`、`go mod download` 或 `go install` 時，Rust 與 Go 工具鏈經常在 TLS 驗證階段直接報錯中斷：

```
# Cargo（crates.io sparse 索引 / libcurl）
error: failed to download from `https://index.crates.io/config.json`
Caused by:
  [60] SSL peer certificate or SSH remote key was not OK
  (SSL certificate problem: unable to get local issuer certificate)

# Rustup（rustls / reqwest）
error: could not download file from 'https://static.rust-lang.org/dist/channel-rust-stable.toml.sha256'
caused by: invalid peer certificate: UnknownIssuer

# Go（go mod download / go get / Go HTTP 用戶端）
go: github.com/gin-gonic/gin@v1.10.0: Get "https://proxy.golang.org/...":
  tls: failed to verify certificate: x509: certificate signed by unknown authority
```

你可以將終端機原始錯誤訊息貼入免費的[企業 SWG 與 SSL 錯誤解碼器](<https://swgbar.com/zh-TW/tools/tls-error-decoder/>)快速定位問題層級，或依下方可跨升級保留的 macOS 信任庫方案修復。

## 1\. 為什麼 Rust（`cargo`/`rustup`）與 Go 會拒絕企業 SWG 憑證

Safari 與 Chrome 透過 macOS 系統鑰匙圈驗證 TLS 憑證鏈，企業 MDM 部署的 SWG 根憑證就安裝在那裡。但系統級開發工具鏈的運作方式不同：

*   **Cargo 與 Rustup**：`cargo` 連結 `libcurl`（拉取 Git 相依套件時使用 `libgit2`），而 `rustup` 使用 `reqwest`/`rustls`。兩者都不會自動將 macOS 系統鑰匙圈與靜態 PEM 憑證包合併，而且 `rustls` 的 X.509 擴充欄位檢查比 macOS 更嚴格，經常直接拒絕舊式企業 SWG 根憑證。
*   **Go（`crypto/x509`）**：macOS 上的 Go 預設呼叫 `Security.framework` 驗證，**但如果**你的 Shell 已設定 `SSL_CERT_FILE` 或 `SSL_CERT_DIR`，Go 會**完全跳過 macOS 系統鑰匙圈**——只要該 PEM 檔只含單一憑證，所有公開 CA 都會立刻失效；此外，當 Go 執行檔跑在 Linux 容器中，或 `go get` 為 `GOPRIVATE` 私有儲存庫呼叫 `git` 時，也會出現同樣的 `x509` 或 SSL 錯誤。

先檢查目前的環境變數與作用中的工具版本：

```
env | grep -E 'SSL_CERT|CURL_CA|CARGO_HTTP|RUSTUP_USE_CURL|GOPROXY'
go env GOPROXY GOSUMDB GOPRIVATE
cargo --version && rustup --version
```

切勿將 `SSL_CERT_FILE` 指向**僅包含企業 SWG 根憑證**的檔案，否則所有未被解密的正常公開 HTTPS 端點在 Go 與 Rust 中都會立即驗證失敗。

## 2\. 建立可跨升級保留的「系統 + 企業 SWG」合併 CA 憑證包

在 `~/.certs/rust-go-combined-ca.pem` 中建立一份合併憑證包，同時收錄 **Apple 內建公開根憑證**與**企業 SWG 根憑證**，避免 Homebrew、Rust 或 Go 升級時遭覆寫：

```
mkdir -p "$HOME/.certs"

# 1. 匯出 Apple 內建受信任的公開根憑證
security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain > "$HOME/.certs/rust-go-combined-ca.pem"

# 2. 附加企業 SWG 根憑證（依實際廠商將 "Zscaler" 替換為 Cloudflare、goskope、Cisco Umbrella、Fortinet 等）
security find-certificate -c "Zscaler" -p /Library/Keychains/System.keychain >> "$HOME/.certs/rust-go-combined-ca.pem"
```

由於標準公開根憑證與企業 SWG 根憑證並存於同一檔案，受解密檢查的套件庫（`index.crates.io`、`static.rust-lang.org`、`proxy.golang.org`、`sum.golang.org`）與直連端點皆能穩定通過驗證。

## 3\. 為 Cargo、Rustup、Go 與 Git 永久設定 CA 信任

在 `~/.zshrc` 中統一匯出 `SSL_CERT_FILE`、`CURL_CA_BUNDLE` 與 `CARGO_HTTP_CAINFO`，讓 Go 的 `crypto/x509`、Cargo HTTP 用戶端與 Rustup 共用同一份合併憑證包：

```
cat <<'EOF' >> ~/.zshrc
export SSL_CERT_FILE="$HOME/.certs/rust-go-combined-ca.pem"
export CURL_CA_BUNDLE="$HOME/.certs/rust-go-combined-ca.pem"
export CARGO_HTTP_CAINFO="$HOME/.certs/rust-go-combined-ca.pem"
EOF
source ~/.zshrc
```

接著持久化 Cargo 設定（請使用展開後的絕對路徑，因 Cargo 不會在 `config.toml` 中展開 `~`），並為 `GOPRIVATE` 與 Cargo Git 相依套件設定 Git 全域信任：

```
mkdir -p "$HOME/.cargo"
cat <<EOF >> "$HOME/.cargo/config.toml"

[http]
cainfo = "$HOME/.certs/rust-go-combined-ca.pem"

[net]
git-fetch-with-cli = true
EOF

git config --global http.sslCAInfo "$HOME/.certs/rust-go-combined-ca.pem"
```

若 `rustup update` 因 `rustls` 拒絕企業 SWG 根憑證的擴充欄位而仍顯示 `invalid peer certificate: UnknownIssuer`，可在 `~/.zshrc` 中加入 `export RUSTUP_USE_CURL=1`，讓 `rustup` 在維持完整 TLS 驗證的前提下改用 `libcurl` 與 `CURL_CA_BUNDLE`。

在不關閉 TLS 驗證的前提下驗證三項工具（**切勿**在 Go `tls.Config` 設定 `InsecureSkipVerify: true`、在 Rust `reqwest` 使用 `danger_accept_invalid_certs(true)`、設定 `git config --global http.sslVerify false` 或使用 `curl -k`）：

```
rustup check
cargo search serde --limit 1
go list -m -versions golang.org/x/text
```

## 4\. 修復 `rust-analyzer`、`gopls` 與 IDE 背景任務

如果在終端機中執行 `cargo build` 與 `go mod download` 正常，但在 **VS Code（`rust-analyzer`、`gopls`）**、**RustRover** 或 **GoLand** 內仍然出現 SSL 錯誤，是因為 macOS 圖形化 App 預設不會載入 `~/.zshrc`。透過以下兩步即可永久修正：

*   **保留 `~/.cargo/config.toml` 的 `[http] cainfo` 與 `~/.gitconfig` 的 `http.sslCAInfo`**：無論是否透過互動式 Shell 啟動，Cargo 與 Git 都會直接讀取這兩份檔案。
*   **為目前登入工作階段的 GUI App 注入環境變數**：
    
    ```
    launchctl setenv SSL_CERT_FILE "$HOME/.certs/rust-go-combined-ca.pem"
    launchctl setenv CURL_CA_BUNDLE "$HOME/.certs/rust-go-combined-ca.pem"
    launchctl setenv CARGO_HTTP_CAINFO "$HOME/.certs/rust-go-combined-ca.pem"
    ```
    
    執行後完全結束並重新開啟 VS Code、RustRover 或 GoLand，讓語言伺服器套用新環境變數。

## 5\. 透過逐網域繞過 SWG 省去手動維護 CA 憑證包

`rustls` 的嚴格憑證驗證、企業中繼憑證輪換以及多語言開發環境，往往讓手動維護的 PEM 憑證包反覆失效。在公司政策允許對開發套件庫逐網域繞過的前提下，[SWG bar](<https://swgbar.com/zh-TW/install/>) 可自動偵測遭解密攔截的網域，並在維持企業 VPN 與 SSO 不中斷的情況下逐網域還原真實 TLS 憑證（提供 14 個實際使用日免費試用）：

```
swgbar probe index.crates.io
swgbar bypass enable index.crates.io
swgbar bypass enable static.rust-lang.org
swgbar bypass enable proxy.golang.org
```

同一台工作用 Mac 上還遇到其他開發工具鏈的 SSL 錯誤？繼續閱讀[修復 Git 與 npm 的 SSL 憑證錯誤](<https://swgbar.com/zh-TW/guides/fix-git-npm-unable-to-get-local-issuer-certificate-mac/>)、[修復 Python `CERTIFICATE_VERIFY_FAILED` 與 Docker `x509` 錯誤](<https://swgbar.com/zh-TW/guides/fix-python-docker-certificate-verify-failed-x509-mac/>)，以及[如何在 Mac 上繞過 SWG](<https://swgbar.com/zh-TW/guides/how-to-bypass-swg/>)。

macOS 14+ · Apple Silicon

## 別再盲猜公司 SWG 解密了哪些網域。

SWG bar 在 Mac 選單列即時偵測 HTTPS 解密，並支援單一網域一鍵繞過，同時保持公司 VPN 與 SSO 正常運作。

[$0 開啟 14 天免費試用](<https://swgbar.com/releases/2.4.13/SWGBar-macOS-arm64.pkg>) [診斷 TLS 錯誤](<https://swgbar.com/zh-TW/tools/tls-error-decoder/>) [免費 Chrome 擴充功能](<https://chromewebstore.google.com/detail/bidclnlfneemkkdeanlcbpjfdalelmbf>)

## 延伸閱讀

*   [如何在 Mac 上繞過 SWG（單網域一鍵繞過與 CLI 指令）](<https://swgbar.com/zh-TW/guides/how-to-bypass-swg/>)
*   [如何在 Mac 上繞過 SSL 檢查（企業 SWG 單網域直連方案）](<https://swgbar.com/zh-TW/guides/bypass-ssl-inspection-mac/>)
*   [如何在 macOS 上繞過 HTTPS 與 TLS 檢查（Break-and-Inspect 指南）](<https://swgbar.com/zh-TW/guides/bypass-https-tls-inspection-mac/>)
*   [如何在 Mac 上繞過企業代理伺服器與 SWG SSL 檢查](<https://swgbar.com/zh-TW/guides/bypass-corporate-proxy-ssl-inspection-mac/>)
*   [如何判斷 Mac 是否被 SWG 劫持（偵測 HTTPS 與 SSL 檢查）](<https://swgbar.com/zh-TW/guides/detect-https-inspection/>)
*   [如何檢查公司或工作用 Mac 是否正在攔截 HTTPS（SSL 檢查）](<https://swgbar.com/zh-TW/guides/check-if-work-mac-intercepting-https/>)
*   [公司在工作用 Mac 上能看到我的瀏覽紀錄、無痕模式與個人帳號嗎？](<https://swgbar.com/zh-TW/guides/can-employer-see-browsing-history-incognito-work-mac/>)
*   [Mac 專用 SSL 檢查偵測工具：在選單列即時發現 HTTPS 攔截](<https://swgbar.com/zh-TW/guides/ssl-inspection-checker-mac/>)
*   [Mac 上的 Zscaler SSL 檢查：如何偵測並按網域繞過](<https://swgbar.com/zh-TW/guides/zscaler-ssl-inspection-bypass-mac/>)
*   [如何在 Mac 上關閉或繞過 Zscaler（當防竄改保護將其鎖定時）](<https://swgbar.com/zh-TW/guides/disable-turn-off-zscaler-on-mac/>)
*   [Mac 上的 Cloudflare WARP 與 Zero Trust TLS 檢查：偵測與繞過](<https://swgbar.com/zh-TW/guides/cloudflare-warp-tls-inspection-mac/>)
*   [Mac 上的 Netskope SSL 檢查：偵測解密與單網域繞過指南](<https://swgbar.com/zh-TW/guides/netskope-ssl-inspection-bypass-mac/>)
*   [Mac 上的 Cisco Umbrella SSL 檢查：偵測解密並按網域繞過](<https://swgbar.com/zh-TW/guides/cisco-umbrella-ssl-inspection-bypass-mac/>)
*   [Mac 上的 Palo Alto GlobalProtect 與 Prisma Access SSL 解密：偵測與繞過](<https://swgbar.com/zh-TW/guides/palo-alto-globalprotect-prisma-ssl-decryption-mac/>)
*   [Mac 上的 Fortinet FortiClient 與 FortiGate（Fortinet\_CA\_SSL）檢查：偵測與繞過](<https://swgbar.com/zh-TW/guides/fortinet-forticlient-ssl-inspection-bypass-mac/>)
*   [修復 Mac 上 Git 與 npm 的 'unable to get local issuer certificate' / SELF\_SIGNED\_CERT\_IN\_CHAIN 錯誤](<https://swgbar.com/zh-TW/guides/fix-git-npm-unable-to-get-local-issuer-certificate-mac/>)
*   [修復 Mac 上 Python 'CERTIFICATE\_VERIFY\_FAILED' 與 Docker 'x509: certificate signed by unknown authority' 錯誤](<https://swgbar.com/zh-TW/guides/fix-python-docker-certificate-verify-failed-x509-mac/>)
*   [修復 Mac 上 GitHub Copilot、OpenAI Codex 與 Gemini CLI 的 SSL 憑證錯誤（Zscaler / SWG）](<https://swgbar.com/zh-TW/guides/fix-codex-copilot-gemini-cli-ssl-certificate-error-mac/>)
*   [修復 Mac 上 Java、Maven、Gradle、IntelliJ 與 Android Studio 的 'PKIX path building failed' 錯誤](<https://swgbar.com/zh-TW/guides/fix-java-maven-gradle-intellij-android-studio-pkix-mac/>)
*   [修復 Mac 上 AWS CLI 與 Boto3 的 'SSL validation failed' 憑證錯誤](<https://swgbar.com/zh-TW/guides/fix-aws-cli-boto3-ssl-validation-failed-mac/>)
*   [修復 Mac 上 Google Cloud (gcloud) 與 Azure CLI (az login) 的 SSL 憑證錯誤](<https://swgbar.com/zh-TW/guides/fix-gcloud-azure-cli-ssl-certificate-verify-failed-mac/>)
*   [修復 Mac 上 Firefox 在 Zscaler 與企業 SWG 下的 'SEC\_ERROR\_UNKNOWN\_ISSUER' 錯誤](<https://swgbar.com/zh-TW/guides/fix-firefox-sec-error-unknown-issuer-mac/>)
*   [修復 Mac 上 Ruby、Bundler 與 CocoaPods 的 OpenSSL::SSL::SSLError](<https://swgbar.com/zh-TW/guides/fix-ruby-bundler-cocoapods-fastlane-ssl-error-mac/>)
*   [修復 Mac 上 kubectl、Helm 與 Minikube 的 x509 憑證錯誤](<https://swgbar.com/zh-TW/guides/fix-kubernetes-kubectl-helm-minikube-x509-mac/>)
*   [修復 Mac 上 curl (60)、Wget 與 PHP Composer 的 SSL 憑證錯誤](<https://swgbar.com/zh-TW/guides/fix-curl-60-wget-php-composer-ssl-error-mac/>)
*   [SWG bar 中的「已確認」與「疑似」HTTPS 檢查狀態解析](<https://swgbar.com/zh-TW/guides/confirmed-vs-suspected-https-inspection/>)
*   [在 SWG bar 中檢查中間人根憑證與核發機構](<https://swgbar.com/zh-TW/guides/inspect-mitm-root-certificates-macos/>)
*   [Mac 上的企業 SWG 與 MDM HTTPS 解密檢查解析](<https://swgbar.com/zh-TW/guides/enterprise-swg-https-inspection-macos/>)
*   [SWG 繞過與 TLS 解密例外（Break-and-Inspect）對比](<https://swgbar.com/zh-TW/guides/swg-bypass-vs-tls-exception/>)
*   [在 Mac 上為多網域 Web 應用、SSO、CDN 與 API 設定 SWG 繞過](<https://swgbar.com/zh-TW/guides/multi-domain-sso-api-cdn-swg-bypass/>)
*   [排解 Mac 上 SWG 繞過的「恢復中」「已暫停」與連線錯誤](<https://swgbar.com/zh-TW/guides/troubleshoot-swg-bypass-recovering-paused-macos/>)
*   [macOS VPN 虛擬介面與 SWG HTTPS 檢查比較](<https://swgbar.com/zh-TW/guides/macos-vpn-virtual-interface-vs-swg-inspection/>)
*   [為什麼憑證固定（Pinning）應用與 mTLS 在 SWG 檢查下會中斷](<https://swgbar.com/zh-TW/guides/certificate-pinning-mtls-swg-inspection-macos/>)
*   [修復 Mac 終端機 CLI 與 AI 工具中的 SWG TLS/SSL 憑證錯誤](<https://swgbar.com/zh-TW/guides/swg-tls-certificate-errors-macos/>)
*   [Mac 在 SWG 下的 Homebrew、Docker、Python 與 Node.js CA 信任設定](<https://swgbar.com/zh-TW/guides/homebrew-docker-python-node-ca-trust-swg-macos/>)
*   [修復 Mac 上 Claude Code 與 Cursor 的 'unable to get local issuer certificate' 錯誤（SWG 與 MCP）](<https://swgbar.com/zh-TW/guides/ai-coding-agents-claude-code-cursor-swg-macos/>)
*   [在 Mac 上使用 openssl 與 security verify-cert 驗證 TLS 憑證](<https://swgbar.com/zh-TW/guides/verify-tls-certificates-openssl-security-verify-cert-macos/>)
*   [SWG bar 權限、本機隱私與 TLS 探測上限說明](<https://swgbar.com/zh-TW/guides/macos-network-extension-privacy-probe-limits/>)
*   [SWG bar 如何檢查 HTTPS 解密](<https://swgbar.com/zh-TW/how-it-works/>)
*   [SWG bar 價格 — macOS 一次買斷授權（個人版與團隊版）](<https://swgbar.com/zh-TW/pricing/>)
*   [下載並安裝 Mac 版 SWG bar（macOS 14+）](<https://swgbar.com/zh-TW/install/>)
*   [偵測 SSL 與 HTTPS 檢查的 Chrome 擴充功能（SWG bar 配套外掛）](<https://swgbar.com/zh-TW/chrome-extension/>)
*   [SWG bar CLI 使用指南](<https://swgbar.com/zh-TW/cli/>)
*   [SWG bar MCP 使用指南](<https://swgbar.com/zh-TW/mcp/>)
*   [SWG bar 版本資訊](<https://swgbar.com/zh-TW/releases/>)
*   [關於 SWG bar](<https://swgbar.com/zh-TW/about/>)
