Skip to content

Commit 1b47dbf

Browse files
committed
Added documentation for scion-ssh
1 parent 6c3c8e1 commit 1b47dbf

File tree

13 files changed

+153
-113
lines changed

13 files changed

+153
-113
lines changed

ssh/client/clientconfig/clientconfig.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package clientconfig
22

3-
import ()
4-
3+
// ClientConfig is a struct containing configuration for the client.
54
type ClientConfig struct {
65
User string `regex:".*"`
76
HostAddress string `regex:"(?P<ia>\\d+-[\\d:A-Fa-f]+),\\[(?P<host>[^\\]]+)\\]"`
@@ -12,18 +11,21 @@ type ClientConfig struct {
1211
IdentityFile []string `regex:".*"`
1312
LocalForward string `regex:".*"`
1413
RemoteForward string `regex:".*"`
14+
UserKnownHostsFile string `regex:".*"`
1515
ProxyCommand string `regex:".*"`
1616
QUICCertificatePath string `regex:".*"`
1717
QUICKeyPath string `regex:".*"`
1818
}
1919

20+
// Create creates a new ClientConfig with the default values.
2021
func Create() *ClientConfig {
2122
return &ClientConfig{
2223
HostAddress: "",
2324
Port: "22",
2425
PasswordAuthentication: "yes",
2526
PubkeyAuthentication: "yes",
2627
StrictHostKeyChecking: "ask",
28+
UserKnownHostsFile: "~/.ssh/known_hosts",
2729
IdentityFile: []string{
2830
"~/.ssh/id_ed25519",
2931
"~/.ssh/id_ecdsa",

ssh/client/clientconfig/clientconfig_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package clientconfig
22

33
import (
44
"fmt"
5-
"github.com/netsec-ethz/scion-apps/ssh/config"
6-
. "github.com/smartystreets/goconvey/convey"
75
"strings"
86
"testing"
7+
8+
"github.com/netsec-ethz/scion-apps/ssh/config"
9+
. "github.com/smartystreets/goconvey/convey"
910
)
1011

1112
func TestDefaultConfig(t *testing.T) {

ssh/client/main.go

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,33 @@ import (
2828

2929
var (
3030
// Connection
31-
SERVER_ADDRESS = kingpin.Arg("host-address", "Server SCION address (without the port)").Required().String()
32-
RUN_COMMAND = kingpin.Arg("command", "Command to run (empty for pty)").Strings()
33-
PORT = kingpin.Flag("port", "The server's port").Default("0").Short('p').Uint16()
34-
LOCAL_FORWARD = kingpin.Flag("local-forward", "Forward remote address connections to listening port. Format: listening_port:remote_address").Short('L').String()
35-
OPTIONS = kingpin.Flag("option", "Set an option").Short('o').Strings()
36-
VERBOSE = kingpin.Flag("verbose", "Be verbose").Short('v').Default("false").Bool()
37-
CONFIG_FILES = kingpin.Flag("config", "Configuration files").Short('c').Default("/etc/ssh/ssh_config", "~/.ssh/config").Strings()
38-
X_DEAD = kingpin.Flag("x-dead", "Placeholder for SCP support").Short('x').Default("false").Bool()
31+
serverAddress = kingpin.Arg("host-address", "Server SCION address (without the port)").Required().String()
32+
runCommand = kingpin.Arg("command", "Command to run (empty for pty)").Strings()
33+
port = kingpin.Flag("port", "The server's port").Default("0").Short('p').Uint16()
34+
localForward = kingpin.Flag("local-forward", "Forward remote address connections to listening port. Format: listening_port:remote_address").Short('L').String()
35+
options = kingpin.Flag("option", "Set an option").Short('o').Strings()
36+
verbose = kingpin.Flag("verbose", "Be verbose").Short('v').Default("false").Bool()
37+
configFiles = kingpin.Flag("config", "Configuration files").Short('c').Default("/etc/ssh/ssh_config", "~/.ssh/config").Strings()
38+
xDead = kingpin.Flag("x-dead", "Placeholder for SCP support").Short('x').Default("false").Bool()
3939

4040
// TODO: additional file paths
41-
KNOWN_HOSTS_FILE = kingpin.Flag("known-hosts", "File where known hosts are stored").ExistingFile()
42-
IDENTITY_FILE = kingpin.Flag("identity", "Identity (private key) file").Short('i').ExistingFile()
41+
knownHostsFile = kingpin.Flag("known-hosts", "File where known hosts are stored").ExistingFile()
42+
identityFile = kingpin.Flag("identity", "Identity (private key) file").Short('i').ExistingFile()
4343

44-
USER = kingpin.Flag("login-name", "Username to login with").String()
44+
loginName = kingpin.Flag("login-name", "Username to login with").String()
4545
)
4646

4747
var clientCCAddr *snet.Addr
4848

49+
// PromptPassword prompts the user for a password to authenticate with.
4950
func PromptPassword() (secret string, err error) {
5051
fmt.Printf("Password: ")
5152
password, _ := terminal.ReadPassword(0)
5253
fmt.Println()
5354
return string(password), nil
5455
}
5556

57+
// PromptAcceptHostKey prompts the user to accept or reject the given host key.
5658
func PromptAcceptHostKey(hostname string, remote net.Addr, publicKey string) bool {
5759
for {
5860
fmt.Printf("Key fingerprint MD5 is: %s do you recognize it? (y/n) ", publicKey)
@@ -81,21 +83,23 @@ func setConfIfNot(conf *clientconfig.ClientConfig, name string, value, not inter
8183
func createConfig() *clientconfig.ClientConfig {
8284
conf := clientconfig.Create()
8385

84-
for _, configFile := range *CONFIG_FILES {
86+
for _, configFile := range *configFiles {
8587
updateConfigFromFile(conf, configFile)
8688
}
8789

88-
for _, option := range *OPTIONS {
90+
for _, option := range *options {
8991
err := config.UpdateFromString(conf, option)
9092
if err != nil {
9193
log.Debug("Error updating config from --option flag: %v", err)
9294
}
9395
}
9496

95-
setConfIfNot(conf, "Port", *PORT, 0)
96-
setConfIfNot(conf, "HostAddress", *SERVER_ADDRESS, "")
97-
setConfIfNot(conf, "IdentityFile", *IDENTITY_FILE, "")
98-
setConfIfNot(conf, "User", *USER, "")
97+
setConfIfNot(conf, "Port", *port, 0)
98+
setConfIfNot(conf, "HostAddress", *serverAddress, "")
99+
setConfIfNot(conf, "IdentityFile", *identityFile, "")
100+
setConfIfNot(conf, "LocalForward", *localForward, "")
101+
setConfIfNot(conf, "User", *loginName, "")
102+
setConfIfNot(conf, "KnownHostsFile", *knownHostsFile, "")
99103

100104
return conf
101105
}
@@ -120,12 +124,6 @@ func main() {
120124
golog.Panicf("Can't find current user: %s", err)
121125
}
122126

123-
knownHostsFile := *KNOWN_HOSTS_FILE
124-
if knownHostsFile == "" {
125-
knownHostsFile = "~/.ssh/known_hosts"
126-
}
127-
knownHostsFile = utils.ParsePath(knownHostsFile)
128-
129127
localhost, err := scionutil.GetLocalhost()
130128
if err != nil {
131129
golog.Panicf("Can't get localhost: %v", err)
@@ -148,25 +146,12 @@ func main() {
148146
}
149147
}
150148

151-
// Create SSH client
152-
sshConfig := &ssh.SSHClientConfig{
153-
VerifyHostKey: conf.StrictHostKeyChecking != "no",
154-
VerifyNewKeyHandler: verifyNewKeyHandler,
155-
KnownHostKeyFile: knownHostsFile,
156-
157-
UsePasswordAuth: conf.PasswordAuthentication == "yes",
158-
PassAuthHandler: PromptPassword,
159-
160-
UsePublicKeyAuth: conf.PubkeyAuthentication == "yes",
161-
PrivateKeyPaths: conf.IdentityFile,
162-
}
163-
164149
remoteUsername := conf.User
165150
if remoteUsername == "" {
166151
remoteUsername = localUser.Username
167152
}
168153

169-
sshClient, err := ssh.Create(remoteUsername, sshConfig)
154+
sshClient, err := ssh.Create(remoteUsername, conf, PromptPassword, verifyNewKeyHandler)
170155
if err != nil {
171156
golog.Panicf("Error creating ssh client: %v", err)
172157
}
@@ -177,7 +162,7 @@ func main() {
177162
if err != nil {
178163
golog.Panicf("Error connecting: %v", err)
179164
}
180-
defer sshClient.Close()
165+
defer sshClient.CloseSession()
181166

182167
if conf.LocalForward != "" {
183168
localForward := strings.SplitN(conf.LocalForward, ":", 2)
@@ -194,7 +179,7 @@ func main() {
194179
}
195180

196181
// TODO Don't just join those!
197-
runCommand := strings.Join((*RUN_COMMAND)[:], " ")
182+
runCommand := strings.Join((*runCommand)[:], " ")
198183

199184
if runCommand == "" {
200185
err = sshClient.Shell()
@@ -209,12 +194,12 @@ func main() {
209194
golog.Panicf("Error connecting pipes: %v", err)
210195
}
211196

212-
err = sshClient.Start(runCommand)
197+
err = sshClient.StartSession(runCommand)
213198
if err != nil {
214199
golog.Panicf("Error running command: %v", err)
215200
}
216201

217-
err = sshClient.Wait()
202+
err = sshClient.WaitSession()
218203
if err != nil {
219204
golog.Panicf("Error waiting for command to complete: %v", err)
220205
}

ssh/client/ssh/shell.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
"github.com/docker/docker/pkg/term"
1212
)
1313

14-
func (client *SSHClient) Shell() error {
14+
// Shell opens a new Shell session on the server this Client is connected to.
15+
func (client *Client) Shell() error {
1516
var (
1617
termWidth, termHeight = 80, 24
1718
)
@@ -52,7 +53,7 @@ func (client *SSHClient) Shell() error {
5253
// monitor for sigwinch
5354
go monWinCh(client.session, os.Stdout.Fd())
5455

55-
err := client.Wait()
56+
err := client.WaitSession()
5657
if err != nil {
5758
return err
5859
}

0 commit comments

Comments
 (0)