summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-08-17 19:42:15 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-08-20 20:27:45 +0200
commita10c5ecd2b4bba6814fd66f0ec1997938d95bf92 (patch)
tree5002b8d9e6709d3c277682039bac3411ffc8f643 /pkg
parent60a35bdde41e8648594dc6a501a11000081ff878 (diff)
[feat] login feedback
- Resolves: #334
Diffstat (limited to 'pkg')
-rw-r--r--pkg/backend/api.go9
-rw-r--r--pkg/backend/status.go1
-rw-r--r--pkg/bitmask/bitmask.go1
-rw-r--r--pkg/bitmask/init.go9
-rw-r--r--pkg/config/config.go4
-rw-r--r--pkg/vpn/bonafide/bonafide.go2
-rw-r--r--pkg/vpn/openvpn.go16
7 files changed, 33 insertions, 9 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
index 7b48906..6609b1b 100644
--- a/pkg/backend/api.go
+++ b/pkg/backend/api.go
@@ -16,16 +16,19 @@ import (
func Login(username, password string) {
success, err := ctx.bm.DoLogin(username, password)
if err != nil {
- // TODO
- log.Printf("Error login: %v", err)
+ log.Printf("Error on login: %v", err)
+ ctx.Errors = "bad_auth_unknown"
} else if success {
- // TODO: Notify success
log.Printf("Logged in as %s", username)
+ ctx.LoginOk = true
+ ctx.LoginDialog = false
} else {
// TODO: display login again with an err
log.Printf("Failed to login as %s", username)
ctx.LoginDialog = true
+ ctx.Errors = "bad_auth"
}
+ go ctx.updateStatus()
}
func SwitchOn() {
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index 5e9a0f8..f06d26d 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -38,6 +38,7 @@ type connectionCtx struct {
DonateDialog bool `json:"donateDialog"`
DonateURL string `json:"donateURL"`
LoginDialog bool `json:"loginDialog"`
+ LoginOk bool `json:"loginOk"`
Version string `json:"version"`
Errors string `json:"errors"`
Status status `json:"status"`
diff --git a/pkg/bitmask/bitmask.go b/pkg/bitmask/bitmask.go
index 927e486..adfc849 100644
--- a/pkg/bitmask/bitmask.go
+++ b/pkg/bitmask/bitmask.go
@@ -20,6 +20,7 @@ type Bitmask interface {
Close()
Version() (string, error)
StartVPN(provider string) error
+ CanStartVPN() bool
StopVPN() error
ReloadFirewall() error
GetStatus() (string, error)
diff --git a/pkg/bitmask/init.go b/pkg/bitmask/init.go
index a96ab87..b86deb8 100644
--- a/pkg/bitmask/init.go
+++ b/pkg/bitmask/init.go
@@ -131,7 +131,10 @@ func maybeStartVPN(b Bitmask, conf *config.Config) error {
return nil
}
- err := b.StartVPN(config.Provider)
- conf.SetUserStoppedVPN(false)
- return err
+ if b.CanStartVPN() {
+ err := b.StartVPN(config.Provider)
+ conf.SetUserStoppedVPN(false)
+ return err
+ }
+ return nil
}
diff --git a/pkg/config/config.go b/pkg/config/config.go
index e9866d2..f3f9e6e 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by vendorize.py
-// At 2020-08-13 22:38:42
+// At 2020-08-15 20:39:01
package config
@@ -15,7 +15,7 @@ const (
AskForDonations = "false"
HelpURL = "https://libraryvpn.org/"
TosURL = "https://libraryvpn.org/"
- APIURL = "https://api.vpnlib.bitmask.net/"
+ APIURL = "https://api.vpnlib.bitmask.net:4430/"
GeolocationAPI = "https://getmyip.vpnlib.bitmask.net/"
)
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go
index 87801cc..dd8c597 100644
--- a/pkg/vpn/bonafide/bonafide.go
+++ b/pkg/vpn/bonafide/bonafide.go
@@ -137,7 +137,7 @@ func (b *Bonafide) GetPemCertificate() ([]byte, error) {
log.Fatal("ERROR: bonafide did not initialize auth")
}
if b.auth.needsCredentials() && b.token == nil {
- log.Println("BUG: expected token to be set, but is not there")
+ log.Println("Needs token, but token is empty")
return nil, errors.New("Needs to login, but it was not logged in. Please, restart the application and report it if it continues happening")
}
diff --git a/pkg/vpn/openvpn.go b/pkg/vpn/openvpn.go
index 31f8738..11bba69 100644
--- a/pkg/vpn/openvpn.go
+++ b/pkg/vpn/openvpn.go
@@ -16,6 +16,7 @@
package vpn
import (
+ "errors"
"fmt"
"io/ioutil"
"log"
@@ -43,9 +44,23 @@ func (b *Bitmask) StartVPN(provider string) error {
}
}
+ if !b.CanStartVPN() {
+ return errors.New("BUG: cannot start vpn")
+ }
return b.startOpenVPN(proxy)
}
+func (b *Bitmask) CanStartVPN() bool {
+ if !b.bonafide.NeedsCredentials() {
+ return true
+ }
+ _, err := b.getCert()
+ if err != nil {
+ return false
+ }
+ return true
+}
+
func (b *Bitmask) startTransport() (proxy string, err error) {
proxy = "127.0.0.1:4430"
if b.shapes != nil {
@@ -150,6 +165,7 @@ func (b *Bitmask) getCert() (certPath string, err error) {
certPath = b.getCertPemPath()
if _, err := os.Stat(certPath); os.IsNotExist(err) {
+ log.Println("Cert does not exist in ", certPath, "...fetching")
cert, err := b.bonafide.GetPemCertificate()
if err != nil {
return "", err