You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.3 KiB
Go

10 years ago
package main
import (
10 years ago
"code.google.com/p/go.crypto/ssh/terminal"
10 years ago
"crypto/rsa"
"encoding/json"
"fmt"
10 years ago
"io"
10 years ago
"net"
"os"
)
type Auth struct {
Nick string
Key rsa.PublicKey
}
func (a *Auth) Kind() string {
return "auth"
}
10 years ago
type ReadWriter struct {
io.Reader
io.Writer
}
10 years ago
func connect() {
10 years ago
if !terminal.IsTerminal(0) {
exit(1, "yeah you have to run this from a tty")
}
10 years ago
f, err := os.Open(options.key)
if err != nil {
exit(1, "unable to open private key file at %s: %v", options.key, err)
}
defer f.Close()
d1 := json.NewDecoder(f)
var key rsa.PrivateKey
if err := d1.Decode(&key); err != nil {
exit(1, "unable to decode key: %v", err)
}
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", options.host, options.port))
if err != nil {
exit(1, "unable to connect to server at %s:%d: %v", options.host, options.port, err)
}
auth := Auth{
Nick: options.nick,
Key: key.PublicKey,
}
encodeRequest(conn, &auth)
10 years ago
old, err := terminal.MakeRaw(0)
if err != nil {
panic(err)
}
defer terminal.Restore(0, old)
r := &ReadWriter{Reader: os.Stdin, Writer: os.Stdout}
term := terminal.NewTerminal(r, "> ")
10 years ago
10 years ago
line, err := term.ReadLine()
switch err {
case io.EOF:
return
case nil:
fmt.Println(line)
default:
exit(1, "error on line read: %v", err)
}
10 years ago
}