summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exports/exports.go14
-rw-r--r--internal/test_data/generate_forged.py22
-rw-r--r--selenium_eduvpn.py1
-rw-r--r--wrappers/python/main.py5
-rwxr-xr-xwrappers/python/setup.py74
-rw-r--r--wrappers/python/src/main.py4
-rw-r--r--wrappers/python/tests.py7
7 files changed, 80 insertions, 47 deletions
diff --git a/exports/exports.go b/exports/exports.go
index 287a4b6..2139254 100644
--- a/exports/exports.go
+++ b/exports/exports.go
@@ -12,13 +12,15 @@ void call_callback(PythonCB callback, const char* oldstate, const char* newstate
}
*/
import "C"
-import "errors"
-import "fmt"
-import "unsafe"
-import "github.com/jwijenbergh/eduvpn-common"
-var P_StateCallback C.PythonCB
+import (
+ "errors"
+ "fmt"
+ "unsafe"
+ "github.com/jwijenbergh/eduvpn-common"
+)
+var P_StateCallback C.PythonCB
var VPNStates map[string]*eduvpn.VPNState
@@ -35,7 +37,6 @@ func StateCallback(old_state string, new_state string, data string) {
C.free(unsafe.Pointer(data_c))
}
-
func GetVPNState(name string) (*eduvpn.VPNState, error) {
state, exists := VPNStates[name]
@@ -127,7 +128,6 @@ func GetOrganizationsList(name *C.char) (*C.char, *C.char) {
return C.CString(organizations), C.CString(ErrorToString(organizationsErr))
}
-
//export GetServersList
func GetServersList(name *C.char) (*C.char, *C.char) {
nameStr := C.GoString(name)
diff --git a/internal/test_data/generate_forged.py b/internal/test_data/generate_forged.py
index 843b32d..9d42adc 100644
--- a/internal/test_data/generate_forged.py
+++ b/internal/test_data/generate_forged.py
@@ -6,32 +6,36 @@ import base64
# Hash server_list.json
with open("server_list.json", "rb") as f:
- b = f.read()
+ b = f.read()
with open("server_list.json.blake2b", "wb") as f:
- f.write(hashlib.blake2b(b).digest())
+ f.write(hashlib.blake2b(b).digest())
# Forge pure signature on hash, see https://github.com/jedisct1/minisign/issues/104
with open("server_list.json.minisig", "rb") as f:
- siglines = f.readlines()
+ siglines = f.readlines()
siglines[0] = b"untrusted comment: this signature has ED changed to Ed\n"
sig = base64.b64decode(siglines[1])
siglines[1] = base64.b64encode(b"Ed" + sig[2:]) + b"\n"
with open("server_list.json.forged_pure.minisig", "wb") as f:
- f.writelines(siglines)
- # Should now work: minisign -Vm server_list.json.blake2b -x server_list.json.forged_pure.minisig -p public-key
+ f.writelines(siglines)
+ # Should now work: minisign -Vm server_list.json.blake2b -x server_list.json.forged_pure.minisig -p public-key
# Try to forge key ID
with open("server_list.json.wrong_key.minisig", "rb") as f:
- siglines = f.readlines()
+ siglines = f.readlines()
-siglines[0] = b"untrusted comment: this signature was created with wrong_secret.key but has key ID changed to that of public.key\n"
+siglines[
+ 0
+] = b"untrusted comment: this signature was created with wrong_secret.key but has key ID changed to that of public.key\n"
sig_wrong = base64.b64decode(siglines[1])
-siglines[1] = base64.b64encode(sig_wrong[:2] + sig[2:2+8] + sig_wrong[2+8:]) + b"\n"
+siglines[1] = (
+ base64.b64encode(sig_wrong[:2] + sig[2 : 2 + 8] + sig_wrong[2 + 8 :]) + b"\n"
+)
with open("server_list.json.forged_keyid.minisig", "wb") as f:
- f.writelines(siglines)
+ f.writelines(siglines)
diff --git a/selenium_eduvpn.py b/selenium_eduvpn.py
index 76e86aa..b1c8cfe 100644
--- a/selenium_eduvpn.py
+++ b/selenium_eduvpn.py
@@ -17,6 +17,7 @@ def login_eduvpn(authURL):
# Cleanup
driver.close()
+
# Logs in to the default vpn user portal with selenium
def login_oauth(driver, authURL):
# Go to the oauth url and verify the title
diff --git a/wrappers/python/main.py b/wrappers/python/main.py
index c887fed..a94281a 100644
--- a/wrappers/python/main.py
+++ b/wrappers/python/main.py
@@ -21,6 +21,7 @@ def ask_profile_input(total: int) -> int:
# The profile is one based, move to zero based input
return profile_index - 1
+
# Sets up the callbacks using the provided class
def setup_callbacks(_eduvpn: eduvpn.EduVPN) -> None:
# The callback that starst OAuth
@@ -33,7 +34,9 @@ def setup_callbacks(_eduvpn: eduvpn.EduVPN) -> None:
# The callback which asks the user for a profile
@_eduvpn.event.on("Ask_Profile", eduvpn.StateType.Enter)
def ask_profile(old_state: str, profiles: str):
- print("Multiple profiles found, you need to select a profile, old state: {old_state}")
+ print(
+ "Multiple profiles found, you need to select a profile, old state: {old_state}"
+ )
# Parse the profiles as JSON
data = json.loads(profiles)
diff --git a/wrappers/python/setup.py b/wrappers/python/setup.py
index 533ba82..2b682cd 100755
--- a/wrappers/python/setup.py
+++ b/wrappers/python/setup.py
@@ -15,47 +15,65 @@ _libname = "eduvpn_common"
def getlibpath(plat_name: str) -> typing.Union[str, None]:
"""Get library path for plat_name relative to exports/lib/ folder."""
- _plat_map = defaultdict(lambda: plat_name, {
- "win32": "win-x86",
- })
+ _plat_map = defaultdict(
+ lambda: plat_name,
+ {
+ "win32": "win-x86",
+ },
+ )
plat_split = _plat_map[plat_name].split("-", 1)
if len(plat_split) != 2:
return None
plat_os, plat_arch = plat_split
- _os_map = defaultdict(lambda: plat_os, {
- "win": "windows",
- })
- _lib_prefixes = defaultdict(lambda: "lib", {
- "windows": "",
- })
- _lib_suffixes = defaultdict(lambda: ".so", {
- "windows": ".dll",
- "darwin": ".dylib",
- })
- _arch_map = defaultdict(lambda: plat_arch, {
- "aarch64_be": "arm64",
- "aarch64": "arm64",
- "armv8b": "arm64",
- "armv8l": "arm64",
- "x86": "386",
- "x86pc": "386",
- "i86pc": "386",
- "i386": "386",
- "i686": "386",
- "x86_64": "amd64",
- "i686-64": "amd64",
- })
+ _os_map = defaultdict(
+ lambda: plat_os,
+ {
+ "win": "windows",
+ },
+ )
+ _lib_prefixes = defaultdict(
+ lambda: "lib",
+ {
+ "windows": "",
+ },
+ )
+ _lib_suffixes = defaultdict(
+ lambda: ".so",
+ {
+ "windows": ".dll",
+ "darwin": ".dylib",
+ },
+ )
+ _arch_map = defaultdict(
+ lambda: plat_arch,
+ {
+ "aarch64_be": "arm64",
+ "aarch64": "arm64",
+ "armv8b": "arm64",
+ "armv8l": "arm64",
+ "x86": "386",
+ "x86pc": "386",
+ "i86pc": "386",
+ "i386": "386",
+ "i686": "386",
+ "x86_64": "amd64",
+ "i686-64": "amd64",
+ },
+ )
processed_os = _os_map[plat_os]
- return f"{processed_os}/{_arch_map[plat_arch]}/" \
- f"{_lib_prefixes[processed_os]}{_libname}{_lib_suffixes[processed_os]}"
+ return (
+ f"{processed_os}/{_arch_map[plat_arch]}/"
+ f"{_lib_prefixes[processed_os]}{_libname}{_lib_suffixes[processed_os]}"
+ )
# Adapted from https://stackoverflow.com/a/51794740
# You would say there would be a better way to do all of this, but I couldn't find it
+
class bdist_wheel(_bdist_wheel):
user_options = _bdist_wheel.user_options + [
("exports-lib-path=", None, "path to exports/lib directory"),
diff --git a/wrappers/python/src/main.py b/wrappers/python/src/main.py
index dd8f36a..47e2893 100644
--- a/wrappers/python/src/main.py
+++ b/wrappers/python/src/main.py
@@ -22,7 +22,9 @@ class EventHandler(object):
return wrapped_f
- def run_state(self, state: str, other_state: str, state_type: StateType, data: str) -> None:
+ def run_state(
+ self, state: str, other_state: str, state_type: StateType, data: str
+ ) -> None:
if (state, state_type) not in self.handlers:
return
for func in self.handlers[(state, state_type)]:
diff --git a/wrappers/python/tests.py b/wrappers/python/tests.py
index 60ed79e..7f17ef6 100644
--- a/wrappers/python/tests.py
+++ b/wrappers/python/tests.py
@@ -7,15 +7,19 @@ import sys
import os
# Import project root directory where the selenium python utility is
-sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+sys.path.append(
+ os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+)
from selenium_eduvpn import login_eduvpn
+
class ConfigTests(unittest.TestCase):
def testConfig(self):
_eduvpn = eduvpn.EduVPN("org.eduvpn.app.linux", "testconfigs")
# This can throw an exception
_eduvpn.register()
+
@_eduvpn.event.on("OAuth_Started", eduvpn.StateType.Enter)
def oauth_initialized(old_state, url):
login_eduvpn(url)
@@ -41,5 +45,6 @@ class ConfigTests(unittest.TestCase):
return
self.fail("No exception thrown on second register")
+
if __name__ == "__main__":
unittest.main()