diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-08-16 13:25:15 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2023-09-25 09:43:37 +0200 |
| commit | f583a28694be3ec3b99318673c6cdb6e42ee1372 (patch) | |
| tree | a80e65573f3db46212f1b31a865ece499e574d66 | |
| parent | b0e1fdb2ee09e10c2f2f8a78e14d39282595fab5 (diff) | |
Client + Exports + Python: Add a startup boolean to getconfig
To be used for autoconnect on startup. If autoconnect on startup set
to true
This ignores any callbacks that require user input (profile,
authorization & location callbacks)
| -rw-r--r-- | client/client.go | 29 | ||||
| -rw-r--r-- | client/client_test.go | 74 | ||||
| -rw-r--r-- | client/zgotext.go | 219 | ||||
| -rw-r--r-- | cmd/cli/main.go | 2 | ||||
| -rw-r--r-- | exports/exports.go | 7 | ||||
| -rw-r--r-- | internal/server/server.go | 9 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/loader.py | 1 | ||||
| -rw-r--r-- | wrappers/python/eduvpn_common/main.py | 13 |
8 files changed, 230 insertions, 124 deletions
diff --git a/client/client.go b/client/client.go index 20e6fa3..f4e31d9 100644 --- a/client/client.go +++ b/client/client.go @@ -375,9 +375,12 @@ func (c *Client) loginCallback(ck *cookie.Cookie, srv server.Server) error { return nil } -func (c *Client) callbacks(ck *cookie.Cookie, srv server.Server, forceauth bool) error { +func (c *Client) callbacks(ck *cookie.Cookie, srv server.Server, forceauth bool, startup bool) error { // location if srv.NeedsLocation() { + if startup { + return i18nerr.Newf("The client tried to autoconnect to the VPN server: %s, but no secure internet location is found. Please manually connect again", server.Name(srv)) + } err := c.locationCallback(ck) if err != nil { return i18nerr.Wrap(err, "The secure internet location could not be set") @@ -398,6 +401,9 @@ func (c *Client) callbacks(ck *cookie.Cookie, srv server.Server, forceauth bool) log.Logger.Debugf("failed to get tokens from client: %v", err) } if server.NeedsRelogin(context.Background(), srv) || forceauth { + if startup { + return i18nerr.Newf("The client tried to autoconnect to the VPN server: %s, but you need to authorizate again. Please manually connect again", server.Name(srv)) + } // mark organizations as expired if the server is a secure internet server b, berr := srv.Base() if berr == nil && b.Type == srvtypes.TypeSecureInternet { @@ -416,13 +422,16 @@ func (c *Client) callbacks(ck *cookie.Cookie, srv server.Server, forceauth bool) return nil } -func (c *Client) profileCallback(ck *cookie.Cookie, srv server.Server) error { +func (c *Client) profileCallback(ck *cookie.Cookie, srv server.Server, startup bool) error { vp, err := server.HasValidProfile(ck.Context(), srv, c.SupportsWireguard) if err != nil { log.Logger.Warningf("failed to determine whether the current protocol is valid with error: %v", err) return err } if !vp { + if startup { + return i18nerr.Newf("The client tried to autoconnect to the VPN server: %s, but no valid profiles were found. Please manually connect again", server.Name(srv)) + } vps, err := server.ValidProfiles(srv, c.SupportsWireguard) if err != nil { return i18nerr.Wrapf(err, "No suitable profiles could be found") @@ -527,7 +536,7 @@ func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes. } // callbacks - err = c.callbacks(ck, srv, false) + err = c.callbacks(ck, srv, false, false) // error is already UI wrapped if err != nil { return err @@ -539,9 +548,9 @@ func (c *Client) AddServer(ck *cookie.Cookie, identifier string, _type srvtypes. return nil } -func (c *Client) config(ck *cookie.Cookie, srv server.Server, pTCP bool, forceAuth bool) (cfg *srvtypes.Configuration, err error) { +func (c *Client) config(ck *cookie.Cookie, srv server.Server, pTCP bool, forceAuth bool, startup bool) (cfg *srvtypes.Configuration, err error) { // do the callbacks to ensure valid profile, location and authorization - err = c.callbacks(ck, srv, forceAuth) + err = c.callbacks(ck, srv, forceAuth, startup) if err != nil { return nil, err } @@ -551,7 +560,7 @@ func (c *Client) config(ck *cookie.Cookie, srv server.Server, pTCP bool, forceAu return nil, err } - err = c.profileCallback(ck, srv) + err = c.profileCallback(ck, srv, startup) if err != nil { return nil, err } @@ -586,7 +595,7 @@ func (c *Client) server(identifier string, _type srvtypes.Type) (srv server.Serv } // GetConfig gets a VPN configuration -func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes.Type, pTCP bool) (cfg *srvtypes.Configuration, err error) { +func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes.Type, pTCP bool, startup bool) (cfg *srvtypes.Configuration, err error) { c.mu.Lock() defer c.mu.Unlock() previousState := c.FSM.Current @@ -626,11 +635,11 @@ func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes. } // get a config and retry with authorization if expired - cfg, err = c.config(ck, srv, pTCP, false) + cfg, err = c.config(ck, srv, pTCP, false, startup) tErr := &oauth.TokensInvalidError{} if err != nil && errors.As(err, &tErr) { log.Logger.Debugf("the tokens were invalid, trying again...") - cfg, err = c.config(ck, srv, pTCP, true) + cfg, err = c.config(ck, srv, pTCP, true, startup) } // tokens might be updated, forward them @@ -886,7 +895,7 @@ func (c *Client) RenewSession(ck *cookie.Cookie) (err error) { // TODO: Maybe this can be deleted because we force auth now server.MarkTokensForRenew(srv) // run the callbacks by forcing auth - return c.callbacks(ck, srv, true) + return c.callbacks(ck, srv, true, false) } func (c *Client) StartFailover(ck *cookie.Cookie, gateway string, mtu int, readRxBytes func() (int64, error)) (bool, error) { diff --git a/client/client_test.go b/client/client_test.go index 34d9ccb..de47022 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -99,7 +99,7 @@ func TestServer(t *testing.T) { if addErr != nil { t.Fatalf("Add error: %v", addErr) } - _, configErr := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false) + _, configErr := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false, false) if configErr != nil { t.Fatalf("Connect error: %v", configErr) } @@ -148,7 +148,7 @@ func TestTokenExpired(t *testing.T) { t.Fatalf("Add error: %v", addErr) } - _, configErr := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false) + _, configErr := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false, false) if configErr != nil { t.Fatalf("Connect error before expired: %v", configErr) @@ -169,7 +169,7 @@ func TestTokenExpired(t *testing.T) { // Wait for TTL so that the tokens expire time.Sleep(time.Duration(expiredInt) * time.Second) - _, configErr = state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false) + _, configErr = state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false, false) if configErr != nil { t.Fatalf("Connect error after expiry: %v", configErr) @@ -215,7 +215,7 @@ func TestInvalidProfileCorrected(t *testing.T) { t.Fatalf("Add error: %v", addErr) } - _, configErr := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false) + _, configErr := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false, false) if configErr != nil { t.Fatalf("First connect error: %v", configErr) @@ -234,7 +234,7 @@ func TestInvalidProfileCorrected(t *testing.T) { previousProfile := base.Profiles.Current base.Profiles.Current = "IDONOTEXIST" - _, configErr = state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false) + _, configErr = state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false, false) if configErr != nil { t.Fatalf("Second connect error: %v", configErr) } @@ -248,6 +248,66 @@ func TestInvalidProfileCorrected(t *testing.T) { } } +// TestConfigStartup tests if the 'startup' variable for getconfig behaves as expected +func TestConfigStartup(t *testing.T) { + serverURI := getServerURI(t) + ck := cookie.NewWithContext(context.Background()) + defer ck.Cancel() //nolint:errcheck + dir := t.TempDir() + state, err := New( + "org.letsconnect-vpn.app.linux", + "0.1.0-test", + dir, + func(old FSMStateID, new FSMStateID, data interface{}) bool { + stateCallback(t, &ck, old, new, data) + return true + }, + false, + ) + if err != nil { + t.Fatalf("Creating client error: %v", err) + } + err = state.Register() + if err != nil { + t.Fatalf("Failed to register with error: %v", err) + } + // we set true as last argument here such that no callbacks are ran + err = state.AddServer(&ck, serverURI, srvtypes.TypeCustom, true) + if err != nil { + t.Fatalf("Failed to add server for trying config startup: %v", err) + } + testTrue := func() { + // Now get config with setting startup to true + startup := true + _, err := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false, startup) + // this should fail as we have not authorized yet/chosen profile and startup=true does not do these callbacks + if err == nil { + t.Fatal("Got no error after getting config with startup true") + } + if !strings.HasPrefix(err.Error(), "The client tried to autoconnect to the VPN server") { + t.Fatalf("GetConfig error for GetConfig with startup=true is not what we expect: %v", err) + } + } + testFalse := func() { + startup := false + // This should succeed + _, err := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false, startup) + // this should fail as we have not authorized yet/chosen profile + if err != nil { + t.Fatalf("Got error after getting config with startup=false: %v", err) + } + } + testTrue() + testFalse() + + // set invalid authorization and test again + // we cannot test by setting invalid profile because the server only has 1 profile + // TODO: support multiple profiles in the test server + state.Servers.CustomServers.Map[serverURI].OAuth().SetTokenRenew() + testTrue() + testFalse() +} + // Test if prefer tcp is handled correctly by checking the returned config and config type. func TestPreferTCP(t *testing.T) { serverURI := getServerURI(t) @@ -278,7 +338,7 @@ func TestPreferTCP(t *testing.T) { } // get a config with preferTCP set to true - config, configErr := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, true) + config, configErr := state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, true, false) // Test server should accept prefer TCP! if config.Protocol != protocol.OpenVPN { @@ -295,7 +355,7 @@ func TestPreferTCP(t *testing.T) { } // get a config with preferTCP set to false - config, configErr = state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false) + config, configErr = state.GetConfig(&ck, serverURI, srvtypes.TypeCustom, false, false) if configErr != nil { t.Fatalf("Config error: %v", configErr) } diff --git a/client/zgotext.go b/client/zgotext.go index 830632f..4015255 100644 --- a/client/zgotext.go +++ b/client/zgotext.go @@ -49,43 +49,46 @@ var messageKeyToIndex = map[string]int{ "An error occurred after getting the discovery files for the list of organizations": 6, "An error occurred after getting the discovery files for the list of servers": 7, "Client has an invalid state": 4, - "Could not retrieve institute access server with URL: '%s' from discovery": 15, - "Failed internal state transition requested by the client from: '%s' to '%s'": 34, - "Failed to cleanup the VPN connection for the current server": 29, - "Failed to get current server for renewing the session": 32, - "Failed to get the current server to cleanup the connection": 28, - "Failed to set the server with identifier: '%s' as the current": 26, - "Failover failed to complete with gateway: '%s' and mtu: '%d'": 33, - "Identifier: '%s' for server with type: '%d' is not valid": 24, - "Identifier: '%s' for server with type: '%d' is not valid for removal": 27, - "Internal state transition error": 0, - "No secure internet server available to set a location for": 31, - "No suitable profiles could be found": 11, - "Not a valid server type: %v": 23, - "Profile with ID: '%s' could not be obtained from the server": 13, - "Profile with ID: '%s' could not be set": 12, - "Server type: '%v' is not valid to be added": 20, - "Server/organization discovery with Let's Connect is not supported": 5, - "Setting a secure internet location with Let's Connect! is not supported": 30, - "The VPN configuration could not be obtained": 21, - "The authorization procedure failed to complete": 10, - "The client registered with an invalid client ID: '%v'": 1, - "The client registered with an invalid version: '%v'": 2, - "The current profile could not be found": 22, - "The current server could not be found when getting it for expiry": 8, - "The custom server with URL: '%s' could not be added": 19, - "The identifier that was passed to the library is incorrect": 14, - "The institute access server with URL: '%s' could not be added": 16, - "The log file with directory: '%s' failed to initialize": 3, - "The operation for getting a VPN configuration was canceled": 25, - "The secure internet location could not be set": 9, - "The secure internet server with organisation ID: '%s' could not be added": 18, - "The secure internet server with organisation ID: '%s' could not be retrieved from discovery": 17, - "timeout reached": 35, - "with cause:": 36, + "Could not retrieve institute access server with URL: '%s' from discovery": 18, + "Failed internal state transition requested by the client from: '%s' to '%s'": 37, + "Failed to cleanup the VPN connection for the current server": 32, + "Failed to get current server for renewing the session": 35, + "Failed to get the current server to cleanup the connection": 31, + "Failed to set the server with identifier: '%s' as the current": 29, + "Failover failed to complete with gateway: '%s' and mtu: '%d'": 36, + "Identifier: '%s' for server with type: '%d' is not valid": 27, + "Identifier: '%s' for server with type: '%d' is not valid for removal": 30, + "Internal state transition error": 0, + "No secure internet server available to set a location for": 34, + "No suitable profiles could be found": 14, + "Not a valid server type: %v": 26, + "Profile with ID: '%s' could not be obtained from the server": 16, + "Profile with ID: '%s' could not be set": 15, + "Server type: '%v' is not valid to be added": 23, + "Server/organization discovery with Let's Connect is not supported": 5, + "Setting a secure internet location with Let's Connect! is not supported": 33, + "The VPN configuration could not be obtained": 24, + "The authorization procedure failed to complete": 12, + "The client registered with an invalid client ID: '%v'": 1, + "The client registered with an invalid version: '%v'": 2, + "The client tried to autoconnect to the VPN server: %s, but no secure internet location is found. Please manually connect again": 9, + "The client tried to autoconnect to the VPN server: %s, but no valid profiles were found. Please manually connect again": 13, + "The client tried to autoconnect to the VPN server: %s, but you need to authorizate again. Please manually connect again": 11, + "The current profile could not be found": 25, + "The current server could not be found when getting it for expiry": 8, + "The custom server with URL: '%s' could not be added": 22, + "The identifier that was passed to the library is incorrect": 17, + "The institute access server with URL: '%s' could not be added": 19, + "The log file with directory: '%s' failed to initialize": 3, + "The operation for getting a VPN configuration was canceled": 28, + "The secure internet location could not be set": 10, + "The secure internet server with organisation ID: '%s' could not be added": 21, + "The secure internet server with organisation ID: '%s' could not be retrieved from discovery": 20, + "timeout reached": 38, + "with cause:": 39, } -var daIndex = []uint32{ // 38 elements +var daIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -97,12 +100,13 @@ var daIndex = []uint32{ // 38 elements 0x00000000, 0x00000000, 0x00000000, 0x00000000, // Entry 20 - 3F 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, -} // Size: 176 bytes + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, +} // Size: 188 bytes const daData string = "" -var deIndex = []uint32{ // 38 elements +var deIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -114,27 +118,29 @@ var deIndex = []uint32{ // 38 elements 0x00000000, 0x00000000, 0x00000000, 0x00000000, // Entry 20 - 3F 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, -} // Size: 176 bytes + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, +} // Size: 188 bytes const deData string = "" -var enIndex = []uint32{ // 38 elements +var enIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000020, 0x00000059, 0x00000090, 0x000000ca, 0x000000e6, 0x00000128, 0x0000017a, - 0x000001c6, 0x00000207, 0x00000235, 0x00000264, - 0x00000288, 0x000002b2, 0x000002f1, 0x0000032c, - 0x00000378, 0x000003b9, 0x00000418, 0x00000464, - 0x0000049b, 0x000004c9, 0x000004f5, 0x0000051c, - 0x0000053b, 0x0000057a, 0x000005b5, 0x000005f6, - 0x00000641, 0x0000067c, 0x000006b8, 0x00000700, + 0x000001c6, 0x00000207, 0x00000289, 0x000002b7, + 0x00000332, 0x00000361, 0x000003db, 0x000003ff, + 0x00000429, 0x00000468, 0x000004a3, 0x000004ef, + 0x00000530, 0x0000058f, 0x000005db, 0x00000612, + 0x00000640, 0x0000066c, 0x00000693, 0x000006b2, + 0x000006f1, 0x0000072c, 0x0000076d, 0x000007b8, // Entry 20 - 3F - 0x0000073a, 0x00000770, 0x000007b3, 0x00000805, - 0x00000815, 0x00000821, -} // Size: 176 bytes + 0x000007f3, 0x0000082f, 0x00000877, 0x000008b1, + 0x000008e7, 0x0000092a, 0x0000097c, 0x0000098c, + 0x00000998, +} // Size: 188 bytes -const enData string = "" + // Size: 2081 bytes +const enData string = "" + // Size: 2456 bytes "\x02Internal state transition error\x02The client registered with an inv" + "alid client ID: '%[1]v'\x02The client registered with an invalid version" + ": '%[1]v'\x02The log file with directory: '%[1]s' failed to initialize" + @@ -142,32 +148,37 @@ const enData string = "" + // Size: 2081 bytes "t's Connect is not supported\x02An error occurred after getting the disc" + "overy files for the list of organizations\x02An error occurred after get" + "ting the discovery files for the list of servers\x02The current server c" + - "ould not be found when getting it for expiry\x02The secure internet loca" + - "tion could not be set\x02The authorization procedure failed to complete" + - "\x02No suitable profiles could be found\x02Profile with ID: '%[1]s' coul" + - "d not be set\x02Profile with ID: '%[1]s' could not be obtained from the " + - "server\x02The identifier that was passed to the library is incorrect\x02" + - "Could not retrieve institute access server with URL: '%[1]s' from discov" + - "ery\x02The institute access server with URL: '%[1]s' could not be added" + - "\x02The secure internet server with organisation ID: '%[1]s' could not b" + - "e retrieved from discovery\x02The secure internet server with organisati" + - "on ID: '%[1]s' could not be added\x02The custom server with URL: '%[1]s'" + - " could not be added\x02Server type: '%[1]v' is not valid to be added\x02" + - "The VPN configuration could not be obtained\x02The current profile could" + - " not be found\x02Not a valid server type: %[1]v\x02Identifier: '%[1]s' f" + - "or server with type: '%[2]d' is not valid\x02The operation for getting a" + - " VPN configuration was canceled\x02Failed to set the server with identif" + - "ier: '%[1]s' as the current\x02Identifier: '%[1]s' for server with type:" + - " '%[2]d' is not valid for removal\x02Failed to get the current server to" + - " cleanup the connection\x02Failed to cleanup the VPN connection for the " + - "current server\x02Setting a secure internet location with Let's Connect!" + - " is not supported\x02No secure internet server available to set a locati" + - "on for\x02Failed to get current server for renewing the session\x02Failo" + - "ver failed to complete with gateway: '%[1]s' and mtu: '%[2]d'\x02Failed " + - "internal state transition requested by the client from: '%[1]s' to '%[2]" + - "s'\x02timeout reached\x02with cause:" + "ould not be found when getting it for expiry\x02The client tried to auto" + + "connect to the VPN server: %[1]s, but no secure internet location is fou" + + "nd. Please manually connect again\x02The secure internet location could " + + "not be set\x02The client tried to autoconnect to the VPN server: %[1]s, " + + "but you need to authorizate again. Please manually connect again\x02The " + + "authorization procedure failed to complete\x02The client tried to autoco" + + "nnect to the VPN server: %[1]s, but no valid profiles were found. Please" + + " manually connect again\x02No suitable profiles could be found\x02Profil" + + "e with ID: '%[1]s' could not be set\x02Profile with ID: '%[1]s' could no" + + "t be obtained from the server\x02The identifier that was passed to the l" + + "ibrary is incorrect\x02Could not retrieve institute access server with U" + + "RL: '%[1]s' from discovery\x02The institute access server with URL: '%[1" + + "]s' could not be added\x02The secure internet server with organisation I" + + "D: '%[1]s' could not be retrieved from discovery\x02The secure internet " + + "server with organisation ID: '%[1]s' could not be added\x02The custom se" + + "rver with URL: '%[1]s' could not be added\x02Server type: '%[1]v' is not" + + " valid to be added\x02The VPN configuration could not be obtained\x02The" + + " current profile could not be found\x02Not a valid server type: %[1]v" + + "\x02Identifier: '%[1]s' for server with type: '%[2]d' is not valid\x02Th" + + "e operation for getting a VPN configuration was canceled\x02Failed to se" + + "t the server with identifier: '%[1]s' as the current\x02Identifier: '%[1" + + "]s' for server with type: '%[2]d' is not valid for removal\x02Failed to " + + "get the current server to cleanup the connection\x02Failed to cleanup th" + + "e VPN connection for the current server\x02Setting a secure internet loc" + + "ation with Let's Connect! is not supported\x02No secure internet server " + + "available to set a location for\x02Failed to get current server for rene" + + "wing the session\x02Failover failed to complete with gateway: '%[1]s' an" + + "d mtu: '%[2]d'\x02Failed internal state transition requested by the clie" + + "nt from: '%[1]s' to '%[2]s'\x02timeout reached\x02with cause:" -var esIndex = []uint32{ // 38 elements +var esIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -179,12 +190,13 @@ var esIndex = []uint32{ // 38 elements 0x00000000, 0x00000000, 0x00000000, 0x00000000, // Entry 20 - 3F 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, -} // Size: 176 bytes + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, +} // Size: 188 bytes const esData string = "" -var frIndex = []uint32{ // 38 elements +var frIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -196,12 +208,13 @@ var frIndex = []uint32{ // 38 elements 0x00000000, 0x00000000, 0x00000000, 0x00000000, // Entry 20 - 3F 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, -} // Size: 176 bytes + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, +} // Size: 188 bytes const frData string = "" -var itIndex = []uint32{ // 38 elements +var itIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -213,12 +226,13 @@ var itIndex = []uint32{ // 38 elements 0x00000000, 0x00000000, 0x00000000, 0x00000000, // Entry 20 - 3F 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, -} // Size: 176 bytes + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, +} // Size: 188 bytes const itData string = "" -var nlIndex = []uint32{ // 38 elements +var nlIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -230,25 +244,27 @@ var nlIndex = []uint32{ // 38 elements 0x00000000, 0x00000000, 0x00000000, 0x00000000, // Entry 20 - 3F 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, -} // Size: 176 bytes + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, +} // Size: 188 bytes const nlData string = "" -var slIndex = []uint32{ // 38 elements +var slIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000021, 0x00000058, 0x0000008f, 0x000000cb, 0x000000eb, 0x00000125, 0x00000165, - 0x000001a5, 0x000001e1, 0x00000211, 0x00000232, - 0x0000025b, 0x0000028e, 0x000002ce, 0x000002ef, - 0x00000347, 0x00000391, 0x000003e9, 0x00000437, - 0x00000473, 0x000004a5, 0x000004c7, 0x000004ef, - 0x00000512, 0x00000544, 0x0000057d, 0x000005ab, - 0x000005ea, 0x0000062d, 0x00000666, 0x0000069c, + 0x000001a5, 0x000001e1, 0x000001e1, 0x00000211, + 0x00000211, 0x00000232, 0x00000232, 0x0000025b, + 0x0000028e, 0x000002ce, 0x000002ef, 0x00000347, + 0x00000391, 0x000003e9, 0x00000437, 0x00000473, + 0x000004a5, 0x000004c7, 0x000004ef, 0x00000512, + 0x00000544, 0x0000057d, 0x000005ab, 0x000005ea, // Entry 20 - 3F - 0x000006de, 0x00000720, 0x00000765, 0x000007b6, - 0x000007c6, 0x000007d0, -} // Size: 176 bytes + 0x0000062d, 0x00000666, 0x0000069c, 0x000006de, + 0x00000720, 0x00000765, 0x000007b6, 0x000007c6, + 0x000007d0, +} // Size: 188 bytes const slData string = "" + // Size: 2000 bytes "\x02Napaka prehoda notranjega stanja\x02Odjemalec se je registriral z na" + @@ -281,7 +297,7 @@ const slData string = "" + // Size: 2000 bytes "ni zaključil\x02Prehod notranjega stanja iz %[1]s v %[2]s, ki ga je zaht" + "eval odjemalec, ni uspel\x02čas je potekel\x02- razlog:" -var ukIndex = []uint32{ // 38 elements +var ukIndex = []uint32{ // 41 elements // Entry 0 - 1F 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -293,9 +309,10 @@ var ukIndex = []uint32{ // 38 elements 0x00000000, 0x00000000, 0x00000000, 0x00000000, // Entry 20 - 3F 0x00000000, 0x00000000, 0x00000000, 0x00000000, - 0x00000000, 0x00000000, -} // Size: 176 bytes + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, +} // Size: 188 bytes const ukData string = "" -// Total table size 5665 bytes (5KiB); checksum: 7F0E767B +// Total table size 6148 bytes (6KiB); checksum: 44229C2F diff --git a/cmd/cli/main.go b/cmd/cli/main.go index ca50799..826d523 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -147,7 +147,7 @@ func getConfig(state *client.Client, url string, srvType srvtypes.Type) (*srvtyp if err != nil { return nil, err } - return state.GetConfig(&ck, url, srvType, false) + return state.GetConfig(&ck, url, srvType, false, false) } // Get a config for a single server, Institute Access or Secure Internet. diff --git a/exports/exports.go b/exports/exports.go index 4a92f1a..9ca053b 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -312,6 +312,8 @@ func ServerList() (*C.char, *C.char) { // - In case of custom server: The base URL // - In case of institute access: The base URL // pTCP is if we prefer TCP or not to get the configuration, non-zero means yes +// startup is if the client is just starting up, set this to true (non-zero) if you autoconnect to a server on startup +// If this startup value is true (non-zero) then any authorization or other callacks (profile/location) are not triggered // If the server cannot be added it returns the error as types/error/error.go Error // Note that the server is removed when an error has occured // The current state callbacks MUST be handled @@ -349,7 +351,7 @@ func ServerList() (*C.char, *C.char) { // This is nil if an error is returned as types/error/error.go Error // //export GetConfig -func GetConfig(c C.uintptr_t, _type C.int, id *C.char, pTCP C.int) (*C.char, *C.char) { +func GetConfig(c C.uintptr_t, _type C.int, id *C.char, pTCP C.int, startup C.int) (*C.char, *C.char) { state, stateErr := getVPNState() if stateErr != nil { return nil, getCError(stateErr) @@ -359,7 +361,8 @@ func GetConfig(c C.uintptr_t, _type C.int, id *C.char, pTCP C.int) (*C.char, *C. return nil, getCError(err) } preferTCPBool := pTCP != 0 - cfg, err := state.GetConfig(ck, C.GoString(id), srvtypes.Type(_type), preferTCPBool) + startupBool := startup != 0 + cfg, err := state.GetConfig(ck, C.GoString(id), srvtypes.Type(_type), preferTCPBool, startupBool) if cfg != nil && err == nil { d, err := getReturnData(cfg) if err == nil { diff --git a/internal/server/server.go b/internal/server/server.go index 45d6ccd..c971c72 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -32,6 +32,15 @@ type Server interface { Public() (interface{}, error) } +// Name gets the name for the server and falls back to a default of "Unknown Server" +func Name(srv Server) string { + n := "Unknown Server" + if b, err := srv.Base(); err == nil { + n = b.URL + } + return n +} + func UpdateTokens(srv Server, t oauth.Token) { srv.OAuth().UpdateTokens(t) } diff --git a/wrappers/python/eduvpn_common/loader.py b/wrappers/python/eduvpn_common/loader.py index 75a6a0a..7da159c 100644 --- a/wrappers/python/eduvpn_common/loader.py +++ b/wrappers/python/eduvpn_common/loader.py @@ -74,6 +74,7 @@ def initialize_functions(lib: CDLL) -> None: c_int, c_char_p, c_int, + c_int, ], DataError lib.AddServer.argtypes, lib.AddServer.restype = [ c_int, diff --git a/wrappers/python/eduvpn_common/main.py b/wrappers/python/eduvpn_common/main.py index 335b78c..5ee0882 100644 --- a/wrappers/python/eduvpn_common/main.py +++ b/wrappers/python/eduvpn_common/main.py @@ -208,14 +208,18 @@ class EduVPN(object): return yes def get_config( - self, _type: ServerType, identifier: str, prefer_tcp: bool = False + self, + _type: ServerType, + identifier: str, + prefer_tcp: bool = False, + startup: bool = False, ) -> str: """Get an OpenVPN/WireGuard configuration from the server :param _type: ServerType: The type of server e.g. SERVER.INSTITUTE_ACCESS :param identifier: str: The identifier of the server, e.g. URL or ORG ID :param prefer_tcp: bool: (Default value = False): Whether or not to prefer TCP - :param tokens: str (Defualt value = ""): The OAuth tokens if available + :param startup: bool: (Default value = False): Whether or not the client is just starting up :meta private: @@ -232,6 +236,7 @@ class EduVPN(object): int(_type), identifier, prefer_tcp, + startup, ) if config_err: @@ -377,7 +382,9 @@ def state_callback(old_state: int, new_state: int, data: str) -> int: global global_object if global_object is None: return 0 - handled = global_object.event_handler.run(State(old_state), State(new_state), data.decode("utf-8")) + handled = global_object.event_handler.run( + State(old_state), State(new_state), data.decode("utf-8") + ) if handled: return 1 return 0 |
