Commit 453b3cad authored by Jose Blaya's avatar Jose Blaya
Browse files

Connect to DIP regions

parent c0324c8c
......@@ -300,3 +300,20 @@ extension Server {
}
}
extension Server {
func dipUsername() -> String? {
if let dipToken = dipToken {
return "dedicated_ip_"+dipToken
}
return nil
}
func dipPassword() -> String? {
if let _ = dipToken, let address = bestAddressForIKEv2() {
return address.ip
}
return nil
}
}
......@@ -170,7 +170,16 @@ public class IKEv2Profile: NetworkExtensionProfile {
if let username = Client.providers.accountProvider.token {
iKEv2Username = username
}
if let dipUsername = configuration.server.dipUsername() { //override the username if DIP
iKEv2Username = dipUsername
}
iKEv2Password = ikev2PasswordReference()
if let dipPassword = configuration.server.dipPassword() { //override the password if DIP
iKEv2Password = dipPassword.data(using: .utf8)
}
let cfg = NEVPNProtocolIKEv2()
if let ip = configuration.server.bestAddressForIKEv2()?.ip {
......
......@@ -223,6 +223,7 @@ class PIAWebServices: WebServices, ConfigurationAccess {
}
func activateDIPToken(tokens: [String], _ callback: LibraryCallback<[Server]>?) {
if let token = Client.providers.accountProvider.token {
self.accountAPI.dedicatedIPs(token: token, ipTokens: tokens) { (dedicatedIps, error) in
if let _ = error {
......@@ -234,8 +235,7 @@ class PIAWebServices: WebServices, ConfigurationAccess {
for dipServer in dedicatedIps {
if dipServer.status == DedicatedIPInformationResponse.Status.active {
//Replace ES with dipServer.id
guard let firstServer = Client.providers.serverProvider.currentServers.first(where: {$0.country == "ES"}) else {
guard let firstServer = Client.providers.serverProvider.currentServers.first(where: {$0.country == dipServer.id}) else {
callback?([], ClientError.malformedResponseData)
return
}
......
......@@ -231,8 +231,8 @@ public class PIATunnelProfile: NetworkExtensionProfile {
let cfg = NETunnelProviderProtocol()
cfg.disconnectOnSleep = configuration.disconnectsOnSleep
cfg.username = configuration.username
cfg.passwordReference = configuration.passwordReference
cfg.username = configuration.server.dipUsername() != nil ? configuration.server.dipUsername() : configuration.username
cfg.passwordReference = configuration.server.dipPassword() != nil ? configuration.server.dipPassword()?.data(using: .utf8) : configuration.passwordReference
cfg.serverAddress = configuration.server.hostname
cfg.providerBundleIdentifier = bundleIdentifier
......
......@@ -250,7 +250,9 @@ public class PIAWGTunnelProfile: NetworkExtensionProfile {
cfg.username = Client.providers.accountProvider.publicUsername
cfg.disconnectOnSleep = configuration.disconnectsOnSleep
cfg.providerConfiguration = [PIAWireguardConfiguration.Keys.token: Client.providers.accountProvider.token,
let token = configuration.server.dipUsername() != nil ? configuration.server.dipUsername() : Client.providers.accountProvider.token
cfg.providerConfiguration = [PIAWireguardConfiguration.Keys.token: token,
PIAWireguardConfiguration.Keys.ping: configuration.server.bestPingAddress().first?.description,
PIAWireguardConfiguration.Keys.serial: configuration.server.serial,
PIAWireguardConfiguration.Keys.cn: serverCN,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment