Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPN apps #278

Merged
merged 106 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 100 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
4ee54d0
Add TUN interface allocation
Darkren Mar 27, 2020
a88430f
Add VPN client draft. Sets up TUN interface and routing
Darkren Mar 30, 2020
1ad5b80
Add STCP table and hypervisors routing, clean up the clean up
Darkren Mar 31, 2020
ad1acdf
Add traffic resending routines, refactor a bit, improve logging
Darkren Mar 31, 2020
46d5263
Add ignoring of loopback routing
Darkren Mar 31, 2020
47b2ba0
Try to simulate servers
Darkren Apr 2, 2020
11ae901
Add server part draft to test connection
Darkren Apr 3, 2020
a66be2d
Replace UDP with TCP
Darkren Apr 3, 2020
22e21ab
Capture traffic
Darkren Apr 3, 2020
1c17758
Capture traff
Darkren Apr 6, 2020
b52a376
Move helper funcs to the separate package
Darkren Apr 8, 2020
49edbf3
Make command to fetch default gateway IP platform dependent. Add impl…
Darkren Apr 8, 2020
2bde6a9
Add VPN server draft
Darkren Apr 9, 2020
27abccd
Add IP/Gateway generation for accepted client connections
Darkren Apr 9, 2020
f4a8e86
Finish vpn server draft?
Darkren Apr 9, 2020
a305e8b
Add possibility to pass envs to app. Add vpn client env processing
Darkren Apr 9, 2020
2bcf9e9
Prepare for testing
Darkren Apr 10, 2020
f2264bd
Improve logging
Darkren Apr 10, 2020
d80f8be
Add default VPN app configs
Darkren Apr 10, 2020
976c3b1
Add VPN apps to Makefile
Darkren Apr 10, 2020
5f85019
Remove import cycle
Darkren Apr 10, 2020
a1033d3
Add uptime tracker IP to be passed to VPN client
Darkren Apr 10, 2020
3b32da9
Add logs
Darkren Apr 10, 2020
b2999f9
Fix search of default network interface
Darkren Apr 10, 2020
7b810c1
Try to fix
Darkren Apr 10, 2020
e4af694
Simplify debugging
Darkren Apr 10, 2020
fe9ae9f
Fix envs on app start
Darkren Apr 10, 2020
20c4e99
Fix envs once again
Darkren Apr 10, 2020
38d9e8a
Hardcode bash path
Darkren Apr 10, 2020
ef0f9ec
Fix IP forward enabling procedure
Darkren Apr 10, 2020
2ebecd7
Fix once again
Darkren Apr 10, 2020
afb1313
Fix IP masquerading for Linux
Darkren Apr 10, 2020
fb9c4b0
Add VPN client port to config
Darkren Apr 10, 2020
ca714ef
Fix some commands not found in PATH
Darkren Apr 11, 2020
af7357a
Merge branch 'develop' of github.com:SkycoinProject/skywire-mainnet i…
Darkren Apr 11, 2020
4a955f5
Hardcode server pub key, add dial retries
Darkren Apr 13, 2020
440518d
Fix flag
Darkren Apr 14, 2020
742b227
Merge branch 'develop' of github.com:SkycoinProject/skywire-mainnet i…
Darkren Apr 14, 2020
c2b714d
Change DMSG server IPs
Darkren Apr 14, 2020
3bc2b98
Fix server cleanup
Darkren Apr 15, 2020
39bf8f2
Fix client cleanup
Darkren Apr 15, 2020
6f6b4d4
Remove testing code
Darkren Apr 15, 2020
72d0c0d
Refactor logging, improve errors returned
Darkren Apr 15, 2020
d8e92f1
Fix routing commands for Linux
Darkren Apr 15, 2020
bb11a10
Update vendor
Darkren Apr 16, 2020
c74d102
Update vendor
Darkren Apr 16, 2020
9d4615a
Try to fix IP generation
Darkren Apr 17, 2020
c116456
Change server-side TUN netmask
Darkren Apr 17, 2020
863c0b9
Fix
Darkren Apr 17, 2020
e500da6
Fix
Darkren Apr 17, 2020
3a4d9be
Fix
Darkren Apr 17, 2020
7c5ac7b
Make IP generator loop over private IP ranges
Darkren Apr 19, 2020
b43bef8
Fix
Darkren Apr 19, 2020
06ca97f
Fix
Darkren Apr 19, 2020
5b091d1
Fix
Darkren Apr 19, 2020
5ae2d31
Fix
Darkren Apr 19, 2020
38b88f5
Fix
Darkren Apr 19, 2020
99f06b8
Fix
Darkren Apr 19, 2020
b123c3b
Fix
Darkren Apr 19, 2020
d9f7ade
Fix
Darkren Apr 19, 2020
bae6ac0
Fix
Darkren Apr 19, 2020
d2bf8c9
Fix
Darkren Apr 19, 2020
7638ae2
Update vendor
Darkren Apr 20, 2020
b86f303
Make visor pass real Dmsg servers to the VPN client
Darkren Apr 20, 2020
83b6eaa
Fix IP generation?
Darkren Apr 20, 2020
c44b7d6
Fix and test IP generation
Darkren Apr 20, 2020
2793fc2
Add func to get pre-reserved private IPs
Darkren Apr 20, 2020
ab43ec8
Add server/client negotiation draft
Darkren Apr 21, 2020
6b9fd7b
Debug
Darkren Apr 21, 2020
e987833
Fix missing server pub key issue
Darkren Apr 21, 2020
fbdc6c6
Remove annoying log line
Darkren Apr 22, 2020
cec2257
Refactor partially
Darkren Apr 22, 2020
63ea172
Second refactoring round
Darkren Apr 23, 2020
a9fde32
Regenerate mocks
Darkren Apr 23, 2020
125dd89
Fix some tests
Darkren Apr 23, 2020
3141315
Fix router data race (#237)
Darkren Apr 23, 2020
6ccab88
Merge branch 'develop' of github.com:SkycoinProject/skywire-mainnet i…
Darkren Apr 23, 2020
b036700
Fix `IPFromEnv` test
Darkren Apr 23, 2020
a5a91ea
Remove hypervisor direct routing
Darkren Apr 23, 2020
d86e599
Make linter happy
Darkren Apr 24, 2020
ac610c4
Fix slice bounds panic
Darkren Apr 24, 2020
1f1bc70
Remove binaries
Darkren Apr 24, 2020
a7f04aa
Start refactoring client code
Darkren Apr 26, 2020
5cb7c93
Group imports
Darkren Apr 26, 2020
63b9d66
Fix var name
Darkren Apr 26, 2020
9f94285
Try to simplify handshake with `ioutil.ReadAll`
Darkren Apr 26, 2020
8e9c449
Revert
Darkren Apr 26, 2020
34be043
Replace `bash` calls with `sh`
Darkren Apr 26, 2020
6bf1aeb
Rename func
Darkren Apr 26, 2020
8d49e84
Add IP generation logic related comments
Darkren Apr 26, 2020
fb92b5b
Refactor client
Darkren Apr 27, 2020
3b1e383
Fix `ipFromEnv`
Darkren Apr 27, 2020
96ec3f8
Refactor VPN client
Darkren Apr 27, 2020
e44d45c
Remove `vpn-client` binary
Darkren Apr 27, 2020
cec4ac9
Refactor a bit
Darkren Apr 27, 2020
0612edc
Merge branch 'develop' of github.com:SkycoinProject/skywire-mainnet i…
Darkren Apr 29, 2020
c6b7cdc
Replace local `netutil` with the one from `dmsg`
Darkren Apr 29, 2020
4183ea4
Utilize skyenv in apps
Darkren Apr 29, 2020
4df12cf
Simplify IP to octets routine
Darkren Apr 29, 2020
378c48a
Remove redundant logs
Darkren Apr 29, 2020
d751263
Try to remove binary route from ifconfig call
Darkren Apr 30, 2020
36c0a39
Add debug logs
Darkren Apr 30, 2020
29cfaa8
Fix PATH once again
Darkren Apr 30, 2020
671b309
Pass PATH env for VPN server too
Darkren Apr 30, 2020
8c2b690
Remove redundant logs
Darkren Apr 30, 2020
c095e85
Add all cmds called by path relative to PATH
Darkren Apr 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ host-apps: ## Build app
${OPTS} go build ${BUILD_OPTS} -o ./apps/helloworld ./cmd/apps/helloworld
${OPTS} go build ${BUILD_OPTS} -o ./apps/skysocks ./cmd/apps/skysocks
${OPTS} go build ${BUILD_OPTS} -o ./apps/skysocks-client ./cmd/apps/skysocks-client
${OPTS} go build ${BUILD_OPTS} -o ./apps/vpn-server ./cmd/apps/vpn-server
${OPTS} go build ${BUILD_OPTS} -o ./apps/vpn-client ./cmd/apps/vpn-client

# Bin
bin: ## Build `skywire-visor`, `skywire-cli`, `hypervisor`
Expand All @@ -139,6 +141,8 @@ release: ## Build `skywire-visor`, `skywire-cli`, `hypervisor` and apps without
${OPTS} go build ${BUILD_OPTS} -o ./apps/helloworld ./cmd/apps/helloworld
${OPTS} go build ${BUILD_OPTS} -o ./apps/skysocks ./cmd/apps/skysocks
${OPTS} go build ${BUILD_OPTS} -o ./apps/skysocks-client ./cmd/apps/skysocks-client
${OPTS} go build ${BUILD_OPTS} -o ./apps/vpn-server ./cmd/apps/vpn-server
${OPTS} go build ${BUILD_OPTS} -o ./apps/vpn-client ./cmd/apps/vpn-client

github-release: ## Create a GitHub release
goreleaser --rm-dist
Expand Down
118 changes: 118 additions & 0 deletions cmd/apps/vpn-client/vpn-client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package main

import (
"context"
"flag"
"fmt"
"net"
"os"
"os/signal"
"syscall"
"time"

"github.com/SkycoinProject/dmsg/cipher"
"github.com/SkycoinProject/dmsg/netutil"
"github.com/SkycoinProject/skycoin/src/util/logging"

"github.com/SkycoinProject/skywire-mainnet/internal/vpn"
"github.com/SkycoinProject/skywire-mainnet/pkg/app"
"github.com/SkycoinProject/skywire-mainnet/pkg/app/appnet"
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
"github.com/SkycoinProject/skywire-mainnet/pkg/skyenv"
)

const (
appName = skyenv.VPNClientName
netType = appnet.TypeSkynet
vpnPort = routing.Port(skyenv.VPNServerPort)
)

const (
serverDialInitBO = 1 * time.Second
serverDialMaxBO = 10 * time.Second
)

var (
log = app.NewLogger(appName)
r = netutil.NewRetrier(log, serverDialInitBO, serverDialMaxBO, 0, 1)
)

var serverPKStr = flag.String("srv", "", "PubKey of the server to connect to")

func dialServer(appCl *app.Client, pk cipher.PubKey) (net.Conn, error) {
var conn net.Conn
err := r.Do(context.Background(), func() error {
var err error
conn, err = appCl.Dial(appnet.Addr{
Net: netType,
PubKey: pk,
Port: vpnPort,
})
return err
})
if err != nil {
return nil, err
}

return conn, nil
}

func main() {
Darkren marked this conversation as resolved.
Show resolved Hide resolved
flag.Parse()

if *serverPKStr == "" {
log.Fatalln("VPN server pub key is missing")
}

serverPK := cipher.PubKey{}
if err := serverPK.UnmarshalText([]byte(*serverPKStr)); err != nil {
log.WithError(err).Fatalln("Invalid VPN server pub key")
}

log.Infof("Connecting to VPN server %s", serverPK.String())

appCfg, err := app.ClientConfigFromEnv()
if err != nil {
log.WithError(err).Fatalln("Error getting app client config")
}

appClient, err := app.NewClient(logging.MustGetLogger(fmt.Sprintf("app_%s", appName)), appCfg)
if err != nil {
log.WithError(err).Fatalln("Error setting up VPN client")
}
defer func() {
appClient.Close()
}()

appConn, err := dialServer(appClient, serverPK)
if err != nil {
log.WithError(err).Fatalln("Error connecting to VPN server")
}
defer func() {
if err := appConn.Close(); err != nil {
log.WithError(err).Errorln("Error closing connection to the VPN server")
}
}()

log.Infof("Dialed %s", appConn.RemoteAddr())

vpnClient, err := vpn.NewClient(log, appConn)
if err != nil {
log.WithError(err).Fatalln("Error creating VPN client")
}

osSigs := make(chan os.Signal, 2)
sigs := []os.Signal{syscall.SIGTERM, syscall.SIGINT}
for _, sig := range sigs {
signal.Notify(osSigs, sig)
}

go func() {
<-osSigs
vpnClient.Close()
}()

if err := vpnClient.Serve(); err != nil {
log.WithError(err).Fatalln("Error serving VPN")
}
}
75 changes: 75 additions & 0 deletions cmd/apps/vpn-server/vpn-server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/SkycoinProject/skycoin/src/util/logging"

"github.com/SkycoinProject/skywire-mainnet/internal/vpn"
"github.com/SkycoinProject/skywire-mainnet/pkg/app"
"github.com/SkycoinProject/skywire-mainnet/pkg/app/appnet"
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
"github.com/SkycoinProject/skywire-mainnet/pkg/skyenv"
)

const (
appName = skyenv.VPNServerName
netType = appnet.TypeSkynet
vpnPort = routing.Port(skyenv.VPNServerPort)
)

var (
log = app.NewLogger(appName)
)

func main() {
Darkren marked this conversation as resolved.
Show resolved Hide resolved
appCfg, err := app.ClientConfigFromEnv()
if err != nil {
log.WithError(err).Errorln("Error getting app client config")
return
}

appClient, err := app.NewClient(logging.MustGetLogger(fmt.Sprintf("app_%s", appName)), appCfg)
if err != nil {
log.WithError(err).Errorln("Error setting up VPN client")
return
}
defer func() {
appClient.Close()
}()

osSigs := make(chan os.Signal, 2)

sigs := []os.Signal{syscall.SIGTERM, syscall.SIGINT}
for _, sig := range sigs {
signal.Notify(osSigs, sig)
}

l, err := appClient.Listen(netType, vpnPort)
if err != nil {
log.WithError(err).Errorf("Error listening network %v on port %d", netType, vpnPort)
return
}

log.Infof("Got app listener, bound to %d", vpnPort)

srv, err := vpn.NewServer(log)
if err != nil {
log.WithError(err).Fatalln("Error creating VPN server")
}
defer func() {
if err := srv.Close(); err != nil {
log.WithError(err).Errorln("Error closing server")
}
}()
go func() {
if err := srv.Serve(l); err != nil {
log.WithError(err).Errorln("Error serving")
}
}()

<-osSigs
}
18 changes: 18 additions & 0 deletions cmd/skywire-cli/commands/visor/gen-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ func defaultConfig() *visor.Config {
defaultSkychatConfig(),
defaultSkysocksConfig(""),
defaultSkysocksClientConfig(),
defaultVPNServerConfig(),
defaultVPNClientConfig(),
}

conf.TrustedVisors = []cipher.PubKey{}
Expand Down Expand Up @@ -207,3 +209,19 @@ func defaultSkysocksClientConfig() visor.AppConfig {
Port: routing.Port(skyenv.SkysocksClientPort),
}
}

func defaultVPNServerConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.VPNServerName,
AutoStart: true,
Port: routing.Port(skyenv.VPNServerPort),
}
}

func defaultVPNClientConfig() visor.AppConfig {
return visor.AppConfig{
App: skyenv.VPNClientName,
AutoStart: false,
Port: routing.Port(skyenv.VPNClientPort),
}
}
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@ module github.com/SkycoinProject/skywire-mainnet
go 1.13

require (
github.com/SkycoinProject/dmsg v0.2.0
github.com/SkycoinProject/dmsg v0.1.1-0.20200420091742-8c1a3d828a49
evanlinjin marked this conversation as resolved.
Show resolved Hide resolved
github.com/SkycoinProject/skycoin v0.27.0
github.com/SkycoinProject/yamux v0.0.0-20191213015001-a36efeefbf6a
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/go-chi/chi v4.0.2+incompatible
github.com/google/uuid v1.1.1
github.com/gorilla/securecookie v1.1.1
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/mholt/archiver/v3 v3.3.0
github.com/pkg/profile v1.3.0
github.com/prometheus/client_golang v1.3.0
github.com/prometheus/common v0.7.0
github.com/rakyll/statik v0.1.7
github.com/schollz/progressbar/v2 v2.15.0
github.com/sirupsen/logrus v1.4.2
github.com/sirupsen/logrus v1.5.0
github.com/skycoin/dmsg v0.0.0-20190805065636-70f4c32a994f // indirect
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
go.etcd.io/bbolt v1.3.4
golang.org/x/crypto v0.0.0-20200427165652-729f1e841bcc // indirect
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
golang.org/x/sys v0.0.0-20200428200454-593003d681fa // indirect
)

// Uncomment for tests with alternate branches of 'dmsg'
Expand Down
Loading