From 6b7e1bf6afdee02f3a5fb08239ba4dfea1331e57 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Wed, 5 Jul 2023 12:56:00 +0200 Subject: [PATCH 01/20] feat(antitracker): create AntiTrackerDns.swift --- IVPNClient.xcodeproj/project.pbxproj | 4 ++++ IVPNClient/Models/AntiTrackerDns.swift | 31 ++++++++++++++++++++++++++ IVPNClient/Models/Application.swift | 3 +++ 3 files changed, 38 insertions(+) create mode 100644 IVPNClient/Models/AntiTrackerDns.swift diff --git a/IVPNClient.xcodeproj/project.pbxproj b/IVPNClient.xcodeproj/project.pbxproj index faffe8b45..53c35be8b 100644 --- a/IVPNClient.xcodeproj/project.pbxproj +++ b/IVPNClient.xcodeproj/project.pbxproj @@ -106,6 +106,7 @@ 825E834F25A327EB00938240 /* CaptchaViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825E834E25A327EB00938240 /* CaptchaViewController.swift */; }; 825E836325A4834200938240 /* APIPublicKeyPin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825E836225A4834200938240 /* APIPublicKeyPin.swift */; }; 825E836425A4834200938240 /* APIPublicKeyPin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825E836225A4834200938240 /* APIPublicKeyPin.swift */; }; + 825ECB2C2A5582570032E986 /* AntiTrackerDns.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825ECB2B2A5582570032E986 /* AntiTrackerDns.swift */; }; 826470C42446F67100403A14 /* Signup.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 826470C32446F67100403A14 /* Signup.storyboard */; }; 8264CFFC22422F6700E1721E /* Date+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D90470216C7DAF0032F3BE /* Date+Ext.swift */; }; 8269CAC32264962F00CF488A /* AntiTrackerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8269CAC22264962F00CF488A /* AntiTrackerViewController.swift */; }; @@ -529,6 +530,7 @@ 825A43FC215CCFE70076131F /* UserDefaults+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Ext.swift"; sourceTree = ""; }; 825E834E25A327EB00938240 /* CaptchaViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaptchaViewController.swift; sourceTree = ""; }; 825E836225A4834200938240 /* APIPublicKeyPin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIPublicKeyPin.swift; sourceTree = ""; }; + 825ECB2B2A5582570032E986 /* AntiTrackerDns.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AntiTrackerDns.swift; sourceTree = ""; }; 826470C32446F67100403A14 /* Signup.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Signup.storyboard; sourceTree = ""; }; 8269CAC22264962F00CF488A /* AntiTrackerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AntiTrackerViewController.swift; sourceTree = ""; }; 8269CD8E2164A8C700D083A1 /* servers-dev.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "servers-dev.json"; sourceTree = ""; }; @@ -995,6 +997,7 @@ 8243587025DBB73E005FDEBB /* SecureDNS.swift */, 827694F2263C04C40058B4DC /* LoginConfirmation.swift */, 821CA2DE288143470067F70D /* PortRange.swift */, + 825ECB2B2A5582570032E986 /* AntiTrackerDns.swift */, ); path = Models; sourceTree = ""; @@ -2280,6 +2283,7 @@ 9CC29DF81E1D59E90080F799 /* Alerts+Ext.swift in Sources */, 9CB2CE1F1DAA5258007A4D2D /* Authentication.swift in Sources */, 82DAB37B2457013900302F4C /* Service.swift in Sources */, + 825ECB2C2A5582570032E986 /* AntiTrackerDns.swift in Sources */, 82C2E5DF21620FF100C5A09F /* UIDevice+Ext.swift in Sources */, 8208525823FD5EB20008C112 /* MainViewController.swift in Sources */, 825E836325A4834200938240 /* APIPublicKeyPin.swift in Sources */, diff --git a/IVPNClient/Models/AntiTrackerDns.swift b/IVPNClient/Models/AntiTrackerDns.swift new file mode 100644 index 000000000..b1138b0bc --- /dev/null +++ b/IVPNClient/Models/AntiTrackerDns.swift @@ -0,0 +1,31 @@ +// +// AntiTrackerDns.swift +// IVPN iOS app +// https://github.com/ivpn/ios-app +// +// Created by Juraj Hilje on 2023-07-05. +// Copyright (c) 2023 Privatus Limited. +// +// This file is part of the IVPN iOS app. +// +// The IVPN iOS app is free software: you can redistribute it and/or +// modify it under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) any later version. +// +// The IVPN iOS app is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +// details. +// +// You should have received a copy of the GNU General Public License +// along with the IVPN iOS app. If not, see . +// + +import Foundation + +struct AntiTrackerDns: Codable { + let name: String + let description: String + let normal: String + let hardcore: String +} diff --git a/IVPNClient/Models/Application.swift b/IVPNClient/Models/Application.swift index 3eff575ad..025651219 100644 --- a/IVPNClient/Models/Application.swift +++ b/IVPNClient/Models/Application.swift @@ -66,6 +66,8 @@ class Application { var geoLookup = GeoLookup(ipAddress: "", countryCode: "", country: "", city: "", isIvpnServer: false, isp: "", latitude: 0, longitude: 0) + var antiTrackerList: [AntiTrackerDns] + static var isKeyPairRequired: Bool { return shared.settings.connectionProtocol.tunnelType() == .wireguard } @@ -78,6 +80,7 @@ class Application { authentication = Authentication() settings = Settings(serverList: serverList) connectionManager = ConnectionManager(settings: settings, authentication: authentication, vpnManager: VPNManager()) + antiTrackerList = [] } // MARK: - Methods - From 8009c05f28fe7cdd63a4c8673037d37b7a6f8a5b Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Thu, 6 Jul 2023 12:10:48 +0200 Subject: [PATCH 02/20] feat(antitracker): update AntiTrackerDns.swift --- IVPNClient/Models/AntiTrackerDns.swift | 18 ++++++++++++++++++ .../Extensions/UserDefaults+Ext.swift | 1 + 2 files changed, 19 insertions(+) diff --git a/IVPNClient/Models/AntiTrackerDns.swift b/IVPNClient/Models/AntiTrackerDns.swift index b1138b0bc..7466aa2cb 100644 --- a/IVPNClient/Models/AntiTrackerDns.swift +++ b/IVPNClient/Models/AntiTrackerDns.swift @@ -24,8 +24,26 @@ import Foundation struct AntiTrackerDns: Codable { + let name: String let description: String let normal: String let hardcore: String + + func save() { + if let encoded = try? JSONEncoder().encode(self) { + UserDefaults.standard.set(encoded, forKey: UserDefaults.Key.antiTrackerDns) + } + } + + static func load() -> AntiTrackerDns? { + if let saved = UserDefaults.standard.object(forKey: UserDefaults.Key.antiTrackerDns) as? Data { + if let loaded = try? JSONDecoder().decode(AntiTrackerDns.self, from: saved) { + return loaded + } + } + + return nil + } + } diff --git a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift index 8841dbd24..175959756 100644 --- a/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift +++ b/IVPNClient/Utilities/Extensions/UserDefaults+Ext.swift @@ -88,6 +88,7 @@ extension UserDefaults { static let killSwitch = "killSwitch" static let selectHost = "selectHost" static let isLoggedIn = "isLoggedIn" + static let antiTrackerDns = "antiTrackerDns" } @objc dynamic var wireguardTunnelProviderError: String { From b8d01c40b3996cbbf1ef715eaf1321059486931e Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Thu, 6 Jul 2023 12:44:27 +0200 Subject: [PATCH 03/20] feat(antitracker): update VPNServerList.swift --- IVPNClient/Models/Application.swift | 3 --- IVPNClient/Models/VPNServerList.swift | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/IVPNClient/Models/Application.swift b/IVPNClient/Models/Application.swift index 025651219..3eff575ad 100644 --- a/IVPNClient/Models/Application.swift +++ b/IVPNClient/Models/Application.swift @@ -66,8 +66,6 @@ class Application { var geoLookup = GeoLookup(ipAddress: "", countryCode: "", country: "", city: "", isIvpnServer: false, isp: "", latitude: 0, longitude: 0) - var antiTrackerList: [AntiTrackerDns] - static var isKeyPairRequired: Bool { return shared.settings.connectionProtocol.tunnelType() == .wireguard } @@ -80,7 +78,6 @@ class Application { authentication = Authentication() settings = Settings(serverList: serverList) connectionManager = ConnectionManager(settings: settings, authentication: authentication, vpnManager: VPNManager()) - antiTrackerList = [] } // MARK: - Methods - diff --git a/IVPNClient/Models/VPNServerList.swift b/IVPNClient/Models/VPNServerList.swift index 9a349b98e..81fcd32b9 100644 --- a/IVPNClient/Models/VPNServerList.swift +++ b/IVPNClient/Models/VPNServerList.swift @@ -33,6 +33,7 @@ class VPNServerList { open private(set) var servers: [VPNServer] open private(set) var ports: [ConnectionSettings] open private(set) var portRanges: [PortRange] + open private(set) var antiTrackerList: [AntiTrackerDns] var filteredFastestServers: [VPNServer] { if UserDefaults.standard.bool(forKey: UserDefaults.Key.fastestServerConfigured) { @@ -85,6 +86,7 @@ class VPNServerList { servers = [VPNServer]() ports = [ConnectionSettings]() portRanges = [PortRange]() + antiTrackerList = [AntiTrackerDns]() if let jsonData = data { var serversList: [[String: Any]]? @@ -132,6 +134,21 @@ class VPNServerList { } } + if let antiTrackerPlus = config["antitracker_plus"] as? [String: Any] { + if let jsonList = antiTrackerPlus["DnsServers"] as? [[String: Any]] { + var list = [AntiTrackerDns]() + for dns in jsonList { + list.append(AntiTrackerDns( + name: dns["Name"] as? String ?? "", + description: dns["Description"] as? String ?? "", + normal: dns["Normal"] as? String ?? "", + hardcore: dns["Hardcore"] as? String ?? "" + )) + } + antiTrackerList = list + } + } + if let api = config["api"] as? [String: Any] { if let ips = api["ips"] as? [String?] { UserDefaults.shared.set(ips, forKey: UserDefaults.Key.hostNames) From 93293bb5ac16a6f94c57f385fe816844388b94c9 Mon Sep 17 00:00:00 2001 From: Juraj Hilje Date: Thu, 6 Jul 2023 13:26:52 +0200 Subject: [PATCH 04/20] feat(antitracker): update AntiTracker view --- IVPNClient/Scenes/Base.lproj/Main.storyboard | 79 ++++++++++++++++++-- 1 file changed, 74 insertions(+), 5 deletions(-) diff --git a/IVPNClient/Scenes/Base.lproj/Main.storyboard b/IVPNClient/Scenes/Base.lproj/Main.storyboard index 37c5fb016..1e52560d9 100644 --- a/IVPNClient/Scenes/Base.lproj/Main.storyboard +++ b/IVPNClient/Scenes/Base.lproj/Main.storyboard @@ -21,7 +21,7 @@ - +