summaryrefslogtreecommitdiff
path: root/pkg/vpn/bonafide/bonafide.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-05-17 17:33:40 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-05-17 17:52:47 +0200
commit86d30f2a2edc0d9b9c54b51258a6566e37476849 (patch)
treef3f6d52eb6bd976e06a224480914c900338cba44 /pkg/vpn/bonafide/bonafide.go
parent083f4095319b734f33f3e28a9f3234ff9cf6a7d7 (diff)
[feat] retry if dns lookup fails
Diffstat (limited to 'pkg/vpn/bonafide/bonafide.go')
-rw-r--r--pkg/vpn/bonafide/bonafide.go41
1 files changed, 40 insertions, 1 deletions
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go
index fc1bc95..a9a7d85 100644
--- a/pkg/vpn/bonafide/bonafide.go
+++ b/pkg/vpn/bonafide/bonafide.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2018-2020 LEAP
+// Copyright (C) 2018-2021 LEAP
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -75,6 +75,17 @@ type geoLocation struct {
SortedGateways []geoGateway `json:"sortedGateways"`
}
+func getAPIAddr(provider string) string {
+ switch provider {
+ case "riseup.net":
+ return "198.252.153.107"
+ case "calyx.net":
+ return "162.247.73.194"
+ default:
+ return ""
+ }
+}
+
// New Bonafide: Initializes a Bonafide object. By default, no Credentials are passed.
func New() *Bonafide {
certs := x509.NewCertPool()
@@ -179,6 +190,17 @@ func (b *Bonafide) GetPemCertificate() ([]byte, error) {
return ioutil.ReadAll(resp.Body)
}
+func (b *Bonafide) GetPemCertificateNoDNS() ([]byte, error) {
+ req, err := http.NewRequest("POST", b.getURLNoDNS("certv3"), strings.NewReader(""))
+ resp, err := b.client.Do(req)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+
+ return ioutil.ReadAll(resp.Body)
+}
+
func (b *Bonafide) getURL(object string) string {
switch object {
case "cert":
@@ -192,6 +214,23 @@ func (b *Bonafide) getURL(object string) string {
return ""
}
+func (b *Bonafide) getURLNoDNS(object string) string {
+ p := strings.ToLower(config.Provider)
+ base := "https://" + getAPIAddr(p) + "/"
+ switch object {
+ case "cert":
+ return base + certPathv1
+ case "certv3":
+ return base + certPathv3
+ case "auth":
+ return base + authPathv3
+ case "eip":
+ return base + "3/config/eip-service.json"
+ }
+ log.Println("BUG: unknown url object")
+ return ""
+}
+
func (b *Bonafide) maybeInitializeEIP() error {
if b.eip == nil {
err := b.fetchEipJSON()