diff options
author | Ruben Pollan <meskio@sindominio.net> | 2018-12-21 18:47:50 +0100 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2018-12-21 19:27:08 +0100 |
commit | 276eb57b559d09581ff1da2154319e9377745f32 (patch) | |
tree | 579a85d2117116e2f5a7a3d2597984e517d8eaf9 | |
parent | 43b06b2e1a6931113c4b0856a1980da2d2152782 (diff) |
[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
-rw-r--r-- | standalone/main.go | 9 | ||||
-rw-r--r-- | 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() |