diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-01-27 20:44:34 -0600 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2020-08-20 20:27:26 +0200 |
commit | c236dfcfdd60ea700e5f50ed2568398cd161dd4c (patch) | |
tree | db298b28716a25012dc8806afd402b6454b2b37b /pkg/vpn/bonafide/eip_service.go | |
parent | 7c4a4f5ae0c02f57eb9073fa8f412a38b8f79363 (diff) |
[feat] add sip authentication
initial merge of the sip authentication mechanism
Diffstat (limited to 'pkg/vpn/bonafide/eip_service.go')
-rw-r--r-- | pkg/vpn/bonafide/eip_service.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/pkg/vpn/bonafide/eip_service.go b/pkg/vpn/bonafide/eip_service.go index c097e8a..148b052 100644 --- a/pkg/vpn/bonafide/eip_service.go +++ b/pkg/vpn/bonafide/eip_service.go @@ -23,6 +23,7 @@ type eipService struct { Gateways []gatewayV3 Locations map[string]location OpenvpnConfiguration openvpnConfig `json:"openvpn_configuration"` + auth string defaultGateway string } @@ -65,6 +66,22 @@ type transportV3 struct { Options map[string]string } +func (b *Bonafide) setupAuthentication(i interface{}) { + switch i.(type) { + case eipService: + switch auth := b.eip.auth; auth { + case "anon": + // Do nothing, we're set on initialization. + case "sip": + b.auth = &SipAuthentication{b} + default: + log.Printf("BUG: unknown authentication method %s", auth) + } + case eipServiceV1: + // Do nothing, no auth on v1. + } +} + func (b *Bonafide) fetchEipJSON() error { resp, err := b.client.Post(eip3API, "", nil) for err != nil { @@ -80,24 +97,25 @@ func (b *Bonafide) fetchEipJSON() error { case 404: buf := make([]byte, 128) resp.Body.Read(buf) - log.Printf("Error fetching eip v3 json: %s", buf) + log.Printf("Error fetching eip v3 json") resp, err = b.client.Post(eip1API, "", nil) if err != nil { return err } defer resp.Body.Close() if resp.StatusCode != 200 { - return fmt.Errorf("get eip json has failed with status: %s", resp.Status) + return fmt.Errorf("Get eip json has failed with status: %s", resp.Status) } b.eip, err = decodeEIP1(resp.Body) default: - return fmt.Errorf("get eip json has failed with status: %s", resp.Status) + return fmt.Errorf("Get eip json has failed with status: %s", resp.Status) } if err != nil { return err } + b.setupAuthentication(b.eip) b.sortGateways() return nil } |