15
15
package main
16
16
17
17
import (
18
- "encoding/json "
18
+ "context "
19
19
"fmt"
20
- "io/ioutil"
21
20
golog "log"
22
21
"net"
23
22
"os"
@@ -28,13 +27,12 @@ import (
28
27
log "github.com/inconshreveable/log15"
29
28
"golang.org/x/term"
30
29
"gopkg.in/alecthomas/kingpin.v2"
30
+ "inet.af/netaddr"
31
31
32
- "github.com/scionproto/scion/go/lib/pathpol"
33
-
32
+ "github.com/netsec-ethz/scion-apps/pkg/pan"
34
33
"github.com/netsec-ethz/scion-apps/ssh/client/clientconfig"
35
34
"github.com/netsec-ethz/scion-apps/ssh/client/ssh"
36
35
"github.com/netsec-ethz/scion-apps/ssh/config"
37
- "github.com/netsec-ethz/scion-apps/ssh/scionutils"
38
36
"github.com/netsec-ethz/scion-apps/ssh/utils"
39
37
)
40
38
46
44
localForward = kingpin .Flag ("local-forward" , "Forward remote address connections to listening port. Format: listening_port:remote_address" ).Short ('L' ).String ()
47
45
options = kingpin .Flag ("option" , "Set an option" ).Short ('o' ).Strings ()
48
46
configFiles = kingpin .Flag ("config" , "Configuration files" ).Short ('c' ).Default ("/etc/ssh/ssh_config" , "~/.ssh/config" ).Strings ()
49
- policyFile = kingpin .Flag ("policy-file" , "Path to the JSON policy file" ).Default ("" ).String ()
50
- policyName = kingpin .Flag ("policy-name" , "Name of policy to be applied." ).Default ("" ).String ()
51
- pathSelection = kingpin .Flag ("selection" , "Path selection mode" ).Default ("arbitrary" ).Enum ("static" , "arbitrary" , "random" , "round-robin" )
47
+ interactive = kingpin .Flag ("interactive" , "Prompt user for interactive path selection" ).Bool ()
48
+ sequence = kingpin .Flag ("sequence" , "Sequence of space separated hop predicates to specify path" ).Default ("" ).String ()
49
+ preference = kingpin .Flag ("preference" , "Preference sorting order for paths. " +
50
+ "Comma-separated list of available sorting options: " +
51
+ strings .Join (pan .AvailablePreferencePolicies , "|" )).Default ("" ).String ()
52
+ pathSelector = kingpin .Flag ("selector" , "Path selection mode" ).Default ("default" ).Enum (ssh .AvailablePathSelectors ... )
52
53
53
54
// TODO: additional file paths
54
55
knownHostsFile = kingpin .Flag ("known-hosts" , "File where known hosts are stored" ).ExistingFile ()
@@ -145,37 +146,20 @@ func main() {
145
146
if remoteUsername == "" {
146
147
remoteUsername = localUser .Username
147
148
}
148
- var policyMap pathpol.PolicyMap
149
- var policy * pathpol.Policy
150
- if * policyFile != "" {
151
- file , err := ioutil .ReadFile (* policyFile )
152
- if err != nil {
153
- golog .Panicf ("Cannot read policy file: %v" , err )
154
- }
155
- err = json .Unmarshal (file , & policyMap )
156
- if err != nil {
157
- golog .Panicf ("Cannot unmarshal policy form file: %v" , err )
158
- }
159
- extPolicy , policyExists := policyMap [* policyName ]
160
-
161
- if ! policyExists {
162
- golog .Panicf ("No policy with name %s exists" , * policyName )
163
- }
164
- policy = extPolicy .Policy
165
- }
166
- appConf , err := scionutils .NewPathAppConf (policy , * pathSelection )
149
+ sshClient , err := ssh .Create (remoteUsername , conf , PromptPassword , verifyNewKeyHandler )
167
150
if err != nil {
168
- golog .Panicf ("Invalid application config : %v" , err )
151
+ golog .Panicf ("Error creating ssh client : %v" , err )
169
152
}
170
153
171
- sshClient , err := ssh . Create ( remoteUsername , conf , PromptPassword , verifyNewKeyHandler , appConf )
154
+ policy , err := pan . PolicyFromCommandline ( * sequence , * preference , * interactive )
172
155
if err != nil {
173
- golog .Panicf ( "Error creating ssh client: %v" , err )
156
+ golog .Fatal ( err )
174
157
}
175
158
176
159
serverAddress := fmt .Sprintf ("%s:%v" , conf .HostAddress , conf .Port )
177
160
178
- err = sshClient .Connect (serverAddress )
161
+ ctx := context .Background ()
162
+ err = sshClient .Connect (ctx , serverAddress , policy , * pathSelector )
179
163
if err != nil {
180
164
golog .Panicf ("Error connecting: %v" , err )
181
165
}
@@ -189,7 +173,8 @@ func main() {
189
173
golog .Panicf ("Error parsing forwarding port: %v" , err )
190
174
}
191
175
192
- err = sshClient .StartTunnel (uint16 (port ), localForward [1 ])
176
+ local := netaddr .IPPortFrom (netaddr.IP {}, uint16 (port ))
177
+ err = sshClient .StartTunnel (local , localForward [1 ])
193
178
if err != nil {
194
179
golog .Panicf ("Error starting tunnel: %v" , err )
195
180
}
@@ -204,7 +189,7 @@ func main() {
204
189
golog .Panicf ("Error starting shell: %v" , err )
205
190
}
206
191
} else {
207
- log .Debug ("Running command: %s " , runCommand )
192
+ log .Debug ("Running command" , "cmd " , runCommand )
208
193
209
194
err = sshClient .ConnectPipes (os .Stdin , os .Stdout )
210
195
if err != nil {
0 commit comments