Skip to content
Snippets Groups Projects
Unverified Commit 70922083 authored by Kali Kaneko's avatar Kali Kaneko
Browse files

[debug] improve error handling for geolocation

parent b9cae0b7
No related branches found
No related tags found
No related merge requests found
[default]
provider = demolib
provider = riseup
[riseup]
......@@ -79,7 +79,7 @@ infoURL = https://libraryvpn.org/
tosURL = https://libraryvpn.org/
helpURL = https://libraryvpn.org/
geolocationAPI = https://getmyip.vpnlib.bitmask.net/
geolocationAPI = https://getmyip.vpnlib.bitmask.net/json
askForDonations = false
donateURL =
// Code generated by go generate; DO NOT EDIT.
// This file was generated by vendorize.py
// At 2020-08-15 20:39:01
// At 2020-08-19 17:38:43
package config
/* All these constants are defined in the vendor.conf file
*/
const (
Provider = "vpnlib.bitmask.net"
ApplicationName = "DemoLib"
BinaryName = "demo-lib"
Auth = "sip"
DonateURL = ""
AskForDonations = "false"
HelpURL = "https://libraryvpn.org/"
TosURL = "https://libraryvpn.org/"
APIURL = "https://api.vpnlib.bitmask.net:4430/"
GeolocationAPI = "https://getmyip.vpnlib.bitmask.net/"
Provider = "riseup.net"
ApplicationName = "RiseupVPN"
BinaryName = "riseup-vpn"
Auth = "anon"
DonateURL = "https://riseup.net/vpn/donate"
AskForDonations = "true"
HelpURL = "https://riseup.net/support"
TosURL = "https://riseup.net/tos"
APIURL = "https://api.black.riseup.net/"
GeolocationAPI = "https://api.black.riseup.net:9001/json"
)
var Version string
......@@ -29,11 +29,34 @@ CaCert : a string containing a representation of the provider CA, used to
*/
var CaCert = []byte(`-----BEGIN CERTIFICATE-----
MIIBQzCB6aADAgECAgEBMAoGCCqGSM49BAMCMBcxFTATBgNVBAMTDExFQVAgUm9v
dCBDQTAeFw0yMDA4MDYxOTA3NDRaFw0yNTA4MDYxOTEyNDRaMBcxFTATBgNVBAMT
DExFQVAgUm9vdCBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABIG5POr4cAdK
kTavKpSJr8nW1V7HLpr27qKaShpk1TUy5ipaAlusmavGLxKsPE+i3AMlv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40,6 @@ func (a *sipAuthentication) needsCredentials() bool {
func (a *sipAuthentication) getToken(user, password string) ([]byte, error) {
/* TODO refresh session token periodically */
if hasRecentToken() {
log.Println("Got cached token")
return readToken()
}
credJSON, err := formatCredentials(user, password)
......
......@@ -232,23 +232,36 @@ func (b *Bonafide) GetOpenvpnArgs() ([]string, error) {
}
func (b *Bonafide) fetchGeolocation() ([]string, error) {
/* FIXME in float deployments, geolocation is served on gemyip.domain/json, with a LE certificate.
So this is a workaround until we streamline that behavior */
resp, err := b.client.Post(config.GeolocationAPI, "", nil)
if err != nil {
return nil, err
client := &http.Client{}
_resp, err := client.Post(config.GeolocationAPI, "", nil)
if err != nil {
log.Println("ERROR: could not fetch geolocation:", fmt.Errorf("%s", err))
return nil, err
}
resp = _resp
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("get geolocation failed with status: %s", resp.Status)
log.Println("ERROR: bad status code while fetching geolocation:", fmt.Errorf("%s", resp.Status))
return nil, fmt.Errorf("Get geolocation failed with status: %s", resp.Status)
}
geo := &geoLocation{}
dataJSON, err := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(dataJSON, &geo)
if err != nil {
_ = fmt.Errorf("get vpn cert has failed with status: %s", resp.Status)
log.Println("ERROR: cannot parse geolocation json", fmt.Errorf("%s", err))
log.Println(string(dataJSON))
_ = fmt.Errorf("bad json")
return nil, err
}
log.Println("Got sorted gateways:", geo.SortedGateways)
return geo.SortedGateways, nil
}
......
......@@ -214,6 +214,7 @@ func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) {
}
}
}
for _, host := range geolocatedGateways {
for _, gw := range eip.Gateways {
if gw.Host == host {
......@@ -221,7 +222,17 @@ func (eip *eipService) sortGatewaysByGeolocation(geolocatedGateways []string) {
}
}
}
eip.Gateways = gws
if len(gws) == 0 {
log.Println("ERROR: avoiding to replace eip.Gateways will null list. Is the geolocation service properly configured?")
} else {
if len(gws) > 2 {
eip.Gateways = gws[:3]
} else {
eip.Gateways = gws
}
log.Println("Picked best gateways for location:", eip.Gateways)
}
}
type gatewayDistance struct {
......
......@@ -158,7 +158,7 @@ func (b *Bitmask) getCert() (certPath string, err error) {
certPath = b.getCertPemPath()
if _, err := os.Stat(certPath); os.IsNotExist(err) {
log.Println("Cert does not exist in ", certPath, "...fetching")
log.Println("Fetching certificate to", certPath)
cert, err := b.bonafide.GetPemCertificate()
if err != nil {
return "", err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment