Skip to content

Commit

Permalink
PIA-675: Added tvOS compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-said-rehouni committed Nov 7, 2023
1 parent 681c1d8 commit ed10005
Show file tree
Hide file tree
Showing 30 changed files with 62 additions and 50 deletions.
8 changes: 4 additions & 4 deletions Sources/PIALibrary/Account/AccountProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import Foundation

/// Business interface related to user account.
public protocol AccountProvider: class {
public protocol AccountProvider: AnyObject {

#if os(iOS)
#if os(iOS) || os(tvOS)
/// The in-app products required to purchase a `Plan`.
var planProducts: [Plan: InAppProduct]? { get }
#endif
Expand Down Expand Up @@ -60,7 +60,7 @@ public protocol AccountProvider: class {
/// The password reference object associated with the currentUser, or `nil` if logged out.
var currentPasswordReference: Data? { get }

#if os(iOS)
#if os(iOS) || os(tvOS)
/// The last pending signup request (useful for recovery).
var lastSignupRequest: SignupRequest? { get }
#endif
Expand Down Expand Up @@ -172,7 +172,7 @@ public protocol AccountProvider: class {
*/
func featureFlags(_ callback: SuccessLibraryCallback?)

#if os(iOS)
#if os(iOS) || os(tvOS)
/**
Lists the available plans with their corresponding product to purchase in order to get them.

Expand Down
6 changes: 3 additions & 3 deletions Sources/PIALibrary/Account/DefaultAccountProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce

// MARK: AccountProvider

#if os(iOS)
#if os(iOS) || os(tvOS)
var planProducts: [Plan: InAppProduct]? {
guard let products = accessedStore.availableProducts else {
return nil
Expand Down Expand Up @@ -137,7 +137,7 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
return accessedDatabase.secure.passwordReference(for: username)
}

#if os(iOS)
#if os(iOS) || os(tvOS)
var lastSignupRequest: SignupRequest? {
guard let email = accessedDatabase.plain.lastSignupEmail else {
return nil
Expand Down Expand Up @@ -356,7 +356,7 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
}

#if os(iOS)
#if os(iOS) || os(tvOS)
func subscriptionInformation(_ callback: LibraryCallback<AppStoreInformation>?) {
log.debug("Fetching available product keys...")

Expand Down
6 changes: 3 additions & 3 deletions Sources/PIALibrary/Client+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ extension Client {
/// The default delay of VPN reconnection attempts.
public var vpnReconnectionDelay: Int

#if os(iOS)
#if os(iOS) || os(tvOS)

// MARK: InApp

Expand Down Expand Up @@ -250,7 +250,7 @@ extension Client {
urlscfg.urlCache = nil
sessionManager = Session(configuration: urlscfg)

#if os(iOS)
#if os(iOS) || os(tvOS)
inAppPlans = [:]
eligibleForTrial = true
#endif
Expand Down Expand Up @@ -322,7 +322,7 @@ extension Client {
return true
}

#if os(iOS)
#if os(iOS) || os(tvOS)

// MARK: InApp

Expand Down
9 changes: 1 addition & 8 deletions Sources/PIALibrary/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class Client {

static var webServices: WebServices = PIAWebServices()

#if os(iOS)
#if os(iOS) || os(tvOS)
static var store: InAppProvider = AppStoreProvider()
#endif

Expand Down Expand Up @@ -140,11 +140,4 @@ public final class Client {
public static func ping(servers: [Server]) {
ServersPinger.shared.ping(withDestinations: servers)
}

/**
Returns the Signup Storyboard owned by the library to be used by the clients
*/
public static func signupStoryboard() -> UIStoryboard {
UIStoryboard(name: "Signup", bundle: Bundle.module)
}
}
4 changes: 2 additions & 2 deletions Sources/PIALibrary/ClientAccess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protocol WebServicesAccess {
}

protocol InAppAccess {
#if os(iOS)
#if os(iOS) || os(tvOS)
var accessedStore: InAppProvider { get }
#endif
}
Expand Down Expand Up @@ -79,7 +79,7 @@ extension WebServicesAccess {
}

extension InAppAccess {
#if os(iOS)
#if os(iOS) || os(tvOS)
var accessedStore: InAppProvider {
return Client.store
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PIALibrary/ClientError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum ClientError: Error, Equatable {
/// Error while checking the dip token renewal.
case dipTokenRenewalError

#if os(iOS)
#if os(iOS) || os(tvOS)
/// No in-app history receipt is available.
case noReceipt

Expand Down
2 changes: 1 addition & 1 deletion Sources/PIALibrary/Mock/Client+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extension Client {
providers.tileProvider = provider
}

#if os(iOS)
#if os(iOS) || os(tvOS)
/**
Uses a mock in-app provider for testing purchases.
*/
Expand Down
6 changes: 3 additions & 3 deletions Sources/PIALibrary/Mock/MockAccountProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {

// MARK: AccountProvider

#if os(iOS)
#if os(iOS) || os(tvOS)
/// :nodoc:
public var planProducts: [Plan : InAppProduct]? {
return delegate.planProducts
Expand Down Expand Up @@ -198,7 +198,7 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
}
}

#if os(iOS)
#if os(iOS) || os(tvOS)
/// :nodoc:
public var lastSignupRequest: SignupRequest? {
return delegate.lastSignupRequest
Expand Down Expand Up @@ -276,7 +276,7 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
delegate.cleanDatabase()
}

#if os(iOS)
#if os(iOS) || os(tvOS)
/// :nodoc:
public func listPlanProducts(_ callback: (([Plan : InAppProduct]?, Error?) -> Void)?) {
delegate.listPlanProducts(callback)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PIALibrary/Mock/MockInAppProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import Foundation

#if os(iOS)
#if os(iOS) || os(tvOS)
private class MockProduct: InAppProduct {
let identifier: String

Expand Down
2 changes: 1 addition & 1 deletion Sources/PIALibrary/Notification+Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extension Notification.Name {

public static let PIAVPNDidFail = Notification.Name("PIAVPNDidFail")

#if os(iOS)
#if os(iOS) || os(tvOS)

// MARK: InApp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import PIACSI
import csi
import UIKit

class PIACSIDeviceInformationProvider: ICSIProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import PIACSI
import csi

class PIACSILastKnownExceptionProvider: ICSIProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import PIACSI
import csi

class PIACSIUserInformationProvider: ICSIProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import PIACSI
import csi

class PIACSIClientStateProvider : IEndPointProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import PIACSI
import csi

class PIACSIProtocolInformationProvider : ICSIProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import Foundation
import PIACSI
import csi

class PIACSIRegionInformationProvider : ICSIProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//

import Foundation
import PIAKPI
import kpi

class PIAKPIClientStateProvider : KPIClientStateProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//

import Foundation
import PIAKPI
import kpi

class PIAKPIStagingClientStateProvider : KPIClientStateProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//

import Foundation
import PIARegions
import regions

class PIARegionClientStateProvider : IRegionEndpointProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import Foundation
import UIKit
import PIAKPI
import kpi
import SwiftyBeaver

private let log = SwiftyBeaver.self
Expand Down Expand Up @@ -227,8 +227,10 @@ public class ServiceQualityManager: NSObject {
switch Client.providers.vpnProvider.currentVPNType {
case IKEv2Profile.vpnType:
return KPIVpnProtocol.ipsec
#if(iOS)
case PIATunnelProfile.vpnType:
return KPIVpnProtocol.ovpn
#endif
case PIAWGTunnelProfile.vpnType:
return KPIVpnProtocol.wireguard
default:
Expand Down
9 changes: 8 additions & 1 deletion Sources/PIALibrary/VPN/IKEv2EncryptionAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,25 @@ public enum IKEv2EncryptionAlgorithm: String, EnumsBuilder {
public func networkExtensionValue() -> NEVPNIKEv2EncryptionAlgorithm {
switch self {
case .algorithmAES128: return NEVPNIKEv2EncryptionAlgorithm.algorithmAES128
case .algorithmAES256: return NEVPNIKEv2EncryptionAlgorithm.algorithmAES256
case .algorithmAES128GCM: return NEVPNIKEv2EncryptionAlgorithm.algorithmAES128GCM
case .algorithmAES256: return NEVPNIKEv2EncryptionAlgorithm.algorithmAES256
case .algorithmAES256GCM: return NEVPNIKEv2EncryptionAlgorithm.algorithmAES256GCM
}
}

public func integrityAlgorithms() -> [IKEv2IntegrityAlgorithm] {
switch self {
#if os(iOS)
case .algorithmAES128: return [.SHA96, .SHA256, .SHA384, .SHA512]
case .algorithmAES256: return [.SHA96, .SHA256, .SHA384, .SHA512]
case .algorithmAES128GCM: return [.SHA96, .SHA160, .SHA256]
case .algorithmAES256GCM: return [.SHA96, .SHA160, .SHA256]
#elseif os(tvOS)
case .algorithmAES128: return [.SHA256, .SHA384, .SHA512]
case .algorithmAES256: return [.SHA256, .SHA384, .SHA512]
case .algorithmAES128GCM: return [.SHA256]
case .algorithmAES256GCM: return [.SHA256]
#endif
}
}

Expand Down
6 changes: 4 additions & 2 deletions Sources/PIALibrary/VPN/IKEv2IntegrityAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import NetworkExtension
public enum IKEv2IntegrityAlgorithm: String, EnumsBuilder {

public static let defaultIntegrity: IKEv2IntegrityAlgorithm = .SHA256

#if os(iOS)
case SHA96 = "SHA96"
case SHA160 = "SHA160"
#endif
case SHA256 = "SHA256"
case SHA384 = "SHA384"
case SHA512 = "SHA512"
Expand All @@ -43,12 +44,13 @@ public enum IKEv2IntegrityAlgorithm: String, EnumsBuilder {

public func networkExtensionValue() -> NEVPNIKEv2IntegrityAlgorithm {
switch self {
#if os(iOS)
case .SHA96: return NEVPNIKEv2IntegrityAlgorithm.SHA96
case .SHA160: return NEVPNIKEv2IntegrityAlgorithm.SHA160
#endif
case .SHA256: return NEVPNIKEv2IntegrityAlgorithm.SHA256
case .SHA384: return NEVPNIKEv2IntegrityAlgorithm.SHA384
case .SHA512: return NEVPNIKEv2IntegrityAlgorithm.SHA512
default: return NEVPNIKEv2IntegrityAlgorithm.SHA96
}
}

Expand Down
5 changes: 4 additions & 1 deletion Sources/PIALibrary/VPN/NetworkExtensionProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extension NetworkExtensionProfile {
self.configureDefaultOnDemandRules(force, vpn, configuration)
}
}

#if os(iOS)
if #available(iOS 14.2, *) {
let selectedProtocol = Client.preferences.vpnType
let isWireGuard = selectedProtocol == PIAWGTunnelProfile.vpnType
Expand All @@ -112,6 +112,7 @@ extension NetworkExtensionProfile {
}
}
}
#endif

log.debug("Configured with server: \(protocolConfiguration.serverAddress!)")
log.debug("Username: \(protocolConfiguration.username!)")
Expand Down Expand Up @@ -209,6 +210,7 @@ extension NetworkExtensionProfile {
}

private func configureOnDemandOnCellularNetworks(_ vpn: NEVPNManager) {
#if os(iOS)
let rules = Client.preferences.nmtGenericRules
let cellularRule = rules[NMTType.cellular.rawValue]

Expand All @@ -226,6 +228,7 @@ extension NetworkExtensionProfile {
ruleIgnore.interfaceTypeMatch = .cellular
vpn.onDemandRules?.append(ruleIgnore)
}
#endif
}

private func configureDefaultOnDemandRules(_ force: Bool,
Expand Down
3 changes: 2 additions & 1 deletion Sources/PIALibrary/VPN/PIATunnelProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// You should have received a copy of the GNU General Public License along with the Private
// Internet Access iOS Client. If not, see <https://www.gnu.org/licenses/>.
//

#if os(iOS)
import Foundation
import TunnelKitOpenVPN
import NetworkExtension
Expand Down Expand Up @@ -346,3 +346,4 @@ public class PIATunnelProfile: NetworkExtensionProfile {
return lines.joined(separator: "\n")
}
}
#endif
Loading

0 comments on commit ed10005

Please sign in to comment.