diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-11-28 14:29:12 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-11-28 14:29:12 +0100 |
| commit | 0bfb35520d7e138e6219e550187e0b55bc8a29ac (patch) | |
| tree | a087049edae0ff932bc7a14fef323783b26a2ff1 | |
| parent | 59e6ccd051452162fab852a25deb4f0f8a9e22b2 (diff) | |
Formatting: Run gofumpt -w
| -rw-r--r-- | client/client.go | 10 | ||||
| -rw-r--r-- | client/client_test.go | 3 | ||||
| -rw-r--r-- | client/fsm.go | 2 | ||||
| -rw-r--r-- | client/server.go | 8 | ||||
| -rw-r--r-- | cmd/cli/main.go | 2 | ||||
| -rw-r--r-- | exports/servers.go | 12 | ||||
| -rw-r--r-- | internal/config/config.go | 2 | ||||
| -rw-r--r-- | internal/discovery/discovery.go | 5 | ||||
| -rw-r--r-- | internal/fsm/fsm.go | 15 | ||||
| -rw-r--r-- | internal/log/log.go | 2 | ||||
| -rw-r--r-- | internal/oauth/oauth.go | 33 | ||||
| -rw-r--r-- | internal/oauth/token.go | 13 | ||||
| -rw-r--r-- | internal/server/common.go | 12 | ||||
| -rw-r--r-- | internal/server/secureinternet.go | 2 |
14 files changed, 60 insertions, 61 deletions
diff --git a/client/client.go b/client/client.go index fda6f6a..d6b04a3 100644 --- a/client/client.go +++ b/client/client.go @@ -65,10 +65,11 @@ type Client struct { } // Register initializes the clientwith the following parameters: -// - name: the name of the client -// - directory: the directory where the config files are stored. Absolute or relative -// - stateCallback: the callback function for the FSM that takes two states (old and new) and the data as an interface -// - debug: whether or not we want to enable debugging +// - name: the name of the client +// - directory: the directory where the config files are stored. Absolute or relative +// - stateCallback: the callback function for the FSM that takes two states (old and new) and the data as an interface +// - debug: whether or not we want to enable debugging +// // It returns an error if initialization failed, for example when discovery cannot be obtained and when there are no servers. func (client *Client) Register( name string, @@ -221,4 +222,3 @@ type LetsConnectNotSupportedError struct{} func (e LetsConnectNotSupportedError) Error() string { return "Any operation that involves discovery is not allowed with the Let's Connect! client" } - diff --git a/client/client_test.go b/client/client_test.go index fe2dec5..1b9a488 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -172,10 +172,9 @@ func TestConnectOAuthParameters(t *testing.T) { var ( failedCallbackParameterError *oauth.CallbackParameterError failedCallbackStateMatchError *oauth.CallbackStateMatchError - failedCallbackISSMatchError *oauth.CallbackISSMatchError + failedCallbackISSMatchError *oauth.CallbackISSMatchError ) - serverURI := getServerURI(t) // serverURI already ends with a / due to using the util EnsureValidURL function iss := serverURI diff --git a/client/fsm.go b/client/fsm.go index 88d71f2..79d0f62 100644 --- a/client/fsm.go +++ b/client/fsm.go @@ -244,7 +244,6 @@ func (e FSMWrongStateError) CustomError() *types.WrappedErrorMessage { ) } - // SetSearchServer sets the FSM to the SEARCH_SERVER state. // This indicates that the user wants to search for a new server. // Returns an error if this state transition is not possible. @@ -437,7 +436,6 @@ func (client *Client) CancelOAuth() error { return nil } - // InFSMState is a helper to check if the FSM is in state `checkState`. func (client *Client) InFSMState(checkState FSMStateID) bool { return client.FSM.InState(checkState) diff --git a/client/server.go b/client/server.go index a32b7df..01f965a 100644 --- a/client/server.go +++ b/client/server.go @@ -4,10 +4,10 @@ import ( "errors" "fmt" - "github.com/eduvpn/eduvpn-common/types" "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/eduvpn/eduvpn-common/internal/server" "github.com/eduvpn/eduvpn-common/internal/util" + "github.com/eduvpn/eduvpn-common/types" ) // getConfigAuth gets a config with authorization and authentication. @@ -298,7 +298,7 @@ func (client *Client) AddSecureInternetHomeServer(orgID string) (server.Server, currentErr := client.Servers.SetSecureInternet(server) if currentErr != nil { client.goBackInternal() - return nil, client.handleError(errorMessage, currentErr) + return nil, client.handleError(errorMessage, currentErr) } // Server has been chosen for authentication @@ -526,7 +526,6 @@ func (client *Client) ChangeSecureLocation() error { return nil } - // RenewSession renews the session for the current VPN server. // This logs the user back in. func (client *Client) RenewSession() error { @@ -539,7 +538,7 @@ func (client *Client) RenewSession() error { // The server has not been chosen yet, this means that we want to manually renew if client.FSM.InState(StateNoServer) { - client.FSM.GoTransition(StateChosenServer) + client.FSM.GoTransition(StateChosenServer) } server.MarkTokensForRenew(currentServer) @@ -623,4 +622,3 @@ func (client *Client) SetProfileID(profileID string) error { base.Profiles.Current = profileID return nil } - diff --git a/cmd/cli/main.go b/cmd/cli/main.go index 878bac9..b1bcaa9 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -7,8 +7,8 @@ import ( "strings" "github.com/eduvpn/eduvpn-common/client" - "github.com/eduvpn/eduvpn-common/types" "github.com/eduvpn/eduvpn-common/internal/server" + "github.com/eduvpn/eduvpn-common/types" ) type ServerTypes int8 diff --git a/exports/servers.go b/exports/servers.go index a1acbee..959475e 100644 --- a/exports/servers.go +++ b/exports/servers.go @@ -102,6 +102,7 @@ func getCPtrProfiles(serverProfiles *server.ProfileInfo) *C.serverProfiles { // Free the profiles by looping through them if there are any // Also free the pointer itself +// //export FreeProfiles func FreeProfiles(profiles *C.serverProfiles) { // We should only free the profiles if we have them (which we should) @@ -203,6 +204,7 @@ func getCPtrServer(state *client.Client, base *client.ServerBase) *C.server { // Function for freeing a single server // Gets the pointer to C struct +// //export FreeServer func FreeServer(info *C.server) { // Free strings @@ -241,9 +243,10 @@ func getCPtrServers( return C.size_t(0), nil } -//export FreeServers // This function takes the servers as a C struct pointer as input // It frees all allocated memory for the server +// +//export FreeServers func FreeServers(cServers *C.servers) { // Free the custom servers if there are any if cServers.total_custom > 0 { @@ -301,9 +304,10 @@ func getSavedServersWithOptions(state *client.Client, servers *server.Servers) * return returnedStruct } -//export GetSavedServers // This function takes the name as input which is the name of the client // It gets the state by name and then returns the saved servers as a c struct belonging to it +// +//export GetSavedServers func GetSavedServers(name *C.char) (*C.servers, *C.error) { nameStr := C.GoString(name) state, stateErr := GetVPNState(nameStr) @@ -314,10 +318,10 @@ func GetSavedServers(name *C.char) (*C.servers, *C.error) { return servers, nil } - -//export GetCurrentServer // This function takes the name as input which is the name of the client // It gets the state by name and then returns the current server as a c struct belonging to it +// +//export GetCurrentServer func GetCurrentServer(name *C.char) (*C.server, *C.error) { nameStr := C.GoString(name) state, stateErr := GetVPNState(nameStr) diff --git a/internal/config/config.go b/internal/config/config.go index bea97f7..96ce742 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -18,7 +18,7 @@ type Config struct { Directory string // Name defines the name of file excluding the .json extension - Name string + Name string } // Init initializes the configuration using the provided directory and name. diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index 40fa165..35c2689 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -11,14 +11,13 @@ import ( "github.com/eduvpn/eduvpn-common/types" ) - // Discovery is the main structure used for this package. type Discovery struct { // organizations represents the organizations that are returned by the discovery server organizations types.DiscoveryOrganizations // servers represents the servers that are returned by the discovery server - servers types.DiscoveryServers + servers types.DiscoveryServers } // discoFile is a helper function that gets a disco JSON and fills the structure with it @@ -79,7 +78,7 @@ func (discovery *Discovery) DetermineOrganizationsUpdate() bool { return discovery.organizations.Timestamp.IsZero() } -// SecureLocationList returns a slice of all the available locations. +// SecureLocationList returns a slice of all the available locations. func (discovery *Discovery) SecureLocationList() []string { var locations []string for _, currentServer := range discovery.servers.List { diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go index 4114a32..0163fed 100644 --- a/internal/fsm/fsm.go +++ b/internal/fsm/fsm.go @@ -8,12 +8,13 @@ import ( "os/exec" "path" "sort" + "github.com/eduvpn/eduvpn-common/types" ) type ( // StateID represents the Identifier of the state. - StateID int8 + StateID int8 // StateIDSlice represents the list of state identifiers. StateIDSlice []StateID ) @@ -33,7 +34,7 @@ func (v StateIDSlice) Swap(i, j int) { // Transition indicates an arrow in the state graph. type Transition struct { // To represents the to-be-new state - To StateID + To StateID // Description is what type of message the arrow gets in the graph Description string } @@ -51,26 +52,26 @@ type State struct { // FSM represents the total graph. type FSM struct { // States is the map from state ID to states - States States + States States // Current is the current state represented by the identifier Current StateID // Name represents the descriptive name of this state machine - Name string + Name string // StateCallback is the function ran when a transition occurs // It takes the old state, the new state and the data and returns if this is handled by the client StateCallback func(StateID, StateID, interface{}) bool // Directory represents the path where the state graph is stored - Directory string + Directory string // Generate represents whether we want to generate the graph - Generate bool + Generate bool // GetStateName gets the name of a state as a string - GetStateName func(StateID) string + GetStateName func(StateID) string } // Init initializes the state machine and sets it to the given current state. diff --git a/internal/log/log.go b/internal/log/log.go index 43bc737..67e41fa 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -19,7 +19,7 @@ type FileLogger struct { Level Level // file represents a pointer to the open log file - file *os.File + file *os.File } type Level int8 diff --git a/internal/oauth/oauth.go b/internal/oauth/oauth.go index 3c1e5d6..6abdb7f 100644 --- a/internal/oauth/oauth.go +++ b/internal/oauth/oauth.go @@ -57,11 +57,13 @@ func genChallengeS256(verifier string) string { // minimum length of 43 characters and a maximum length of 128 // characters. // We implement it according to the note: -// NOTE: The code verifier SHOULD have enough entropy to make it -// impractical to guess the value. It is RECOMMENDED that the output of -// a suitable random number generator be used to create a 32-octet -// sequence. The octet sequence is then base64url-encoded to produce a -// 43-octet URL safe string to use as the code verifier. +// +// NOTE: The code verifier SHOULD have enough entropy to make it +// impractical to guess the value. It is RECOMMENDED that the output of +// a suitable random number generator be used to create a 32-octet +// sequence. The octet sequence is then base64url-encoded to produce a +// 43-octet URL safe string to use as the code verifier. +// // See: https://datatracker.ietf.org/doc/html/rfc7636#section-4.1 func genVerifier() (string, error) { randomBytes, err := util.MakeRandomByteSlice(32) @@ -78,19 +80,19 @@ func genVerifier() (string, error) { // OAuth defines the main structure for this package. type OAuth struct { // ISS indicates the issuer indentifier of the authorization server as defined in RFC 9207 - ISS string `json:"iss"` + ISS string `json:"iss"` // BaseAuthorizationURL is the URL where authorization should take place - BaseAuthorizationURL string `json:"base_authorization_url"` + BaseAuthorizationURL string `json:"base_authorization_url"` // TokenURL is the URL where tokens should be obtained - TokenURL string `json:"token_url"` + TokenURL string `json:"token_url"` // session is the internal in progress OAuth session - session ExchangeSession `json:"-"` + session ExchangeSession `json:"-"` // Token is where the access and refresh tokens are stored along with the timestamps - token Token `json:"-"` + token Token `json:"-"` } // ExchangeSession is a structure that gets passed to the callback for easy access to the current state. @@ -102,19 +104,19 @@ type ExchangeSession struct { ClientID string // ISS indicates the issuer inditifer - ISS string + ISS string // State is the expected URL state paremeter - State string + State string // Verifier is the preimage of the challenge Verifier string // Context is the context used for cancellation - Context context.Context + Context context.Context // Server is the server of the session - Server *http.Server + Server *http.Server // Listener is the listener where the servers 'listens' on Listener net.Listener @@ -332,7 +334,7 @@ main { // oauthResponseHTML is a structure that is used to give back the OAuth response. type oauthResponseHTML struct { - Title string + Title string Message string } @@ -385,7 +387,6 @@ func (oauth *OAuth) Callback(w http.ResponseWriter, req *http.Request) { ) return } - } // Make sure the state is present and matches to protect against cross-site request forgeries diff --git a/internal/oauth/token.go b/internal/oauth/token.go index eb79357..bd17647 100644 --- a/internal/oauth/token.go +++ b/internal/oauth/token.go @@ -5,26 +5,25 @@ import "time" // TokenResponse defines the OAuth response from the server that includes the tokens. type TokenResponse struct { // Access is the access token returned by the server - Access string `json:"access_token"` + Access string `json:"access_token"` // Refresh token is the refresh token returned by the server - Refresh string `json:"refresh_token"` + Refresh string `json:"refresh_token"` // Type indicates which type of tokens we have - Type string `json:"token_type"` + Type string `json:"token_type"` // Expires is the expires time returned by the server - Expires int64 `json:"expires_in"` - + Expires int64 `json:"expires_in"` } // Token is a structure that contains our access and refresh tokens and a timestamp when they expire. type Token struct { // Access is the access token returned by the server - access string + access string // Refresh token is the refresh token returned by the server - refresh string + refresh string // ExpiredTimestamp is the Expires field but converted to a Go timestamp expiredTimestamp time.Time diff --git a/internal/server/common.go b/internal/server/common.go index e8c8e51..e8eedd0 100644 --- a/internal/server/common.go +++ b/internal/server/common.go @@ -15,8 +15,8 @@ type Base struct { URL string `json:"base_url"` DisplayName map[string]string `json:"display_name"` SupportContact []string `json:"support_contact"` - Endpoints Endpoints `json:"endpoints"` - Profiles ProfileInfo `json:"profiles"` + Endpoints Endpoints `json:"endpoints"` + Profiles ProfileInfo `json:"profiles"` StartTime time.Time `json:"start_time"` EndTime time.Time `json:"expire_time"` Type string `json:"server_type"` @@ -35,7 +35,7 @@ type Servers struct { CustomServers InstituteAccessServers `json:"custom_servers"` InstituteServers InstituteAccessServers `json:"institute_servers"` SecureInternetHomeServer SecureInternetHomeServer `json:"secure_internet_home"` - IsType Type `json:"is_secure_internet"` + IsType Type `json:"is_secure_internet"` } type Server interface { @@ -60,7 +60,7 @@ type ProfileListInfo struct { } type ProfileInfo struct { - Current string `json:"current_profile"` + Current string `json:"current_profile"` Info ProfileListInfo `json:"info"` } @@ -503,10 +503,10 @@ func Config(server Server, clientSupportsWireguard bool, preferTCP bool) (string // A wireguard connect call needs to generate a wireguard key and add it to the config // Also the server could send back an OpenVPN config if it supports OpenVPN config, configType, configErr = wireguardGetConfig(server, preferTCP, supportsOpenVPN) - // The config only supports OpenVPN + // The config only supports OpenVPN } else if supportsOpenVPN { config, configType, configErr = openVPNGetConfig(server, preferTCP) - // The config supports no available protocol because the profile only supports WireGuard but the client doesn't + // The config supports no available protocol because the profile only supports WireGuard but the client doesn't } else { return "", "", types.NewWrappedError(errorMessage, errors.New("no supported protocol found")) } diff --git a/internal/server/secureinternet.go b/internal/server/secureinternet.go index fa4c9c9..998390d 100644 --- a/internal/server/secureinternet.go +++ b/internal/server/secureinternet.go @@ -12,7 +12,7 @@ import ( // A secure internet server which has its own OAuth tokens // It specifies the current location url it is connected to. type SecureInternetHomeServer struct { - Auth oauth.OAuth `json:"oauth"` + Auth oauth.OAuth `json:"oauth"` DisplayName map[string]string `json:"display_name"` // The home server has a list of info for each configured server location |
