1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:54:39 -07:00

exp/ssh: various small fixes

transport.go:
* remove unused nil check.

doc.go:
* improve documentation about supported auth
methods and update Run example.

Thanks Jacek Masiulaniec for both reports.

R=jacek.masiulaniec, agl
CC=golang-dev
https://golang.org/cl/5501075
This commit is contained in:
Dave Cheney 2011-12-27 09:49:19 -05:00 committed by Adam Langley
parent 6a88f1c4cb
commit 7f20bcbbcb
2 changed files with 24 additions and 8 deletions

View File

@ -78,8 +78,26 @@ present a simple terminal interface.
return return
}() }()
An SSH client is represented with a ClientConn. Currently only the "password" To authenticate with the remote server you must pass at least one implementation of
authentication method is supported. ClientAuth via the Auth field in ClientConfig.
// password implements the ClientPassword interface
type password string
func (p password) Password(user string) (string, error) {
return string(p), nil
}
config := &ssh.ClientConfig {
User: "username",
Auth: []ClientAuth {
// ClientAuthPassword wraps a ClientPassword implementation
// in a type that implements ClientAuth.
ClientAuthPassword(password("yourpassword")),
}
}
An SSH client is represented with a ClientConn.
config := &ClientConfig{ config := &ClientConfig{
User: "username", User: "username",
@ -94,12 +112,12 @@ Each ClientConn can support multiple interactive sessions, represented by a Sess
Once a Session is created, you can execute a single command on the remote side Once a Session is created, you can execute a single command on the remote side
using the Run method. using the Run method.
b := bytes.NewBuffer()
session.Stdin = b
if err := session.Run("/usr/bin/whoami"); err != nil { if err := session.Run("/usr/bin/whoami"); err != nil {
panic("Failed to exec: " + err.String()) panic("Failed to exec: " + err.String())
} }
reader := bufio.NewReader(session.Stdin) fmt.Println(bytes.String())
line, _, _ := reader.ReadLine()
fmt.Println(line)
session.Close() session.Close()
*/ */
package ssh package ssh

View File

@ -117,9 +117,7 @@ func (r *reader) readOnePacket() ([]byte, error) {
return nil, err return nil, err
} }
mac := packet[length-1:] mac := packet[length-1:]
if r.cipher != nil { r.cipher.XORKeyStream(packet, packet[:length-1])
r.cipher.XORKeyStream(packet, packet[:length-1])
}
if r.mac != nil { if r.mac != nil {
r.mac.Write(packet[:length-1]) r.mac.Write(packet[:length-1])