summaryrefslogtreecommitdiff
path: root/exports/exports.go
blob: e6be4881f97f44935a2f9fb4a08fc576c2405bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main

/*
#include <stdlib.h>
*/
import "C"
import "unsafe"

import "github.com/jwijenbergh/eduvpn-common/src"

// Functions here should probably not take string parameters, see https://pkg.go.dev/cmd/cgo#hdr-C_references_to_Go
// GetOrganizationsList gets the list of organizations from the disco server.
// Returns the json data as a string and an error code. This is used as key for looking up data.
//export GetOrganizationsList
func GetOrganizationsList() (*C.char, *C.char) {
	body, err := eduvpn.GetOrganizationsList()
	if err != nil {
		return nil, C.CString(err.Error())
	}
	return C.CString(body), nil
}

//export Register
func Register(name *C.char, url *C.char) {
	eduvpn.Register(eduvpn.GetVPNState(), C.GoString(name), C.GoString(url))
}

//export InitializeOAuth
func InitializeOAuth() (*C.char, *C.char) {
	url, err := eduvpn.InitializeOAuth(eduvpn.GetVPNState())
	if err != nil {
		return nil, C.CString(err.Error())
	}
	return C.CString(url), nil
}

// GetServersList gets the list of servers from the disco server.
// Returns the json data as a string and an error code. This is used as key for looking up data.
//export GetServersList
func GetServersList() (*C.char, *C.char) {
	body, err := eduvpn.GetServersList()
	if err != nil {
		return nil, C.CString(err.Error())
	}
	return C.CString(body), nil
}

//export FreeString
func FreeString(addr *C.char) {
	C.free(unsafe.Pointer(addr))
}

// Verify verifies a signature on a JSON file. See eduvpn.Verify for more details.
// It returns 0 for a valid signature and a nonzero eduvpn.VerifyErrorCode otherwise.
// signatureFileContent must be UTF-8-encoded.
//export Verify
func Verify(signatureFileContent []byte, signedJson []byte, expectedFileName []byte, minSignTime uint64) (int8, *C.char) {
	valid, err := eduvpn.Verify(string(signatureFileContent), signedJson, string(expectedFileName), minSignTime, false)
	if valid {
		return 0, nil
	} else {
		return 1, C.CString(err.Error())
	}
}

// InsecureTestingSetExtraKey adds an extra allowed key for verification with Verify.
// ONLY USE FOR TESTING. Not Thread-safe. Do not call in parallel to Verify.
// keyString must be an ASCII Base64-encoded key.
//export InsecureTestingSetExtraKey
func InsecureTestingSetExtraKey(keyString []byte) {
	eduvpn.InsecureTestingSetExtraKey(string(keyString))
}

// Not used in library, but needed to compile.
func main() { panic("compile with -buildmode=c-shared") }