Skip to content

Commit 0e63a95

Browse files
committed
feat: optional embedded Mozilla fallback roots (EMBED_CA=1)
Build tag embedca blank-imports x/crypto/x509roots/fallback: the embedded bundle activates only when the system provides no certificate pool, so HTTPS plugins work on minimal images (OpenWrt before 21.02, bare buildroot) without ca-certificates. Off by default; costs ~160KB when enabled. Signed-off-by: Date Huang <tjjh89017@hotmail.com>
1 parent 2e18b83 commit 0e63a95

5 files changed

Lines changed: 23 additions & 3 deletions

File tree

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ run:
33
# builtin_all lints every built-in at once; GOOS is swept by `make lint`.
44
build-tags:
55
- builtin_all
6+
- embedca
67
linters:
78
enable:
89
- protogetter

Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ TRIMPATH ?= 1
99
UPX ?= 0
1010
EXTRA_MIN ?= 0
1111
BUILTIN ?= all
12+
# EMBED_CA=1 embeds the Mozilla root bundle (build tag embedca), used only
13+
# when the system has no CA store. For images without ca-certificates.
14+
EMBED_CA ?= 0
1215
# Empty selects the per-platform default from the internal/wg build constraints:
1316
# wgcli on freebsd, wgctrl elsewhere. Set to override.
1417
BACKEND ?=
@@ -49,9 +52,14 @@ ifeq ($(BUILTIN),all)
4952
override BUILTIN := builtin_all
5053
endif
5154

52-
# Combine BUILTIN and BACKEND tags. An empty BACKEND adds no tag, leaving the
53-
# backend choice to the build constraints in internal/wg.
54-
ALL_TAGS := $(strip $(BUILTIN) $(BACKEND))
55+
CA_TAG =
56+
ifneq ($(EMBED_CA),0)
57+
CA_TAG := embedca
58+
endif
59+
60+
# Combine BUILTIN, BACKEND and EMBED_CA tags. An empty BACKEND adds no tag,
61+
# leaving the backend choice to the build constraints in internal/wg.
62+
ALL_TAGS := $(strip $(BUILTIN) $(BACKEND) $(CA_TAG))
5563
TAGS_FLAGS = $(if $(ALL_TAGS),-tags '$(ALL_TAGS)',)
5664

5765
UPX_TARGET =

embedca.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build embedca
2+
3+
package main
4+
5+
// The embedded Mozilla roots activate only when the system provides no
6+
// certificate store, so HTTPS plugins work on minimal images (e.g. OpenWrt
7+
// before 21.02, bare buildroot) without a ca-certificates package.
8+
import _ "golang.org/x/crypto/x509roots/fallback"

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
go.uber.org/mock v0.6.0
1212
go.yaml.in/yaml/v3 v3.0.4
1313
golang.org/x/crypto v0.54.0
14+
golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e
1415
golang.org/x/net v0.57.0
1516
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20241231184526-a9ab2273dd10
1617
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
6060
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
6161
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
6262
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
63+
golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e h1:9TjMDOuGaMMTP5f7GXeHeA0JvFqGmv4DYRIWkzoePGI=
64+
golang.org/x/crypto/x509roots/fallback v0.0.0-20260723152544-d701c51f7e4e/go.mod h1:+UoQFNBq2p2wO+Q6ddVtYc25GZ6VNdOMyyrd4nrqrKs=
6365
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
6466
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
6567
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=

0 commit comments

Comments
 (0)