sshttp

package
v0.0.0-...-4c5b182 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package sshttp provides HTTP-over-SSH functionality, allowing HTTP requests to be tunneled through SSH connections using a custom "sshttp" channel type.

This package is useful for scenarios where you need to proxy HTTP traffic through SSH connections, such as accessing internal services through secure tunnels or implementing HTTP APIs over SSH.

The package provides two main components:

  • Server: Accepts custom "sshttp" channels and forwards them to an HTTP handler
  • Dialer: Provides a dialer function that tunnels connections through SSH

Example server usage:

// Create an HTTP handler
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello from SSH tunnel!")
})

// Create the HTTP-over-SSH server
server := &sshttp.Server{
	Name:           "my-server",
	Handler:        handler,
	HostSigners:    []gssh.Signer{hostSigner},
	AuthorizedKeys: set.Of(string(clientPubKey.Marshal())),
}

// Listen for connections and serve
ln, _ := net.Listen("tcp", ":2222")
server.Serve(ln)

Example client usage with Dialer:

// Create SSH client config with whatever is needed to connect
config := &ssh.ClientConfig{
	// ... SSH client configuration
}

// Create dialer for tunneling through SSH
dialer := &sshttp.Dialer{
	SSHAddr: "ssh-server:2222",
	Config:  config,
}

// Create HTTP client using the SSH dialer
client := &http.Client{
	Transport: &http.Transport{
		DialContext: dialer.DialContext,
	},
}

// Make HTTP request through SSH tunnel
resp, err := client.Get("http://ignored/api")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialer

type Dialer struct {
	// SSHAddr is the address of the SSH server in the format "host:port".
	// The port must be provided.
	SSHAddr string
	// BaseDialer is the base dialer to use for the SSH connection.
	// If nil, a net.Dialer will be used.
	BaseDialer *net.Dialer

	// Config is the client config to use for the SSH connection.
	// It must be provided.
	Config *ssh.ClientConfig
}

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, _ string) (net.Conn, error)

type Server

type Server struct {
	// Name is the name of the server to use for the SSH server.
	// If empty, "sshttp" will be used.
	Name string
	// HostSigners are the host signers to use for the SSH server.
	// It must be provided.
	HostSigners []gssh.Signer
	// AuthorizedKeys are the authorized keys to use for the SSH server.
	// It must be provided.
	AuthorizedKeys set.Set[string]
	// Handler is the HTTP handler to use for the SSH server.
	// It must be provided.
	Handler http.Handler
}

Server provides HTTP-over-SSH functionality by accepting custom "sshttp" channels and forwarding them to an HTTP handler. The server handles SSH authentication via public keys and manages the SSH server lifecycle.

func (*Server) Handle

func (s *Server) Handle(srv *gssh.Server, sshConn *ssh.ServerConn, newChan ssh.NewChannel, ctx gssh.Context)

Handle processes incoming "sshttp" channels and forwards them to the HTTP handler. It accepts the channel and serves HTTP requests over the SSH channel using the configured Handler.

func (*Server) HandleConn

func (s *Server) HandleConn(conn net.Conn)

func (*Server) Serve

func (s *Server) Serve(ln net.Listener)

Jump to

Keyboard shortcuts

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