Skip to content

Commit

Permalink
Merge branch 'feature/antitracker-plus' into staging-2.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Jul 10, 2023
2 parents 8ac90e8 + a0b7b25 commit 51ae4a6
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 21 deletions.
14 changes: 14 additions & 0 deletions IVPNClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -163,6 +164,10 @@
829DF27D2497949A000DC2DB /* PlanLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 829DF27B2497949A000DC2DB /* PlanLabel.swift */; };
829DF27E2497949A000DC2DB /* SelectPlanView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 829DF27C2497949A000DC2DB /* SelectPlanView.swift */; };
829DF2822497953C000DC2DB /* UIButton+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 829DF2812497953C000DC2DB /* UIButton+Ext.swift */; };
829F5EAF2A56E067005919AF /* AntiTrackerListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 829F5EAE2A56E067005919AF /* AntiTrackerListViewController.swift */; };
829F5EB02A570322005919AF /* AntiTrackerDns.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825ECB2B2A5582570032E986 /* AntiTrackerDns.swift */; };
829F5EB12A570323005919AF /* AntiTrackerDns.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825ECB2B2A5582570032E986 /* AntiTrackerDns.swift */; };
829F5EB22A570323005919AF /* AntiTrackerDns.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825ECB2B2A5582570032E986 /* AntiTrackerDns.swift */; };
829F5FC729A13CAE009E1AD3 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 829F5FC629A13CAE009E1AD3 /* KeychainAccess */; };
829F5FC929A13CEA009E1AD3 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 829F5FC829A13CEA009E1AD3 /* KeychainAccess */; };
829F5FCB29A13CF2009E1AD3 /* KeychainAccess in Frameworks */ = {isa = PBXBuildFile; productRef = 829F5FCA29A13CF2009E1AD3 /* KeychainAccess */; };
Expand Down Expand Up @@ -528,6 +533,7 @@
825A43FC215CCFE70076131F /* UserDefaults+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Ext.swift"; sourceTree = "<group>"; };
825E834E25A327EB00938240 /* CaptchaViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaptchaViewController.swift; sourceTree = "<group>"; };
825E836225A4834200938240 /* APIPublicKeyPin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIPublicKeyPin.swift; sourceTree = "<group>"; };
825ECB2B2A5582570032E986 /* AntiTrackerDns.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AntiTrackerDns.swift; sourceTree = "<group>"; };
826470C32446F67100403A14 /* Signup.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Signup.storyboard; sourceTree = "<group>"; };
8269CAC22264962F00CF488A /* AntiTrackerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AntiTrackerViewController.swift; sourceTree = "<group>"; };
8269CD8E2164A8C700D083A1 /* servers-dev.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "servers-dev.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -573,6 +579,7 @@
829DF27B2497949A000DC2DB /* PlanLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlanLabel.swift; sourceTree = "<group>"; };
829DF27C2497949A000DC2DB /* SelectPlanView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectPlanView.swift; sourceTree = "<group>"; };
829DF2812497953C000DC2DB /* UIButton+Ext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIButton+Ext.swift"; sourceTree = "<group>"; };
829F5EAE2A56E067005919AF /* AntiTrackerListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AntiTrackerListViewController.swift; sourceTree = "<group>"; };
82A160B8221C4E2000730577 /* Server+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Server+CoreDataClass.swift"; sourceTree = "<group>"; };
82A160B9221C4E2000730577 /* Server+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Server+CoreDataProperties.swift"; sourceTree = "<group>"; };
82A3422224AB660C00761AB0 /* ApplicationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -993,6 +1000,7 @@
8243587025DBB73E005FDEBB /* SecureDNS.swift */,
827694F2263C04C40058B4DC /* LoginConfirmation.swift */,
821CA2DE288143470067F70D /* PortRange.swift */,
825ECB2B2A5582570032E986 /* AntiTrackerDns.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -1237,6 +1245,7 @@
821CA2D6287C5AB20067F70D /* PortViewController.swift */,
82AB0874291A6B5F0084625A /* AddCustomPortViewController.swift */,
82052E5529C1D83700227CF9 /* MTUViewController.swift */,
829F5EAE2A56E067005919AF /* AntiTrackerListViewController.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -2094,6 +2103,7 @@
82EEB6CD25F9422900915837 /* DNSProtocolType.swift in Sources */,
820EA86C2322430700E16B2D /* Result.swift in Sources */,
823FFB092338E09A00F91A5D /* Capability.swift in Sources */,
829F5EB12A570323005919AF /* AntiTrackerDns.swift in Sources */,
82DC75BD22B7647500D3C73C /* APIClient.swift in Sources */,
825E836425A4834200938240 /* APIPublicKeyPin.swift in Sources */,
823BD9E4231D4C8F002E631D /* ErrorResult.swift in Sources */,
Expand Down Expand Up @@ -2145,6 +2155,7 @@
82C61DA929E6C53C00AF972A /* Array+Ext.swift in Sources */,
82A38A1029E2D46000C88372 /* StatusViewModel.swift in Sources */,
8206BAFC29ED6C9600F916B7 /* Notification.swift in Sources */,
829F5EB22A570323005919AF /* AntiTrackerDns.swift in Sources */,
82A38A1B29E3201F00C88372 /* UserDefaults.swift in Sources */,
82C61D9929E6B4C600AF972A /* LocationView.swift in Sources */,
82E3B21E29DDD32B00998F67 /* MainView.swift in Sources */,
Expand All @@ -2169,6 +2180,7 @@
82E716932181E90500D6B7C2 /* ConnectionSettings.swift in Sources */,
82ED17592A1262F800E7926D /* Data+Ext.swift in Sources */,
823FFB082338E09900F91A5D /* Capability.swift in Sources */,
829F5EB02A570322005919AF /* AntiTrackerDns.swift in Sources */,
82ED17482A125C9100E7926D /* TimerManager.swift in Sources */,
826F7F4323A7AAD200777DB9 /* Array+Ext.swift in Sources */,
82ED17542A1261A000E7926D /* x25519.c in Sources */,
Expand Down Expand Up @@ -2276,6 +2288,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 */,
Expand Down Expand Up @@ -2322,6 +2335,7 @@
82C293BF21CCD49A000B74EC /* NavigationController.swift in Sources */,
82061F67238D2730009DDF4D /* PingManager.swift in Sources */,
9CDDD5AF1D9D2F9F00D39924 /* AppDelegate.swift in Sources */,
829F5EAF2A56E067005919AF /* AntiTrackerListViewController.swift in Sources */,
82CE59A725ED491B0078099D /* DNSResolver.swift in Sources */,
82BBF26121AD213500589766 /* Theme.swift in Sources */,
829AA4732267372A00037198 /* Designable+Ext.swift in Sources */,
Expand Down
55 changes: 55 additions & 0 deletions IVPNClient/Models/AntiTrackerDns.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// 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 <https://www.gnu.org/licenses/>.
//

import Foundation

struct AntiTrackerDns: Codable {

let name: String
let description: String
let normal: String
let hardcore: String

static let basicList = ["Basic", "Comprehensive", "Restrictive"]

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
}

static func == (lhs: AntiTrackerDns, rhs: AntiTrackerDns) -> Bool {
return lhs.name == rhs.name && lhs.normal == rhs.normal
}

}
32 changes: 24 additions & 8 deletions IVPNClient/Models/VPNServerList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -47,6 +48,14 @@ class VPNServerList {
return serversWithPing.isEmpty
}

var antiTrackerBasicList: [AntiTrackerDns] {
return antiTrackerList.filter { AntiTrackerDns.basicList.contains($0.name) }
}

var antiTrackerIndividualList: [AntiTrackerDns] {
return antiTrackerList.filter { !AntiTrackerDns.basicList.contains($0.name) }
}

// MARK: - Initialize -

// This initializer without parameters will try to load either cached servers.json file
Expand Down Expand Up @@ -85,6 +94,7 @@ class VPNServerList {
servers = [VPNServer]()
ports = [ConnectionSettings]()
portRanges = [PortRange]()
antiTrackerList = [AntiTrackerDns]()

if let jsonData = data {
var serversList: [[String: Any]]?
Expand Down Expand Up @@ -119,15 +129,21 @@ class VPNServerList {
}

if let config = config {
if let antitracker = config["antitracker"] as? [String: Any] {
if let defaultObj = antitracker["default"] as? [String: Any] {
if let ipAddress = defaultObj["ip"] as? String {
UserDefaults.shared.set(ipAddress, forKey: UserDefaults.Key.antiTrackerDNS)
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 ?? ""
))
}
}
if let hardcore = antitracker["hardcore"] as? [String: Any] {
if let ipAddress = hardcore["ip"] as? String {
UserDefaults.shared.set(ipAddress, forKey: UserDefaults.Key.antiTrackerHardcoreDNS)
antiTrackerList = list
if AntiTrackerDns.load() == nil {
antiTrackerList.first?.save()
}
}
}
Expand Down
Loading

0 comments on commit 51ae4a6

Please sign in to comment.