From 3fdbb895b8372caa080044cade00f2de6b00ce91 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Mon, 31 May 2021 02:34:21 +0200 Subject: [feat] obfs4 selectable from gui --- pkg/backend/actions.go | 5 ++--- pkg/backend/api.go | 4 ++-- pkg/bitmask/bitmask.go | 1 - pkg/bitmask/init.go | 2 +- pkg/vpn/openvpn.go | 29 +++++++++++++++-------------- 5 files changed, 20 insertions(+), 21 deletions(-) (limited to 'pkg') diff --git a/pkg/backend/actions.go b/pkg/backend/actions.go index 1860b09..9e0941b 100644 --- a/pkg/backend/actions.go +++ b/pkg/backend/actions.go @@ -24,9 +24,8 @@ func getGateway() string { return ctx.bm.GetCurrentGateway() } -// TODO return bool? -func useTransport(transport string) { - err := ctx.bm.UseTransport(transport) +func setTransport(t string) { + err := ctx.bm.SetTransport(t) if err != nil { log.Println(err) } diff --git a/pkg/backend/api.go b/pkg/backend/api.go index e96c65b..53800b3 100644 --- a/pkg/backend/api.go +++ b/pkg/backend/api.go @@ -79,8 +79,8 @@ func UseAutomaticGateway() { } } -func UseTransport(label string) { - ctx.bm.UseTransport(label) +func SetTransport(label string) { + ctx.bm.SetTransport(label) } func GetTransport() *C.char { diff --git a/pkg/bitmask/bitmask.go b/pkg/bitmask/bitmask.go index b430808..364312e 100644 --- a/pkg/bitmask/bitmask.go +++ b/pkg/bitmask/bitmask.go @@ -36,7 +36,6 @@ type Bitmask interface { GetCurrentLocation() string GetCurrentCountry() string IsManualLocation() bool - UseTransport(transport string) error NeedsCredentials() bool DoLogin(username, password string) (bool, error) } diff --git a/pkg/bitmask/init.go b/pkg/bitmask/init.go index b6b41b4..ab40fed 100644 --- a/pkg/bitmask/init.go +++ b/pkg/bitmask/init.go @@ -109,7 +109,7 @@ func InitializeBitmask(conf *config.Config) (Bitmask, error) { func setTransport(b Bitmask, conf *config.Config) error { if conf.Obfs4 { log.Printf("Use transport Obfs4") - err := b.UseTransport("obfs4") + err := b.SetTransport("obfs4") if err != nil { log.Printf("Error setting transport: %v", err) return err diff --git a/pkg/vpn/openvpn.go b/pkg/vpn/openvpn.go index d69f4e6..1a92d66 100644 --- a/pkg/vpn/openvpn.go +++ b/pkg/vpn/openvpn.go @@ -319,15 +319,25 @@ func (b *Bitmask) UseAutomaticGateway() { b.bonafide.SetAutomaticGateway() } -// UseTransport selects an obfuscation transport to use -func (b *Bitmask) UseTransport(transport string) error { - if transport != "obfs4" { - return fmt.Errorf("Transport %s not implemented", transport) +// SetTransport selects an obfuscation transport to use +func (b *Bitmask) SetTransport(t string) error { + if t != "openvpn" && t != "obfs4" { + return fmt.Errorf("Transport %s not implemented", t) + } + log.Println("Setting transport to", t) + // compare and set string looks strange, but if assigning directly + // we're getting some kind of corruption with the transport string. + // I suspect something's + // not quite right with the c<->go char pointers handling. + if t == "obfs4" { + b.transport = "obfs4" + } else if t == "openvpn" { + b.transport = "openvpn" } - b.transport = transport return nil } +// GetTransport gets the obfuscation transport to use. Only obfs4 available for now. func (b *Bitmask) GetTransport() string { if b.transport == "obfs4" { return "obfs4" @@ -336,15 +346,6 @@ func (b *Bitmask) GetTransport() string { } } -func (b *Bitmask) SetTransport(t string) error { - if t != "openvpn" && t != "obfs4" { - return errors.New("Transport not supported: " + t) - } - log.Println("Setting transport to", t) - b.transport = t - return nil -} - func (b *Bitmask) getTempCertPemPath() string { return path.Join(b.tempdir, "openvpn.pem") } -- cgit v1.2.3