From 66667f94e1cc9bb8af3e5586be4f08a1308853d3 Mon Sep 17 00:00:00 2001 From: "Quentin McGaw (desktop)" Date: Mon, 10 Feb 2020 18:17:22 +0000 Subject: [PATCH] Refactored region parsing for PIA --- internal/constants/pia.go | 220 +++++++++++--------------------------- internal/models/alias.go | 2 +- internal/params/pia.go | 4 +- internal/pia/conf.go | 6 +- 4 files changed, 71 insertions(+), 161 deletions(-) diff --git a/internal/constants/pia.go b/internal/constants/pia.go index a1bc1b92..cd09c175 100644 --- a/internal/constants/pia.go +++ b/internal/constants/pia.go @@ -1,6 +1,9 @@ package constants import ( + "fmt" + "strings" + "github.com/qdm12/private-internet-access-docker/internal/models" ) @@ -18,163 +21,68 @@ const ( PIACertificate_STRONG = "MIIHqzCCBZOgAwIBAgIJAJ0u+vODZJntMA0GCSqGSIb3DQEBDQUAMIHoMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNVBAcTCkxvc0FuZ2VsZXMxIDAeBgNVBAoTF1ByaXZhdGUgSW50ZXJuZXQgQWNjZXNzMSAwHgYDVQQLExdQcml2YXRlIEludGVybmV0IEFjY2VzczEgMB4GA1UEAxMXUHJpdmF0ZSBJbnRlcm5ldCBBY2Nlc3MxIDAeBgNVBCkTF1ByaXZhdGUgSW50ZXJuZXQgQWNjZXNzMS8wLQYJKoZIhvcNAQkBFiBzZWN1cmVAcHJpdmF0ZWludGVybmV0YWNjZXNzLmNvbTAeFw0xNDA0MTcxNzQwMzNaFw0zNDA0MTIxNzQwMzNaMIHoMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEzARBgNVBAcTCkxvc0FuZ2VsZXMxIDAeBgNVBAoTF1ByaXZhdGUgSW50ZXJuZXQgQWNjZXNzMSAwHgYDVQQLExdQcml2YXRlIEludGVybmV0IEFjY2VzczEgMB4GA1UEAxMXUHJpdmF0ZSBJbnRlcm5ldCBBY2Nlc3MxIDAeBgNVBCkTF1ByaXZhdGUgSW50ZXJuZXQgQWNjZXNzMS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gQWNjZXNzMSAwHgYDVQQDExdQcml2YXRlIEludGVybmV0IEFjY2VzczEgMB4GA1UEKRMXUHJpdmF0ZSBJbnRlcm5ldCBBY2Nlc3MxLzAtBgkqhkiG9w0BCQEWIHNlY3VyZUBwcml2YXRlaW50ZXJuZXRhY2Nlc3MuY29tggkAnS7684Nkme0wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQ0FAAOCAgEAJsfhsPk3r8kLXLxY+v+vHzbr4ufNtqnL9/1Uuf8NrsCtpXAoyZ0YqfbkWx3NHTZ7OE9ZRhdMP/RqHQE1p4N4Sa1nZKhTKasV6KhHDqSCt/dvEm89xWm2MVA7nyzQxVlHa9AkcBaemcXEiyT19XdpiXOP4Vhs+J1R5m8zQOxZlV1GtF9vsXmJqWZpOVPmZ8f35BCsYPvv4yMewnrtAC8PFEK/bOPeYcKN50bol22QYaZuLfpkHfNiFTnfMh8sl/ablPyNY7DUNiP5DRcMdIwmfGQxR5WEQoHL3yPJ42LkB5zs6jIm26DGNXfwura/mi105+ENH1CaROtRYwkiHb08U6qLXXJz80mWJkT90nr8Asj35xN2cUppg74nG3YVav/38P48T56hG1NHbYF5uOCske19F6wi9maUoto/3vEr0rnXJUp2KODmKdvBI7co245lHBABWikk8VfejQSlCtDBXn644ZMtAdoxKNfR2WTFVEwJiyd1Fzx0yujuiXDROLhISLQDRjVVAvawrAtLZWYK31bY7KlezPlQnl/D9Asxe85l8jO5+0LdJ6VyOs/Hd4w52alDW/MFySDZSfQHMTIc30hLBJ8OnCEIvluVQQ2UQvoW+no177N9L2Y+M9TcTA62ZyMXShHQGeh20rb4kK8f+iFX8NxtdHVSkxMEFSfDDyQ=" ) -const ( - AUMelbourne models.PIARegion = "AU Melbourne" - AUPerth models.PIARegion = "AU Perth" - AUSydney models.PIARegion = "AU Sydney" - Austria models.PIARegion = "Austria" - Belgium models.PIARegion = "Belgium" - CAMontreal models.PIARegion = "CA Montreal" - CAToronto models.PIARegion = "CA Toronto" - CAVancouver models.PIARegion = "CA Vancouver" - CzechRepublic models.PIARegion = "Czech Republic" - DEBerlin models.PIARegion = "DE Berlin" - DEFrankfurt models.PIARegion = "DE Frankfurt" - Denmark models.PIARegion = "Denmark" - Finland models.PIARegion = "Finland" - France models.PIARegion = "France" - HongKong models.PIARegion = "Hong Kong" - Hungary models.PIARegion = "Hungary" - India models.PIARegion = "India" - Ireland models.PIARegion = "Ireland" - Israel models.PIARegion = "Israel" - Italy models.PIARegion = "Italy" - Japan models.PIARegion = "Japan" - Luxembourg models.PIARegion = "Luxembourg" - Mexico models.PIARegion = "Mexico" - Netherlands models.PIARegion = "Netherlands" - NewZealand models.PIARegion = "New Zealand" - Norway models.PIARegion = "Norway" - Poland models.PIARegion = "Poland" - Romania models.PIARegion = "Romania" - Singapore models.PIARegion = "Singapore" - Spain models.PIARegion = "Spain" - Sweden models.PIARegion = "Sweden" - Switzerland models.PIARegion = "Switzerland" - UAE models.PIARegion = "UAE" - UKLondon models.PIARegion = "UK London" - UKManchester models.PIARegion = "UK Manchester" - UKSouthampton models.PIARegion = "UK Southampton" - USAtlanta models.PIARegion = "US Atlanta" - USCalifornia models.PIARegion = "US California" - USChicago models.PIARegion = "US Chicago" - USDenver models.PIARegion = "US Denver" - USEast models.PIARegion = "US East" - USFlorida models.PIARegion = "US Florida" - USHouston models.PIARegion = "US Houston" - USLasVegas models.PIARegion = "US Las Vegas" - USNewYorkCity models.PIARegion = "US New York City" - USSeattle models.PIARegion = "US Seattle" - USSiliconValley models.PIARegion = "US Silicon Valley" - USTexas models.PIARegion = "US Texas" - USWashingtonDC models.PIARegion = "US Washington DC" - USWest models.PIARegion = "US West" -) +func PIAGeoChoices() []string { + return []string{"AU Melbourne", "AU Perth", "AU Sydney", "Austria", "Belgium", "CA Montreal", "CA Toronto", "CA Vancouver", "Czech Republic", "DE Berlin", "DE Frankfurt", "Denmark", "Finland", "France", "Hong Kong", "Hungary", "India", "Ireland", "Israel", "Italy", "Japan", "Luxembourg", "Mexico", "Netherlands", "New Zealand", "Norway", "Poland", "Romania", "Singapore", "Spain", "Sweden", "Switzerland", "UAE", "UK London", "UK Manchester", "UK Southampton", "US Atlanta", "US California", "US Chicago", "US Denver", "US East", "US Florida", "US Houston", "US Las Vegas", "US New York City", "US Seattle", "US Silicon Valley", "US Texas", "US Washington DC", "US West"} +} -const ( - PIASubdomainAUMelbourne string = "au-melbourne" - PIASubdomainAUPerth string = "au-perth" - PIASubdomainAUSydney string = "au-sydney" - PIASubdomainAustria string = "austria" - PIASubdomainBelgium string = "belgium" - PIASubdomainCAMontreal string = "ca-montreal" - PIASubdomainCAToronto string = "ca-toronto" - PIASubdomainCAVancouver string = "ca-vancouver" - PIASubdomainCzechRepublic string = "czech" - PIASubdomainDEBerlin string = "de-berlin" - PIASubdomainDEFrankfurt string = "de-frankfurt" - PIASubdomainDenmark string = "denmark" - PIASubdomainFinland string = "fi" - PIASubdomainFrance string = "france" - PIASubdomainHongKong string = "hk" - PIASubdomainHungary string = "hungary" - PIASubdomainIndia string = "in" - PIASubdomainIreland string = "ireland" - PIASubdomainIsrael string = "israel" - PIASubdomainItaly string = "italy" - PIASubdomainJapan string = "japan" - PIASubdomainLuxembourg string = "lu" - PIASubdomainMexico string = "mexico" - PIASubdomainNetherlands string = "nl" - PIASubdomainNewZealand string = "nz" - PIASubdomainNorway string = "no" - PIASubdomainPoland string = "poland" - PIASubdomainRomania string = "ro" - PIASubdomainSingapore string = "sg" - PIASubdomainSpain string = "spain" - PIASubdomainSweden string = "sweden" - PIASubdomainSwitzerland string = "swiss" - PIASubdomainUAE string = "ae" - PIASubdomainUKLondon string = "uk-london" - PIASubdomainUKManchester string = "uk-manchester" - PIASubdomainUKSouthampton string = "uk-southampton" - PIASubdomainUSAtlanta string = "us-atlanta" - PIASubdomainUSCalifornia string = "us-california" - PIASubdomainUSChicago string = "us-chicago" - PIASubdomainUSDenver string = "us-denver" - PIASubdomainUSEast string = "us-east" - PIASubdomainUSFlorida string = "us-florida" - PIASubdomainUSHouston string = "us-houston" - PIASubdomainUSLasVegas string = "us-lasvegas" - PIASubdomainUSNewYorkCity string = "us-newyorkcity" - PIASubdomainUSSeattle string = "us-seattle" - PIASubdomainUSSiliconValley string = "us-siliconvalley" - PIASubdomainUSTexas string = "us-texas" - PIASubdomainUSWashingtonDC string = "us-washingtondc" - PIASubdomainUSWest string = "us-west" -) - -var PIARegionToSubdomainMapping = map[models.PIARegion]string{ - AUMelbourne: PIASubdomainAUMelbourne, - AUPerth: PIASubdomainAUPerth, - AUSydney: PIASubdomainAUSydney, - Austria: PIASubdomainAustria, - Belgium: PIASubdomainBelgium, - CAMontreal: PIASubdomainCAMontreal, - CAToronto: PIASubdomainCAToronto, - CAVancouver: PIASubdomainCAVancouver, - CzechRepublic: PIASubdomainCzechRepublic, - DEBerlin: PIASubdomainDEBerlin, - DEFrankfurt: PIASubdomainDEFrankfurt, - Denmark: PIASubdomainDenmark, - Finland: PIASubdomainFinland, - France: PIASubdomainFrance, - HongKong: PIASubdomainHongKong, - Hungary: PIASubdomainHungary, - India: PIASubdomainIndia, - Ireland: PIASubdomainIreland, - Israel: PIASubdomainIsrael, - Italy: PIASubdomainItaly, - Japan: PIASubdomainJapan, - Luxembourg: PIASubdomainLuxembourg, - Mexico: PIASubdomainMexico, - Netherlands: PIASubdomainNetherlands, - NewZealand: PIASubdomainNewZealand, - Norway: PIASubdomainNorway, - Poland: PIASubdomainPoland, - Romania: PIASubdomainRomania, - Singapore: PIASubdomainSingapore, - Spain: PIASubdomainSpain, - Sweden: PIASubdomainSweden, - Switzerland: PIASubdomainSwitzerland, - UAE: PIASubdomainUAE, - UKLondon: PIASubdomainUKLondon, - UKManchester: PIASubdomainUKManchester, - UKSouthampton: PIASubdomainUKSouthampton, - USAtlanta: PIASubdomainUSAtlanta, - USCalifornia: PIASubdomainUSCalifornia, - USChicago: PIASubdomainUSChicago, - USDenver: PIASubdomainUSDenver, - USEast: PIASubdomainUSEast, - USFlorida: PIASubdomainUSFlorida, - USHouston: PIASubdomainUSHouston, - USLasVegas: PIASubdomainUSLasVegas, - USNewYorkCity: PIASubdomainUSNewYorkCity, - USSeattle: PIASubdomainUSSeattle, - USSiliconValley: PIASubdomainUSSiliconValley, - USTexas: PIASubdomainUSTexas, - USWashingtonDC: PIASubdomainUSWashingtonDC, - USWest: PIASubdomainUSWest, +func PIAGeoToSubdomainMapping(region models.PIARegion) (subdomain string, err error) { + mapping := map[models.PIARegion]string{ + models.PIARegion("AU Melbourne"): "au-melbourne", + models.PIARegion("AU Perth"): "au-perth", + models.PIARegion("AU Sydney"): "au-sydney", + models.PIARegion("Austria"): "austria", + models.PIARegion("Belgium"): "belgium", + models.PIARegion("CA Montreal"): "ca-montreal", + models.PIARegion("CA Toronto"): "ca-toronto", + models.PIARegion("CA Vancouver"): "ca-vancouver", + models.PIARegion("Czech Republic"): "czech", + models.PIARegion("DE Berlin"): "de-berlin", + models.PIARegion("DE Frankfurt"): "de-frankfurt", + models.PIARegion("Denmark"): "denmark", + models.PIARegion("Finland"): "fi", + models.PIARegion("France"): "france", + models.PIARegion("Hong Kong"): "hk", + models.PIARegion("Hungary"): "hungary", + models.PIARegion("India"): "in", + models.PIARegion("Ireland"): "ireland", + models.PIARegion("Israel"): "israel", + models.PIARegion("Italy"): "italy", + models.PIARegion("Japan"): "japan", + models.PIARegion("Luxembourg"): "lu", + models.PIARegion("Mexico"): "mexico", + models.PIARegion("Netherlands"): "nl", + models.PIARegion("New Zealand"): "nz", + models.PIARegion("Norway"): "no", + models.PIARegion("Poland"): "poland", + models.PIARegion("Romania"): "ro", + models.PIARegion("Singapore"): "sg", + models.PIARegion("Spain"): "spain", + models.PIARegion("Sweden"): "sweden", + models.PIARegion("Switzerland"): "swiss", + models.PIARegion("UAE"): "ae", + models.PIARegion("UK London"): "uk-london", + models.PIARegion("UK Manchester"): "uk-manchester", + models.PIARegion("UK Southampton"): "uk-southampton", + models.PIARegion("US Atlanta"): "us-atlanta", + models.PIARegion("US California"): "us-california", + models.PIARegion("US Chicago"): "us-chicago", + models.PIARegion("US Denver"): "us-denver", + models.PIARegion("US East"): "us-east", + models.PIARegion("US Florida"): "us-florida", + models.PIARegion("US Houston"): "us-houston", + models.PIARegion("US Las Vegas"): "us-lasvegas", + models.PIARegion("US New York City"): "us-newyorkcity", + models.PIARegion("US Seattle"): "us-seattle", + models.PIARegion("US Silicon Valley"): "us-siliconvalley", + models.PIARegion("US Texas"): "us-texas", + models.PIARegion("US Washington DC"): "us-washingtondc", + models.PIARegion("US West"): "us-west", + } + subdomain, ok := mapping[region] + if !ok { + return "", fmt.Errorf("PIA region %q does not exist and can only be one of ", strings.Join(PIAGeoChoices(), ",")) + } + return subdomain, nil } const ( diff --git a/internal/models/alias.go b/internal/models/alias.go index 05d6fc8b..532ad77e 100644 --- a/internal/models/alias.go +++ b/internal/models/alias.go @@ -9,7 +9,7 @@ type ( DNSHost string // PIAEncryption defines the level of encryption for communication with PIA servers PIAEncryption string - // PIARegion contains the list of regions available for PIA + // PIARegion is used to define the list of regions available for PIA PIARegion string // URL is an HTTP(s) URL address URL string diff --git a/internal/params/pia.go b/internal/params/pia.go index c66edff7..bee3952e 100644 --- a/internal/params/pia.go +++ b/internal/params/pia.go @@ -76,9 +76,7 @@ func (p *paramsReader) GetPIAEncryption() (models.PIAEncryption, error) { // GetPIARegion obtains the region for the PIA server from the // environment variable REGION func (p *paramsReader) GetPIARegion() (region models.PIARegion, err error) { - choices := []string{ - string(constants.AUMelbourne), string(constants.AUPerth), string(constants.AUSydney), string(constants.Austria), string(constants.Belgium), string(constants.CAMontreal), string(constants.CAToronto), string(constants.CAVancouver), string(constants.CzechRepublic), string(constants.DEBerlin), string(constants.DEFrankfurt), string(constants.Denmark), string(constants.Finland), string(constants.France), string(constants.HongKong), string(constants.Hungary), string(constants.India), string(constants.Ireland), string(constants.Israel), string(constants.Italy), string(constants.Japan), string(constants.Luxembourg), string(constants.Mexico), string(constants.Netherlands), string(constants.NewZealand), string(constants.Norway), string(constants.Poland), string(constants.Romania), string(constants.Singapore), string(constants.Spain), string(constants.Sweden), string(constants.Switzerland), string(constants.UAE), string(constants.UKLondon), string(constants.UKManchester), string(constants.UKSouthampton), string(constants.USAtlanta), string(constants.USCalifornia), string(constants.USChicago), string(constants.USDenver), string(constants.USEast), string(constants.USFlorida), string(constants.USHouston), string(constants.USLasVegas), string(constants.USNewYorkCity), string(constants.USSeattle), string(constants.USSiliconValley), string(constants.USTexas), string(constants.USWashingtonDC), string(constants.USWest), - } + choices := constants.PIAGeoChoices() s, err := p.envParams.GetValueIfInside("REGION", choices) if len(s) == 0 { // Suggestion by @rorph https://github.com/rorph s = choices[rand.Int()%len(choices)] diff --git a/internal/pia/conf.go b/internal/pia/conf.go index a0ee6f09..b9e858c9 100644 --- a/internal/pia/conf.go +++ b/internal/pia/conf.go @@ -34,7 +34,10 @@ func (c *configurator) BuildConf(region models.PIARegion, protocol models.Networ port = 501 } } - subdomain := constants.PIARegionToSubdomainMapping[region] + subdomain, err := constants.PIAGeoToSubdomainMapping(region) + if err != nil { + return nil, 0, err + } IPs, err = c.lookupIP(subdomain + ".privateinternetaccess.com") if err != nil { return nil, 0, err @@ -56,6 +59,7 @@ func (c *configurator) BuildConf(region models.PIARegion, protocol models.Networ "pull-filter ignore \"auth-token\"", // prevent auth failed loops "auth-retry nointeract", "disable-occ", + "remote-random", // Modified variables fmt.Sprintf("auth-user-pass %s", constants.OpenVPNAuthConf),