cmd

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerUrlEnvName = "PIPING_SERVER"
)

Variables

View Source
var RootCmd = &cobra.Command{
	Use:          os.Args[0],
	Short:        "piping-sshd",
	Long:         "SSH server from anywhere with Piping Server",
	SilenceUsage: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		if showsVersion {
			fmt.Println(version.Version)
			return nil
		}
		if sshPassword == "" {
			if !allowsEmptyPassword {
				return fmt.Errorf("specify non-empty --password or --allow-empty-password")
			}
		}

		clientToServerPath, serverToClientPath, err := generatePaths(args)
		if err != nil {
			return err
		}
		headers, err := piping_util.ParseKeyValueStrings(headerKeyValueStrs)
		if err != nil {
			return err
		}
		httpClient := util.CreateHttpClient(insecure, httpWriteBufSize, httpReadBufSize)
		if dnsServer != "" {

			httpClient.Transport.(*http.Transport).DialContext = util.CreateDialContext(dnsServer)
		}
		serverToClientUrl, err := util.UrlJoin(serverUrl, serverToClientPath)
		if err != nil {
			return err
		}
		clientToServerUrl, err := util.UrlJoin(serverUrl, clientToServerPath)
		if err != nil {
			return err
		}

		sshPrintHintForClientHost(clientToServerUrl, serverToClientUrl, clientToServerPath, serverToClientPath)

		sshConfig := &ssh.ServerConfig{

			PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {

				if (sshUser == "" || c.User() == sshUser) && string(pass) == sshPassword {
					return nil, nil
				}
				return nil, fmt.Errorf("password rejected for %q", c.User())
			},

			NoClientAuth: sshPassword == "",
		}

		pri, err := ssh.ParsePrivateKey([]byte(priv_key.PrivateKeyPem))
		if err != nil {
			return err
		}
		sshConfig.AddHostKey(pri)

		if !sshYamux {
			duplex, err := piping_util.DuplexConnect(httpClient, headers, serverToClientUrl, clientToServerUrl)
			if err != nil {
				return err
			}

			sshConn, chans, reqs, err := ssh.NewServerConn(util.NewDuplexConn(duplex), sshConfig)
			if err != nil {
				log.Printf("Failed to handshake (%s)", err)
				return nil
			}

			log.Printf("New SSH connection from (%s)", sshConn.ClientVersion())
			go ssh_server.HandleGlobalRequests(sshConn, reqs)

			ssh_server.HandleChannels(sshShell, chans)
		}

		if sshYamux {
			log.Printf("Multiplexing with yamux")
			return sshHandleWithYamux(sshConfig, httpClient, headers, clientToServerUrl, serverToClientUrl)
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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