dial

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dial 实现 XOps v2 基于 golang.org/x/crypto/ssh 的真实 SSH 拨号、传输连接与会话适配器 (ports.DialerPort / ports.TransportConn / ports.RemoteSession / ports.KeySignerPort,ADR-009 / ADR-015)。

核心安全与并发不变量:

  • 全包 0 裸 go 语句,所有异步看门狗与数据面流泵均受 core/conc.Nursery(RunScoped/NewNursery)监督;
  • 所有基于 ssh.Channel(无原生 SetDeadline)的多跳连接均封装为 chanconn.WatchedConn, 在取消或截止时间到期时经看门狗立即关闭通道唤醒阻塞读写(ADR-015);
  • 严禁给 ssh.Session.Stdin 赋值(规避 x/crypto/ssh 孤儿拷贝协程泄漏),统一由 remotesess.Session 预绑定管道;
  • 严禁使用 ssh.InsecureIgnoreHostKey,所有服务端主机密钥均经 ports.HostTrustPort 强制核验;
  • 全部明文凭据均通过 SecretVault.WithSecret + box.Use 或 secret.WithBytes 同步消费,全包零 nolint 豁免;
  • 面向 Wave 2(sshnet/{sftp,forward,mux})在 TransportConn 上暴露受 lifeNursery 监督的通道与子系统原语 (OpenChannel / OpenWatchedChannel / OpenSubsystem / SendGlobalRequest / WaitDone / OpenRemoteFS)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// HostTrust 是必填的主机密钥信任库端口(严禁缺省或降级为不校验模式)。
	HostTrust ports.HostTrustPort
	// Vault 可选注入凭据库,用于 Password、加密私钥口令及 Keyboard-Interactive 凭据/TOTP 消费。
	Vault ports.SecretVault
	// KeySigner 可选注入外部公钥签名器端口。
	KeySigner ports.KeySignerPort
	// Agent 可选注入本机 SSH Agent 端口。
	Agent ports.SSHAgentPort
	// ReadFS 可选注入操作员本地只读文件端口,用于按策略读取私钥与证书文件(绝不直接调用 os.Open)。
	ReadFS ports.OperatorReadFS
	// Process 可选注入子进程端口,用于执行 ProxyCommand(DialStdio)与 Keyboard-Interactive RuleCommand。
	Process ports.ProcessPort
	// Interaction 可选注入人工交互端口,用于 StrictHostKeyChecking=ask 确认及未知质询应答。
	Interaction ports.InteractionPort
	// Clock 可选注入时钟端口(用于 TOTP 窗口与通道截止时间判断,为空时回退系统时间)。
	Clock ports.Clock
	// Env 可选注入只读环境与本机身份信息端口,用于展开私钥路径 "~/" 与 ProxyCommand 令牌。
	Env ports.EnvPort
	// DialContext 可选覆盖底层 TCP 拨号器。
	DialContext DialContextFunc
	// OpenRemoteFS 可选注入 SFTP 子系统工厂(未配置时 TransportConn.OpenRemoteFS 返回 ErrUnsupported)。
	OpenRemoteFS RemoteFSFactory
	// ClientVersion 可选覆盖 SSH 客户端标识串(须以 "SSH-2.0-" 开头且不含换行)。
	ClientVersion string
}

Config 描述 Dialer 的显式出站依赖配置(全依赖注入,零全局单例与隐式环境变量)。

type DialContextFunc

type DialContextFunc func(ctx context.Context, network, addr string) (net.Conn, error)

DialContextFunc 定义底层流传输拨号函数签名(为空时默认使用 (&net.Dialer{}).DialContext)。 测试夹具可注入回环重定向函数将测试端点映射至进程内 127.0.0.1 SSH 桩,绝不连接外部真实主机。

type Dialer

type Dialer struct {
	// contains filtered or unexported fields
}

Dialer 是基于 golang.org/x/crypto/ssh 的真实多跳拨号适配器,实现 ports.DialerPort;零值恒失败关闭。

func NewDialer

func NewDialer(cfg Config) (*Dialer, error)

NewDialer 校验必填 HostTrustPort 与可选客户端版本标识并构造不可变 Dialer。

func (*Dialer) DialHop

func (d *Dialer) DialHop(ctx context.Context, hop plan.HopSpec, hopDigest plan.HopDigest, parent ports.TransportConn) (ports.TransportConn, error)

DialHop 按不可变 HopSpec 与 Merkle HopDigest 建立单跳或多跳(经 parent.DialTCP 隧道)SSH 传输连接。 所有底层拨号与 SSH 握手均受 core/conc.RunScoped 取消/超时看门狗监督,多跳通道自动封装为 chanconn.WatchedConn。

type KeySigner

type KeySigner = keysigner.KeySigner

KeySignerConfig 与 KeySigner 为 core/internal/sshnet/dial/keysigner 的便捷别名, 供上层装配与测试在不直接感知子包路径时统一构造 ports.KeySignerPort。

func NewKeySigner

func NewKeySigner(cfg KeySignerConfig) (*KeySigner, error)

NewKeySigner 构造基于 OperatorReadFS / SecretVault / SSHAgentPort 的真实 ports.KeySignerPort 适配器。

type KeySignerConfig

type KeySignerConfig = keysigner.Config

KeySignerConfig 与 KeySigner 为 core/internal/sshnet/dial/keysigner 的便捷别名, 供上层装配与测试在不直接感知子包路径时统一构造 ports.KeySignerPort。

type RemoteFSFactory

type RemoteFSFactory func(ctx context.Context, conn *TransportConn) (ports.RemoteFSPort, error)

RemoteFSFactory 为 Phase 4(P4-T2 sshnet/sftp)预留的 SFTP 客户端构造注入点: 接收 *TransportConn 以便直接复用 OpenSubsystem(ctx, "sftp")、WaitDone 与 lifeNursery/WatchedConn 护栏。

type TransportConn

type TransportConn struct {
	// contains filtered or unexported fields
}

TransportConn 封装已认证的 *ssh.Client 及其被动断连监督生命周期,实现 ports.TransportConn;零值恒失败关闭。 同时面向 Wave 2(sshnet/{sftp,forward,mux})暴露受 lifeNursery 监督的通道、子系统与全局请求原语。

func (*TransportConn) Close

func (c *TransportConn) Close() error

Close 幂等关闭底层 SSH 传输连接、等待 client.Wait 退出并收敛所有看门狗协程(零泄漏)。

func (*TransportConn) DialStreamLocal

func (c *TransportConn) DialStreamLocal(ctx context.Context, remoteSocket pathalg.RemotePath) (net.Conn, error)

DialStreamLocal 经 "direct-streamlocal@openssh.com" 连接远端 Unix 域套接字并封装为 chanconn.WatchedConn。

func (*TransportConn) DialTCP

func (c *TransportConn) DialTCP(ctx context.Context, target netaddr.HostPort) (net.Conn, error)

DialTCP 经 "direct-tcpip" 打开上游 SSH 隧道并强制封装为 chanconn.WatchedConn(ADR-015)。 绝不调用 (*ssh.Client).DialContext(其在上游库内部存在取消后孤儿 goroutine 泄漏风险)。

func (*TransportConn) Endpoint

func (c *TransportConn) Endpoint() netaddr.Endpoint

Endpoint 返回当前传输连接绑定的不可变规范化目标端点。

func (*TransportConn) HopDigest

func (c *TransportConn) HopDigest() plan.HopDigest

HopDigest 返回当前传输连接绑定的不可变 Merkle 跳板摘要。

func (*TransportConn) IsAlive

func (c *TransportConn) IsAlive() bool

IsAlive 报告底层 SSH 传输是否仍处于已初始化且未断连/未关闭的存活状态。

func (*TransportConn) ListenStreamLocal

func (c *TransportConn) ListenStreamLocal(ctx context.Context, remoteSocket pathalg.RemotePath) (net.Listener, error)

ListenStreamLocal 在远端 SSH 服务端发起 streamlocal-forward@openssh.com 监听。

func (*TransportConn) ListenTCP

func (c *TransportConn) ListenTCP(ctx context.Context, bindAddr string) (net.Listener, error)

ListenTCP 在远端 SSH 服务端发起 tcpip-forward 监听。

func (*TransportConn) OpenChannel

func (c *TransportConn) OpenChannel(ctx context.Context, chanType string, extraData []byte) (ssh.Channel, <-chan *ssh.Request, error)

OpenChannel 在 lifeNursery 监督下打开任意 RFC 4254 SSH 通道(取消时异步关闭并排空孤立请求,零泄漏)。 供 Wave 2 sshnet/{sftp,forward,mux} 打开受控底层通道使用。

func (*TransportConn) OpenRemoteFS

func (c *TransportConn) OpenRemoteFS(ctx context.Context) (ports.RemoteFSPort, error)

OpenRemoteFS 若已注入 SFTP 子系统工厂则传入当前 *TransportConn 打开 RemoteFSPort,否则返回 ports.ErrUnsupported。

func (*TransportConn) OpenSession

func (c *TransportConn) OpenSession(ctx context.Context) (ports.RemoteSession, error)

OpenSession 打开隔离的 SSH 会话通道,并立即预绑定 StdinPipe/StdoutPipe/StderrPipe(绝不赋值 Session.Stdin)。

func (*TransportConn) OpenSubsystem

func (c *TransportConn) OpenSubsystem(ctx context.Context, subsystem string) (*chanconn.WatchedConn, error)

OpenSubsystem 在 "session" 通道上请求启动命名 SSH 子系统(如 "sftp"), 全程受 lifeNursery 取消看门狗监督并返回带截止看门狗与 CloseWrite() 的 *chanconn.WatchedConn(供 P4-T2 sshnet/sftp 复用)。

func (*TransportConn) OpenSubsystemStream

func (c *TransportConn) OpenSubsystemStream(ctx context.Context, subsystem string) (io.ReadWriteCloser, error)

OpenSubsystemStream 以纯标准库 io.ReadWriteCloser 签名暴露受看门狗保护的命名 SSH 子系统流, 供 pool.pinnedTransportConn 与 sshnet/mux 在零额外跨包依赖下透明透传 SFTP 子系统。

func (*TransportConn) OpenTUN

func (c *TransportConn) OpenTUN(ctx context.Context, spec ports.TUNSpec) (io.ReadWriteCloser, error)

OpenTUN 经 OpenSSH "tun@openssh.com" 协议打开 L2/L3 隧道通道并封装为 chanconn.WatchedConn。

func (*TransportConn) OpenWatchedChannel

func (c *TransportConn) OpenWatchedChannel(ctx context.Context, chanType string, extraData []byte, remoteAddr net.Addr) (*chanconn.WatchedConn, error)

OpenWatchedChannel 打开 SSH 通道并强制封装为带 ADR-015 O(1) 截止/黑洞看门狗的 *chanconn.WatchedConn, 直接暴露 CloseWrite() 与完整 net.Conn 能力(零额外类型断言)。

func (*TransportConn) SSHClient

func (c *TransportConn) SSHClient() *ssh.Client

SSHClient 返回底层 *ssh.Client 仅供同仓 Wave 2(sshnet/sftp)在确需直连协议库时使用; 若连接未初始化或已关闭则返回 nil,优先推荐直接调用 OpenSubsystem / OpenWatchedChannel。

func (*TransportConn) SendGlobalRequest

func (c *TransportConn) SendGlobalRequest(ctx context.Context, name string, wantReply bool, payload []byte) (bool, []byte, error)

SendGlobalRequest 在连接生命周期 Nursery 监督下发送 RFC 4254 全局请求,供 sshnet/{forward,mux} 复用。

func (*TransportConn) SendKeepalive

func (c *TransportConn) SendKeepalive(ctx context.Context) error

SendKeepalive 发送标准 OpenSSH "keepalive@openssh.com" 全局保活请求(受连接生命周期 Nursery 监督,单次取消不误杀父连接)。 OpenSSH 服务端按惯例回复 REQUEST_FAILURE(ok==false, err==nil),仅传输级 err!=nil 视为探测失败。

func (*TransportConn) WaitDone

func (c *TransportConn) WaitDone() <-chan struct{}

WaitDone 返回只读通道,当底层 SSH 传输断开或关闭完成后立即关闭;供 sshnet/{forward,mux} 零轮询感知断连。

Directories

Path Synopsis
Package chanconn 为 XOps v2 的 ssh.Channel 虚拟连接提供受 core/conc.Nursery 监督的 取消/截止时间看门狗与多路复用操作原语(ADR-009 / ADR-015)。
Package chanconn 为 XOps v2 的 ssh.Channel 虚拟连接提供受 core/conc.Nursery 监督的 取消/截止时间看门狗与多路复用操作原语(ADR-009 / ADR-015)。
Package keysigner 实现 XOps v2 基于 golang.org/x/crypto/ssh 的私钥解析、指纹核验与签名器适配器 (ports.KeySignerPort,ADR-011 / INV-F1)。
Package keysigner 实现 XOps v2 基于 golang.org/x/crypto/ssh 的私钥解析、指纹核验与签名器适配器 (ports.KeySignerPort,ADR-011 / INV-F1)。
Package remotesess 实现 XOps v2 基于 *ssh.Session 的远端命令与交互式 Shell 会话适配器 (ports.RemoteSession,ADR-009 / ADR-015)。
Package remotesess 实现 XOps v2 基于 *ssh.Session 的远端命令与交互式 Shell 会话适配器 (ports.RemoteSession,ADR-009 / ADR-015)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL