Commit 43f8f35c authored by Jose Blaya's avatar Jose Blaya
Browse files

wip

parent 2897214c
Pod::Spec.new do |s|
s.name = "PIALibrary"
s.version = "2.2.2"
s.version = "2.2.4"
s.summary = "PIA client library in Swift."
s.homepage = "https://www.privateinternetaccess.com/"
......@@ -40,6 +40,7 @@ Pod::Spec.new do |s|
p.pod_target_xcconfig = { "APPLICATION_EXTENSION_API_ONLY" => "YES" }
p.dependency "TunnelKit"
p.dependency "PIAWireguard"
p.dependency "PIALibrary/Library"
end
......
......@@ -275,6 +275,7 @@
DD6DC5B921B6A83400F9D538 /* UIViewLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6DC5B821B6A83400F9D538 /* UIViewLoading.swift */; };
DD6DC5BC21B6A8FC00F9D538 /* pia-spinner.json in Resources */ = {isa = PBXBuildFile; fileRef = DD6DC5BB21B6A8FC00F9D538 /* pia-spinner.json */; };
DD6FB0372224355600A84F05 /* UIDevice+WiFi.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD6FB0362224355600A84F05 /* UIDevice+WiFi.swift */; };
DD7411A923EC35B40058CEF3 /* PIAWGTunnelProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD7411A823EC35B40058CEF3 /* PIAWGTunnelProfile.swift */; };
DD76292821ECDFF80092DF50 /* Usage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292721ECDFF80092DF50 /* Usage.swift */; };
DD76292921ECDFF80092DF50 /* Usage.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292721ECDFF80092DF50 /* Usage.swift */; };
DD76292E21ECEC3F0092DF50 /* DataManipulation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */; };
......@@ -577,6 +578,7 @@
DD6DC5B821B6A83400F9D538 /* UIViewLoading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewLoading.swift; sourceTree = "<group>"; };
DD6DC5BB21B6A8FC00F9D538 /* pia-spinner.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "pia-spinner.json"; sourceTree = "<group>"; };
DD6FB0362224355600A84F05 /* UIDevice+WiFi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIDevice+WiFi.swift"; sourceTree = "<group>"; };
DD7411A823EC35B40058CEF3 /* PIAWGTunnelProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PIAWGTunnelProfile.swift; sourceTree = "<group>"; };
DD76292721ECDFF80092DF50 /* Usage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Usage.swift; sourceTree = "<group>"; };
DD76292D21ECEC3F0092DF50 /* DataManipulation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataManipulation.swift; sourceTree = "<group>"; };
DD86BAF021EF5B6D004A988F /* UIViewAutolayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewAutolayout.swift; sourceTree = "<group>"; };
......@@ -1105,6 +1107,7 @@
children = (
0EFEB4BF2007784A00F81029 /* PIATunnelProvider+Profile.swift */,
0EFEB4C02007784A00F81029 /* PIATunnelProfile.swift */,
DD7411A823EC35B40058CEF3 /* PIAWGTunnelProfile.swift */,
);
path = VPN;
sourceTree = "<group>";
......@@ -1492,6 +1495,7 @@
"${BUILT_PRODUCTS_DIR}/DynamicBlurView/DynamicBlurView.framework",
"${BUILT_PRODUCTS_DIR}/Gloss/Gloss.framework",
"${PODS_ROOT}/OpenSSL-Apple/frameworks/iPhone/openssl.framework",
"${BUILT_PRODUCTS_DIR}/PIAWireguard/PIAWireguard.framework",
"${BUILT_PRODUCTS_DIR}/PopupDialog/PopupDialog.framework",
"${BUILT_PRODUCTS_DIR}/QuickLayout/QuickLayout.framework",
"${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework",
......@@ -1506,6 +1510,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DynamicBlurView.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Gloss.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PIAWireguard.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PopupDialog.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QuickLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
......@@ -1530,6 +1535,7 @@
"${BUILT_PRODUCTS_DIR}/DynamicBlurView/DynamicBlurView.framework",
"${BUILT_PRODUCTS_DIR}/Gloss/Gloss.framework",
"${PODS_ROOT}/OpenSSL-Apple/frameworks/iPhone/openssl.framework",
"${BUILT_PRODUCTS_DIR}/PIAWireguard/PIAWireguard.framework",
"${BUILT_PRODUCTS_DIR}/PopupDialog/PopupDialog.framework",
"${BUILT_PRODUCTS_DIR}/QuickLayout/QuickLayout.framework",
"${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework",
......@@ -1544,6 +1550,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DynamicBlurView.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Gloss.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/openssl.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PIAWireguard.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PopupDialog.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/QuickLayout.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
......@@ -1800,6 +1807,7 @@
0EA8072F20A1E7C60033EC1A /* GlossRedeem.swift in Sources */,
0EA4C4311FDDD48F0041C3D8 /* Server.swift in Sources */,
DD56E3F4225F5D22002EDFB2 /* GlossProduct.swift in Sources */,
DD7411A923EC35B40058CEF3 /* PIAWGTunnelProfile.swift in Sources */,
84577FC5213D9B4D006DEC3D /* UILabel+LineHeight.swift in Sources */,
0EB9667E1FDF36490086ABC2 /* GlossParser.swift in Sources */,
DDA4A7BE21F5C31400A02ACD /* IKEv2Profile.swift in Sources */,
......@@ -2248,9 +2256,12 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = YES;
INFOPLIST_FILE = PIALibrary/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 2.2.4;
PRODUCT_BUNDLE_IDENTIFIER = com.privateinternetaccess.apple.PIALibrary;
PRODUCT_NAME = PIALibrary;
PROVISIONING_PROFILE_SPECIFIER = "";
......@@ -2273,9 +2284,12 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = YES;
INFOPLIST_FILE = PIALibrary/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 2.2.4;
PRODUCT_BUNDLE_IDENTIFIER = com.privateinternetaccess.apple.PIALibrary;
PRODUCT_NAME = PIALibrary;
PROVISIONING_PROFILE_SPECIFIER = "";
......
......@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.2.2</string>
<string>2.2.4</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
......
//
// PIAWGTunnelProfile.swift
// PIALibrary
//
// Created by Jose Antonio Blaya Garcia on 06/02/2020.
// Copyright © 2020 Private Internet Access, Inc.
//
// This file is part of the Private Internet Access iOS Client.
//
// The Private Internet Access iOS Client 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 Private Internet Access iOS Client 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 Private
// Internet Access iOS Client. If not, see <https://www.gnu.org/licenses/>.
//
import Foundation
import PIAWireguard
import NetworkExtension
/// Implementation of `VPNProfile` providing OpenVPN connectivity.
public class PIAWGTunnelProfile: NetworkExtensionProfile {
public func parsedCustomConfiguration(from map: [String : Any]) -> VPNCustomConfiguration? {
return nil
}
public func requestLog(withCustomConfiguration customConfiguration: VPNCustomConfiguration?, _ callback: LibraryCallback<String>?) {
find { (vpn, error) in
guard let vpn = vpn else {
callback?(nil, error)
return
}
do {
let session = vpn.connection as? NETunnelProviderSession
if #available(iOSApplicationExtension 12.0, *) {
try session?.sendProviderMessage(WGPacketTunnelProvider.Message.requestLog.data) { (data) in
guard let data = data, !data.isEmpty else {
callback?(nil, nil)
return
}
let log = String(data: data, encoding: .utf8)
callback?(log, nil)
}
} else {
// Fallback on earlier versions
}
} catch let e {
callback?(nil, e)
}
}
}
public func requestDataUsage(withCustomConfiguration customConfiguration: VPNCustomConfiguration?, _ callback: LibraryCallback<Usage>?) {
find { (vpn, error) in
guard let vpn = vpn else {
callback?(nil, error)
return
}
do {
let session = vpn.connection as? NETunnelProviderSession
if #available(iOSApplicationExtension 12.0, *) {
try session?.sendProviderMessage(WGPacketTunnelProvider.Message.dataCount.data) { (data) in
guard let data = data, !data.isEmpty else {
callback?(nil, ClientError.vpnProfileUnavailable)
return
}
let downloaded = data.getInt64(start: 0)
let uploaded = data.getInt64(start: 8)
let usage = Usage(uploaded: uploaded, downloaded: downloaded)
callback?(usage,
nil)
}
} else {
// Fallback on earlier versions
}
} catch let e {
callback?(nil, e)
}
}
}
private let bundleIdentifier: String
/**
Default initializer.
- Parameter bundleIdentifier: The bundle identifier of a Packet Tunnel Provider extension subclassing `PIATunnelProvider` from `PIATunnel`.
*/
public init(bundleIdentifier: String) {
self.bundleIdentifier = bundleIdentifier
}
// MARK: VPNProfile
/// :nodoc:
public static var vpnType: String {
return "PIA Wireguard"
}
/// :nodoc:
public static var isTunnel: Bool {
return true
}
/// :nodoc:
public var native: Any?
/// :nodoc:
public func prepare() {
find(completionHandler: nil)
}
/// :nodoc:
public func save(withConfiguration configuration: VPNConfiguration, force: Bool, _ callback: SuccessLibraryCallback?) {
find { (vpn, error) in
guard let vpn = vpn else {
callback?(error)
return
}
self.doSave(vpn, withConfiguration: configuration, force: force, callback)
}
}
/// :nodoc:
public func connect(withConfiguration configuration: VPNConfiguration, _ callback: SuccessLibraryCallback?) {
find { (vpn, error) in
guard let vpn = vpn else {
callback?(error)
return
}
self.doSave(vpn, withConfiguration: configuration, force: true) { (error) in
if let _ = error {
callback?(error)
return
}
do {
let session = vpn.connection as? NETunnelProviderSession
try session?.startTunnel(options: nil)
callback?(nil)
} catch let e {
callback?(e)
}
}
}
}
/// :nodoc:
public func disconnect(_ callback: SuccessLibraryCallback?) {
find { (vpn, error) in
guard let vpn = vpn else {
callback?(error)
return
}
// prevent reconnection
vpn.isOnDemandEnabled = false
vpn.saveToPreferences { (error) in
if let error = error {
vpn.connection.stopVPNTunnel()
callback?(error)
return
}
vpn.connection.stopVPNTunnel()
callback?(nil)
}
}
}
/// :nodoc:
public func updatePreferences(_ callback: SuccessLibraryCallback?) {
find { (vpn, error) in
guard let vpn = vpn else {
callback?(error)
return
}
vpn.saveToPreferences { (error) in
if let error = error {
callback?(error)
return
}
callback?(nil)
}
}
}
/// :nodoc:
public func disable(_ callback: SuccessLibraryCallback?) {
find { (vpn, error) in
guard let vpn = vpn else {
return
}
vpn.isEnabled = false
vpn.isOnDemandEnabled = false
vpn.saveToPreferences(completionHandler: callback)
}
}
/// :nodoc:
public func remove(_ callback: SuccessLibraryCallback?) {
find { (vpn, error) in
guard let vpn = vpn else {
return
}
vpn.removeFromPreferences(completionHandler: callback)
}
}
// MARK: NetworkExtensionProfile
/// :nodoc:
public func generatedProtocol(withConfiguration configuration: VPNConfiguration) -> NEVPNProtocol {
if #available(iOSApplicationExtension 12.0, *) {
var interface = InterfaceConfiguration(privateKey: Curve25519.generatePrivateKey())
interface.addresses = [IPAddressRange(from: String(format: "192.168.%d.%d/32", Int.random(in: 1 ... 10), Int.random(in: 1 ... 254)))!]
interface.dns = ["8.8.8.8", "8.8.4.4"].map { DNSServer(from: $0)! }
var peer = PeerConfiguration(publicKey: Curve25519.generatePublicKey(fromPrivateKey: Curve25519.generatePrivateKey()))
peer.endpoint = PIAWireguard.Endpoint(from: "blade1.madrid-rack404.nodes.gen4.ninja")
peer.allowedIPs = [IPAddressRange(from: "0.0.0.0/0")!]
let tunnelConfiguration = TunnelConfiguration(name: "pia-wg", interface: interface, peers: [peer])
let cfg = NETunnelProviderProtocol(tunnelConfiguration: tunnelConfiguration)
cfg?.providerBundleIdentifier = bundleIdentifier
cfg?.username = "db4a0ba4106ef94bf77420f341ba1b0197b224a5"
cfg?.passwordReference = "ec953684cd2431ef8a1067af0a8ac0f5e27d5f7c".data(using: .utf8)
return cfg!
} else {
return NETunnelProviderProtocol()
}
}
// MARK: Helpers
private func find(completionHandler: LibraryCallback<NETunnelProviderManager>?) {
PIAWGTunnelProfile.find(withBundleIdentifier: bundleIdentifier) { (vpn, error) in
self.native = vpn
completionHandler?(vpn, error)
}
}
private static func find(withBundleIdentifier identifier: String?, completionHandler: LibraryCallback<NETunnelProviderManager>?) {
NETunnelProviderManager.loadAllFromPreferences { (managers, error) in
guard let managers = managers else {
completionHandler?(nil, error)
return
}
var foundVPN: NETunnelProviderManager?
for m in managers {
guard let tunnelProtocol = m.protocolConfiguration as? NETunnelProviderProtocol else {
continue
}
guard ((identifier == nil) || (tunnelProtocol.providerBundleIdentifier == identifier)) else {
continue
}
foundVPN = m
break
}
let vpn = foundVPN ?? NETunnelProviderManager()
completionHandler?(vpn, nil)
}
}
}
......@@ -14,6 +14,7 @@ abstract_target 'PIALibrary' do
pod 'lottie-ios'
pod 'PopupDialog'
pod 'TunnelKit', :git => 'https://github.com/pia-foss/tunnelkit', :commit => 'd19b9de'
pod 'PIAWireguard', :path => "/Users/ueshiba/Projects/PIA/PIAWireguard"
target 'PIALibrary-iOS' do
platform :ios, '11.0'
......
......@@ -4,6 +4,12 @@ PODS:
- Gloss (2.1.0)
- lottie-ios (3.0.3)
- OpenSSL-Apple (1.1.1d.5a)
- PIAWireguard (1.0.0):
- PIAWireguard/AppExtension (= 1.0.0)
- PIAWireguard/Core (= 1.0.0)
- PIAWireguard/AppExtension (1.0.0):
- PIAWireguard/Core
- PIAWireguard/Core (1.0.0)
- PopupDialog (0.9.2):
- DynamicBlurView (~> 3.0.1)
- QuickLayout (2.0.2)
......@@ -27,6 +33,7 @@ DEPENDENCIES:
- Alamofire (~> 4)
- Gloss (~> 2)
- lottie-ios
- PIAWireguard (from `/Users/ueshiba/Projects/PIA/PIAWireguard`)
- PopupDialog
- ReachabilitySwift
- SwiftEntryKit (= 0.7.2)
......@@ -47,6 +54,8 @@ SPEC REPOS:
- SwiftyBeaver
EXTERNAL SOURCES:
PIAWireguard:
:path: "/Users/ueshiba/Projects/PIA/PIAWireguard"
TunnelKit:
:commit: d19b9de
:git: https://github.com/pia-foss/tunnelkit
......@@ -62,6 +71,7 @@ SPEC CHECKSUMS:
Gloss: 13ab6b4b0ff4cb2448466edc957479b1bccea8ba
lottie-ios: 06e0b54aab85ba128e332687d7f4ac4861a7a7ae
OpenSSL-Apple: 2c9efbc94e0a1ada434cc197b02bd70052a82281
PIAWireguard: de9a053e00b729feb13de4b4f59f3fbfa470a4e2
PopupDialog: f4bb461bf70ff422be0b56656566424ee9273080
QuickLayout: a730730b646b231fd4ef7cffaeb1e81fe0e1ca92
ReachabilitySwift: 408477d1b6ed9779dba301953171e017c31241f3
......@@ -69,6 +79,6 @@ SPEC CHECKSUMS:
SwiftyBeaver: 4cc0080d2e23f980652e28978db11a5c9da39165
TunnelKit: 1733ed87934deb57edc7aa5f4b25185bf302a7d4
PODFILE CHECKSUM: aab003f0cc1605940cc158f926b5148d27317625
PODFILE CHECKSUM: 6c1a2eea2e9f871398d147405a981d26ab3f0123
COCOAPODS: 1.7.5
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