@@ -28,31 +28,33 @@ import (
28
28
29
29
var (
30
30
// 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 ()
39
39
40
40
// 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 ()
43
43
44
- USER = kingpin .Flag ("login-name" , "Username to login with" ).String ()
44
+ loginName = kingpin .Flag ("login-name" , "Username to login with" ).String ()
45
45
)
46
46
47
47
var clientCCAddr * snet.Addr
48
48
49
+ // PromptPassword prompts the user for a password to authenticate with.
49
50
func PromptPassword () (secret string , err error ) {
50
51
fmt .Printf ("Password: " )
51
52
password , _ := terminal .ReadPassword (0 )
52
53
fmt .Println ()
53
54
return string (password ), nil
54
55
}
55
56
57
+ // PromptAcceptHostKey prompts the user to accept or reject the given host key.
56
58
func PromptAcceptHostKey (hostname string , remote net.Addr , publicKey string ) bool {
57
59
for {
58
60
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
81
83
func createConfig () * clientconfig.ClientConfig {
82
84
conf := clientconfig .Create ()
83
85
84
- for _ , configFile := range * CONFIG_FILES {
86
+ for _ , configFile := range * configFiles {
85
87
updateConfigFromFile (conf , configFile )
86
88
}
87
89
88
- for _ , option := range * OPTIONS {
90
+ for _ , option := range * options {
89
91
err := config .UpdateFromString (conf , option )
90
92
if err != nil {
91
93
log .Debug ("Error updating config from --option flag: %v" , err )
92
94
}
93
95
}
94
96
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 , "" )
99
103
100
104
return conf
101
105
}
@@ -120,12 +124,6 @@ func main() {
120
124
golog .Panicf ("Can't find current user: %s" , err )
121
125
}
122
126
123
- knownHostsFile := * KNOWN_HOSTS_FILE
124
- if knownHostsFile == "" {
125
- knownHostsFile = "~/.ssh/known_hosts"
126
- }
127
- knownHostsFile = utils .ParsePath (knownHostsFile )
128
-
129
127
localhost , err := scionutil .GetLocalhost ()
130
128
if err != nil {
131
129
golog .Panicf ("Can't get localhost: %v" , err )
@@ -148,25 +146,12 @@ func main() {
148
146
}
149
147
}
150
148
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
-
164
149
remoteUsername := conf .User
165
150
if remoteUsername == "" {
166
151
remoteUsername = localUser .Username
167
152
}
168
153
169
- sshClient , err := ssh .Create (remoteUsername , sshConfig )
154
+ sshClient , err := ssh .Create (remoteUsername , conf , PromptPassword , verifyNewKeyHandler )
170
155
if err != nil {
171
156
golog .Panicf ("Error creating ssh client: %v" , err )
172
157
}
@@ -177,7 +162,7 @@ func main() {
177
162
if err != nil {
178
163
golog .Panicf ("Error connecting: %v" , err )
179
164
}
180
- defer sshClient .Close ()
165
+ defer sshClient .CloseSession ()
181
166
182
167
if conf .LocalForward != "" {
183
168
localForward := strings .SplitN (conf .LocalForward , ":" , 2 )
@@ -194,7 +179,7 @@ func main() {
194
179
}
195
180
196
181
// TODO Don't just join those!
197
- runCommand := strings .Join ((* RUN_COMMAND )[:], " " )
182
+ runCommand := strings .Join ((* runCommand )[:], " " )
198
183
199
184
if runCommand == "" {
200
185
err = sshClient .Shell ()
@@ -209,12 +194,12 @@ func main() {
209
194
golog .Panicf ("Error connecting pipes: %v" , err )
210
195
}
211
196
212
- err = sshClient .Start (runCommand )
197
+ err = sshClient .StartSession (runCommand )
213
198
if err != nil {
214
199
golog .Panicf ("Error running command: %v" , err )
215
200
}
216
201
217
- err = sshClient .Wait ()
202
+ err = sshClient .WaitSession ()
218
203
if err != nil {
219
204
golog .Panicf ("Error waiting for command to complete: %v" , err )
220
205
}
0 commit comments