summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/shazow/ssh-chat/sshd/client.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-12-03 01:24:05 +0100
committerWim <wim@42.be>2017-12-03 01:24:05 +0100
commited9118b34620f1ecd5f28506328d4ffe1b04793d (patch)
tree442998012f6779446a463e402fa7c0836edcac91 /vendor/github.com/shazow/ssh-chat/sshd/client.go
parent59e55cfbd5cc3c82236c5e8b95e5baff256f7143 (diff)
downloadmatterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.tar.gz
matterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.tar.bz2
matterbridge-msglm-ed9118b34620f1ecd5f28506328d4ffe1b04793d.zip
Add sshchat dependencies in vendor
Diffstat (limited to 'vendor/github.com/shazow/ssh-chat/sshd/client.go')
-rw-r--r--vendor/github.com/shazow/ssh-chat/sshd/client.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/vendor/github.com/shazow/ssh-chat/sshd/client.go b/vendor/github.com/shazow/ssh-chat/sshd/client.go
new file mode 100644
index 00000000..004aa473
--- /dev/null
+++ b/vendor/github.com/shazow/ssh-chat/sshd/client.go
@@ -0,0 +1,76 @@
+package sshd
+
+import (
+ "crypto/rand"
+ "crypto/rsa"
+ "io"
+
+ "golang.org/x/crypto/ssh"
+)
+
+// NewRandomSigner generates a random key of a desired bit length.
+func NewRandomSigner(bits int) (ssh.Signer, error) {
+ key, err := rsa.GenerateKey(rand.Reader, bits)
+ if err != nil {
+ return nil, err
+ }
+ return ssh.NewSignerFromKey(key)
+}
+
+// NewClientConfig creates a barebones ssh.ClientConfig to be used with ssh.Dial.
+func NewClientConfig(name string) *ssh.ClientConfig {
+ return &ssh.ClientConfig{
+ User: name,
+ Auth: []ssh.AuthMethod{
+ ssh.KeyboardInteractive(func(user, instruction string, questions []string, echos []bool) (answers []string, err error) {
+ return
+ }),
+ },
+ HostKeyCallback: ssh.InsecureIgnoreHostKey(),
+ }
+}
+
+// ConnectShell makes a barebones SSH client session, used for testing.
+func ConnectShell(host string, name string, handler func(r io.Reader, w io.WriteCloser) error) error {
+ config := NewClientConfig(name)
+ conn, err := ssh.Dial("tcp", host, config)
+ if err != nil {
+ return err
+ }
+ defer conn.Close()
+
+ session, err := conn.NewSession()
+ if err != nil {
+ return err
+ }
+ defer session.Close()
+
+ in, err := session.StdinPipe()
+ if err != nil {
+ return err
+ }
+
+ out, err := session.StdoutPipe()
+ if err != nil {
+ return err
+ }
+
+ /*
+ err = session.RequestPty("xterm", 80, 40, ssh.TerminalModes{})
+ if err != nil {
+ return err
+ }
+ */
+
+ err = session.Shell()
+ if err != nil {
+ return err
+ }
+
+ _, err = session.SendRequest("ping", true, nil)
+ if err != nil {
+ return err
+ }
+
+ return handler(out, in)
+}