Skip to content

Commit

Permalink
Migrate to Swift 3 for all. Made it buildable on iOS 10 device.
Browse files Browse the repository at this point in the history
Changes also included
- set not to ignore Podfile.lock

When you clone this project and build on your system, you need to do
this thing (based on Xcode 8.2 and iOS 10.2 device).

- Add @escaping in front of callback parameters for ActionHandler as
  defined on top of the file
- Request to use some features in Network extension API by making a
  request to Apple via
  https://developer.apple.com/contact/network-extension/.

Right now, this changes are still waiting for response back from Apple
from step 2 above. As tested, if not request and get permission from
Apple to use core feature in Network extension as needed in this
project, it will always failed similar to "permission denied".

It seems like Apple ties team account string to be able to use such
features of Network extension API.
  • Loading branch information
haxpor committed Dec 17, 2016
1 parent 0f76b6e commit c61c515
Show file tree
Hide file tree
Showing 103 changed files with 1,900 additions and 1,572 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -42,7 +42,8 @@ DerivedData
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
Pods/
Podfile.lock
# Add Podfile.lock for future maintenance reason
#Podfile.lock

# Carthage
Carthage/Build
Expand Down
8 changes: 4 additions & 4 deletions Library/Aspects/Aspects/Source/Aspects.swift
Expand Up @@ -15,14 +15,14 @@ struct Aspect {
}

public enum AspectOptions {
case Before
case After
case Instead
case before
case after
case instead
}

public extension NSObject {

public class func aspectHook(originalSelector: Selector, swizzledSelector: Selector, options: AspectOptions = .Instead) {
public class func aspectHook(_ originalSelector: Selector, swizzledSelector: Selector, options: AspectOptions = .instead) {
let originalMethod = class_getInstanceMethod(self, originalSelector)
let swizzledMethod = class_getInstanceMethod(self, swizzledSelector)

Expand Down
22 changes: 11 additions & 11 deletions Library/ICSMainFramework/ICSMainFramework/AppConfiguration.swift
Expand Up @@ -27,26 +27,26 @@ public struct LifeCycleKey {

let appConfig = AppConfig.sharedConfig

public class AppConfig {
open class AppConfig {

public var lifeCycleConfig = [String: [AppLifeCycleItem]]()
public var customConfig = [String: AnyObject]()
open var lifeCycleConfig = [String: [AppLifeCycleItem]]()
open var customConfig = [String: AnyObject]()

public class var sharedConfig: AppConfig {
open class var sharedConfig: AppConfig {
return sharedConfigInstance
}

public func loadConfig(fileName: String) {
var components = fileName.componentsSeparatedByString(".")
open func loadConfig(_ fileName: String) {
var components = fileName.components(separatedBy: ".")
let type = components.popLast()
let name = components.joinWithSeparator(".")
if let path = NSBundle.mainBundle().pathForResource(name, ofType: type) {
let name = components.joined(separator: ".")
if let path = Bundle.main.path(forResource: name, ofType: type) {
let configDict = NSDictionary(contentsOfFile: path) as! [String: AnyObject]
loadConfig(configDict)
}
}

public func loadConfig(dictionary: [String: AnyObject]) {
open func loadConfig(_ dictionary: [String: AnyObject]) {
if let lifeCycleDict = dictionary[ConfigKey.lifeCycle] as? [String: AnyObject] {
loadLifeCycleConfig(lifeCycleDict)
}
Expand All @@ -55,7 +55,7 @@ public class AppConfig {
}
}

func loadLifeCycleConfig(dictionary: [String: AnyObject]) {
func loadLifeCycleConfig(_ dictionary: [String: AnyObject]) {
for (key, value) in dictionary {
var items = [AppLifeCycleItem]()
if let itemArray = value as? [AnyObject] {
Expand All @@ -65,7 +65,7 @@ public class AppConfig {
}
}

func loadCustomConfig(dictionary: [String: AnyObject]) {
func loadCustomConfig(_ dictionary: [String: AnyObject]) {
customConfig = dictionary
}

Expand Down
32 changes: 16 additions & 16 deletions Library/ICSMainFramework/ICSMainFramework/AppDelegate.swift
Expand Up @@ -8,17 +8,17 @@

import UIKit

public class AppDelegate: UIResponder, UIApplicationDelegate {
open class AppDelegate: UIResponder, UIApplicationDelegate {

public var bootstrapViewController: UIViewController {
open var bootstrapViewController: UIViewController {
return UIViewController()
}
public var window: UIWindow?
open var window: UIWindow?

public func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
open func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.backgroundColor = UIColor.whiteColor()
window = UIWindow(frame: UIScreen.main.bounds)
window?.backgroundColor = UIColor.white
window?.makeKeyAndVisible()
appConfig.loadConfig("config.plist")
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.didFinishLaunchingWithOptions] {
Expand All @@ -29,12 +29,12 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

public func applicationWillResignActive(application: UIApplication) {
open func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

public func applicationDidEnterBackground(application: UIApplication) {
open func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.didEnterBackground] {
Expand All @@ -44,7 +44,7 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

public func applicationWillEnterForeground(application: UIApplication) {
open func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.willEnterForeground] {
for item in lifeCycleItems{
Expand All @@ -53,7 +53,7 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

public func applicationDidBecomeActive(application: UIApplication) {
open func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.didBecomeActive] {
for item in lifeCycleItems{
Expand All @@ -62,7 +62,7 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

public func applicationWillTerminate(application: UIApplication) {
open func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.willTerminate] {
for item in lifeCycleItems{
Expand All @@ -71,36 +71,36 @@ public class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

public func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
open func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.remoteNotification] {
for item in lifeCycleItems{
item.object?.application?(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}
}

public func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
open func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.remoteNotification] {
for item in lifeCycleItems{
item.object?.application?(application, didFailToRegisterForRemoteNotificationsWithError: error)
}
}
}

public func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
open func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.remoteNotification] {
for item in lifeCycleItems{
item.object?.application?(application, didReceiveRemoteNotification: userInfo, fetchCompletionHandler: completionHandler)
}
}
}

public func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
open func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
var handled = false
if let lifeCycleItems = appConfig.lifeCycleConfig[LifeCycleKey.openURL] {
for item in lifeCycleItems{
if #available(iOSApplicationExtension 9.0, *) {
if let res = item.object?.application?(app, openURL: url, options: options) where res{
if let res = item.object?.application?(app, open: url, options: options), res{
handled = res
}
} else {
Expand Down
20 changes: 10 additions & 10 deletions Library/ICSMainFramework/ICSMainFramework/AppEnvironment.swift
Expand Up @@ -13,27 +13,27 @@ public struct AppEnv {
// App Version
// App Build
public static var version: String {
return NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
return Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
}

public static var fullVersion: String {
return "\(AppEnv.version) Build \(AppEnv.build)"
}

public static var build: String {
return NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleVersion") as! String
return Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String
}

public static var countryCode: String {
return NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as? String ?? "US"
return (Locale.current as NSLocale).object(forKey: NSLocale.Key.countryCode) as? String ?? "US"
}

public static var languageCode: String {
return NSLocale.currentLocale().objectForKey(NSLocaleLanguageCode) as? String ?? "en"
return (Locale.current as NSLocale).object(forKey: NSLocale.Key.languageCode) as? String ?? "en"
}

public static var appName: String {
return NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleDisplayName") as! String
return Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
}

public static var isTestFlight: Bool {
Expand All @@ -47,16 +47,16 @@ public struct AppEnv {
return true
}

private static var isAppStoreReceiptSandbox: Bool {
let b = NSBundle.mainBundle().appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
fileprivate static var isAppStoreReceiptSandbox: Bool {
let b = Bundle.main.appStoreReceiptURL?.lastPathComponent == "sandboxReceipt"
NSLog("isAppStoreReceiptSandbox: \(b)")
return b
}

private static var hasEmbeddedMobileProvision: Bool {
let b = NSBundle.mainBundle().pathForResource("embedded", ofType: "mobileprovision") != nil
fileprivate static var hasEmbeddedMobileProvision: Bool {
let b = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") != nil
NSLog("hasEmbeddedMobileProvision: \(b)")
return b
}

}
}
8 changes: 4 additions & 4 deletions Library/ShadowPath/ShadowPath.xcodeproj/project.pbxproj
Expand Up @@ -1885,7 +1885,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = ShadowPathDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.touchingapp.ShadowPathDemo;
PRODUCT_BUNDLE_IDENTIFIER = io.wasin.ShadowPathDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
USER_HEADER_SEARCH_PATHS = "";
};
Expand All @@ -1897,7 +1897,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = ShadowPathDemo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.touchingapp.ShadowPathDemo;
PRODUCT_BUNDLE_IDENTIFIER = io.wasin.ShadowPathDemo;
PRODUCT_NAME = "$(TARGET_NAME)";
USER_HEADER_SEARCH_PATHS = "";
};
Expand Down Expand Up @@ -2023,7 +2023,7 @@
"-DUDPRELAY_LOCAL",
"-DMODULE_LOCAL",
);
PRODUCT_BUNDLE_IDENTIFIER = com.touchingapp.ShadowPath;
PRODUCT_BUNDLE_IDENTIFIER = io.wasin.ShadowPath;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
USER_HEADER_SEARCH_PATHS = "";
Expand Down Expand Up @@ -2059,7 +2059,7 @@
"-DUDPRELAY_LOCAL",
"-DMODULE_LOCAL",
);
PRODUCT_BUNDLE_IDENTIFIER = com.touchingapp.ShadowPath;
PRODUCT_BUNDLE_IDENTIFIER = io.wasin.ShadowPath;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
USER_HEADER_SEARCH_PATHS = "";
Expand Down
2 changes: 1 addition & 1 deletion PacketProcessor/TunnelInterface.m
Expand Up @@ -16,7 +16,7 @@
#import "tun2socks/tun2socks.h"
@import CocoaAsyncSocket;

#define kTunnelInterfaceErrorDomain @"com.touchingapp.potatso.TunnelInterface"
#define kTunnelInterfaceErrorDomain @"io.wasin.potatso.TunnelInterface"

@interface TunnelInterface () <GCDAsyncUdpSocketDelegate>
@property (nonatomic) NEPacketTunnelFlow *tunnelPacketFlow;
Expand Down
4 changes: 2 additions & 2 deletions PacketProcessor/tun2socks-iOS/system/BTime.c
Expand Up @@ -41,7 +41,7 @@ struct _BTime_global btime_global = {
#include <mach/clock.h>
#include <mach/mach.h>

int clock_gettime(int clk_id, struct timespec* t)
/*int clock_gettime(int clk_id, struct timespec* t)
{
clock_serv_t cclock;
mach_timespec_t mts;
Expand All @@ -51,5 +51,5 @@ int clock_gettime(int clk_id, struct timespec* t)
t->tv_sec = mts.tv_sec;
t->tv_nsec = mts.tv_nsec;
return 0;
}
}*/
#endif
2 changes: 1 addition & 1 deletion PacketProcessor/tun2socks-iOS/system/BTime.h
Expand Up @@ -71,7 +71,7 @@ struct _BTime_global {

#ifdef __MACH__
#define CLOCK_MONOTONIC 1
int clock_gettime(int clk_id, struct timespec* t);
//int clock_gettime(int clk_id, struct timespec* t);
#endif

extern struct _BTime_global btime_global;
Expand Down
6 changes: 4 additions & 2 deletions PacketTunnel/Info.plist
Expand Up @@ -18,8 +18,6 @@
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.4.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>121</string>
<key>Fabric</key>
Expand Down Expand Up @@ -48,5 +46,9 @@
<key>NSExtensionPrincipalClass</key>
<string>PacketTunnelProvider</string>
</dict>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>gamekit</string>
</array>
</dict>
</plist>
Expand Up @@ -2,15 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.networking.networkextension</key>
<key>com.apple.security.application-groups</key>
<array>
<string>packet-tunnel-provider</string>
<string>app-proxy-provider</string>
<string>content-filter-provider</string>
<string>group.io.wasin.potatso</string>
</array>
<key>com.apple.security.application-groups</key>
<key>keychain-access-groups</key>
<array>
<string>group.com.touchingapp.potatso</string>
<string>$(AppIdentifierPrefix)io.wasin.potatso.tunnel</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion PacketTunnel/PacketTunnelProvider.m
Expand Up @@ -57,7 +57,7 @@ - (void)updateUserDefaults {
}

- (void)setupWormhole {
self.wormhole = [[MMWormhole alloc] initWithApplicationGroupIdentifier:@"group.com.touchingapp.potatso" optionalDirectory:@"wormhole"];
self.wormhole = [[MMWormhole alloc] initWithApplicationGroupIdentifier:@"group.io.wasin.potatso" optionalDirectory:@"wormhole"];
__weak typeof(self) weakSelf = self;
[self.wormhole listenForMessageWithIdentifier:@"getTunnelStatus" listener:^(id _Nullable messageObject) {
[weakSelf.wormhole passMessageObject:@"ok" identifier:@"tunnelStatus"];
Expand Down
6 changes: 3 additions & 3 deletions PacketTunnel/ProxyManager.m
Expand Up @@ -78,7 +78,7 @@ - (void)onSocksProxyCallback:(int)fd {
self.socksProxyPort = sock_port(fd);
self.socksProxyRunning = YES;
}else {
error = [NSError errorWithDomain:@"com.touchingapp.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start socks proxy"}];
error = [NSError errorWithDomain:@"io.wasin.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start socks proxy"}];
}
if (self.socksCompletion) {
self.socksCompletion(self.socksProxyPort, error);
Expand Down Expand Up @@ -142,7 +142,7 @@ - (void)onShadowsocksCallback:(int)fd {
self.shadowsocksProxyPort = sock_port(fd);
self.shadowsocksProxyRunning = YES;
}else {
error = [NSError errorWithDomain:@"com.touchingapp.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start http proxy"}];
error = [NSError errorWithDomain:@"io.wasin.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start http proxy"}];
}
if (self.shadowsocksCompletion) {
self.shadowsocksCompletion(self.shadowsocksProxyPort, error);
Expand Down Expand Up @@ -179,7 +179,7 @@ - (void)onHttpProxyCallback:(int)fd {
self.httpProxyPort = sock_port(fd);
self.httpProxyRunning = YES;
}else {
error = [NSError errorWithDomain:@"com.touchingapp.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start http proxy"}];
error = [NSError errorWithDomain:@"io.wasin.potatso" code:100 userInfo:@{NSLocalizedDescriptionKey: @"Fail to start http proxy"}];
}
if (self.httpCompletion) {
self.httpCompletion(self.httpProxyPort, error);
Expand Down

0 comments on commit c61c515

Please sign in to comment.