diff --git a/go.mod b/go.mod index 97acfcd..f68d5de 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/aau-network-security/gwireguard go 1.13 require ( - github.com/golang-jwt/jwt v3.2.2+incompatible // indirect + github.com/golang-jwt/jwt v3.2.2+incompatible github.com/rs/zerolog v1.19.0 golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect diff --git a/go.sum b/go.sum index 5b9af42..5d16b51 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,6 @@ github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnht github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -19,6 +17,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= diff --git a/vpn/backend.go b/vpn/backend.go index 81921b5..7cca59d 100644 --- a/vpn/backend.go +++ b/vpn/backend.go @@ -33,6 +33,7 @@ func (w *wireguard) InitializeI(ctx context.Context, r *pb.IReq) (*pb.IResp, err log.Info().Msgf("Initializing interface for %s ", r.IName) privKey, err := generatePrivateKey(w.config.WgConfig.Dir + r.IName + "_priv") if err != nil { + log.Error().Err(err).Str("privatekey: ", privKey).Msg("Problem in generating the privatekey") return &pb.IResp{}, err } log.Info().Msgf("Private key is generated %s with name %s", w.config.WgConfig.Dir, r.IName) @@ -52,11 +53,16 @@ func (w *wireguard) InitializeI(ctx context.Context, r *pb.IReq) (*pb.IResp, err out, err := genInterfaceConf(wgI, w.config.WgConfig.Dir) if err != nil { + log.Error().Err(err).Str("interface:%s ", wgI.iName).Msg("Problem in configuration of the interface") + return &pb.IResp{Message: out}, fmt.Errorf("Problem in configuration of the interface -- %v", err) } out, err = upDown(r.IName, "up") + if err != nil { + + log.Error().Err(err).Str("interface: ", out).Msg("Problem in making the interface UP") return &pb.IResp{Message: out}, fmt.Errorf("PROBLEM IN THE FUNCTION upDown -- %v", err) } log.Debug().Str("Address: ", r.Address). @@ -149,9 +155,11 @@ func (w *wireguard) GenPublicKey(ctx context.Context, r *pb.PubKeyReq) (*pb.PubK // check whether private key exists or not, if not generate one if _, err := os.Stat(w.config.WgConfig.Dir + r.PrivKeyName + "_pub"); os.IsNotExist(err) { fmt.Printf("PrivateKeyFile is not exists, creating one ... %s\n", r.PrivKeyName) - _, err := generatePrivateKey(w.config.WgConfig.Dir + r.PrivKeyName + "_priv") + privKey, err := generatePrivateKey(w.config.WgConfig.Dir + r.PrivKeyName + "_priv") if err != nil { + log.Error().Err(err).Str("Privatekey: %s ", privKey).Msg("Problem in generation of private key") return &pb.PubKeyResp{Message: "Error"}, fmt.Errorf("error in generation of private key %v", err) + } } diff --git a/vpn/vpn.go b/vpn/vpn.go index ea7ed5d..23abde6 100644 --- a/vpn/vpn.go +++ b/vpn/vpn.go @@ -31,8 +31,9 @@ const ( var ( // todo: fix configuration variables //variablesvariablesĪ©os.Setenv("FOO", "1") - configPath = getConfigPath() - configuration, _ = config.NewConfig(configPath) + configuration, _ = config.NewConfig(os.Getenv("CONFIG_PATH")) + //configPath = getConfigPath() + //configuration, _ = config.NewConfig(configPath) ) type Interface struct { @@ -185,6 +186,7 @@ func upDown(nic, cmd string) (string, error) { return "", fmt.Errorf("failed to execute command: %s error: %v", command, err) } + return "Interface " + nic + " is " + cmd, nil } @@ -300,4 +302,8 @@ func getConfigPath() string { fullPathToconfig := fmt.Sprintf("%s%s", dir, "/config/config.yml") return fullPathToconfig -} \ No newline at end of file +} + +func init() { + getConfigPath() +}