Skip to content

Commit

Permalink
PIA-1291: Make wireguard the default option
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-juan-docal committed Feb 8, 2024
1 parent 0a2d002 commit 937b29e
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 56 deletions.
1 change: 0 additions & 1 deletion PIA VPN-tvOS/Bootstraper/BootstraperFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class BootstraperFactory {
let defaults = Client.preferences.defaults
defaults.isPersistentConnection = true
defaults.mace = false
defaults.vpnType = IKEv2Profile.vpnType
}

private static func cleanCurrentAccount() {
Expand Down
30 changes: 27 additions & 3 deletions PIA VPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 54;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -388,6 +388,10 @@
AA36CDDB28A6860F00180A33 /* TweetNacl in Frameworks */ = {isa = PBXBuildFile; productRef = AA36CDDA28A6860F00180A33 /* TweetNacl */; };
AA36CDDE28A6878000180A33 /* AlamofireImage in Frameworks */ = {isa = PBXBuildFile; productRef = AA36CDDD28A6878000180A33 /* AlamofireImage */; };
AA52C59F28E5ECD400D025AF /* PIAWidgetVpnDetaislRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA52C59E28E5ECD400D025AF /* PIAWidgetVpnDetaislRow.swift */; };
AAA4707B2B737FC100F28590 /* IsWireguardMigrationPerformed.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAA4707A2B737FC100F28590 /* IsWireguardMigrationPerformed.swift */; };
AAA4707D2B737FDD00F28590 /* SetWireguardMigrationPerformed.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAA4707C2B737FDD00F28590 /* SetWireguardMigrationPerformed.swift */; };
AAA4707F2B73801600F28590 /* PerformWireguardMigration.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAA4707E2B73801600F28590 /* PerformWireguardMigration.swift */; };
AAA470812B7380EA00F28590 /* IsIkev2SelectedWithDefaultSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAA470802B7380EA00F28590 /* IsIkev2SelectedWithDefaultSettings.swift */; };
AABF826D28AD185E00CDAC64 /* TweetNacl in Frameworks */ = {isa = PBXBuildFile; productRef = AABF826C28AD185E00CDAC64 /* TweetNacl */; };
AABF826F28AD187800CDAC64 /* Popover in Frameworks */ = {isa = PBXBuildFile; productRef = AABF826E28AD187800CDAC64 /* Popover */; };
AABF827128AD188700CDAC64 /* AlamofireImage in Frameworks */ = {isa = PBXBuildFile; productRef = AABF827028AD188700CDAC64 /* AlamofireImage */; };
Expand Down Expand Up @@ -1134,6 +1138,10 @@
82E20B0D24F5666E0065EFE3 /* PIAAccount.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PIAAccount.framework; path = ../account/build/bin/iOS/PIAAccountReleaseFramework/PIAAccount.framework; sourceTree = "<group>"; };
82F41375264E8AC20098FF4B /* SettingOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingOptions.swift; sourceTree = "<group>"; };
AA52C59E28E5ECD400D025AF /* PIAWidgetVpnDetaislRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAWidgetVpnDetaislRow.swift; sourceTree = "<group>"; };
AAA4707A2B737FC100F28590 /* IsWireguardMigrationPerformed.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IsWireguardMigrationPerformed.swift; sourceTree = "<group>"; };
AAA4707C2B737FDD00F28590 /* SetWireguardMigrationPerformed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetWireguardMigrationPerformed.swift; sourceTree = "<group>"; };
AAA4707E2B73801600F28590 /* PerformWireguardMigration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PerformWireguardMigration.swift; sourceTree = "<group>"; };
AAA470802B7380EA00F28590 /* IsIkev2SelectedWithDefaultSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IsIkev2SelectedWithDefaultSettings.swift; sourceTree = "<group>"; };
AAE8789B28E4679500557F26 /* WidgetPersistenceDatasource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetPersistenceDatasource.swift; sourceTree = "<group>"; };
AAE8789E28E4696300557F26 /* PIAWidgetProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAWidgetProvider.swift; sourceTree = "<group>"; };
AAE878A028E46C1600557F26 /* PIAWidgetPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAWidgetPreview.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1639,6 +1647,7 @@
0E9160551DA6F7EC00A13AA7 /* Core */ = {
isa = PBXGroup;
children = (
AAA470772B737DAA00F28590 /* Protocols */,
82CAB878255AEA2800BB08EF /* Messages */,
DD3B503E24B756B80002F4B5 /* Cards */,
DD829EDD2449A14800E2EE55 /* Siri */,
Expand Down Expand Up @@ -2358,6 +2367,17 @@
name = Settings;
sourceTree = "<group>";
};
AAA470772B737DAA00F28590 /* Protocols */ = {
isa = PBXGroup;
children = (
AAA4707A2B737FC100F28590 /* IsWireguardMigrationPerformed.swift */,
AAA4707C2B737FDD00F28590 /* SetWireguardMigrationPerformed.swift */,
AAA4707E2B73801600F28590 /* PerformWireguardMigration.swift */,
AAA470802B7380EA00F28590 /* IsIkev2SelectedWithDefaultSettings.swift */,
);
name = Protocols;
sourceTree = "<group>";
};
AAE8789628E45C5D00557F26 /* Domain */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3799,6 +3819,7 @@
DD125DC521E77046004ECCB6 /* QuickConnectTile.swift in Sources */,
82A1AD2624B86AF60003DD02 /* PIACardsViewController.swift in Sources */,
DD1AA4962180AD92005116D7 /* CustomDNSSettingsViewController.swift in Sources */,
AAA470812B7380EA00F28590 /* IsIkev2SelectedWithDefaultSettings.swift in Sources */,
0EFDC1EF1FE4B9E6007C0B9B /* AppConfiguration.swift in Sources */,
0E9452A21FDB568700891948 /* MenuItemCell.swift in Sources */,
829EB51125359DBB003E74DD /* DedicatedIpRowViewCell.swift in Sources */,
Expand Down Expand Up @@ -3839,6 +3860,7 @@
DD3B504924B75A1E0002F4B5 /* CardFactory.swift in Sources */,
DD829EDF2449A1EF00E2EE55 /* SiriShortcutsBuilder.swift in Sources */,
DDC8124C2176185000CB290C /* SwiftGen+SeguesStoryboards.swift in Sources */,
AAA4707D2B737FDD00F28590 /* SetWireguardMigrationPerformed.swift in Sources */,
E51693D82AFBE5680089FB8F /* CAGradientLayer+Image.swift in Sources */,
DDD271E121D6262100B6D20F /* PropertyStoring.swift in Sources */,
82A1AD2F24B87CF20003DD02 /* PIACard.swift in Sources */,
Expand All @@ -3856,6 +3878,7 @@
E59E8FAF2AEA7A81009278F5 /* MagicLinkLoginViewController.swift in Sources */,
8276DFE62608B63800BB7B40 /* ShowConnectionStatsViewController.swift in Sources */,
827570D424DAA317008F9800 /* NetworkRuleOptionView.swift in Sources */,
AAA4707F2B73801600F28590 /* PerformWireguardMigration.swift in Sources */,
0E9452A51FDB578400891948 /* RegionCell.swift in Sources */,
DD829EE22449A4A400E2EE55 /* SiriShortcutsManager.swift in Sources */,
E51693D12AFADCC20089FB8F /* SwiftGen+Strings.swift in Sources */,
Expand Down Expand Up @@ -3911,6 +3934,7 @@
DD1C138621E60BAE004004B3 /* IPTile.swift in Sources */,
0E9452961FDB4C5800891948 /* AboutComponentCell.swift in Sources */,
0E53A83B1FE5A156000C2A18 /* AccountProvider+Refresh.swift in Sources */,
AAA4707B2B737FC100F28590 /* IsWireguardMigrationPerformed.swift in Sources */,
82B7374B26527E330097FFF6 /* GeneralSettingsViewController.swift in Sources */,
0EFDC1E01FE4A450007C0B9B /* AppPreferences.swift in Sources */,
E51693D52AFBDB8A0089FB8F /* NavigationBar+Appearence..swift in Sources */,
Expand Down Expand Up @@ -5640,8 +5664,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pia-foss/mobile-ios-library.git";
requirement = {
branch = master;
kind = branch;
kind = revision;
revision = b0e0707c83db9d5f2f697bac97f1554f901736b7;
};
};
/* End XCRemoteSwiftPackageReference section */
Expand Down
2 changes: 1 addition & 1 deletion PIA VPN/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ extension AccountViewController {
class func logout(_ completion: ((Bool?) -> ())? = nil) {
Client.providers.accountProvider.logout({ error in
guard let _ = error else {
AppPreferences.shared.clean()
AppPreferences.shared.reset()
completion?(false)
return
}
Expand Down
2 changes: 1 addition & 1 deletion PIA VPN/AddEmailToAccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class AddEmailToAccountViewController: AutolayoutViewController, BrandableNaviga
Client.providers.accountProvider.logout({ error in
guard let _ = error else {
self.dismiss(animated: true) {
AppPreferences.shared.clean()
AppPreferences.shared.reset()
}
return
}
Expand Down
79 changes: 34 additions & 45 deletions PIA VPN/AppPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ class AppPreferences {
Entries.useConnectSiriShortcuts: false,
Entries.useDisconnectSiriShortcuts: false,
Entries.todayWidgetButtonTitle: L10n.Localizable.Today.Widget.login,
Entries.todayWidgetVpnProtocol: IKEv2Profile.vpnType,
Entries.todayWidgetVpnPort: "500",
Entries.todayWidgetVpnProtocol: PIAWGTunnelProfile.vpnType,
Entries.todayWidgetVpnPort: "1337",
Entries.todayWidgetVpnSocket: "UDP",
Entries.todayWidgetTrustedNetwork: false,
Entries.quickSettingThemeVisible: true,
Expand Down Expand Up @@ -706,6 +706,35 @@ class AppPreferences {
}

}

func migrateWireguard() {
let isWireguardMigrationPerformed = IsWireguardMigrationPerformed(
preferences: Client.preferences
)
let isIkev2SelectedWithDefaultSettings = IsIkev2SelectedWithDefaultSettings(
preferences: Client.preferences
)
let performWireguardMigration = PerformWireguardMigration(
preferences: Client.preferences
)
let setWireguardMigrationPerformed = SetWireguardMigrationPerformed(
preferences: Client.preferences
)

if (isWireguardMigrationPerformed()) {
log.debug("Wireguard migration already performed. Return")
return
}

setWireguardMigrationPerformed()

if (!isIkev2SelectedWithDefaultSettings()) {
log.debug("Wireguard migration aborted as the user is not on default settings. Return")
return
}

performWireguardMigration()
}
#endif

func migrateNMT() {
Expand Down Expand Up @@ -855,52 +884,12 @@ class AppPreferences {
ikeV2UseSmallPackets = true
usesCustomDNS = false
wireGuardUseSmallPackets = true
todayWidgetVpnProtocol = IKEv2Profile.vpnType
todayWidgetVpnPort = "500"
todayWidgetVpnSocket = "UDP"
todayWidgetTrustedNetwork = false
Client.resetServers(completionBlock: {_ in })
successDisconnections = 0
successConnections = 0
failureConnections = 0
showGeoServers = true
showServiceMessages = false
dedicatedTokenIPReleation = [:]
appEnvironmentIsProduction = Client.environment == .production ? true : false
#if os(iOS)
MessagesManager.shared.reset()
#endif
userInteractedWithSurvey = false
successConnectionsUntilSurvey = nil
Client.preferences.lastKnownException = nil
}

func clean() {
#if os(iOS)
piaHandshake = .rsa4096
piaSocketType = nil
favoriteServerIdentifiersGen4 = []
useConnectSiriShortcuts = false
useDisconnectSiriShortcuts = false
connectShortcut = nil
disconnectShortcut = nil
todayWidgetVpnStatus = L10n.Localizable.Today.Widget.login
todayWidgetButtonTitle = L10n.Localizable.Today.Widget.login
todayWidgetVpnProtocol = IKEv2Profile.vpnType
todayWidgetVpnPort = "500"
todayWidgetVpnProtocol = PIAWGTunnelProfile.vpnType
todayWidgetVpnPort = "1337"
todayWidgetVpnSocket = "UDP"
todayWidgetTrustedNetwork = false
#endif
quickSettingThemeVisible = true
quickSettingKillswitchVisible = true
quickSettingNetworkToolVisible = true
quickSettingPrivateBrowserVisible = true
useSmallPackets = false
ikeV2UseSmallPackets = true
usesCustomDNS = false
wireGuardUseSmallPackets = true
let preferences = Client.preferences.editable().reset()
preferences.commit()
Client.resetServers(completionBlock: {_ in })
successDisconnections = 0
successConnections = 0
Expand All @@ -909,10 +898,10 @@ class AppPreferences {
showServiceMessages = false
dismissedMessages = []
dedicatedTokenIPReleation = [:]
appEnvironmentIsProduction = Client.environment == .production ? true : false
#if os(iOS)
MessagesManager.shared.reset()
#endif
appEnvironmentIsProduction = Client.environment == .production ? true : false
userInteractedWithSurvey = false
successConnectionsUntilSurvey = nil
Client.preferences.lastKnownException = nil
Expand Down
9 changes: 5 additions & 4 deletions PIA VPN/Bootstrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,19 @@ class Bootstrapper {
Client.configuration.enablesConnectivityUpdates = true
Client.configuration.enablesServerUpdates = true
Client.configuration.enablesServerPings = true
#if os(iOS)
#if os(iOS)
Client.configuration.bundledServersJSON = bundledServersJSON
#endif
#endif
Client.configuration.webTimeout = AppConfiguration.ClientConfiguration.webTimeout
Client.configuration.vpnProfileName = AppConfiguration.VPN.profileName
#if os(iOS)
Client.configuration.addVPNProfile(IKEv2Profile())
Client.configuration.addVPNProfile(PIATunnelProfile(bundleIdentifier: AppConstants.Extensions.tunnelBundleIdentifier))
Client.configuration.addVPNProfile(PIAWGTunnelProfile(bundleIdentifier: AppConstants.Extensions.tunnelWireguardBundleIdentifier))
#endif
let defaults = Client.preferences.defaults
defaults.isPersistentConnection = true
defaults.mace = false
defaults.vpnType = IKEv2Profile.vpnType
#if os(iOS)
defaults.vpnCustomConfigurations = [
PIATunnelProfile.vpnType: AppConfiguration.VPN.piaDefaultConfigurationBuilder.build(),
Expand All @@ -156,7 +156,7 @@ class Bootstrapper {
} else {
ServiceQualityManager.shared.stop()
}

Client.providers.accountProvider.featureFlags({ _ in
AppPreferences.shared.showsDedicatedIPView = Client.configuration.featureFlags.contains(Client.FeatureFlags.dedicatedIp)
AppPreferences.shared.checksDipExpirationRequest = Client.configuration.featureFlags.contains(Client.FeatureFlags.checkDipExpirationRequest)
Expand Down Expand Up @@ -229,6 +229,7 @@ class Bootstrapper {
pref.commit()
#if os(iOS)
AppPreferences.shared.migrateOVPN()
AppPreferences.shared.migrateWireguard()

// Business objects

Expand Down
2 changes: 1 addition & 1 deletion PIA VPN/DashboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ class DashboardViewController: AutolayoutViewController {

@objc private func closeSession() {
log.debug("Account: Logging out...")
AppPreferences.shared.clean()
AppPreferences.shared.reset()
if let window = self.view.window,
let rootViewController = window.rootViewController {
rootViewController.dismiss(animated: false, completion: nil)
Expand Down
30 changes: 30 additions & 0 deletions PIA VPN/IsIkev2SelectedWithDefaultSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// IsIkev2SelectedWithDefaultSettings.swift
// PIA VPN
//
// Created by Juan Docal on 2024-02-05.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import Foundation
import PIALibrary

class IsIkev2SelectedWithDefaultSettings {

private let DEFAULT_IKEV2_ENCRYPTION = "aes-256-gcm"
private let DEFAULT_IKEV2_HANDSHAKE = "sha256"
private let DEFAULT_IKEV2_MTU = 0

private let preferences: Client.Preferences

init(preferences: Client.Preferences) {
self.preferences = preferences
}

func callAsFunction() -> Bool {
return preferences.vpnType == IKEv2Profile.vpnType &&
preferences.ikeV2EncryptionAlgorithm.lowercased() == DEFAULT_IKEV2_ENCRYPTION &&
preferences.ikeV2IntegrityAlgorithm.lowercased() == DEFAULT_IKEV2_HANDSHAKE &&
preferences.ikeV2PacketSize == DEFAULT_IKEV2_MTU
}
}
23 changes: 23 additions & 0 deletions PIA VPN/IsWireguardMigrationPerformed.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// WasWireguardMigrationPerformed.swift
// PIA VPN
//
// Created by Juan Docal on 2024-02-05.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import Foundation
import PIALibrary

class IsWireguardMigrationPerformed {

private let preferences: Client.Preferences

init(preferences: Client.Preferences) {
self.preferences = preferences
}

func callAsFunction() -> Bool {
return preferences.wireguardMigrationPerformed
}
}
23 changes: 23 additions & 0 deletions PIA VPN/PerformWireguardMigration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// PerformWireguardMigration.swift
// PIA VPN
//
// Created by Juan Docal on 2024-02-05.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import Foundation
import PIALibrary

class PerformWireguardMigration {

private let preferences: Client.Preferences

init(preferences: Client.Preferences) {
self.preferences = preferences
}

func callAsFunction() {
preferences.setVpnTypeToWireguard()
}
}
23 changes: 23 additions & 0 deletions PIA VPN/SetWireguardMigrationPerformed.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// SetWireguardMigrationPerformed.swift
// PIA VPN
//
// Created by Juan Docal on 2024-02-05.
// Copyright © 2024 Private Internet Access Inc. All rights reserved.
//

import Foundation
import PIALibrary

class SetWireguardMigrationPerformed {

private let preferences: Client.Preferences

init(preferences: Client.Preferences) {
self.preferences = preferences
}

func callAsFunction() {
preferences.wireguardMigrationPerformed = true
}
}

0 comments on commit 937b29e

Please sign in to comment.