summaryrefslogtreecommitdiff
path: root/state.go
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroenwijenbergh@protonmail.com>2022-04-29 15:08:32 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-29 15:08:32 +0200
commit0e1f9826f2aea1a059529f9c3d1c921d7d4ac3d4 (patch)
tree2d26bd6dbd33abde910bff00078f520dad890a4d /state.go
parent6c7a1c7a9245cf457a86fd15bdc14bc93b55d508 (diff)
Secure Internet: Basic implementation and add support to cli
Diffstat (limited to 'state.go')
-rw-r--r--state.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/state.go b/state.go
index 3ca0a4b..c69cf37 100644
--- a/state.go
+++ b/state.go
@@ -2,6 +2,7 @@ package eduvpn
import (
"errors"
+
"github.com/jwijenbergh/eduvpn-common/internal"
)
@@ -86,16 +87,26 @@ func (state *VPNState) CancelOAuth() error {
return nil
}
-func (state *VPNState) Connect(url string) (string, error) {
+func (state *VPNState) connectWithOptions(url string, isSecureInternet bool) (string, error) {
if state.FSM.InState(internal.DEREGISTERED) {
return "", errors.New("app not registered")
}
// New server chosen, ensure the server is fresh
- server, serverErr := state.Servers.EnsureServer(url, &state.FSM, &state.Logger)
+ server, serverErr := state.Servers.EnsureServer(url, &state.FSM, &state.Logger, true)
if serverErr != nil {
return "", serverErr
}
+
+ // When we connect to secure internet, copy over the tokens from the home server
+ if isSecureInternet {
+ // Ensure the secure home server
+ state.Servers.EnsureServer(state.Servers.SecureHome, &state.FSM, &state.Logger, false)
+
+ // Copy the tokens
+ state.Servers.CopySecureInternetOAuth(server)
+ }
+
// Make sure we are in the chosen state if available
state.FSM.GoTransition(internal.CHOSEN_SERVER)
// Relogin with oauth
@@ -113,6 +124,9 @@ func (state *VPNState) Connect(url string) (string, error) {
state.FSM.GoTransition(internal.AUTHORIZED)
}
+ // Set the home server if it is not set already
+ state.Servers.EnsureSecureHome(server)
+
state.FSM.GoTransition(internal.REQUEST_CONFIG)
config, configErr := server.GetConfig()
@@ -126,6 +140,14 @@ func (state *VPNState) Connect(url string) (string, error) {
return config, nil
}
+func (state *VPNState) ConnectInstituteAccess(url string) (string, error) {
+ return state.connectWithOptions(url, false)
+}
+
+func (state *VPNState) ConnectSecureInternet(url string) (string, error) {
+ return state.connectWithOptions(url, true)
+}
+
func (state *VPNState) GetDiscoOrganizations() (string, error) {
if state.FSM.InState(internal.DEREGISTERED) {
return "", errors.New("app not registered")
@@ -133,7 +155,6 @@ func (state *VPNState) GetDiscoOrganizations() (string, error) {
return state.Discovery.GetOrganizationsList()
}
-
func (state *VPNState) GetDiscoServers() (string, error) {
if state.FSM.InState(internal.DEREGISTERED) {
return "", errors.New("app not registered")