summaryrefslogtreecommitdiff
path: root/wrappers/python
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-07-05 13:17:24 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-07-05 13:17:24 +0200
commit1865b016d0cca74cd3703db5a3b4217917988dec (patch)
tree3da84dbc4f1ad49221c25fb83f402d27deb34138 /wrappers/python
parente39b9a8a405fa8e5f73c32bb03a3f349f7f9f92d (diff)
Refactor: Handling of different servers and identifiers
- Uses OrgID for Secure Internet and gets the data from discovery - Uses URL for Institute/Custom and gets the data from discovery - Implements SKIP WAYF as we now have the needed data - Implements an initial change location with a default location (NL right now)
Diffstat (limited to 'wrappers/python')
-rw-r--r--wrappers/python/main.py4
-rw-r--r--wrappers/python/src/__init__.py11
-rw-r--r--wrappers/python/src/main.py15
-rw-r--r--wrappers/python/tests.py2
4 files changed, 24 insertions, 8 deletions
diff --git a/wrappers/python/main.py b/wrappers/python/main.py
index a94281a..5422d93 100644
--- a/wrappers/python/main.py
+++ b/wrappers/python/main.py
@@ -68,7 +68,7 @@ if __name__ == "__main__":
print("Failed registering:", e)
server = input(
- "Which Institute Access server do you want to connect to? (e.g. https://eduvpn.example.com): "
+ "Which server (Custom/Institute Access) do you want to connect to? (e.g. https://eduvpn.example.com): "
)
# Ensure we have a valid http prefix
@@ -78,7 +78,7 @@ if __name__ == "__main__":
# Get a Wireguard/OpenVPN config
try:
- config, config_type = _eduvpn.get_config_institute_access(server)
+ config, config_type = _eduvpn.get_config_custom_server(server)
except Exception as e:
print("Failed to connect:", e)
print(f"Got a config with type: {config_type} and contents:\n{config}")
diff --git a/wrappers/python/src/__init__.py b/wrappers/python/src/__init__.py
index 1ec0bec..f2ae66e 100644
--- a/wrappers/python/src/__init__.py
+++ b/wrappers/python/src/__init__.py
@@ -47,10 +47,19 @@ VPNStateChange = CFUNCTYPE(None, c_char_p, c_char_p, c_char_p, c_char_p)
# Exposed functions
# We have to use c_void_p instead of c_char_p to free it properly
# See https://stackoverflow.com/questions/13445568/python-ctypes-how-to-free-memory-getting-invalid-pointer-error
-lib.GetConnectConfig.argtypes, lib.GetConnectConfig.restype = [
+lib.GetConfigSecureInternet.argtypes, lib.GetConfigSecureInternet.restype = [
c_char_p,
c_char_p,
c_int,
+], MultipleDataError
+lib.GetConfigInstituteAccess.argtypes, lib.GetConfigInstituteAccess.restype = [
+ c_char_p,
+ c_char_p,
+ c_int,
+], MultipleDataError
+lib.GetConfigCustomServer.argtypes, lib.GetConfigCustomServer.restype = [
+ c_char_p,
+ c_char_p,
c_int,
], MultipleDataError
lib.Deregister.argtypes, lib.Deregister.restype = [c_char_p], c_void_p
diff --git a/wrappers/python/src/main.py b/wrappers/python/src/main.py
index 76a08ab..dda3250 100644
--- a/wrappers/python/src/main.py
+++ b/wrappers/python/src/main.py
@@ -1,4 +1,5 @@
from . import lib, VPNStateChange, encode_args, decode_res
+from enum import Enum
from typing import Optional, Tuple
import threading
from .event import StateType, EventHandler
@@ -90,14 +91,15 @@ class EduVPN(object):
return organizations
def get_config(
- self, url: str, is_secure_internet: bool = False, force_tcp: bool = False
+ self, url: str, func: callable, force_tcp: bool = False
):
# Because it could be the case that a profile callback is started, store a threading event
# In the constructor, we have defined a wait event for Ask_Profile, this waits for this event to be set
# The event is set in self.set_profile
self.profile_event = threading.Event()
+
config, config_type, config_err = self.go_function(
- lib.GetConnectConfig, url, is_secure_internet, force_tcp
+ func, url, force_tcp
)
if config_err:
@@ -107,15 +109,20 @@ class EduVPN(object):
return config, config_type
+ def get_config_custom_server(
+ self, url: str, force_tcp: bool = False
+ ) -> Tuple[str, str]:
+ return self.get_config(url, lib.GetConfigCustomServer, force_tcp)
+
def get_config_institute_access(
self, url: str, force_tcp: bool = False
) -> Tuple[str, str]:
- return self.get_config(url, False, force_tcp)
+ return self.get_config(url, lib.GetConfigInstituteAccess, force_tcp)
def get_config_secure_internet(
self, url: str, force_tcp: bool = False
) -> Tuple[str, str]:
- return self.get_config(url, True, force_tcp)
+ return self.get_config(url, lib.GetConfigSecureInternet, force_tcp)
def set_connected(self) -> None:
connect_err = self.go_function(lib.SetConnected)
diff --git a/wrappers/python/tests.py b/wrappers/python/tests.py
index 7f17ef6..e58e67d 100644
--- a/wrappers/python/tests.py
+++ b/wrappers/python/tests.py
@@ -29,7 +29,7 @@ class ConfigTests(unittest.TestCase):
self.fail("No SERVER_URI environment variable given")
# This can throw an exception
- _eduvpn.get_config_institute_access(server_uri)
+ _eduvpn.get_config_custom_server(server_uri)
# Deregister
_eduvpn.deregister()