diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-09-08 02:23:18 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-09-08 19:58:25 +0200 |
commit | e591c3147e3c504611ff612e8918018125ffa2eb (patch) | |
tree | d4004f33ddc2c7f9f70d95d0244b93ac27b9eb76 | |
parent | c2871f4aece61b939e0e6c8d7a94677fb055620a (diff) |
[bug] pass json as bytes to go side
-rw-r--r-- | branding/scripts/gen-providers-json.py | 3 | ||||
-rw-r--r-- | gui/backend.go | 8 | ||||
-rw-r--r-- | gui/handlers.cpp | 4 | ||||
-rw-r--r-- | gui/main.cpp | 8 | ||||
-rw-r--r-- | gui/providers/providers.json | 24 | ||||
-rw-r--r-- | pkg/backend/api.go | 27 |
6 files changed, 62 insertions, 12 deletions
diff --git a/branding/scripts/gen-providers-json.py b/branding/scripts/gen-providers-json.py index b57965b..8e1c10b 100644 --- a/branding/scripts/gen-providers-json.py +++ b/branding/scripts/gen-providers-json.py @@ -23,10 +23,11 @@ def generateProvidersJSON(configPath, outputJSONPath): providers = {} defaultProvider = getDefaultProvider(config) providers['default'] = defaultProvider + providers['providers'] = [] providerData = getProviderData(defaultProvider, config) addCaData(providerData, configPath) - providers[defaultProvider] = providerData + providers['providers'].append(providerData) with open(outputJSONPath, 'w', encoding='utf-8') as f: json.dump(providers, f, ensure_ascii=False, indent=4) diff --git a/gui/backend.go b/gui/backend.go index 5fa6134..a1dafe8 100644 --- a/gui/backend.go +++ b/gui/backend.go @@ -7,6 +7,7 @@ package main import ( "C" + "log" "unsafe" "0xacab.org/leap/bitmask-vpn/pkg/backend" @@ -53,8 +54,11 @@ func SubscribeToEvent(event string, f unsafe.Pointer) { } //export InitializeBitmaskContext -func InitializeBitmaskContext() { - opts := &backend.InitOpts{} +func InitializeBitmaskContext(provider string, jsonPtr unsafe.Pointer, jsonLen C.int) { + log.Println("DEBUG: provider=", provider) + json := C.GoBytes(jsonPtr, jsonLen) + log.Println("DEBUG: json=", string(json)) + opts := backend.InitOptsFromJSON(provider, string(json)) backend.InitializeBitmaskContext(opts) } diff --git a/gui/handlers.cpp b/gui/handlers.cpp index 71e5d38..4910aa2 100644 --- a/gui/handlers.cpp +++ b/gui/handlers.cpp @@ -8,7 +8,9 @@ GoString toGoStr(QString s) { - char *c = s.toLocal8Bit().data(); + // TODO verify that it's more correct + // char *c = s.toLocal8Bit().data(); + const char *c = s.toUtf8().constData(); return (GoString){c, (long int)strlen(c)}; } diff --git a/gui/main.cpp b/gui/main.cpp index 8c7de4f..4ba9dd6 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -145,8 +145,14 @@ int main(int argc, char **argv) { GoString statusChangedEvt = {stCh, (long int)strlen(stCh)}; SubscribeToEvent(statusChangedEvt, (void *)onStatusChanged); + QJsonValue defaultProvider = providers->json().object().value("default"); + /* we send json as bytes because it breaks as a simple string */ + QString QProvidersJSON(providers->json().toJson(QJsonDocument::Compact)); + /* let the Go side initialize its internal state */ - InitializeBitmaskContext(); + InitializeBitmaskContext( + toGoStr(defaultProvider.toString()), + (char*)QProvidersJSON.toUtf8().data(), strlen(QProvidersJSON.toUtf8().data())); /* if requested, enable web api for controlling the VPN */ if (webAPI) { diff --git a/gui/providers/providers.json b/gui/providers/providers.json index 7ba0ef9..f0132f5 100644 --- a/gui/providers/providers.json +++ b/gui/providers/providers.json @@ -1,4 +1,20 @@ -[ - {"name": "provider1", "url": "https://example.com"}, - {"name": "provider2", "url": "https://foobar.com"} -] +{ + "default": "demolib", + "providers": [ + { + "name": "demolib", + "applicationName": "DemoLib", + "binaryName": "demo-lib", + "auth": "sip", + "providerURL": "vpnlib.bitmask.net", + "tosURL": "https://libraryvpn.org/", + "helpURL": "https://libraryvpn.org/", + "askForDonations": "false", + "donateURL": "", + "apiURL": "https://api.vpnlib.bitmask.net:4430/", + "geolocationAPI": "https://getmyip.vpnlib.bitmask.net/json", + "caCertString": "-----BEGIN CERTIFICATE-----\nMIIBQzCB6aADAgECAgEBMAoGCCqGSM49BAMCMBcxFTATBgNVBAMTDExFQVAgUm9v\ndCBDQTAeFw0yMDA4MDYxOTA3NDRaFw0yNTA4MDYxOTEyNDRaMBcxFTATBgNVBAMT\nDExFQVAgUm9vdCBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABIG5POr4cAdK\nkTavKpSJr8nW1V7HLpr27qKaShpk1TUy5ipaAlusmavGLxKsPE+i3AMlvf/f6ch3\n1MjAtIf5rYujJjAkMA4GA1UdDwEB/wQEAwICpDASBgNVHRMBAf8ECDAGAQH/AgEB\nMAoGCCqGSM49BAMCA0kAMEYCIQDXj280LNZbSbi0Y2WvtQrJBUw4wdm8qAeOeuH7\n6XiLEwIhAPBRsmst/ujcChsG2t6LpG+p8s4rfIfh8YLo/4qrcc5p\n-----END CERTIFICATE-----", + "timeStamp": "2020-09-08 01:01:08" + } + ] +}
\ No newline at end of file diff --git a/pkg/backend/api.go b/pkg/backend/api.go index 125f7f5..59b386b 100644 --- a/pkg/backend/api.go +++ b/pkg/backend/api.go @@ -4,6 +4,7 @@ package backend import ( "C" + "encoding/json" "log" "strconv" "unsafe" @@ -61,10 +62,30 @@ func SubscribeToEvent(event string, f unsafe.Pointer) { subscribe(event, f) } +type Providers struct { + Default string `json:"default"` + Data []InitOpts +} + type InitOpts struct { - Provider string - AppName string - SkipLaunch bool + Provider string `json:"name"` + AppName string `json:"applicationName"` + BinaryName string `json:"binaryName"` + Auth string `json:"auth"` + ProviderURL string `json:"providerURL"` + TosURL string `json:"tosURL"` + HelpURL string `json:"helpURL"` + AskForDonations bool `json:"askForDonations"` + SkipLaunch bool +} + +func InitOptsFromJSON(provider, providersJSON string) *InitOpts { + opts := InitOpts{} + err := json.Unmarshal([]byte(providersJSON), &opts) + if err != nil { + log.Println("ERROR: %v", err) + } + return &opts } func InitializeBitmaskContext(opts *InitOpts) { |