Maint: use narrower interfaces for firewall config

This commit is contained in:
Quentin McGaw (desktop)
2021-07-26 16:07:50 +00:00
parent 430512dd27
commit 7a222923c7
19 changed files with 29 additions and 24 deletions

View File

@@ -37,7 +37,7 @@ type Loop struct {
targetConfPath string targetConfPath string
// Configurators // Configurators
conf StarterAuthWriter conf StarterAuthWriter
fw firewall.Configurator fw firewallConfigurer
routing routing.Routing routing routing.Routing
// Other objects // Other objects
logger, pfLogger logging.Logger logger, pfLogger logging.Logger
@@ -54,13 +54,18 @@ type Loop struct {
backoffTime time.Duration backoffTime time.Duration
} }
type firewallConfigurer interface {
firewall.VPNConnectionSetter
firewall.PortAllower
}
const ( const (
defaultBackoffTime = 15 * time.Second defaultBackoffTime = 15 * time.Second
) )
func NewLoop(settings configuration.OpenVPN, func NewLoop(settings configuration.OpenVPN,
username string, puid, pgid int, allServers models.AllServers, username string, puid, pgid int, allServers models.AllServers,
conf Configurator, fw firewall.Configurator, routing routing.Routing, conf Configurator, fw firewallConfigurer, routing routing.Routing,
logger logging.ParentLogger, client *http.Client, logger logging.ParentLogger, client *http.Client,
tunnelReady chan<- struct{}) *Loop { tunnelReady chan<- struct{}) *Loop {
start := make(chan struct{}) start := make(chan struct{})

View File

@@ -10,7 +10,7 @@ import (
) )
func (c *Cyberghost) PortForward(ctx context.Context, client *http.Client, func (c *Cyberghost) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Cyberghost") panic("port forwarding is not supported for Cyberghost")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (f *Fastestvpn) PortForward(ctx context.Context, client *http.Client, func (f *Fastestvpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for FastestVPN") panic("port forwarding is not supported for FastestVPN")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (f *HideMyAss) PortForward(ctx context.Context, client *http.Client, func (f *HideMyAss) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for HideMyAss") panic("port forwarding is not supported for HideMyAss")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (i *Ipvanish) PortForward(ctx context.Context, client *http.Client, func (i *Ipvanish) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Ipvanish") panic("port forwarding is not supported for Ipvanish")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (i *Ivpn) PortForward(ctx context.Context, client *http.Client, func (i *Ivpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Ivpn") panic("port forwarding is not supported for Ivpn")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (m *Mullvad) PortForward(ctx context.Context, client *http.Client, func (m *Mullvad) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding logic is not needed for Mullvad") panic("port forwarding logic is not needed for Mullvad")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (n *Nordvpn) PortForward(ctx context.Context, client *http.Client, func (n *Nordvpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for NordVPN") panic("port forwarding is not supported for NordVPN")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (p *Privado) PortForward(ctx context.Context, client *http.Client, func (p *Privado) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Privado") panic("port forwarding is not supported for Privado")
} }

View File

@@ -28,7 +28,7 @@ var (
// PortForward obtains a VPN server side port forwarded from PIA. // PortForward obtains a VPN server side port forwarded from PIA.
//nolint:gocognit //nolint:gocognit
func (p *PIA) PortForward(ctx context.Context, client *http.Client, func (p *PIA) PortForward(ctx context.Context, client *http.Client,
logger logging.Logger, gateway net.IP, fw firewall.Configurator, logger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
commonName := p.activeServer.ServerName commonName := p.activeServer.ServerName
if !p.activeServer.PortForward { if !p.activeServer.PortForward {
@@ -96,7 +96,7 @@ func (p *PIA) PortForward(ctx context.Context, client *http.Client,
logger.Error(err.Error()) logger.Error(err.Error())
} }
if err := fw.SetAllowedPort(ctx, data.Port, string(constants.TUN)); err != nil { if err := portAllower.SetAllowedPort(ctx, data.Port, string(constants.TUN)); err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
} }
@@ -109,7 +109,7 @@ func (p *PIA) PortForward(ctx context.Context, client *http.Client,
case <-ctx.Done(): case <-ctx.Done():
removeCtx, cancel := context.WithTimeout(context.Background(), time.Second) removeCtx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel() defer cancel()
if err := fw.RemoveAllowedPort(removeCtx, data.Port); err != nil { if err := portAllower.RemoveAllowedPort(removeCtx, data.Port); err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
} }
if !keepAliveTimer.Stop() { if !keepAliveTimer.Stop() {
@@ -140,10 +140,10 @@ func (p *PIA) PortForward(ctx context.Context, client *http.Client,
durationToExpiration := data.Expiration.Sub(p.timeNow()) durationToExpiration := data.Expiration.Sub(p.timeNow())
logger.Info("Port forwarded is " + strconv.Itoa(int(data.Port)) + logger.Info("Port forwarded is " + strconv.Itoa(int(data.Port)) +
" expiring in " + format.FriendlyDuration(durationToExpiration)) " expiring in " + format.FriendlyDuration(durationToExpiration))
if err := fw.RemoveAllowedPort(ctx, oldPort); err != nil { if err := portAllower.RemoveAllowedPort(ctx, oldPort); err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
} }
if err := fw.SetAllowedPort(ctx, data.Port, string(constants.TUN)); err != nil { if err := portAllower.SetAllowedPort(ctx, data.Port, string(constants.TUN)); err != nil {
logger.Error(err.Error()) logger.Error(err.Error())
} }
filepath := syncState(data.Port) filepath := syncState(data.Port)

View File

@@ -10,7 +10,7 @@ import (
) )
func (p *Privatevpn) PortForward(ctx context.Context, client *http.Client, func (p *Privatevpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for PrivateVPN") panic("port forwarding is not supported for PrivateVPN")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (p *Protonvpn) PortForward(ctx context.Context, client *http.Client, func (p *Protonvpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for ProtonVPN") panic("port forwarding is not supported for ProtonVPN")
} }

View File

@@ -37,7 +37,7 @@ type Provider interface {
GetOpenVPNConnection(selection configuration.ServerSelection) (connection models.OpenVPNConnection, err error) GetOpenVPNConnection(selection configuration.ServerSelection) (connection models.OpenVPNConnection, err error)
BuildConf(connection models.OpenVPNConnection, username string, settings configuration.OpenVPN) (lines []string) BuildConf(connection models.OpenVPNConnection, username string, settings configuration.OpenVPN) (lines []string)
PortForward(ctx context.Context, client *http.Client, PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) syncState func(port uint16) (pfFilepath string))
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (p *Purevpn) PortForward(ctx context.Context, client *http.Client, func (p *Purevpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for PureVPN") panic("port forwarding is not supported for PureVPN")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (s *Surfshark) PortForward(ctx context.Context, client *http.Client, func (s *Surfshark) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Surfshark") panic("port forwarding is not supported for Surfshark")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (t *Torguard) PortForward(ctx context.Context, client *http.Client, func (t *Torguard) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Torguard") panic("port forwarding is not supported for Torguard")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (p *Provider) PortForward(ctx context.Context, client *http.Client, func (p *Provider) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for VPN Unlimited") panic("port forwarding is not supported for VPN Unlimited")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (v *Vyprvpn) PortForward(ctx context.Context, client *http.Client, func (v *Vyprvpn) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Vyprvpn") panic("port forwarding is not supported for Vyprvpn")
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func (w *Windscribe) PortForward(ctx context.Context, client *http.Client, func (w *Windscribe) PortForward(ctx context.Context, client *http.Client,
pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator, pfLogger logging.Logger, gateway net.IP, portAllower firewall.PortAllower,
syncState func(port uint16) (pfFilepath string)) { syncState func(port uint16) (pfFilepath string)) {
panic("port forwarding is not supported for Windscribe") panic("port forwarding is not supported for Windscribe")
} }