Commit ee125793 authored by Jose Blaya's avatar Jose Blaya

Refactor

parent 9f54f2d6
......@@ -159,6 +159,8 @@ public class Server: Hashable {
public let dipToken: String?
public let dipStatus: DedicatedIPStatus?
public let dipUsername: String?
var isAutomatic: Bool
......@@ -180,6 +182,7 @@ public class Server: Hashable {
dipExpire: Date? = nil,
dipToken: String? = nil,
dipStatus: DedicatedIPStatus? = nil,
dipUsername: String? = nil,
regionIdentifier: String) {
self.serial = serial
......@@ -202,7 +205,8 @@ public class Server: Hashable {
self.dipExpire = dipExpire
self.dipToken = dipToken
self.dipStatus = dipStatus
self.dipUsername = dipUsername
isAutomatic = false
}
......@@ -293,16 +297,9 @@ extension Server {
}
extension Server {
func dipUsername() -> String? {
if let dipToken = dipToken {
return "dedicated_ip_"+dipToken+"_"+String.random(length: 8)
}
return nil
}
func dipPassword() -> Data? {
if let dipUsername = dipToken {
if let dipUsername = dipUsername {
return Client.database.secure.passwordReference(forDipToken: dipUsername)
}
return nil
......
......@@ -167,9 +167,9 @@ public class IKEv2Profile: NetworkExtensionProfile {
var iKEv2Username = ""
var iKEv2Password: Data?
if let dipUsername = configuration.server.dipUsername() { //override the username if DIP
if let dipUsername = configuration.server.dipUsername, let dipToken = configuration.server.dipToken { //override the username if DIP
iKEv2Username = dipUsername
iKEv2Password = Client.database.secure.passwordReference(forDipToken: dipUsername)
iKEv2Password = configuration.server.dipPassword()
} else {
if let username = Client.providers.accountProvider.token {
iKEv2Username = username
......
......@@ -248,13 +248,15 @@ class PIAWebServices: WebServices, ConfigurationAccess {
let status = DedicatedIPStatus(fromAPIStatus: dipServer.status)
let server = Server.ServerAddressIP(ip: ip, cn: cn)
let dipRegion = Server(serial: firstServer.serial, name: firstServer.name, country: firstServer.country, hostname: firstServer.hostname, openVPNAddressesForTCP: [server], openVPNAddressesForUDP: [server], wireGuardAddressesForUDP: [server], iKEv2AddressesForUDP: [server], pingAddress: firstServer.pingAddress, geo: false, meta: nil, dipExpire: expiringDate, dipToken: dipServer.dipToken, dipStatus: status, regionIdentifier: firstServer.regionIdentifier)
let dipUsername = "dedicated_ip_"+dipServer.dipToken+"_"+String.random(length: 8)
let dipRegion = Server(serial: firstServer.serial, name: firstServer.name, country: firstServer.country, hostname: firstServer.hostname, openVPNAddressesForTCP: [server], openVPNAddressesForUDP: [server], wireGuardAddressesForUDP: [server], iKEv2AddressesForUDP: [server], pingAddress: firstServer.pingAddress, geo: false, meta: nil, dipExpire: expiringDate, dipToken: dipServer.dipToken, dipStatus: status, dipUsername: dipUsername, regionIdentifier: firstServer.regionIdentifier)
dipRegions.append(dipRegion)
if status == .active {
Client.database.secure.setDIPToken(dipServer.dipToken)
Client.database.secure.setPassword(ip, forDipToken: dipServer.dipToken)
Client.database.secure.setPassword(ip, forDipToken: dipUsername)
}
}
......
......@@ -249,8 +249,8 @@ public class PIATunnelProfile: NetworkExtensionProfile {
let cfg = NETunnelProviderProtocol()
cfg.disconnectOnSleep = configuration.disconnectsOnSleep
cfg.username = configuration.server.dipUsername() != nil ? configuration.server.dipUsername() : configuration.username
cfg.passwordReference = configuration.server.dipUsername() != nil ? configuration.server.dipPassword() : configuration.passwordReference
cfg.username = configuration.server.dipUsername != nil ? configuration.server.dipUsername : configuration.username
cfg.passwordReference = configuration.server.dipUsername != nil ? configuration.server.dipPassword() : configuration.passwordReference
cfg.serverAddress = serverAddress
cfg.providerBundleIdentifier = bundleIdentifier
cfg.providerConfiguration = customCfg?.serialized()
......
......@@ -250,7 +250,7 @@ public class PIAWGTunnelProfile: NetworkExtensionProfile {
cfg.username = Client.providers.accountProvider.publicUsername
cfg.disconnectOnSleep = configuration.disconnectsOnSleep
let token = configuration.server.dipUsername() != nil ? configuration.server.dipUsername() : 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.bestAddress()?.description,
......
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