Feat: ExpressVPN support (#623)
This commit is contained in:
44
internal/provider/expressvpn/connection.go
Normal file
44
internal/provider/expressvpn/connection.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package expressvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Provider) GetConnection(selection configuration.ServerSelection) (
|
||||
connection models.Connection, err error) {
|
||||
port := getPort(selection)
|
||||
protocol := utils.GetProtocol(selection)
|
||||
|
||||
servers, err := p.filterServers(selection)
|
||||
if err != nil {
|
||||
return connection, err
|
||||
}
|
||||
|
||||
var connections []models.Connection
|
||||
for _, server := range servers {
|
||||
for _, IP := range server.IPs {
|
||||
connection := models.Connection{
|
||||
Type: selection.VPN,
|
||||
IP: IP,
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
Hostname: server.Hostname,
|
||||
}
|
||||
connections = append(connections, connection)
|
||||
}
|
||||
}
|
||||
|
||||
return utils.PickConnection(connections, selection, p.randSource)
|
||||
}
|
||||
|
||||
func getPort(selection configuration.ServerSelection) (port uint16) {
|
||||
const (
|
||||
defaultOpenVPNTCP = 0
|
||||
defaultOpenVPNUDP = 1195
|
||||
defaultWireguard = 0
|
||||
)
|
||||
return utils.GetPort(selection, defaultOpenVPNTCP,
|
||||
defaultOpenVPNUDP, defaultWireguard)
|
||||
}
|
||||
97
internal/provider/expressvpn/connection_test.go
Normal file
97
internal/provider/expressvpn/connection_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package expressvpn
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_Provider_GetConnection(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.ExpressvpnServer
|
||||
selection configuration.ServerSelection
|
||||
connection models.Connection
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.ExpressvpnServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(1, 1, 1, 1),
|
||||
Port: 1195,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"target IP": {
|
||||
selection: configuration.ServerSelection{
|
||||
TargetIP: net.IPv4(2, 2, 2, 2),
|
||||
},
|
||||
servers: []models.ExpressvpnServer{
|
||||
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1195,
|
||||
Protocol: constants.UDP,
|
||||
},
|
||||
},
|
||||
"with filter": {
|
||||
selection: configuration.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, UDP: true},
|
||||
{Hostname: "b", IPs: []net.IP{net.IPv4(2, 2, 2, 2)}, UDP: true},
|
||||
{Hostname: "a", IPs: []net.IP{net.IPv4(3, 3, 3, 3)}, UDP: true},
|
||||
},
|
||||
connection: models.Connection{
|
||||
IP: net.IPv4(2, 2, 2, 2),
|
||||
Port: 1195,
|
||||
Protocol: constants.UDP,
|
||||
Hostname: "b",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
randSource := rand.NewSource(0)
|
||||
|
||||
m := New(testCase.servers, randSource)
|
||||
|
||||
connection, err := m.GetConnection(testCase.selection)
|
||||
|
||||
if testCase.err != nil {
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, testCase.err.Error(), err.Error())
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, testCase.connection, connection)
|
||||
})
|
||||
}
|
||||
}
|
||||
28
internal/provider/expressvpn/filter.go
Normal file
28
internal/provider/expressvpn/filter.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package expressvpn
|
||||
|
||||
import (
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Provider) filterServers(selection configuration.ServerSelection) (
|
||||
servers []models.ExpressvpnServer, err error) {
|
||||
for _, server := range p.servers {
|
||||
switch {
|
||||
case
|
||||
utils.FilterByPossibilities(server.Country, selection.Countries),
|
||||
utils.FilterByPossibilities(server.City, selection.Cities),
|
||||
utils.FilterByPossibilities(server.Hostname, selection.Hostnames),
|
||||
utils.FilterByProtocol(selection, server.TCP, server.UDP):
|
||||
default:
|
||||
servers = append(servers, server)
|
||||
}
|
||||
}
|
||||
|
||||
if len(servers) == 0 {
|
||||
return nil, utils.NoServerFoundError(selection)
|
||||
}
|
||||
|
||||
return servers, nil
|
||||
}
|
||||
119
internal/provider/expressvpn/filter_test.go
Normal file
119
internal/provider/expressvpn/filter_test.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package expressvpn
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_Expressvpn_filterServers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
servers []models.ExpressvpnServer
|
||||
selection configuration.ServerSelection
|
||||
filtered []models.ExpressvpnServer
|
||||
err error
|
||||
}{
|
||||
"no server available": {
|
||||
selection: configuration.ServerSelection{
|
||||
VPN: constants.OpenVPN,
|
||||
},
|
||||
err: errors.New("no server found: for VPN openvpn; protocol udp"),
|
||||
},
|
||||
"no filter": {
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.ExpressvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by country": {
|
||||
selection: configuration.ServerSelection{
|
||||
Countries: []string{"b"},
|
||||
},
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Country: "a", UDP: true},
|
||||
{Country: "b", UDP: true},
|
||||
{Country: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.ExpressvpnServer{
|
||||
{Country: "b", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by city": {
|
||||
selection: configuration.ServerSelection{
|
||||
Cities: []string{"b"},
|
||||
},
|
||||
servers: []models.ExpressvpnServer{
|
||||
{City: "a", UDP: true},
|
||||
{City: "b", UDP: true},
|
||||
{City: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.ExpressvpnServer{
|
||||
{City: "b", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by hostname": {
|
||||
selection: configuration.ServerSelection{
|
||||
Hostnames: []string{"b"},
|
||||
},
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.ExpressvpnServer{
|
||||
{Hostname: "b", UDP: true},
|
||||
},
|
||||
},
|
||||
"filter by protocol": {
|
||||
selection: configuration.ServerSelection{
|
||||
OpenVPN: configuration.OpenVPNSelection{
|
||||
TCP: true,
|
||||
},
|
||||
},
|
||||
servers: []models.ExpressvpnServer{
|
||||
{Hostname: "a", UDP: true},
|
||||
{Hostname: "b", UDP: true, TCP: true},
|
||||
{Hostname: "c", UDP: true},
|
||||
},
|
||||
filtered: []models.ExpressvpnServer{
|
||||
{Hostname: "b", UDP: true, TCP: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
randSource := rand.NewSource(0)
|
||||
|
||||
m := New(testCase.servers, randSource)
|
||||
|
||||
servers, err := m.filterServers(testCase.selection)
|
||||
|
||||
if testCase.err != nil {
|
||||
require.Error(t, err)
|
||||
assert.Equal(t, testCase.err.Error(), err.Error())
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
assert.Equal(t, testCase.filtered, servers)
|
||||
})
|
||||
}
|
||||
}
|
||||
85
internal/provider/expressvpn/openvpnconf.go
Normal file
85
internal/provider/expressvpn/openvpnconf.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package expressvpn
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/configuration"
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
func (p *Provider) BuildConf(connection models.Connection,
|
||||
settings configuration.OpenVPN) (lines []string, err error) {
|
||||
if settings.Cipher == "" {
|
||||
settings.Cipher = constants.AES256cbc
|
||||
}
|
||||
if settings.Auth == "" {
|
||||
settings.Auth = constants.SHA512
|
||||
}
|
||||
|
||||
if settings.MSSFix == 0 {
|
||||
settings.MSSFix = 1200
|
||||
}
|
||||
|
||||
lines = []string{
|
||||
"client",
|
||||
"nobind",
|
||||
"tls-exit",
|
||||
"dev " + settings.Interface,
|
||||
"verb " + strconv.Itoa(settings.Verbosity),
|
||||
|
||||
// Expressvpn specific
|
||||
"fast-io",
|
||||
"fragment 1300",
|
||||
"mssfix " + strconv.Itoa(int(settings.MSSFix)),
|
||||
"sndbuf 524288",
|
||||
"rcvbuf 524288",
|
||||
"verify-x509-name Server name-prefix", // security hole I guess?
|
||||
"remote-cert-tls server", // updated name of ns-cert-type
|
||||
"key-direction 1",
|
||||
"auth-user-pass " + constants.OpenVPNAuthConf,
|
||||
"auth " + settings.Auth,
|
||||
|
||||
// Added constant values
|
||||
"mute-replay-warnings",
|
||||
"auth-nocache",
|
||||
"pull-filter ignore \"auth-token\"", // prevent auth failed loops
|
||||
"auth-retry nointeract",
|
||||
"suppress-timestamps",
|
||||
|
||||
// Modified variables
|
||||
connection.OpenVPNProtoLine(),
|
||||
connection.OpenVPNRemoteLine(),
|
||||
}
|
||||
|
||||
lines = append(lines, utils.CipherLines(settings.Cipher, settings.Version)...)
|
||||
|
||||
if connection.Protocol == constants.UDP {
|
||||
lines = append(lines, "explicit-exit-notify")
|
||||
}
|
||||
|
||||
if !settings.Root {
|
||||
lines = append(lines, "user "+settings.ProcUser)
|
||||
lines = append(lines, "persist-tun")
|
||||
lines = append(lines, "persist-key")
|
||||
}
|
||||
|
||||
if !settings.IPv6 {
|
||||
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
||||
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
||||
}
|
||||
|
||||
lines = append(lines, utils.WrapOpenvpnCert(
|
||||
constants.ExpressvpnCert)...)
|
||||
lines = append(lines, utils.WrapOpenvpnRSAKey(
|
||||
constants.ExpressvpnRSAKey)...)
|
||||
lines = append(lines, utils.WrapOpenvpnTLSAuth(
|
||||
constants.ExpressvpnTLSAuthOpenvpnStaticKeyV1)...)
|
||||
lines = append(lines, utils.WrapOpenvpnCA(
|
||||
constants.ExpressvpnCA)...)
|
||||
|
||||
lines = append(lines, "")
|
||||
|
||||
return lines, nil
|
||||
}
|
||||
23
internal/provider/expressvpn/provider.go
Normal file
23
internal/provider/expressvpn/provider.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package expressvpn
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||
)
|
||||
|
||||
type Provider struct {
|
||||
servers []models.ExpressvpnServer
|
||||
randSource rand.Source
|
||||
utils.NoPortForwarder
|
||||
}
|
||||
|
||||
func New(servers []models.ExpressvpnServer, randSource rand.Source) *Provider {
|
||||
return &Provider{
|
||||
servers: servers,
|
||||
randSource: randSource,
|
||||
NoPortForwarder: utils.NewNoPortForwarding(constants.Expressvpn),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user