From 276eb57b559d09581ff1da2154319e9377745f32 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Fri, 21 Dec 2018 18:47:50 +0100 Subject: [bug] get vpn cert on vpn start Is not uncommon for the systray to be launched without internet access. For example in the autostart if the network hasn't come up yet. Let's fetch the vpn cert when the vpn is starting, instead of in the initialization of the standalone bitmask. So if the initialization happens when there is no network the systray doesn't fail to start. - Resolves: #88 --- standalone/main.go | 9 --------- standalone/vpn.go | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/standalone/main.go b/standalone/main.go index 357d53f..8f697c0 100644 --- a/standalone/main.go +++ b/standalone/main.go @@ -50,15 +50,6 @@ func Init() (*Bitmask, error) { if err != nil { return nil, err } - - cert, err := b.bonafide.getCertPem() - if err != nil { - return nil, err - } - err = ioutil.WriteFile(b.getCertPemPath(), cert, 0600) - if err != nil { - return nil, err - } err = ioutil.WriteFile(b.getCaCertPath(), caCert, 0600) go b.openvpnManagement() diff --git a/standalone/vpn.go b/standalone/vpn.go index fddda6e..e3ecca4 100644 --- a/standalone/vpn.go +++ b/standalone/vpn.go @@ -16,6 +16,8 @@ package bitmask import ( + "io/ioutil" + "os" "path" ) @@ -30,6 +32,11 @@ func (b *Bitmask) StartVPN(provider string) error { if err != nil { return err } + certPemPath, err := b.getCert() + if err != nil { + return err + } + err = b.launch.firewallStart(gateways) if err != nil { return err @@ -42,7 +49,6 @@ func (b *Bitmask) StartVPN(provider string) error { for _, gw := range gateways { arg = append(arg, "--remote", gw.IPAddress, "443", "tcp4") } - certPemPath := b.getCertPemPath() arg = append(arg, "--verb", "1", "--management-client", @@ -53,6 +59,20 @@ func (b *Bitmask) StartVPN(provider string) error { return b.launch.openvpnStart(arg...) } +func (b *Bitmask) getCert() (certPath string, err error) { + certPath = b.getCertPemPath() + + if _, err := os.Stat(certPath); os.IsNotExist(err) { + cert, err := b.bonafide.getCertPem() + if err != nil { + return "", err + } + err = ioutil.WriteFile(certPath, cert, 0600) + } + + return certPath, err +} + // StopVPN or cancel func (b *Bitmask) StopVPN() error { err := b.launch.firewallStop() -- cgit v1.2.3