Skip to content

Commit

Permalink
bug: avoid crash when gateways not initialzed
Browse files Browse the repository at this point in the history
fix also wrong call to sort by tz - should prefer menshen.
  • Loading branch information
kalikaneko committed Mar 8, 2023
1 parent da06217 commit ffa9ab6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions gui/providers/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"apiURL": "https://api.black.riseup.net/",
"geolocationAPI": "https://api.black.riseup.net:9001/json",
"caCertString": "-----BEGIN CERTIFICATE-----\nMIIFjTCCA3WgAwIBAgIBATANBgkqhkiG9w0BAQ0FADBZMRgwFgYDVQQKDA9SaXNl\ndXAgTmV0d29ya3MxGzAZBgNVBAsMEmh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UE\nAwwXUmlzZXVwIE5ldHdvcmtzIFJvb3QgQ0EwHhcNMTQwNDI4MDAwMDAwWhcNMjQw\nNDI4MDAwMDAwWjBZMRgwFgYDVQQKDA9SaXNldXAgTmV0d29ya3MxGzAZBgNVBAsM\nEmh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UEAwwXUmlzZXVwIE5ldHdvcmtzIFJv\nb3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC76J4ciMJ8Sg0m\nTP7DF2DT9zNe0Csk4myoMFC57rfJeqsAlJCv1XMzBmXrw8wq/9z7XHv6n/0sWU7a\n7cF2hLR33ktjwODlx7vorU39/lXLndo492ZBhXQtG1INMShyv+nlmzO6GT7ESfNE\nLliFitEzwIegpMqxCIHXFuobGSCWF4N0qLHkq/SYUMoOJ96O3hmPSl1kFDRMtWXY\niw1SEKjUvpyDJpVs3NGxeLCaA7bAWhDY5s5Yb2fA1o8ICAqhowurowJpW7n5ZuLK\n5VNTlNy6nZpkjt1QycYvNycffyPOFm/Q/RKDlvnorJIrihPkyniV3YY5cGgP+Qkx\nHUOT0uLA6LHtzfiyaOqkXwc4b0Z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bAjarnJ\nUN9SaWRlWKSdP4haujnzCoJbM7dU9bjvlGZNyXEekgeT0W2qFeGGp+yyUWw8tNsp\n0BuC1b7uW/bBn/xKm319wXVDvBgZgcktMolak39V7DVO\n-----END CERTIFICATE-----\n-----BEGIN CERTIFICATE-----\nMIIBYjCCAQigAwIBAgIBATAKBggqhkjOPQQDAjAXMRUwEwYDVQQDEwxMRUFQIFJv\nb3QgQ0EwHhcNMjExMTAyMTkwNTM3WhcNMjYxMTAyMTkxMDM3WjAXMRUwEwYDVQQD\nEwxMRUFQIFJvb3QgQ0EwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQxOXBGu+gf\npjHzVteGTWL6XnFxtEnKMFpKaJkA/VOHmESzoLsZRQxt88GssxaqC01J17idQiqv\nzgNpedmtvFtyo0UwQzAOBgNVHQ8BAf8EBAMCAqQwEgYDVR0TAQH/BAgwBgEB/wIB\nATAdBgNVHQ4EFgQUZdoUlJrCIUNFrpffAq+LQjnwEz4wCgYIKoZIzj0EAwIDSAAw\nRQIgfr3w4tnRG+NdI3LsGPlsRktGK20xHTzsB3orB0yC6cICIQCB+/9y8nmSStfN\nVUMUyk2hNd7/kC8nL222TTD7VZUtsg==\n-----END CERTIFICATE-----",
"timeStamp": "2021-12-02 16:08:02"
"timeStamp": "2023-03-08 11:47:43"
},
{
"name": "RiseupBeta",
Expand All @@ -31,7 +31,7 @@
"apiURL": "https://api.float.hexacab.org:4430/",
"geolocationAPI": "https://menshen.float.hexacab.org/json",
"caCertString": "-----BEGIN CERTIFICATE-----\nMIIFjTCCA3WgAwIBAgIBATANBgkqhkiG9w0BAQ0FADBZMRgwFgYDVQQKDA9SaXNl\ndXAgTmV0d29ya3MxGzAZBgNVBAsMEmh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UE\nAwwXUmlzZXVwIE5ldHdvcmtzIFJvb3QgQ0EwHhcNMTQwNDI4MDAwMDAwWhcNMjQw\nNDI4MDAwMDAwWjBZMRgwFgYDVQQKDA9S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SAAw\nRQIgfr3w4tnRG+NdI3LsGPlsRktGK20xHTzsB3orB0yC6cICIQCB+/9y8nmSStfN\nVUMUyk2hNd7/kC8nL222TTD7VZUtsg==\n-----END CERTIFICATE-----",
"timeStamp": "2021-12-02 16:08:02"
"timeStamp": "2023-03-08 11:47:43"
}
]
}
2 changes: 0 additions & 2 deletions pkg/config/version/checknewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

const verURI = "https://downloads.leap.se/RiseupVPN/"

var VERSION string

// returns true if there's a newer version string published on the server
// this needs to manually bump latest version for every platform in the
// downloads server.
Expand Down
7 changes: 7 additions & 0 deletions pkg/vpn/bonafide/bonafide.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ func (b *Bonafide) maybeInitializeEIP() error {
b.watchSnowflakeProgress(ch)
snowflake.BootstrapWithSnowflakeProxies(p, getAPIAddr(p), ch)
}
if b.gateways == nil {
return errors.New("no gateways")
}
err := b.parseEipJSONFromFile()
if err != nil {
return err
Expand All @@ -281,6 +284,9 @@ func (b *Bonafide) maybeInitializeEIP() error {
}
b.gateways = newGatewayPool(b.eip)
}
if b.gateways == nil {
return errors.New("no gateways")
}

// XXX For now, we just initialize once per session.
// We might update the menshen gateways every time we 'maybe initilize EIP'
Expand Down Expand Up @@ -317,6 +323,7 @@ func (b *Bonafide) GetAllGateways(transport string) ([]Gateway, error) {
err := b.maybeInitializeEIP()
// XXX needs to wait for bonafide too
if err != nil {
log.Printf("%v\n", err)
return nil, err
}
gws, err := b.gateways.getAll(transport, b.tzOffsetHours)
Expand Down
8 changes: 5 additions & 3 deletions pkg/vpn/bonafide/gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (p *gatewayPool) getAll(transport string, tz int) ([]Gateway, error) {
}

log.Println("seems to be initialized...")
if len(p.recommended) == 0 {
if len(p.recommended) != 0 {
return p.getGatewaysFromMenshen(transport, 999)
}
return p.getGatewaysByTimezone(transport, tz, 999)
Expand All @@ -340,6 +340,7 @@ func (p *gatewayPool) getGatewaysFromMenshen(transport string, max int) ([]Gatew

/* the old timezone based heuristic, when everything goes wrong */
func (p *gatewayPool) getGatewaysByTimezone(transport string, tzOffsetHours, max int) ([]Gateway, error) {
log.Println("Sorting gateways by timezone")
gws := make([]Gateway, 0)
gwVector := []gatewayDistance{}

Expand All @@ -348,9 +349,10 @@ func (p *gatewayPool) getGatewaysByTimezone(transport string, tzOffsetHours, max
continue
}
distance := 13
gwOffset, err := strconv.Atoi(p.locations[gw.Location].Timezone)
tz := p.locations[gw.Location].Timezone
gwOffset, err := strconv.Atoi(tz)
if err != nil {
log.Printf("Error sorting gateways: %v", err)
log.Printf("Error sorting gateways: loc=%s, tz=%s; %v", gw.Location, tz, err)
return gws, err
}
distance = tzDistance(tzOffsetHours, gwOffset)
Expand Down
2 changes: 1 addition & 1 deletion pkg/vpn/openvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (b *Bitmask) getCert() (certPath string, err error) {

// Explicit call to GetGateways, to be able to fetch them all before starting the vpn
func (b *Bitmask) fetchGateways() {
log.Println("Fetching gateways...")
log.Printf("Fetching gateways (%s)...", b.transport)
_, err := b.bonafide.GetAllGateways(b.transport)
if err != nil {
log.Println("ERROR Cannot fetch gateways")
Expand Down

0 comments on commit ffa9ab6

Please sign in to comment.