Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ config_version = 2
keystore = "./ids-passkey.keystore"
```

相对路径以配置文件目录为准。设备身份和加密会话放在平台用户持久目录;上科大必需的网关证书域名由程序提供,证书验证继续开启。普通用户无需填写应用 ID、网关 IP 或协议回退开关。
相对路径以配置文件目录为准。设备身份和加密会话放在平台用户持久目录;上科大必需的网关证书域名由程序提供,默认开启证书验证。普通用户无需填写应用 ID、网关 IP 或协议回退开关。

配置按 `controller`、`auth`、`proxy`、`web`、`dns`、`storage`、`logging` 分组。监听地址省略时采用默认值,空字符串表示禁用。`controller.compatibility` 选择 `auto`、`shanghaitech`、`ecnu` 或 `generic`;它用于控制器兼容适配。`auth.mode` 支持 `auto`、`client`、`browser`;browser 模式不能绑定授信终端。

文件权限检查和设置问题默认输出英文警告。在 `[storage]` 中设置 `strict_permissions = true` 后,这些问题会阻止操作。新文件仍会尝试设置私有权限;文件内容的格式校验始终保留,实际读写失败仍会报错。旧格式使用顶层 `strict_permissions`,迁移时会保留该设置。

在 `[tls.gateway]` 中设置 `insecure_skip_verify = true` 可跳过网关 TLS 证书验证,包括证书有效期、域名和 CA 检查。默认值为 `false`;开启后无法通过证书确认网关身份。该设置只影响网关隧道,控制器 HTTPS 仍验证证书。旧格式使用顶层 `insecure_skip_verify`,迁移时会保留该设置。

旧格式继续可读,不自动重写。检查和迁移命令:

```sh
Expand Down
2 changes: 2 additions & 0 deletions client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ defer conn.Close()

控制器兼容适配默认为 `compatibility.Auto`。上科大的已验证 TLS 身份和缺字段补充由内部适配提供;未知控制器采用 `Generic`。`Fallbacks=nil` 使用适配默认,`&compatibility.Fallbacks{}` 关闭全部兜底。TLS 设置放在 `Network.GatewayTLS`,正常 CA 验证成功时不强制检查 pin;未知 CA 的兜底需要原子的 `CheckOrEnroll`,并继续验证证书身份和有效期。

`Network.GatewayTLS.Config.InsecureSkipVerify=true` 可显式跳过网关证书验证和 pin 检查,默认关闭;开启后无法通过证书确认网关身份。调用方提供的 TLS 验证回调仍会执行,控制器 HTTPS 不受此设置影响。

SDK 默认仅使用控制器 DNS;额外来源由 `DNS.FallbackLookup` 明确提供。CLI 的 `auto` 顺序在命令转换层保留。`Network.AllowedGateways=nil` 不额外限制,显式空列表拒绝全部线路。`CheckTarget` 收到地址、协议、端口和代;`DNSQueryTarget` 区分基础 DNS 查询,只能收紧访问权限。

`Status` 返回安全快照;`Subscribe(ctx)` 为每个订阅者提供独立有界队列,慢订阅者不会阻塞连接。`ImplementedCapabilities()` 表示 SDK 实现范围,不代表资源授权或目标连通。`ExchangeICMPEcho` 仅支持未分片 IPv4 Echo,UDP 保留数据报边界,payload 上限为 1372 字节。IPv6 目标未实现。
Expand Down
2 changes: 1 addition & 1 deletion cmd/geektrust/config_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func cmdConfig(path string, args []string) error {
fmt.Println("configuration valid")
return nil
}
fmt.Printf("config_version = %d\ncontroller = %q\ncompatibility = %q\nauth_mode = %q\ndns_strategy = %q\nkeystore = %q\nstate_file = %q\nstrict_permissions = %t\n", c.Version, c.BaseURL, c.Compatibility, c.ClientType, c.DNSStrategy, c.Keystore, c.StateFile, c.StrictPermissions)
fmt.Printf("config_version = %d\ncontroller = %q\ncompatibility = %q\nauth_mode = %q\ndns_strategy = %q\nkeystore = %q\nstate_file = %q\nstrict_permissions = %t\ninsecure_skip_verify = %t\n", c.Version, c.BaseURL, c.Compatibility, c.ClientType, c.DNSStrategy, c.Keystore, c.StateFile, c.StrictPermissions, c.InsecureSkipVerify)
return nil
case "migrate":
fs := flag.NewFlagSet("config migrate", flag.ContinueOnError)
Expand Down
4 changes: 2 additions & 2 deletions cmd/geektrust/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func commandClient(cfg *config.Config, logger *slog.Logger) (*runtime.Runtime, e
if cfg.ClientType == "client" {
o.Auth.Mode = runtime.DesktopMode
}
if cfg.GatewayTLSName != "" {
o.Network.GatewayTLS.Config = &tls.Config{ServerName: cfg.GatewayTLSName}
if cfg.GatewayTLSName != "" || cfg.InsecureSkipVerify {
o.Network.GatewayTLS.Config = &tls.Config{ServerName: cfg.GatewayTLSName, InsecureSkipVerify: cfg.InsecureSkipVerify}
}
if cfg.CAFile != "" {
b, e := os.ReadFile(cfg.CAFile)
Expand Down
3 changes: 2 additions & 1 deletion config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ keystore = "./ids-passkey.keystore"
# [logging]
# level = "info"

# 高级设置只在实际部署需要时填写。证书验证始终开启。
# 高级设置只在实际部署需要时填写。默认验证网关证书。
# [tls.gateway]
# server_name = ""
# ca_file = ""
# insecure_skip_verify = false # true 跳过网关证书验证,包括证书有效期和域名检查
# [routing]
# gateway_filter = [] # 显式空列表拒绝所有线路;省略不额外筛选
# fallback_app_id = ""
17 changes: 9 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ const DefaultWebListen = "127.0.0.1:8081"

// Config is the top-level configuration.
type Config struct {
UnknownFields []string `toml:"-"`
Version int `toml:"-"`
Compatibility public.Profile `toml:"-"`
DNSStrategy string `toml:"-"`
Directory string `toml:"-"`
CAFile string `toml:"-"`
AppID string `toml:"app_id"`
StrictPermissions bool `toml:"strict_permissions"`
UnknownFields []string `toml:"-"`
Version int `toml:"-"`
Compatibility public.Profile `toml:"-"`
DNSStrategy string `toml:"-"`
Directory string `toml:"-"`
CAFile string `toml:"-"`
AppID string `toml:"app_id"`
StrictPermissions bool `toml:"strict_permissions"`
InsecureSkipVerify bool `toml:"insecure_skip_verify"`

Fallbacks public.Fallbacks `toml:"-"`
GatewayTLSName string `toml:"-"`
Expand Down
29 changes: 29 additions & 0 deletions internal/config/tls_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package config

import "testing"

func TestGatewayInsecureSkipVerify(t *testing.T) {
for _, format := range []struct{ name, base string }{
{"legacy", "keystore = 'credential'\n"},
{"v2", "config_version = 2\n[auth.passkey]\nkeystore = 'credential'\n[storage]\ndirectory = './private'\n[tls.gateway]\n"},
} {
for _, tc := range []struct {
name, setting string
want bool
}{
{"default", "", false},
{"disabled", "insecure_skip_verify = false\n", false},
{"enabled", "insecure_skip_verify = true\n", true},
} {
t.Run(format.name+"/"+tc.name, func(t *testing.T) {
cfg, err := Load(writeConfig(t, format.base+tc.setting))
if err != nil {
t.Fatal(err)
}
if cfg.InsecureSkipVerify != tc.want || len(cfg.UnknownFields) != 0 {
t.Fatalf("insecure_skip_verify=%t, unknown fields=%v", cfg.InsecureSkipVerify, cfg.UnknownFields)
}
})
}
}
}
7 changes: 5 additions & 2 deletions internal/config/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ type FileV2 struct {
} `toml:"logging"`
TLS struct {
Gateway struct {
ServerName string `toml:"server_name"`
CAFile string `toml:"ca_file"`
ServerName string `toml:"server_name"`
CAFile string `toml:"ca_file"`
InsecureSkipVerify bool `toml:"insecure_skip_verify"`
} `toml:"gateway"`
} `toml:"tls"`
Routing struct {
Expand Down Expand Up @@ -170,6 +171,7 @@ func loadV2(path string, data []byte) (*Config, error) {
cfg.GatewayTLSName = f.TLS.Gateway.ServerName
}
cfg.CAFile = resolve(f.TLS.Gateway.CAFile)
cfg.InsecureSkipVerify = f.TLS.Gateway.InsecureSkipVerify
socks, http, web := "127.0.0.1:1080", "127.0.0.1:8080", DefaultWebListen
if meta.IsDefined("proxy", "socks5", "listen") {
socks = f.Proxy.SOCKS5.Listen
Expand Down Expand Up @@ -314,6 +316,7 @@ func Migration(path string) ([]byte, error) {
f.Logging.Level = c.LogLevel
f.Routing.FallbackAppID = c.AppID
f.TLS.Gateway.ServerName = c.GatewayTLSName
f.TLS.Gateway.InsecureSkipVerify = c.InsecureSkipVerify
var b bytes.Buffer
e = toml.NewEncoder(&b).Encode(f)
return b.Bytes(), e
Expand Down
5 changes: 4 additions & 1 deletion internal/config/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestV2StrictAndLegacyMigration(t *testing.T) {
t.Fatal("invalid v2 accepted")
}
}
old := "keystore='credential'\ndevice_id='0123456789ABCDEF0123456789ABCDEF'\nclient_type='browser'\napp_id='custom'\nunknown_old_key=true\n"
old := "keystore='credential'\ndevice_id='0123456789ABCDEF0123456789ABCDEF'\nclient_type='browser'\napp_id='custom'\ninsecure_skip_verify=true\nunknown_old_key=true\n"
os.WriteFile(p, []byte(old), 0600)
b, e := Migration(p)
if e != nil {
Expand All @@ -70,6 +70,9 @@ func TestV2StrictAndLegacyMigration(t *testing.T) {
if c.StateFile != expectedState {
t.Fatal("migration changed the effective session path")
}
if !c.InsecureSkipVerify {
t.Fatal("migration lost the gateway certificate verification setting")
}
if !strings.Contains(string(b), "0123456789ABCDEF0123456789ABCDEF") || !strings.Contains(string(b), "browser") || !strings.Contains(string(b), "custom") {
t.Fatal("migration lost existing semantics")
}
Expand Down
5 changes: 3 additions & 2 deletions internal/runtime/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestOptionsCopiedAndProfileDefaults(t *testing.T) {
o.Compatibility.Fallbacks.ApplicationID = "custom-app"
o.Compatibility.Fallbacks.Gateways = []string{"configured.example:441"}
o.DNS.Servers = []netip.Addr{netip.MustParseAddr("10.0.0.53")}
template := &tls.Config{ServerName: "gateway.example"}
template := &tls.Config{ServerName: "gateway.example", InsecureSkipVerify: true}
o.Network.GatewayTLS.Config = template
c, e := New(o)
if e != nil {
Expand All @@ -83,6 +83,7 @@ func TestOptionsCopiedAndProfileDefaults(t *testing.T) {
defer c.Close()
o.Compatibility.Fallbacks.Gateways[0] = "mutated.example:441"
template.ServerName = "mutated"
template.InsecureSkipVerify = false
info, e := c.Connect(context.Background())
if e != nil {
t.Fatal(e)
Expand All @@ -95,7 +96,7 @@ func TestOptionsCopiedAndProfileDefaults(t *testing.T) {
t.Fatal("application fallback lost")
}
_, sc := c.provider.ActiveSession()
if c.manager.GatewayTLSConfig.ServerName != "gateway.example" || sc.LoginDomain != "custom-domain" {
if c.manager.GatewayTLSConfig.ServerName != "gateway.example" || !c.manager.GatewayTLSConfig.InsecureSkipVerify || sc.LoginDomain != "custom-domain" {
t.Fatal("TLS/login settings lost")
}
}
Expand Down
3 changes: 0 additions & 3 deletions internal/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ func New(opts Options) (*Runtime, error) {
if (opts.Network.GatewayTLS.Mode == VerifyCAOrTOFU) != (opts.Network.GatewayTLS.PinStore != nil) {
return nil, errors.New("gateway pin store requires CA-or-TOFU mode")
}
if t := opts.Network.GatewayTLS.Config; t != nil && t.InsecureSkipVerify {
return nil, errors.New("gateway certificate verification cannot be disabled")
}
if opts.Logger == nil {
opts.Logger = slog.New(slog.NewTextHandler(io.Discard, nil))
}
Expand Down
74 changes: 51 additions & 23 deletions internal/tunnel/tls_callback_regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ func TestCallbackRejectionDoesNotEnrollGatewayPin(t *testing.T) {
server := httptest.NewTLSServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
defer server.Close()
rejected := errors.New("caller rejected certificate")
config := &tls.Config{VerifyConnection: func(tls.ConnectionState) error { return rejected }}
pins := &testPinStore{pins: map[string][]byte{}}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
if conn, err := probeGatewayTLSWithDialer(ctx, strings.TrimPrefix(server.URL, "https://"), nil, config, pins); err == nil {
conn.Close()
t.Fatal("caller rejection was ignored")
} else if !errors.Is(err, rejected) {
t.Fatalf("callback error = %v", err)
}
if len(pins.pins) != 0 {
t.Fatal("a caller-rejected certificate was enrolled")
for _, skip := range []bool{false, true} {
config := &tls.Config{InsecureSkipVerify: skip, VerifyConnection: func(tls.ConnectionState) error { return rejected }}
pins := &testPinStore{pins: map[string][]byte{}}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
conn, err := probeGatewayTLSWithDialer(ctx, strings.TrimPrefix(server.URL, "https://"), nil, config, pins)
cancel()
if err == nil {
conn.Close()
t.Fatal("caller rejection was ignored")
} else if !errors.Is(err, rejected) {
t.Fatalf("callback error = %v", err)
}
if len(pins.pins) != 0 {
t.Fatal("a caller-rejected certificate was enrolled")
}
}
}

Expand Down Expand Up @@ -123,16 +126,41 @@ func TestCAOrTOFUHonorsConfiguredClock(t *testing.T) {
roots := x509.NewCertPool()
roots.AddCert(server.Certificate())
future := server.Certificate().NotAfter.Add(time.Hour)
config := &tls.Config{RootCAs: roots, Time: func() time.Time { return future }}
pins := &testPinStore{pins: map[string][]byte{}}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
conn, err := probeGatewayTLSWithDialer(ctx, strings.TrimPrefix(server.URL, "https://"), nil, config, pins)
if err == nil {
conn.Close()
t.Fatal("expired certificate was accepted under the configured clock")
}
if len(pins.pins) != 0 {
t.Fatal("expired certificate enrolled a fallback pin")
for _, tc := range []struct {
name string
tofu, skip bool
}{
{"CA", false, false},
{"CA/skip", false, true},
{"CA-or-TOFU", true, false},
{"CA-or-TOFU/skip", true, true},
} {
t.Run(tc.name, func(t *testing.T) {
config := &tls.Config{RootCAs: roots, Time: func() time.Time { return future }, InsecureSkipVerify: tc.skip}
pins := &testPinStore{pins: map[string][]byte{}}
var trust GatewayTrustStore
if tc.tofu {
trust = pins
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
conn, err := probeGatewayTLSWithDialer(ctx, strings.TrimPrefix(server.URL, "https://"), nil, config, trust)
if conn != nil {
conn.Close()
}
if tc.skip {
if err != nil {
t.Fatalf("explicit certificate verification bypass failed: %v", err)
}
} else {
var invalid x509.CertificateInvalidError
if !errors.As(err, &invalid) || invalid.Reason != x509.Expired {
t.Fatalf("expected expired certificate rejection, got %v", err)
}
}
if len(pins.pins) != 0 {
t.Fatal("expired certificate enrolled a fallback pin")
}
})
}
}
2 changes: 1 addition & 1 deletion internal/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ type GatewayTrustStore interface {

func gatewayTLSConfigWithTrust(ctx context.Context, addr string, template *tls.Config, trust GatewayTrustStore) *tls.Config {
cfg := gatewayTLSConfigWithTemplate(addr, template)
if trust == nil {
if trust == nil || cfg.InsecureSkipVerify {
return cfg
}
previous := cfg.VerifyConnection
Expand Down
12 changes: 6 additions & 6 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading