summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exports/exports.go11
-rw-r--r--internal/fsm/fsm.go2
-rw-r--r--state.go29
-rw-r--r--wrappers/python/src/__init__.py1
-rw-r--r--wrappers/python/src/main.py6
5 files changed, 48 insertions, 1 deletions
diff --git a/exports/exports.go b/exports/exports.go
index 76c882a..ce8faa2 100644
--- a/exports/exports.go
+++ b/exports/exports.go
@@ -270,6 +270,17 @@ func SetConnected(name *C.char) *C.char {
return C.CString(ErrorToString(setConnectedErr))
}
+//export RenewSession
+func RenewSession(name *C.char) *C.char {
+ nameStr := C.GoString(name)
+ state, stateErr := GetVPNState(nameStr)
+ if stateErr != nil {
+ return C.CString(ErrorToString(stateErr))
+ }
+ renewSessionErr := state.RenewSession()
+ return C.CString(ErrorToString(renewSessionErr))
+}
+
//export ShouldRenewButton
func ShouldRenewButton(name *C.char) C.int {
nameStr := C.GoString(name)
diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go
index 8b5875b..5a88885 100644
--- a/internal/fsm/fsm.go
+++ b/internal/fsm/fsm.go
@@ -141,7 +141,7 @@ func (fsm *FSM) Init(name string, callback func(string, string, string), directo
AUTHORIZED: FSMState{Transitions: []FSMTransition{{OAUTH_STARTED, "Re-authorize with OAuth"}, {REQUEST_CONFIG, "Client requests a config"}}},
REQUEST_CONFIG: FSMState{Transitions: []FSMTransition{{ASK_PROFILE, "Multiple profiles found and no profile chosen"}, {HAS_CONFIG, "Only one profile or profile already chosen"}, {NO_SERVER, "Cancel or Error"}, {OAUTH_STARTED, "Re-authorize"}}},
ASK_PROFILE: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "User chooses profile"}, {NO_SERVER, "Cancel or Error"}, {SEARCH_SERVER, "Cancel or Error"}}},
- HAS_CONFIG: FSMState{Transitions: []FSMTransition{{CONNECTING, "OS reports it is trying to connect"}, {REQUEST_CONFIG, "User chooses a new profile"}, {NO_SERVER, "User wants to choose a new server"}}, BackState: NO_SERVER},
+ HAS_CONFIG: FSMState{Transitions: []FSMTransition{{CONNECTING, "OS reports it is trying to connect"}, {REQUEST_CONFIG, "User chooses a new profile"}, {NO_SERVER, "User wants to choose a new server"}, {OAUTH_STARTED, "Re-authorize with OAuth"}}, BackState: NO_SERVER},
CONNECTING: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "Cancel or Error"}, {CONNECTED, "Done connecting"}}},
CONNECTED: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "OS reports disconnected"}}},
}
diff --git a/state.go b/state.go
index 7f29369..c046185 100644
--- a/state.go
+++ b/state.go
@@ -7,8 +7,10 @@ import (
"github.com/jwijenbergh/eduvpn-common/internal/discovery"
"github.com/jwijenbergh/eduvpn-common/internal/fsm"
"github.com/jwijenbergh/eduvpn-common/internal/log"
+ "github.com/jwijenbergh/eduvpn-common/internal/oauth"
"github.com/jwijenbergh/eduvpn-common/internal/server"
"github.com/jwijenbergh/eduvpn-common/internal/types"
+ "github.com/jwijenbergh/eduvpn-common/internal/util"
)
type VPNState struct {
@@ -388,6 +390,33 @@ func (state *VPNState) SetDisconnected() error {
return nil
}
+func (state *VPNState) RenewSession() error {
+ errorMessage := "failed to renew session"
+
+ currentServer, currentServerErr := state.Servers.GetCurrentServer()
+
+ if currentServerErr != nil {
+ return &types.WrappedErrorMessage{Message: "failed to renew session", Err: currentServerErr}
+ }
+
+ oauthStructure := currentServer.GetOAuth()
+ oauthStructure.Token = oauth.OAuthToken{Access: "",Refresh: "",Type: "",Expires: 0,ExpiredTimestamp: util.GetCurrentTime()}
+ // Make sure the FSM is initialized
+ oauthStructure.FSM = &state.FSM
+
+ loginErr := server.Login(currentServer)
+
+ if loginErr != nil {
+ // We are possibly in oauth started
+ // Go back
+ state.GoBack()
+ return &types.WrappedErrorMessage{Message: errorMessage, Err: loginErr}
+ }
+
+ return nil
+}
+
+
func (state *VPNState) ShouldRenewButton() bool {
if !state.FSM.InState(fsm.CONNECTED) {
return false
diff --git a/wrappers/python/src/__init__.py b/wrappers/python/src/__init__.py
index 2c933ca..be06525 100644
--- a/wrappers/python/src/__init__.py
+++ b/wrappers/python/src/__init__.py
@@ -87,6 +87,7 @@ lib.SetConnecting.argtypes, lib.SetConnecting.restype = [c_char_p], c_void_p
lib.SetDisconnected.argtypes, lib.SetDisconnected.restype = [c_char_p], c_void_p
lib.SetSearchServer.argtypes, lib.SetSearchServer.restype = [c_char_p], c_void_p
lib.ShouldRenewButton.argtypes, lib.ShouldRenewButton.restype = [], int
+lib.RenewSession.argtypes, lib.RenewSession.restype = [c_char_p], c_void_p
lib.FreeString.argtypes, lib.FreeString.restype = [c_void_p], None
diff --git a/wrappers/python/src/main.py b/wrappers/python/src/main.py
index a2a0d14..ac44073 100644
--- a/wrappers/python/src/main.py
+++ b/wrappers/python/src/main.py
@@ -207,5 +207,11 @@ class EduVPN(object):
if location_err:
raise Exception(location_err)
+ def renew_session(self) -> None:
+ renew_err = self.go_function(lib.RenewSession)
+
+ if renew_err:
+ raise Exception(renew_err)
+
def should_renew_button(self) -> bool:
return self.go_function(lib.ShouldRenewButton)