Skip to content
Snippets Groups Projects
Verified Commit b4fe45c4 authored by Pea Nut's avatar Pea Nut
Browse files

Rename Bitmask3 back to Bitmask

parent b22edc65
Branches
No related tags found
1 merge request!198v5 implementation with a single Bitmask struct
......@@ -33,9 +33,7 @@ import (
obfsvpn "0xacab.org/leap/obfsvpn/client"
)
// Bitmask3 holds the bitmask client data
// Bitmask3 implements Bitmask interface (api version v3)
type Bitmask3 struct {
type Bitmask struct {
tempdir string
onGateway bonafide.Gateway
ptGateway bonafide.Gateway
......@@ -57,7 +55,7 @@ type Bitmask3 struct {
}
// Init the connection to bitmask
func Init() (*Bitmask3, error) {
func Init() (*Bitmask, error) {
statusCh := make(chan string, 10)
tempdir, err := ioutil.TempDir("", "leap-")
if err != nil {
......@@ -71,7 +69,7 @@ func Init() (*Bitmask3, error) {
return nil, err
}
b := Bitmask3{
b := Bitmask{
tempdir,
bonafide.Gateway{},
bonafide.Gateway{}, statusCh, nil, bf, launch,
......@@ -105,11 +103,11 @@ func Init() (*Bitmask3, error) {
return &b, err
}
func (b *Bitmask3) SetProvider(p string) {
func (b *Bitmask) SetProvider(p string) {
b.provider = p
}
func (b *Bitmask3) checkForUpgrades() {
func (b *Bitmask) checkForUpgrades() {
// SNAPS have their own way of upgrading. We probably should also try to detect
// if we've been installed via another package manager.
......@@ -121,21 +119,21 @@ func (b *Bitmask3) checkForUpgrades() {
b.canUpgrade = version.CanUpgrade()
}
func (b *Bitmask3) checkForMOTD() {
func (b *Bitmask) checkForMOTD() {
b.motd = motd.FetchLatest()
}
// GetStatusCh returns a channel that will recieve VPN status changes
func (b *Bitmask3) GetStatusCh() <-chan string {
func (b *Bitmask) GetStatusCh() <-chan string {
return b.statusCh
}
func (b *Bitmask3) GetSnowflakeCh() <-chan *snowflake.StatusEvent {
func (b *Bitmask) GetSnowflakeCh() <-chan *snowflake.StatusEvent {
return b.bonafide.SnowflakeCh
}
// Close the connection to bitmask, and does cleanup of temporal files
func (b *Bitmask3) Close() {
func (b *Bitmask) Close() {
log.Info().Msg("Close: cleanup and vpn shutdown...")
err := b.StopVPN()
if err != nil {
......@@ -160,32 +158,32 @@ func (b *Bitmask3) Close() {
}
// Version gets the bitmask version string
func (b *Bitmask3) Version() (string, error) {
func (b *Bitmask) Version() (string, error) {
return "", nil
}
func (b *Bitmask3) NeedsCredentials() bool {
func (b *Bitmask) NeedsCredentials() bool {
return b.bonafide.NeedsCredentials()
}
func (b *Bitmask3) DoLogin(username, password string) (bool, error) {
func (b *Bitmask) DoLogin(username, password string) (bool, error) {
return b.bonafide.DoLogin(username, password)
}
func (b *Bitmask3) UseUDP(udp bool) {
func (b *Bitmask) UseUDP(udp bool) {
b.udp = udp
}
func (b *Bitmask3) UseSnowflake(s bool) error {
func (b *Bitmask) UseSnowflake(s bool) error {
b.snowflake = s
return nil
}
func (b *Bitmask3) OffersUDP() bool {
func (b *Bitmask) OffersUDP() bool {
return b.bonafide.IsUDPAvailable()
}
func (b *Bitmask3) GetMotd() string {
func (b *Bitmask) GetMotd() string {
bytes, err := json.Marshal(b.motd)
if err != nil {
log.Warn().
......@@ -195,6 +193,6 @@ func (b *Bitmask3) GetMotd() string {
return string(bytes)
}
func (b *Bitmask3) CanUpgrade() bool {
func (b *Bitmask) CanUpgrade() bool {
return b.canUpgrade
}
......@@ -41,7 +41,7 @@ const (
)
// StartVPN for provider
func (b *Bitmask3) StartVPN(provider string) error {
func (b *Bitmask) StartVPN(provider string) error {
if !b.CanStartVPN() {
log.Warn().Msg("BUG cannot start")
return errors.New("BUG: cannot start vpn")
......@@ -61,14 +61,14 @@ func (b *Bitmask3) StartVPN(provider string) error {
return b.startOpenVPN(ctx)
}
func (b *Bitmask3) CanStartVPN() bool {
func (b *Bitmask) CanStartVPN() bool {
/* FIXME this is not enough. We should check, if provider needs
* credentials, if we have a valid token, otherwise remove it and
make sure that we're asking for the credentials input */
return !b.bonafide.NeedsCredentials()
}
func (b *Bitmask3) startTransportForPrivateBridge(ctx context.Context, gw bonafide.Gateway) (proxy string, err error) {
func (b *Bitmask) startTransportForPrivateBridge(ctx context.Context, gw bonafide.Gateway) (proxy string, err error) {
proxyAddr := "127.0.0.1:8080"
kcpMode := false
if os.Getenv("LEAP_KCP") == "1" {
......@@ -92,7 +92,7 @@ func (b *Bitmask3) startTransportForPrivateBridge(ctx context.Context, gw bonafi
return proxyAddr, nil
}
func (b *Bitmask3) startTransport(ctx context.Context, host string) (proxy string, err error) {
func (b *Bitmask) startTransport(ctx context.Context, host string) (proxy string, err error) {
// TODO configure socks port if not available
// TODO get port from UI/config file
proxyAddr := "127.0.0.1:8080"
......@@ -173,7 +173,7 @@ func maybeGetPrivateGateway() (bonafide.Gateway, bool) {
}
// generates a password and returns the path for a temporary file where this password is written
func (b *Bitmask3) generateManagementPassword() string {
func (b *Bitmask) generateManagementPassword() string {
pass := getRandomPass(12)
tmpFile, err := ioutil.TempFile(b.tempdir, "leap-vpn-")
if err != nil {
......@@ -186,7 +186,7 @@ func (b *Bitmask3) generateManagementPassword() string {
return tmpFile.Name()
}
func (b *Bitmask3) startOpenVPN(ctx context.Context) error {
func (b *Bitmask) startOpenVPN(ctx context.Context) error {
arg := b.openvpnArgs
/*
XXX has this changed??
......@@ -324,7 +324,7 @@ func (b *Bitmask3) startOpenVPN(ctx context.Context) error {
return b.launch.OpenvpnStart(arg...)
}
func (b *Bitmask3) getCert() (certPath string, err error) {
func (b *Bitmask) getCert() (certPath string, err error) {
log.Info().Msg("Getting certificate...")
persistentCertFile := filepath.Join(config.Path, strings.ToLower(config.Provider)+".pem")
if _, err := os.Stat(persistentCertFile); !os.IsNotExist(err) && isValidCert(persistentCertFile) {
......@@ -363,7 +363,7 @@ func (b *Bitmask3) getCert() (certPath string, err error) {
}
// Explicit call to GetGateways, to be able to fetch them all before starting the vpn
func (b *Bitmask3) fetchGateways() {
func (b *Bitmask) fetchGateways() {
log.Info().Msg("Fetching gateways...")
_, err := b.bonafide.GetAllGateways(b.transport)
if err != nil {
......@@ -374,7 +374,7 @@ func (b *Bitmask3) fetchGateways() {
}
// StopVPN or cancel
func (b *Bitmask3) StopVPN() error {
func (b *Bitmask) StopVPN() error {
err := b.launch.FirewallStop()
if err != nil {
return err
......@@ -388,14 +388,14 @@ func (b *Bitmask3) StopVPN() error {
return nil
}
func (b *Bitmask3) tryStopFromManagement() {
func (b *Bitmask) tryStopFromManagement() {
if b.managementClient != nil {
b.managementClient.SendSignal("SIGTERM")
}
}
// Reconnect to the VPN
func (b *Bitmask3) Reconnect() error {
func (b *Bitmask) Reconnect() error {
if !b.CanStartVPN() {
return errors.New("BUG: cannot start vpn")
}
......@@ -427,7 +427,7 @@ func (b *Bitmask3) Reconnect() error {
}
// ReloadFirewall restarts the firewall
func (b *Bitmask3) ReloadFirewall() error {
func (b *Bitmask) ReloadFirewall() error {
err := b.launch.FirewallStop()
if err != nil {
return err
......@@ -449,7 +449,7 @@ func (b *Bitmask3) ReloadFirewall() error {
}
// GetStatus returns the VPN status
func (b *Bitmask3) GetStatus() (string, error) {
func (b *Bitmask) GetStatus() (string, error) {
status := Off
if b.isFailed() {
status = Failed
......@@ -465,37 +465,37 @@ func (b *Bitmask3) GetStatus() (string, error) {
return status, nil
}
func (b *Bitmask3) InstallHelpers() error {
func (b *Bitmask) InstallHelpers() error {
// TODO use pickle module from here
return nil
}
// VPNCheck returns if the helpers are installed and up to date and if polkit is running
func (b *Bitmask3) VPNCheck() (helpers bool, privilege bool, err error) {
func (b *Bitmask) VPNCheck() (helpers bool, privilege bool, err error) {
return b.launch.Check()
}
func (b *Bitmask3) ListLocationFullness(transport string) map[string]float64 {
func (b *Bitmask) ListLocationFullness(transport string) map[string]float64 {
return b.bonafide.ListLocationFullness(transport)
}
func (b *Bitmask3) ListLocationLabels(transport string) map[string][]string {
func (b *Bitmask) ListLocationLabels(transport string) map[string][]string {
return b.bonafide.ListLocationLabels(transport)
}
// UseGateway selects a gateway, by label, as the default gateway
func (b *Bitmask3) UseGateway(label string) {
func (b *Bitmask) UseGateway(label string) {
b.bonafide.SetManualGateway(label)
}
// UseAutomaticGateway sets the gateway to be selected automatically
// best gateway will be used
func (b *Bitmask3) UseAutomaticGateway() {
func (b *Bitmask) UseAutomaticGateway() {
b.bonafide.SetAutomaticGateway()
}
// SetTransport selects an obfuscation transport to use
func (b *Bitmask3) SetTransport(t string) error {
func (b *Bitmask) SetTransport(t string) error {
if t != "openvpn" && t != "obfs4" {
return fmt.Errorf("Transport %s not implemented", t)
}
......@@ -515,7 +515,7 @@ func (b *Bitmask3) SetTransport(t string) error {
}
// GetTransport gets the obfuscation transport to use. Only obfs4 available for now.
func (b *Bitmask3) GetTransport() string {
func (b *Bitmask) GetTransport() string {
if b.transport == "obfs4" {
return "obfs4"
} else {
......@@ -523,11 +523,11 @@ func (b *Bitmask3) GetTransport() string {
}
}
func (b *Bitmask3) getTempCertPemPath() string {
func (b *Bitmask) getTempCertPemPath() string {
return filepath.Join(b.tempdir, "openvpn.pem")
}
func (b *Bitmask3) getTempCaCertPath() string {
func (b *Bitmask) getTempCaCertPath() string {
return filepath.Join(b.tempdir, "cacert.pem")
}
......
......@@ -46,7 +46,7 @@ var statusNames = map[string]string{
"FAILED": Off,
}
func (b *Bitmask3) openvpnManagement() {
func (b *Bitmask) openvpnManagement() {
// TODO: we should warn the user on ListenAndServe errors
newConnection := func(conn management.IncomingConn) {
eventCh := make(chan management.Event, 10)
......@@ -68,7 +68,7 @@ func (b *Bitmask3) openvpnManagement() {
}
}
func (b *Bitmask3) eventHandler(eventCh <-chan management.Event) {
func (b *Bitmask) eventHandler(eventCh <-chan management.Event) {
for event := range eventCh {
log.Debug().
Str("event", event.String()).
......@@ -105,27 +105,27 @@ func (b *Bitmask3) eventHandler(eventCh <-chan management.Event) {
b.statusCh <- Off
}
func (b *Bitmask3) GetCurrentGateway() string {
func (b *Bitmask) GetCurrentGateway() string {
return b.onGateway.Host
}
func (b *Bitmask3) GetCurrentLocation() string {
func (b *Bitmask) GetCurrentLocation() string {
return b.onGateway.LocationName
}
func (b *Bitmask3) GetCurrentCountry() string {
func (b *Bitmask) GetCurrentCountry() string {
return b.onGateway.CountryCode
}
func (b *Bitmask3) GetBestLocation(transport string) string {
func (b *Bitmask) GetBestLocation(transport string) string {
return b.bonafide.GetBestLocation(transport)
}
func (b *Bitmask3) IsManualLocation() bool {
func (b *Bitmask) IsManualLocation() bool {
return b.bonafide.IsManualLocation()
}
func (b *Bitmask3) getOpenvpnState() (string, error) {
func (b *Bitmask) getOpenvpnState() (string, error) {
if b.managementClient == nil {
return "", fmt.Errorf("No management connected")
}
......@@ -140,6 +140,6 @@ func (b *Bitmask3) getOpenvpnState() (string, error) {
return status, nil
}
func (b *Bitmask3) isFailed() bool {
func (b *Bitmask) isFailed() bool {
return b.launch.Failed
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment