Single connection written to openvpn configuration (#258)

- From now only a single OpenVPN connection is written to the OpenVPN configuration file
- If multiple connections are matched given the user parameters (i.e. city, region), it is picked at pseudo random using the current time as the pseudo random seed.
- Not relying on Openvpn picking a random remote address, may refer to #229 
- Program is aware of which connection is to be used, in order to use its matching CN for port forwarding TLS verification with PIA v4 servers, see #236 
- Simplified firewall mechanisms
This commit is contained in:
Quentin McGaw
2020-10-12 15:29:58 -04:00
committed by GitHub
parent 9f6450502c
commit c4354871f7
18 changed files with 279 additions and 354 deletions

View File

@@ -14,33 +14,33 @@ import (
// Provider contains methods to read and modify the openvpn configuration to connect as a client
type Provider interface {
GetOpenVPNConnections(selection models.ServerSelection) (connections []models.OpenVPNConnection, err error)
BuildConf(connections []models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string, extras models.ExtraConfigOptions) (lines []string)
GetOpenVPNConnection(selection models.ServerSelection) (connection models.OpenVPNConnection, err error)
BuildConf(connection models.OpenVPNConnection, verbosity, uid, gid int, root bool, cipher, auth string, extras models.ExtraConfigOptions) (lines []string)
PortForward(ctx context.Context, client *http.Client,
fileManager files.FileManager, pfLogger logging.Logger, gateway net.IP, fw firewall.Configurator,
syncState func(port uint16) (pfFilepath models.Filepath))
}
func New(provider models.VPNProvider, allServers models.AllServers) Provider {
func New(provider models.VPNProvider, allServers models.AllServers, timeNow timeNowFunc) Provider {
switch provider {
case constants.PrivateInternetAccess:
return newPrivateInternetAccessV4(allServers.Pia.Servers)
return newPrivateInternetAccessV4(allServers.Pia.Servers, timeNow)
case constants.PrivateInternetAccessOld:
return newPrivateInternetAccessV3(allServers.PiaOld.Servers)
return newPrivateInternetAccessV3(allServers.PiaOld.Servers, timeNow)
case constants.Mullvad:
return newMullvad(allServers.Mullvad.Servers)
return newMullvad(allServers.Mullvad.Servers, timeNow)
case constants.Windscribe:
return newWindscribe(allServers.Windscribe.Servers)
return newWindscribe(allServers.Windscribe.Servers, timeNow)
case constants.Surfshark:
return newSurfshark(allServers.Surfshark.Servers)
return newSurfshark(allServers.Surfshark.Servers, timeNow)
case constants.Cyberghost:
return newCyberghost(allServers.Cyberghost.Servers)
return newCyberghost(allServers.Cyberghost.Servers, timeNow)
case constants.Vyprvpn:
return newVyprvpn(allServers.Vyprvpn.Servers)
return newVyprvpn(allServers.Vyprvpn.Servers, timeNow)
case constants.Nordvpn:
return newNordvpn(allServers.Nordvpn.Servers)
return newNordvpn(allServers.Nordvpn.Servers, timeNow)
case constants.Purevpn:
return newPurevpn(allServers.Purevpn.Servers)
return newPurevpn(allServers.Purevpn.Servers, timeNow)
default:
return nil // should never occur
}