Skip to content

Commit 6c3c8e1

Browse files
committed
Removed ssh/scionutils.InitSCIONConnection(...)
(in favor of lib/scionutil.InitSCION)
1 parent 73642ad commit 6c3c8e1

File tree

5 files changed

+58
-94
lines changed

5 files changed

+58
-94
lines changed

ssh/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ sudo apt-get install libpam0g-dev
1717

1818
To generate TLS connection certificates:
1919
```
20-
# These are valid for 365 days, so you'll have to renew them
20+
# These are valid for 365 days, so you'll have to renew them periodically
2121
# Client
2222
cd ~/.ssh
2323
openssl req -newkey rsa:2048 -nodes -keyout quic-conn-key.pem -x509 -days 365 -out quic-conn-certificate.pem
@@ -32,7 +32,7 @@ cd ~/.ssh
3232
ssh-keygen -t rsa -f id_rsa
3333
```
3434

35-
And create an authorized key file for the server with the public key (note that you'd usually place this in `/etc/ssh/authorized_keys`):
35+
And create an authorized key file for the server with the public key (note that you'd usually place this in `/home/<user>/.ssh/authorized_keys` whereas `<user>` is the user on the server you want to gain access to, but make sure not to overwrite an existing file):
3636
```
3737
cd $GOPATH/src/github.com/netsec-ethz/scion-apps/ssh/server
3838
cp ~/.ssh/id_rsa.pub ./authorized_keys
@@ -50,7 +50,7 @@ sudo -E ./server -oPort=2200 -oAuthorizedKeysFile=./authorized_keys
5050
Running the client:
5151
```
5252
cd $GOPATH/src/github.com/netsec-ethz/scion-apps/ssh/client
53-
./client 1-11,[127.0.0.1]:2200
53+
./client -p 2200 1-11,[127.0.0.1]
5454
```
5555

5656
Using SCP (make sure you've done `chmod +x ./scp.sh` first):

ssh/client/main.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,29 @@ import (
1313

1414
"gopkg.in/alecthomas/kingpin.v2"
1515

16+
scionlog "github.com/scionproto/scion/go/lib/log"
1617
"github.com/scionproto/scion/go/lib/snet"
18+
"github.com/scionproto/scion/go/lib/snet/squic"
1719

20+
"github.com/netsec-ethz/scion-apps/lib/scionutil"
1821
"github.com/netsec-ethz/scion-apps/ssh/client/clientconfig"
1922
"github.com/netsec-ethz/scion-apps/ssh/client/ssh"
2023
"github.com/netsec-ethz/scion-apps/ssh/config"
21-
"github.com/netsec-ethz/scion-apps/ssh/scionutils"
2224
"github.com/netsec-ethz/scion-apps/ssh/utils"
2325

2426
log "github.com/inconshreveable/log15"
2527
)
2628

2729
var (
2830
// Connection
29-
SERVER_ADDRESS = kingpin.Arg("host-address", "Server SCION address (without the port)").Required().String()
30-
RUN_COMMAND = kingpin.Arg("command", "Command to run (empty for pty)").Strings()
31-
PORT = kingpin.Flag("port", "The server's port").Default("0").Short('p').Uint16()
32-
USE_IA_SCIOND_PATH = kingpin.Flag("sciond-path-from-ia", "Use IA when resolving SCIOND socket path").Bool()
33-
LOCAL_FORWARD = kingpin.Flag("local-forward", "Forward remote address connections to listening port. Format: listening_port:remote_address").Short('L').String()
34-
OPTIONS = kingpin.Flag("option", "Set an option").Short('o').Strings()
35-
VERBOSE = kingpin.Flag("verbose", "Be verbose").Short('v').Default("false").Bool()
36-
CONFIG_FILES = kingpin.Flag("config", "Configuration files").Short('c').Default("/etc/ssh/ssh_config", "~/.ssh/config").Strings()
37-
X_DEAD = kingpin.Flag("x-dead", "Placeholder for SCP support").Short('x').Default("false").Bool()
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()
3839

3940
// TODO: additional file paths
4041
KNOWN_HOSTS_FILE = kingpin.Flag("known-hosts", "File where known hosts are stored").ExistingFile()
@@ -110,6 +111,7 @@ func updateConfigFromFile(conf *clientconfig.ClientConfig, pth string) {
110111

111112
func main() {
112113
kingpin.Parse()
114+
scionlog.SetupLogConsole("debug")
113115

114116
conf := createConfig()
115117

@@ -124,10 +126,19 @@ func main() {
124126
}
125127
knownHostsFile = utils.ParsePath(knownHostsFile)
126128

127-
// Initialize SCION library
128-
err = scionutils.InitSCIONConnection(utils.ParsePath(conf.QUICKeyPath), utils.ParsePath(conf.QUICCertificatePath), *USE_IA_SCIOND_PATH)
129+
localhost, err := scionutil.GetLocalhost()
129130
if err != nil {
130-
golog.Panicf("Error initializing SCION connection: %s", err)
131+
golog.Panicf("Can't get localhost: %v", err)
132+
}
133+
134+
err = scionutil.InitSCION(localhost)
135+
if err != nil {
136+
golog.Panicf("Error initializing SCION: %v", err)
137+
}
138+
139+
err = squic.Init(utils.ParsePath(conf.QUICKeyPath), utils.ParsePath(conf.QUICCertificatePath))
140+
if err != nil {
141+
golog.Panicf("Error initializing SQUIC: %v", err)
131142
}
132143

133144
verifyNewKeyHandler := PromptAcceptHostKey

ssh/scionutils/scionutils.go

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,99 +2,36 @@ package scionutils
22

33
import (
44
"fmt"
5-
"io/ioutil"
6-
"os"
7-
"path/filepath"
85
"regexp"
96

107
"github.com/lucas-clemente/quic-go"
118

12-
"github.com/scionproto/scion/go/lib/addr"
13-
scionlog "github.com/scionproto/scion/go/lib/log"
14-
"github.com/scionproto/scion/go/lib/sciond"
159
"github.com/scionproto/scion/go/lib/snet"
1610
"github.com/scionproto/scion/go/lib/snet/squic"
1711

18-
log "github.com/inconshreveable/log15"
19-
12+
"github.com/netsec-ethz/scion-apps/lib/scionutil"
2013
"github.com/netsec-ethz/scion-apps/ssh/quicconn"
2114
)
2215

2316
var addressPortSplitRegex, _ = regexp.Compile(`(.*,\[.*\]):(\d+)`)
2417

25-
func InitSCIONConnection(tlsKeyFile, tlsCertFile string, useIASCIONDPath bool) error {
26-
scionlog.SetupLogConsole("debug")
27-
28-
log.Debug("Initializing SCION connection...")
29-
30-
localAddress, err := getLocalBindAddress(0)
31-
if err != nil {
32-
return err
33-
}
34-
35-
localCCAddr, err := snet.AddrFromString(localAddress)
36-
if err != nil {
37-
return err
38-
}
39-
40-
sciondPath := sciond.GetDefaultSCIONDPath(nil)
41-
if useIASCIONDPath {
42-
sciondPath = sciond.GetDefaultSCIONDPath(&localCCAddr.IA)
43-
}
44-
45-
err = snet.Init(localCCAddr.IA, sciondPath, "/run/shm/dispatcher/default.sock")
46-
if err != nil {
47-
return err
48-
}
49-
50-
if tlsKeyFile != "" || tlsCertFile != "" {
51-
err = squic.Init(tlsKeyFile, tlsCertFile)
52-
if err != nil {
53-
return err
54-
}
55-
}
56-
57-
return nil
58-
}
59-
60-
func GetIA() (*addr.IA, error) {
61-
iaFmt, err := ioutil.ReadFile(filepath.Join(os.Getenv("SC"), "gen/ia"))
62-
if err != nil {
63-
return nil, err
64-
}
65-
66-
res, err := addr.IAFromFileFmt(string(iaFmt), false)
67-
if err != nil {
68-
return nil, err
69-
}
70-
71-
return &res, nil
72-
}
73-
7418
func SplitHostPort(hostport string) (host, port string, err error) {
7519
split := addressPortSplitRegex.FindAllStringSubmatch(hostport, -1)
7620
if len(split) == 1 {
7721
return split[0][1], split[0][2], nil
78-
} else {
79-
// Shouldn't happen
80-
return "", "", fmt.Errorf("Invalid SCION address provided")
81-
}
82-
}
83-
84-
func getLocalBindAddress(port uint16) (string, error) {
85-
defaultIA, err := GetIA()
86-
if err != nil {
87-
return "", err
8822
}
89-
return fmt.Sprintf("%s,[127.0.0.1]:%v", (*defaultIA).String(), port), nil
23+
// Shouldn't happen
24+
return "", "", fmt.Errorf("Invalid SCION address provided")
9025
}
9126

9227
func DialSCION(remoteAddress string) (*quicconn.QuicConn, error) {
93-
localAddress, err := getLocalBindAddress(0)
28+
localhost, err := scionutil.GetLocalhostString()
9429
if err != nil {
9530
return nil, err
9631
}
9732

33+
localAddress := fmt.Sprintf("%v:%v", localhost, 0)
34+
9835
localCCAddr, err := snet.AddrFromString(localAddress)
9936
if err != nil {
10037
return nil, err
@@ -123,11 +60,13 @@ func DialSCION(remoteAddress string) (*quicconn.QuicConn, error) {
12360
}
12461

12562
func ListenSCION(port uint16) (quic.Listener, error) {
126-
localAddress, err := getLocalBindAddress(port)
63+
localhost, err := scionutil.GetLocalhostString()
12764
if err != nil {
12865
return nil, err
12966
}
13067

68+
localAddress := fmt.Sprintf("%v:%v", localhost, port)
69+
13170
localCCAddr, err := snet.AddrFromString(localAddress)
13271
if err != nil {
13372
return nil, err

ssh/server/main.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"gopkg.in/alecthomas/kingpin.v2"
99

10+
"github.com/netsec-ethz/scion-apps/lib/scionutil"
1011
"github.com/netsec-ethz/scion-apps/ssh/config"
1112
"github.com/netsec-ethz/scion-apps/ssh/quicconn"
1213
"github.com/netsec-ethz/scion-apps/ssh/scionutils"
@@ -15,6 +16,9 @@ import (
1516
"github.com/netsec-ethz/scion-apps/ssh/utils"
1617

1718
log "github.com/inconshreveable/log15"
19+
20+
scionlog "github.com/scionproto/scion/go/lib/log"
21+
"github.com/scionproto/scion/go/lib/snet/squic"
1822
)
1923

2024
const (
@@ -23,9 +27,8 @@ const (
2327

2428
var (
2529
// Connection
26-
listenAddress = kingpin.Flag("address", "SCION address to listen on").Default("").String()
27-
useIASCIoNDPath = kingpin.Flag("sciond-path-from-ia", "Use IA address when resolving SCIOND socket path").Short('P').Bool()
28-
options = kingpin.Flag("option", "Set an option").Short('o').Strings()
30+
listenAddress = kingpin.Flag("address", "SCION address to listen on").Default("").String()
31+
options = kingpin.Flag("option", "Set an option").Short('o').Strings()
2932

3033
// Configuration file
3134
configurationFile = kingpin.Flag("config-file", "SSH server configuration file").Short('f').Default("/etc/ssh/sshd_config").ExistingFile()
@@ -68,14 +71,25 @@ func updateConfigFromFile(conf *serverconfig.ServerConfig, pth string) {
6871

6972
func main() {
7073
kingpin.Parse()
74+
scionlog.SetupLogConsole("debug")
7175

7276
log.Debug("Starting SCION SSH server...")
7377

7478
conf := createConfig()
7579

76-
err := scionutils.InitSCIONConnection(utils.ParsePath(conf.QUICKeyPath), utils.ParsePath(conf.QUICCertificatePath), *useIASCIoNDPath)
80+
localhost, err := scionutil.GetLocalhost()
81+
if err != nil {
82+
golog.Panicf("Can't get localhost: %v", err)
83+
}
84+
85+
err = scionutil.InitSCION(localhost)
86+
if err != nil {
87+
golog.Panicf("Error initializing SCION: %v", err)
88+
}
89+
90+
err = squic.Init(utils.ParsePath(conf.QUICKeyPath), utils.ParsePath(conf.QUICCertificatePath))
7791
if err != nil {
78-
golog.Panicf("Error initializing SCION connection: %v", err)
92+
golog.Panicf("Error initializing SQUIC: %v", err)
7993
}
8094

8195
sshServer, err := ssh.Create(conf, version)

vendor/vendor.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
"revisionTime": "2018-11-12T14:05:56Z"
239239
},
240240
{
241-
"checksumSHA1": "WD7GMln/NoduJr0DbumjOE59xI8=",
241+
"checksumSHA1": "m3MNVovby5ZvMSiXIrfnjda1SMo=",
242242
"path": "github.com/kr/pty",
243243
"revision": "b6e1bdd4a4f88614e0c6e5e8089c7abed98aae17",
244244
"revisionTime": "2019-04-01T03:15:51Z"
@@ -328,7 +328,7 @@
328328
"revisionTime": "2018-06-23T06:33:31Z"
329329
},
330330
{
331-
"checksumSHA1": "fV/dWDjobpxleSwnZ4lR1/8hDu4=",
331+
"checksumSHA1": "lVlMU1vyM9Svh642UFG1haNui8Q=",
332332
"path": "github.com/marten-seemann/qtls",
333333
"revision": "65ca381cd298d7e0aef0de8ba523a870ec5a96fe",
334334
"revisionTime": "2019-03-29T07:59:07Z"
@@ -794,7 +794,7 @@
794794
"revisionTime": "2019-04-17T02:59:34Z"
795795
},
796796
{
797-
"checksumSHA1": "iV2FonJPeLV+iF4JHS3TRRXegF4=",
797+
"checksumSHA1": "lyMOyBzKMVR2jJOYQf6Vr/1x77Q=",
798798
"path": "golang.org/x/image/font/basicfont",
799799
"revision": "59b11bec70c7cc648cf3cc54683683b76d5b5e6b",
800800
"revisionTime": "2019-04-17T02:59:34Z"

0 commit comments

Comments
 (0)