├── ShadowVPN ├── checkmark@2x.png ├── checkmark_empty@2x.png ├── ShadowVPN-Bridging-Header.h ├── ShadowVPN.entitlements ├── Info.plist ├── ConfigurationTextCell.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── SimpleTableViewController.swift ├── AppDelegate.swift ├── ConfigurationValidator.swift ├── Base.lproj │ └── LaunchScreen.storyboard ├── MainViewController.swift └── ConfigurationViewController.swift ├── ShadowVPN.xcodeproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── project.pbxproj ├── Podfile ├── ShadowVPN.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── Podfile.lock ├── tunnel ├── ChinaDNSRunner.h ├── tunnel-Bridging-Header.h ├── tunnel.entitlements ├── SVCrypto.h ├── NSData+Hex.swift ├── chinadns.h ├── Info.plist ├── crypto_secretbox_salsa208poly1305.h ├── crypto_secretbox_salsa208poly1305.c ├── crypto.c ├── crypto.h ├── RouteManager.swift ├── ChinaDNSRunner.m ├── SVCrypto.m ├── PacketTunnelProvider.swift ├── iplist.txt └── chinadns.m ├── README.md ├── .gitignore └── LICENSE /ShadowVPN/checkmark@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyKite/ShadowVPN-iOS/HEAD/ShadowVPN/checkmark@2x.png -------------------------------------------------------------------------------- /ShadowVPN/checkmark_empty@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FlyKite/ShadowVPN-iOS/HEAD/ShadowVPN/checkmark_empty@2x.png -------------------------------------------------------------------------------- /ShadowVPN/ShadowVPN-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // Use this file to import your target's public headers that you would like to expose to Swift. 3 | // 4 | 5 | -------------------------------------------------------------------------------- /ShadowVPN.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | # platform :ios, '6.0' 3 | 4 | target 'ShadowVPN' do 5 | 6 | platform:ios, '9.0' 7 | 8 | end 9 | 10 | target 'tunnel' do 11 | 12 | platform:ios, '9.0' 13 | 14 | pod 'libsodium' 15 | 16 | end 17 | 18 | -------------------------------------------------------------------------------- /ShadowVPN.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ShadowVPN.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ShadowVPN.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - libsodium (1.0.3) 3 | 4 | DEPENDENCIES: 5 | - libsodium 6 | 7 | SPEC REPOS: 8 | https://github.com/cocoapods/specs.git: 9 | - libsodium 10 | 11 | SPEC CHECKSUMS: 12 | libsodium: be547e31dc75725629acc5717dc0a40fc05ef243 13 | 14 | PODFILE CHECKSUM: e7d0a5d72765e37bb84101bbd357cde346210255 15 | 16 | COCOAPODS: 1.5.3 17 | -------------------------------------------------------------------------------- /tunnel/ChinaDNSRunner.h: -------------------------------------------------------------------------------- 1 | // 2 | // ChinaDNSRunner.h 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 8/9/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ChinaDNSRunner : NSObject 12 | 13 | - (instancetype)initWithDNS:(NSString *)dns; 14 | 15 | + (BOOL)checkWiFiNetwork; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /tunnel/tunnel-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | // 2 | // tunnel-Bridging-Header.h 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 7/18/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | #ifndef tunnel_Bridging_Header_h 10 | #define tunnel_Bridging_Header_h 11 | 12 | #import "SVCrypto.h" 13 | #import "ChinaDNSRunner.h" 14 | 15 | #endif /* tunnel_Bridging_Header_h */ 16 | -------------------------------------------------------------------------------- /tunnel/tunnel.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.developer.networking.networkextension 6 | 7 | packet-tunnel-provider 8 | app-proxy-provider 9 | content-filter-provider 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tunnel/SVCrypto.h: -------------------------------------------------------------------------------- 1 | // 2 | // SVCrypto.h 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 7/18/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SVCrypto : NSObject 12 | 13 | + (void)setPassword:(NSString *)password; 14 | 15 | + (NSData *)encryptWithData:(NSData *)data userToken:(NSData *)userToken; 16 | 17 | // when token is enabled, skip header 18 | + (NSData *)decryptWithData:(NSData *)data userToken:(NSData *)userToken; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /tunnel/NSData+Hex.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Hex.swift 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 8/9/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension Data { 12 | init(fromHex hexString: String) { 13 | var bytes: [UInt8] = [] 14 | var temp = "" 15 | for char in hexString { 16 | temp.append(char) 17 | if temp.lengthOfBytes(using: .utf8) == 2 { 18 | let scanner = Scanner(string: temp) 19 | var value: CUnsignedInt = 0 20 | scanner.scanHexInt32(&value) 21 | bytes.append(UInt8(value)) 22 | temp = "" 23 | } 24 | } 25 | self.init(bytes) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /ShadowVPN/ShadowVPN.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | application-identifier 6 | 77M64ZZJGP.com.FlyKite.ShadowVPN 7 | com.apple.developer.networking.networkextension 8 | 9 | app-proxy-provider 10 | content-filter-provider 11 | packet-tunnel-provider 12 | 13 | com.apple.developer.networking.vpn.api 14 | 15 | allow-vpn 16 | 17 | com.apple.developer.team-identifier 18 | 77M64ZZJGP 19 | get-task-allow 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ShadowVPN for iOS 2 | ![Platform](https://img.shields.io/badge/iOS-9.0-lightgray.svg) 3 | ![Language](https://img.shields.io/badge/Language-Swift_5.0-orange.svg) 4 | ![Build](https://img.shields.io/badge/Build-Success-brightgreen.svg) 5 | ![Xcode](https://img.shields.io/badge/Xcode-10.2-blue.svg) 6 | [![License](https://img.shields.io/badge/License-GPL_v3-green.svg)](https://github.com/FlyKite/ShadowVPN-iOS/master/blob/master/LICENSE) 7 | ================= 8 | 9 | [ShadowVPN](https://github.com/clowwindy/ShadowVPN) for iOS 9, using the new Network Extension API. 10 | 11 | Features 12 | - Stateless VPN 13 | - Server NAT support 14 | - CHNRoutes 15 | - ChinaDNS 16 | 17 | Work in progress. Checkout the [development plan](https://github.com/clowwindy/ShadowVPNiOS/issues). 18 | 19 | Please contact us if you're interested in [testing the alpha version](https://github.com/clowwindy/ShadowVPN-iOS/wiki/How-To-Test-Beta-Version). 20 | 21 | License: GPLv3 22 | 23 | -------------------------------------------------------------------------------- /tunnel/chinadns.h: -------------------------------------------------------------------------------- 1 | /* ChinaDNS 2 | Copyright (C) 2015 clowwindy 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #ifndef chinadns_h 19 | #define chinadns_h 20 | 21 | #import 22 | 23 | // a hack 24 | // caller set it to 1 when Reachability changes 25 | // will be reset to 0 when the changes is handled by ChinaDNS 26 | extern int remote_recreate_required; 27 | 28 | // ChinaDNS main 29 | // should be called from a background thread 30 | int chinadns_main(int argc, char **argv); 31 | 32 | #endif /* chinadns_h */ 33 | -------------------------------------------------------------------------------- /tunnel/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | tunnel 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | XPC! 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | NSExtension 26 | 27 | NSExtensionPointIdentifier 28 | com.apple.networkextension.packet-tunnel 29 | NSExtensionPrincipalClass 30 | $(PRODUCT_MODULE_NAME).PacketTunnelProvider 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /tunnel/crypto_secretbox_salsa208poly1305.h: -------------------------------------------------------------------------------- 1 | /** 2 | crypto_secretbox_salsa208poly1305.h 3 | 4 | Copyright (C) 2015 clowwindy 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | #ifndef CRYPTO_SECRETBOX_SALSA208POLY1305_H 22 | #define CRYPTO_SECRETBOX_SALSA208POLY1305_H 23 | 24 | int crypto_secretbox_salsa208poly1305( 25 | unsigned char *c, 26 | const unsigned char *m,unsigned long long mlen, 27 | const unsigned char *n, 28 | const unsigned char *k 29 | ); 30 | 31 | int crypto_secretbox_salsa208poly1305_open( 32 | unsigned char *m, 33 | const unsigned char *c,unsigned long long clen, 34 | const unsigned char *n, 35 | const unsigned char *k 36 | ); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /ShadowVPN/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 8 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ShadowVPN/ConfigurationTextCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConfigurationTextCell.swift 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 8/8/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | let labelWidth = CGFloat(120.0) 12 | 13 | class ConfigurationTextCell: UITableViewCell { 14 | 15 | let textField: UITextField = UITextField() 16 | 17 | init() { 18 | super.init(style: .default, reuseIdentifier: nil) 19 | self.contentView.addSubview(textField) 20 | } 21 | 22 | override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { 23 | super.init(style: style, reuseIdentifier: reuseIdentifier) 24 | self.contentView.addSubview(textField) 25 | } 26 | 27 | required init?(coder aDecoder: NSCoder) { 28 | fatalError("init(coder:) has not been implemented") 29 | } 30 | 31 | override func layoutSubviews() { 32 | super.layoutSubviews() 33 | guard let label = self.textLabel else { 34 | return 35 | } 36 | let oldFrame = label.frame 37 | label.frame = CGRect(x: oldFrame.origin.x, 38 | y: oldFrame.origin.y, 39 | width: labelWidth, 40 | height: oldFrame.height) 41 | textField.frame = CGRect(x: oldFrame.origin.x + labelWidth + 10, 42 | y: oldFrame.origin.y, 43 | width: self.frame.width - oldFrame.origin.x + labelWidth + 10, 44 | height: oldFrame.height) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | .build/ 41 | 42 | # CocoaPods 43 | # 44 | # We recommend against adding the Pods directory to your .gitignore. However 45 | # you should judge for yourself, the pros and cons are mentioned at: 46 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 47 | # 48 | Pods/ 49 | 50 | # Carthage 51 | # 52 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 53 | # Carthage/Checkouts 54 | 55 | Carthage/Build 56 | 57 | # fastlane 58 | # 59 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 60 | # screenshots whenever they are needed. 61 | # For more information about the recommended setup visit: 62 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 63 | 64 | fastlane/report.xml 65 | fastlane/Preview.html 66 | fastlane/screenshots 67 | fastlane/test_output 68 | .DS_Store 69 | -------------------------------------------------------------------------------- /tunnel/crypto_secretbox_salsa208poly1305.c: -------------------------------------------------------------------------------- 1 | /** 2 | crypto_secretbox_salsa208poly1305.c 3 | 4 | Copyright (C) 2015 clowwindy 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | #include 22 | 23 | int crypto_secretbox_salsa208poly1305( 24 | unsigned char *c, 25 | const unsigned char *m,unsigned long long mlen, 26 | const unsigned char *n, 27 | const unsigned char *k 28 | ) 29 | { 30 | int i; 31 | if (mlen < 32) return -1; 32 | crypto_stream_salsa208_xor(c,m,mlen,n,k); 33 | crypto_onetimeauth_poly1305(c + 16,c + 32,mlen - 32,c); 34 | for (i = 0;i < 16;++i) c[i] = 0; 35 | return 0; 36 | } 37 | 38 | int crypto_secretbox_salsa208poly1305_open( 39 | unsigned char *m, 40 | const unsigned char *c,unsigned long long clen, 41 | const unsigned char *n, 42 | const unsigned char *k 43 | ) 44 | { 45 | int i; 46 | unsigned char subkey[32]; 47 | if (clen < 32) return -1; 48 | crypto_stream_salsa208(subkey,32,n,k); 49 | if (crypto_onetimeauth_poly1305_verify(c + 16,c + 32,clen - 32,subkey) != 0) return -1; 50 | crypto_stream_salsa208_xor(m,c,clen,n,k); 51 | for (i = 0;i < 32;++i) m[i] = 0; 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /ShadowVPN/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /tunnel/crypto.c: -------------------------------------------------------------------------------- 1 | /** 2 | crypto.c 3 | 4 | Copyright (C) 2015 clowwindy 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | #include 22 | #include 23 | #include "crypto_secretbox_salsa208poly1305.h" 24 | 25 | // will not copy key any more 26 | static unsigned char key[32]; 27 | 28 | int crypto_init() { 29 | if (-1 == sodium_init()) 30 | return 1; 31 | randombytes_set_implementation(&randombytes_salsa20_implementation); 32 | randombytes_stir(); 33 | return 0; 34 | } 35 | 36 | int crypto_set_password(const char *password, 37 | unsigned long long password_len) { 38 | return crypto_generichash(key, sizeof key, (unsigned char *)password, 39 | password_len, NULL, 0); 40 | } 41 | 42 | int crypto_encrypt(unsigned char *c, unsigned char *m, 43 | unsigned long long mlen) { 44 | unsigned char nonce[8]; 45 | randombytes_buf(nonce, 8); 46 | int r = crypto_secretbox_salsa208poly1305(c, m, mlen + 32, nonce, key); 47 | if (r != 0) return r; 48 | // copy nonce to the head 49 | memcpy(c + 8, nonce, 8); 50 | return 0; 51 | } 52 | 53 | int crypto_decrypt(unsigned char *m, unsigned char *c, 54 | unsigned long long clen) { 55 | unsigned char nonce[8]; 56 | memcpy(nonce, c + 8, 8); 57 | int r = crypto_secretbox_salsa208poly1305_open(m, c, clen + 32, nonce, key); 58 | if (r != 0) return r; 59 | return 0; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /tunnel/crypto.h: -------------------------------------------------------------------------------- 1 | /** 2 | crypto.h 3 | 4 | Copyright (C) 2015 clowwindy 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | #ifndef CRYPTO_H 22 | #define CRYPTO_H 23 | 24 | /* call once after start */ 25 | int crypto_init(); 26 | 27 | // TODO use a struct to hold context instead 28 | /* call when password changed */ 29 | int crypto_set_password(const char *password, 30 | unsigned long long password_len); 31 | 32 | int crypto_encrypt(unsigned char *c, unsigned char *m, 33 | unsigned long long mlen); 34 | 35 | int crypto_decrypt(unsigned char *m, unsigned char *c, 36 | unsigned long long clen); 37 | 38 | #define SHADOWVPN_KEY_LEN 32 39 | 40 | /* 41 | buffer layout 42 | 43 | [SALSA20_RESERVED 8] [NONCE 8] [MAC 16] [OPTIONAL USERTOKEN 8] [PAYLOAD MTU] 44 | 45 | Buffer total size: 46 | SHADOWVPN_ZERO_BYTES + USERTOKEN + MTU 47 | 48 | TUN reads & writes at: 49 | SHADOWVPN_ZERO_BYTES + USERTOKEN 50 | 51 | UDP packet sendto & recvfrom at: 52 | SHADOWVPN_PACKET_OFFSET = SALSA20_RESERVED 53 | 54 | Plain text starts from in buffer: 55 | SHADOWVPN_ZERO_BYTES = SALSA20_RESERVED + NONCE + MAC 56 | 57 | Plain text starts from in UDP packet: 58 | SHADOWVPN_OVERHEAD_LEN = NONCE + MAC 59 | 60 | */ 61 | 62 | #define SHADOWVPN_ZERO_BYTES 32 63 | #define SHADOWVPN_OVERHEAD_LEN 24 64 | #define SHADOWVPN_PACKET_OFFSET 8 65 | #define SHADOWVPN_USERTOKEN_LEN 8 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /ShadowVPN/SimpleTableViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SimpleTableViewController.swift 3 | // ShadowVPN 4 | // 5 | // Created by FlyKite on 2018/5/23. 6 | // Copyright © 2018年 clowwindy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SimpleTableViewController: UITableViewController { 12 | 13 | private var labels: [String] 14 | private var values: [String] 15 | private var selectedValue: String? 16 | private var selectionHandler: (String) -> Void 17 | 18 | init(labels: [String], values: [String], initialValue: String?, selectionHandler: @escaping (String) -> Void) { 19 | self.labels = labels 20 | self.values = values 21 | self.selectedValue = initialValue 22 | self.selectionHandler = selectionHandler 23 | super.init(nibName: nil, bundle: nil) 24 | } 25 | 26 | required init?(coder aDecoder: NSCoder) { 27 | fatalError("init(coder:) has not been implemented") 28 | } 29 | 30 | override func viewDidLoad() { 31 | super.viewDidLoad() 32 | self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") 33 | } 34 | 35 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 36 | let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 37 | cell.textLabel?.text = self.labels[indexPath.row] 38 | if self.values[indexPath.row] == self.selectedValue { 39 | cell.accessoryType = .checkmark 40 | } else { 41 | cell.accessoryType = .none 42 | } 43 | return cell 44 | } 45 | 46 | override func numberOfSections(in tableView: UITableView) -> Int { 47 | return 1 48 | } 49 | 50 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 51 | return self.labels.count 52 | } 53 | 54 | override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 55 | let value = self.values[indexPath.row] 56 | self.selectedValue = value 57 | let rowCount = tableView.numberOfRows(inSection: 0) 58 | for index in 0 ..< rowCount { 59 | if index != indexPath.row { 60 | tableView.cellForRow(at: IndexPath(row: index, section: 0))?.accessoryType = .none 61 | } 62 | } 63 | tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark 64 | tableView.deselectRow(at: indexPath, animated: true) 65 | self.selectionHandler(value) 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /ShadowVPN/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 7/18/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { 17 | // Override point for customization after application launch. 18 | let window = UIWindow(frame: UIScreen.main.bounds) 19 | let viewController = UINavigationController(rootViewController: MainViewController(style: .grouped)) 20 | window.rootViewController = viewController 21 | window.makeKeyAndVisible() 22 | self.window = window 23 | return true 24 | } 25 | 26 | func applicationWillResignActive(_ application: UIApplication) { 27 | // 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. 28 | // 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. 29 | } 30 | 31 | func applicationDidEnterBackground(_ application: UIApplication) { 32 | // 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. 33 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 34 | } 35 | 36 | func applicationWillEnterForeground(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationDidBecomeActive(_ application: UIApplication) { 41 | // 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. 42 | } 43 | 44 | func applicationWillTerminate(_ application: UIApplication) { 45 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 46 | } 47 | 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /tunnel/RouteManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RouteManager.swift 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 8/9/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import NetworkExtension 11 | 12 | class RouteManager: NSObject { 13 | var cidrToSubnetMask = [ 14 | "32": "255.255.255.255", 15 | "31": "255.255.255.254", 16 | "30": "255.255.255.252", 17 | "29": "255.255.255.248", 18 | "28": "255.255.255.240", 19 | "27": "255.255.255.224", 20 | "26": "255.255.255.192", 21 | "25": "255.255.255.128", 22 | "24": "255.255.255.0", 23 | "23": "255.255.254.0", 24 | "22": "255.255.252.0", 25 | "21": "255.255.248.0", 26 | "20": "255.255.240.0", 27 | "19": "255.255.224.0", 28 | "18": "255.255.192.0", 29 | "17": "255.255.128.0", 30 | "16": "255.255.0.0", 31 | "15": "255.254.0.0", 32 | "14": "255.252.0.0", 33 | "13": "255.248.0.0", 34 | "12": "255.240.0.0", 35 | "11": "255.224.0.0", 36 | "10": "255.192.0.0", 37 | "9": "255.128.0.0", 38 | "8": "255.0.0.0", 39 | "7": "254.0.0.0", 40 | "6": "252.0.0.0", 41 | "5": "248.0.0.0", 42 | "4": "240.0.0.0", 43 | "3": "224.0.0.0", 44 | "2": "192.0.0.0", 45 | "1": "128.0.0.0", 46 | "0": "0.0.0.0" 47 | ] 48 | init(route: String?, IPv4Settings: NEIPv4Settings) { 49 | super.init() 50 | if route == "chnroutes" { 51 | parseCHNRoutes(IPv4Settings: IPv4Settings) 52 | } else { 53 | NSLog("using default route") 54 | // TODO also support https://github.com/ashi009/bestroutetb 55 | IPv4Settings.includedRoutes = [NEIPv4Route.default()] 56 | } 57 | } 58 | 59 | func parseCHNRoutes(IPv4Settings: NEIPv4Settings) { 60 | NSLog("parsing chnroutes") 61 | var routes = [NEIPv4Route]() 62 | let chnroutesPath = Bundle.main.path(forResource: "chnroutes", ofType: "txt") 63 | do { 64 | let content = try String(contentsOfFile: chnroutesPath!) 65 | let lines = content.components(separatedBy: "\n") 66 | for line in lines { 67 | let parts = line.components(separatedBy: "/") 68 | if parts.count == 2 { 69 | let address = parts[0] 70 | let subnet = self.cidrToSubnetMask[parts[1]] 71 | // NSLog("adding route %@", address) 72 | routes.append(NEIPv4Route(destinationAddress: address, subnetMask: subnet!)) 73 | } 74 | } 75 | } catch { 76 | print(String(describing: error)) 77 | } 78 | IPv4Settings.includedRoutes = [NEIPv4Route.default()] 79 | IPv4Settings.excludedRoutes = routes 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /tunnel/ChinaDNSRunner.m: -------------------------------------------------------------------------------- 1 | // 2 | // ChinaDNSRunner.m 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 8/9/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #import "chinadns.h" 15 | 16 | #import "ChinaDNSRunner.h" 17 | 18 | #define MAX_ARG 64 19 | #define ADD_ARGV(arg) do { argv[argc] = arg; argc++; } while (0) 20 | 21 | static BOOL _wifiStatus; 22 | 23 | @implementation ChinaDNSRunner { 24 | NSString *_dns; 25 | dispatch_queue_t _queue; 26 | } 27 | 28 | - (instancetype)initWithDNS:(NSString *)dns { 29 | self = [super init]; 30 | if (self) { 31 | _dns = [dns copy]; 32 | _queue = dispatch_queue_create("shadowvpn.dns", DISPATCH_QUEUE_SERIAL); 33 | dispatch_async(_queue, ^{ 34 | [self run]; 35 | }); 36 | } 37 | 38 | return self; 39 | } 40 | 41 | 42 | - (void)run { 43 | int argc = 0; 44 | char *(argv)[MAX_ARG]; 45 | 46 | char *iplistPath = strdup([[[NSBundle mainBundle] pathForResource:@"iplist" ofType:@"txt"] cStringUsingEncoding:NSUTF8StringEncoding]); 47 | char *chnroutesPath = strdup([[[NSBundle mainBundle] pathForResource:@"chnroutes" ofType:@"txt"] cStringUsingEncoding:NSUTF8StringEncoding]); 48 | char *dns = strdup([_dns cStringUsingEncoding:NSUTF8StringEncoding]); 49 | NSLog(@"%s", iplistPath); 50 | NSLog(@"%s", chnroutesPath); 51 | 52 | ADD_ARGV("chinadns"); 53 | ADD_ARGV("-l"); 54 | ADD_ARGV(iplistPath); 55 | ADD_ARGV("-c"); 56 | ADD_ARGV(chnroutesPath); 57 | ADD_ARGV("-s"); 58 | ADD_ARGV(dns); 59 | ADD_ARGV("-b"); 60 | ADD_ARGV("127.0.0.1"); 61 | ADD_ARGV("-p"); 62 | ADD_ARGV("53"); 63 | ADD_ARGV("-v"); 64 | int r = chinadns_main(argc, argv); 65 | free(iplistPath); 66 | free(chnroutesPath); 67 | free(dns); 68 | exit(r); 69 | } 70 | 71 | + (BOOL)checkWiFiNetwork { 72 | struct ifaddrs* interfaces = NULL; 73 | struct ifaddrs* temp_addr = NULL; 74 | BOOL found = NO; 75 | 76 | NSInteger success = getifaddrs(&interfaces); 77 | if (success == 0) 78 | { 79 | temp_addr = interfaces; 80 | while (temp_addr != NULL) 81 | { 82 | if (temp_addr->ifa_addr->sa_family == AF_INET) 83 | { 84 | NSString* name = [NSString stringWithUTF8String:temp_addr->ifa_name]; 85 | NSString* address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]; 86 | // NSLog(@"%@ %@", name, address); 87 | if ([name rangeOfString:@"en"].location == 0) { 88 | found = YES; 89 | break; 90 | } 91 | } 92 | 93 | temp_addr = temp_addr->ifa_next; 94 | } 95 | } 96 | 97 | if (_wifiStatus != found) { 98 | remote_recreate_required = 1; 99 | } 100 | _wifiStatus = found; 101 | freeifaddrs(interfaces); 102 | return found; 103 | } 104 | 105 | @end 106 | -------------------------------------------------------------------------------- /tunnel/SVCrypto.m: -------------------------------------------------------------------------------- 1 | // 2 | // SVCrypto.m 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 7/18/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | #import "SVCrypto.h" 10 | #import "crypto.h" 11 | 12 | static const int max_mtu = 2048; 13 | static const int sv_buf_size = max_mtu + SHADOWVPN_ZERO_BYTES + SHADOWVPN_USERTOKEN_LEN; 14 | 15 | static NSString *kTunBufKey = @"SVTunBuf"; 16 | static NSString *kUdpBufKey = @"SVUdpBuf"; 17 | 18 | @implementation SVCrypto 19 | 20 | + (void)load { 21 | crypto_init(); 22 | } 23 | 24 | + (void)setPassword:(NSString *)password { 25 | crypto_set_password([password cStringUsingEncoding:NSUTF8StringEncoding], password.length); 26 | } 27 | 28 | + (NSMutableData *)tunbuf { 29 | NSMutableData *buf = [[NSThread currentThread] threadDictionary][kTunBufKey]; 30 | if (buf == nil) { 31 | buf = [[NSMutableData alloc] initWithLength:sv_buf_size]; 32 | [[NSThread currentThread] threadDictionary][kTunBufKey] = buf; 33 | } 34 | return buf; 35 | } 36 | 37 | + (NSMutableData *)udpbuf { 38 | NSMutableData *buf = [[NSThread currentThread] threadDictionary][kUdpBufKey]; 39 | if (buf == nil) { 40 | buf = [[NSMutableData alloc] initWithLength:sv_buf_size]; 41 | [[NSThread currentThread] threadDictionary][kUdpBufKey] = buf; 42 | } 43 | return buf; 44 | } 45 | 46 | + (NSData *)encryptWithData:(NSData *)data userToken:(NSData *)userToken { 47 | int usertoken_len = 0; 48 | if (data.length > max_mtu) { 49 | return nil; 50 | } 51 | unsigned char *tun_buf = [[SVCrypto tunbuf] mutableBytes]; 52 | unsigned char *udp_buf = [[SVCrypto udpbuf] mutableBytes]; 53 | 54 | if (userToken) { 55 | NSAssert(userToken.length == SHADOWVPN_USERTOKEN_LEN, @"invalid user token length"); 56 | usertoken_len = SHADOWVPN_USERTOKEN_LEN; 57 | memcpy(tun_buf + SHADOWVPN_ZERO_BYTES, userToken.bytes, userToken.length); 58 | } 59 | memcpy(tun_buf + SHADOWVPN_ZERO_BYTES + usertoken_len, data.bytes, data.length); 60 | crypto_encrypt(udp_buf, tun_buf, usertoken_len + data.length); 61 | NSData *result = [NSData dataWithBytes:udp_buf + SHADOWVPN_PACKET_OFFSET length:SHADOWVPN_OVERHEAD_LEN + usertoken_len + data.length]; 62 | return result; 63 | } 64 | 65 | + (NSData *)decryptWithData:(NSData *)data userToken:(NSData *)userToken { 66 | int usertoken_len = 0; 67 | if (data.length > max_mtu || data.length < SHADOWVPN_OVERHEAD_LEN) { 68 | return nil; 69 | } 70 | unsigned char *tun_buf = [[SVCrypto tunbuf] mutableBytes]; 71 | unsigned char *udp_buf = [[SVCrypto udpbuf] mutableBytes]; 72 | if (userToken) { 73 | NSAssert(userToken.length == SHADOWVPN_USERTOKEN_LEN, @"invalid user token length"); 74 | usertoken_len = SHADOWVPN_USERTOKEN_LEN; 75 | // TODO compare user token and log warnings 76 | } 77 | memcpy(udp_buf + SHADOWVPN_PACKET_OFFSET, data.bytes, data.length); 78 | crypto_decrypt(tun_buf, udp_buf, data.length - SHADOWVPN_OVERHEAD_LEN); 79 | NSData *result = [NSData dataWithBytes:tun_buf + SHADOWVPN_ZERO_BYTES + usertoken_len length:data.length - SHADOWVPN_OVERHEAD_LEN - usertoken_len]; 80 | return result; 81 | } 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /ShadowVPN/ConfigurationValidator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConfigurationValidator.swift 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 8/10/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ConfigurationValidator: NSObject { 12 | 13 | // return nil if there's no error 14 | class func validateIP(ip: String) -> String? { 15 | let parts = ip.components(separatedBy: ".") 16 | if parts.count != 4 { 17 | return "Invalid IP: " + ip 18 | } 19 | for part in parts { 20 | let n = Int(part) 21 | if n == nil || n! < 0 || n! > 255 { 22 | return "Invalid IP: " + ip 23 | } 24 | } 25 | return nil 26 | } 27 | 28 | // return nil if there's no error 29 | class func validate(configuration: [String: Any]) -> String? { 30 | // 1. server must be not empty 31 | guard let server = configuration["server"] as? String, server.count > 0 else { 32 | return "Server must not be empty" 33 | } 34 | // 2. port must be int 1, 65535 35 | guard let portStr = configuration["port"] as? String, portStr.count > 0, let port = Int(portStr) else { 36 | return "Port must not be empty" 37 | } 38 | if port < 1 || port > 65535 { 39 | return "Port is invalid" 40 | } 41 | // 3. password must be not empty 42 | guard let password = configuration["password"] as? String, password.count > 0 else { 43 | return "Password must not be empty" 44 | } 45 | // 4. usertoken must be empty or hex of 8 bytes 46 | if let usertoken = configuration["usertoken"] as? String { 47 | let data = Data(fromHex: usertoken) 48 | if data.count != 8 && data.count != 0 { 49 | return "Usertoken must be HEX of 8 bytes (example: 7e335d67f1dc2c01)" 50 | } 51 | } 52 | // 5. ip must be valid IP 53 | guard let ip = configuration["ip"] as? String, ip.count > 0 else { 54 | return "IP must not be empty" 55 | } 56 | if let result = validateIP(ip: ip) { 57 | return result 58 | } 59 | // 6. subnet must be valid subnet 60 | guard let subnet = configuration["subnet"] as? String, subnet.count > 0 else { 61 | return "Subnet must not be empty" 62 | } 63 | if let result = validateIP(ip: subnet) { 64 | return result 65 | } 66 | // 7. dns must be comma separated ip addresses 67 | guard let dns = configuration["dns"] as? String, dns.count > 0 else { 68 | return "DNS must not be empty" 69 | } 70 | let ips = dns.components(separatedBy: ",") 71 | if ips.count == 0 { 72 | return "DNS must not be empty" 73 | } 74 | for ip in ips { 75 | if let result = validateIP(ip: ip) { 76 | return result 77 | } 78 | } 79 | // 8. mtu must be int 80 | guard let mtuStr = configuration["mtu"] as? String, mtuStr.count > 0, let mtu = Int(mtuStr) else { 81 | return "MTU must not be empty" 82 | } 83 | if mtu < 100 || mtu > 9000 { 84 | return "MTU is invalid" 85 | } 86 | // 9. routes must be empty or chnroutes 87 | return nil 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /ShadowVPN/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /ShadowVPN/MainViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MainViewController.swift 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 8/6/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import NetworkExtension 11 | 12 | let kTunnelProviderBundle = "clowwindy.ShadowVPN.tunnel" 13 | 14 | class MainViewController: UITableViewController { 15 | 16 | var vpnManagers = [NETunnelProviderManager]() 17 | var currentVPNManager: NETunnelProviderManager? 18 | var vpnStatusSwitch = UISwitch() 19 | var vpnStatusLabel = UILabel() 20 | 21 | override func viewDidLoad() { 22 | super.viewDidLoad() 23 | self.title = "ShadowVPN" 24 | self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addConfiguration)) 25 | 26 | NotificationCenter.default.addObserver(self, selector: #selector(VPNStatusDidChange(notification:)), name: .NEVPNStatusDidChange, object: nil) 27 | vpnStatusSwitch.addTarget(self, action: #selector(vpnStatusSwitchValueDidChange(sender:)), for: .valueChanged) 28 | // vpnStatusLabel.textAlignment = .Right 29 | // vpnStatusLabel.textColor = UIColor.grayColor() 30 | } 31 | 32 | deinit { 33 | NotificationCenter.default.removeObserver(self, name: .NEVPNStatusDidChange, object: nil) 34 | } 35 | 36 | @objc func vpnStatusSwitchValueDidChange(sender: UISwitch) { 37 | do { 38 | if vpnManagers.count > 0 { 39 | if let currentVPNManager = self.currentVPNManager { 40 | if sender.isOn { 41 | try currentVPNManager.connection.startVPNTunnel() 42 | } else { 43 | currentVPNManager.connection.stopVPNTunnel() 44 | } 45 | } 46 | } 47 | } catch { 48 | print(String(describing: error)) 49 | } 50 | } 51 | 52 | @objc func VPNStatusDidChange(notification: NSNotification?) { 53 | var on = false 54 | var enabled = false 55 | if let currentVPNManager = self.currentVPNManager { 56 | let status = currentVPNManager.connection.status 57 | switch status { 58 | case .connecting: 59 | on = true 60 | enabled = false 61 | vpnStatusLabel.text = "Connecting..." 62 | break 63 | case .connected: 64 | on = true 65 | enabled = true 66 | vpnStatusLabel.text = "Connected" 67 | break 68 | case .disconnecting: 69 | on = false 70 | enabled = false 71 | vpnStatusLabel.text = "Disconnecting..." 72 | break 73 | case .disconnected: 74 | on = false 75 | enabled = true 76 | vpnStatusLabel.text = "Not Connected" 77 | break 78 | default: 79 | on = false 80 | enabled = true 81 | break 82 | } 83 | vpnStatusSwitch.isOn = on 84 | vpnStatusSwitch.isEnabled = enabled 85 | UIApplication.shared.isNetworkActivityIndicatorVisible = !enabled 86 | } 87 | } 88 | 89 | override func viewWillAppear(_ animated: Bool) { 90 | super.viewWillAppear(animated) 91 | self.loadConfigurationFromSystem() 92 | 93 | } 94 | 95 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 96 | if indexPath.section == 0 { 97 | let cell = UITableViewCell(style: .value1, reuseIdentifier: "status") 98 | cell.selectionStyle = .none 99 | cell.textLabel?.text = "Status" 100 | vpnStatusLabel = cell.detailTextLabel! 101 | cell.accessoryView = vpnStatusSwitch 102 | return cell 103 | } else { 104 | let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "configuration") 105 | let vpnManager = self.vpnManagers[indexPath.row] 106 | cell.textLabel?.text = vpnManager.protocolConfiguration?.serverAddress 107 | cell.detailTextLabel?.text = (vpnManager.protocolConfiguration as? NETunnelProviderProtocol)?.providerConfiguration?["description"] as? String 108 | if vpnManager.isEnabled { 109 | cell.imageView?.image = UIImage(named: "checkmark") 110 | } else { 111 | cell.imageView?.image = UIImage(named: "checkmark_empty") 112 | } 113 | cell.accessoryType = .detailButton 114 | return cell 115 | } 116 | } 117 | 118 | override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 119 | if indexPath.section == 1 { 120 | tableView.deselectRow(at: indexPath, animated: true) 121 | let vpnManager = self.vpnManagers[indexPath.row] 122 | vpnManager.isEnabled = true 123 | vpnManager.saveToPreferences { (error) -> Void in 124 | self.loadConfigurationFromSystem() 125 | } 126 | } 127 | } 128 | 129 | override func numberOfSections(in tableView: UITableView) -> Int { 130 | return 2 131 | } 132 | 133 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 134 | if section == 0 { 135 | return 1 136 | } else { 137 | return self.vpnManagers.count 138 | } 139 | } 140 | 141 | override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { 142 | let configurationController = ConfigurationViewController(style:.grouped) 143 | configurationController.providerManager = self.vpnManagers[indexPath.row] 144 | self.navigationController?.pushViewController(configurationController, animated: true) 145 | } 146 | 147 | @objc func addConfiguration() { 148 | let manager = NETunnelProviderManager() 149 | manager.loadFromPreferences { (error) -> Void in 150 | let providerProtocol = NETunnelProviderProtocol() 151 | providerProtocol.providerBundleIdentifier = kTunnelProviderBundle 152 | providerProtocol.providerConfiguration = [String: AnyObject]() 153 | manager.protocolConfiguration = providerProtocol 154 | 155 | let configurationController = ConfigurationViewController(style:.grouped) 156 | configurationController.providerManager = manager 157 | self.navigationController?.pushViewController(configurationController, animated: true) 158 | manager.saveToPreferences(completionHandler: { (error) -> Void in 159 | if let error = error { 160 | print(error) 161 | } 162 | }) 163 | } 164 | } 165 | 166 | func loadConfigurationFromSystem() { 167 | NETunnelProviderManager.loadAllFromPreferences() { newManagers, error in 168 | if let error = error { 169 | print(error) 170 | } 171 | guard let vpnManagers = newManagers else { return } 172 | self.vpnManagers.removeAll() 173 | for vpnManager in vpnManagers { 174 | if let providerProtocol = vpnManager.protocolConfiguration as? NETunnelProviderProtocol { 175 | if providerProtocol.providerBundleIdentifier == kTunnelProviderBundle { 176 | if vpnManager.isEnabled { 177 | self.currentVPNManager = vpnManager 178 | } 179 | self.vpnManagers.append(vpnManager) 180 | } 181 | } 182 | } 183 | self.vpnStatusSwitch.isEnabled = vpnManagers.count > 0 184 | self.tableView.reloadData() 185 | self.VPNStatusDidChange(notification: nil) 186 | } 187 | } 188 | 189 | } 190 | -------------------------------------------------------------------------------- /tunnel/PacketTunnelProvider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PacketTunnelProvider.swift 3 | // tunnel 4 | // 5 | // Created by clowwindy on 7/18/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | import NetworkExtension 10 | 11 | class PacketTunnelProvider: NEPacketTunnelProvider { 12 | var session: NWUDPSession? 13 | var conf: [String: Any] = [:] 14 | var pendingStartCompletion: ((Error?) -> Void)? 15 | var userToken: Data? 16 | var chinaDNS: ChinaDNSRunner? 17 | var routeManager: RouteManager? 18 | // var wifi = ChinaDNSRunner.checkWiFiNetwork() 19 | var queue: DispatchQueue? 20 | 21 | override func startTunnel(options: [String : NSObject]? = nil, completionHandler: @escaping (Error?) -> Void) { 22 | queue = DispatchQueue(label: "shadowvpn.queue") 23 | conf = (self.protocolConfiguration as? NETunnelProviderProtocol)?.providerConfiguration ?? [:] 24 | self.pendingStartCompletion = completionHandler 25 | chinaDNS = ChinaDNSRunner(dns: conf["dns"] as? String) 26 | if let userTokenString = conf["usertoken"] as? String { 27 | if userTokenString.count == 16 { 28 | userToken = Data(fromHex: userTokenString) 29 | } 30 | } 31 | NSLog("setPassword") 32 | SVCrypto.setPassword(conf["password"] as? String ?? "") 33 | self.recreateUDP() 34 | let keyPath = "defaultPath" 35 | let options = NSKeyValueObservingOptions([.new, .old]) 36 | self.addObserver(self, forKeyPath: keyPath, options: options, context: nil) 37 | NSLog("readPacketsFromTUN") 38 | self.readPacketsFromTUN() 39 | } 40 | 41 | func recreateUDP() { 42 | if self.session != nil { 43 | self.reasserting = true 44 | self.session = nil 45 | } 46 | queue?.async { 47 | if let serverAddress = self.protocolConfiguration.serverAddress { 48 | if let port = self.conf["port"] as? String { 49 | self.reasserting = false 50 | self.setTunnelNetworkSettings(nil, completionHandler: { (error) in 51 | if let error = error { 52 | print(error) 53 | // NSLog("%@", error) 54 | // simply kill the extension process since it does no harm and ShadowVPN is expected to be always on 55 | // exit(1) 56 | } 57 | self.queue?.async { 58 | print("recreateUDP") 59 | self.session = self.createUDPSession(to: NWHostEndpoint(hostname: serverAddress, port: port), from: nil) 60 | self.updateNetwork() 61 | } 62 | }) 63 | } 64 | } 65 | } 66 | } 67 | 68 | func updateNetwork() { 69 | NSLog("updateNetwork") 70 | let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: self.protocolConfiguration.serverAddress!) 71 | newSettings.ipv4Settings = NEIPv4Settings(addresses: [conf["ip"] as? String ?? ""], subnetMasks: [conf["subnet"] as? String ?? ""]) 72 | routeManager = RouteManager(route: conf["route"] as? String, IPv4Settings: newSettings.ipv4Settings!) 73 | if let mtuStr = conf["mtu"] as? String, let mtu = Int(mtuStr) { 74 | newSettings.mtu = NSNumber(value: mtu) 75 | } else { 76 | newSettings.mtu = 1432 77 | } 78 | if "chnroutes" == (conf["route"] as? String) { 79 | NSLog("using ChinaDNS") 80 | newSettings.dnsSettings = NEDNSSettings(servers: ["127.0.0.1"]) 81 | } else if let dns = conf["dns"] as? String { 82 | NSLog("using DNS") 83 | newSettings.dnsSettings = NEDNSSettings(servers: dns.components(separatedBy: ",")) 84 | } 85 | NSLog("setTunnelNetworkSettings") 86 | self.setTunnelNetworkSettings(newSettings) { (error) in 87 | self.readPacketsFromUDP() 88 | NSLog("readPacketsFromUDP") 89 | if let completionHandler = self.pendingStartCompletion { 90 | // send an packet 91 | // self.log("completion") 92 | if let error = error { 93 | print(error) 94 | } 95 | // NSLog("%@", String(error)) 96 | NSLog("VPN started") 97 | completionHandler(error) 98 | if error != nil { 99 | // simply kill the extension process since it does no harm and ShadowVPN is expected to be always on 100 | exit(1) 101 | } 102 | } 103 | } 104 | } 105 | 106 | func readPacketsFromTUN() { 107 | self.packetFlow.readPackets { (packets, protocols) in 108 | for packet in packets { 109 | // NSLog("TUN: %d", packet.length) 110 | self.session?.writeDatagram(SVCrypto.encrypt(with: packet, userToken: self.userToken), completionHandler: { (error) in 111 | if let error = error { 112 | print(error) 113 | // self.recreateUDP() 114 | // return 115 | } 116 | }) 117 | } 118 | self.readPacketsFromTUN() 119 | } 120 | 121 | } 122 | 123 | func readPacketsFromUDP() { 124 | session?.setReadHandler({ (newPackets, error) in 125 | // self.log("readPacketsFromUDP") 126 | guard let packets = newPackets else { return } 127 | var protocols = [NSNumber]() 128 | var decryptedPackets = [Data]() 129 | for packet in packets { 130 | // NSLog("UDP: %d", packet.length) 131 | // currently IPv4 only 132 | let decrypted = SVCrypto.decrypt(with: packet, userToken: self.userToken) 133 | // NSLog("write to TUN: %d", decrypted.length) 134 | decryptedPackets.append(decrypted!) 135 | protocols.append(2) 136 | } 137 | self.packetFlow.writePackets(decryptedPackets, withProtocols: protocols) 138 | }, maxDatagrams: NSIntegerMax) 139 | } 140 | 141 | override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { 142 | if let object = object as? NSObject { 143 | if object == self { 144 | if let keyPath = keyPath { 145 | if keyPath == "defaultPath" { 146 | // commented out since when switching from 4G to Wi-Fi, this will be called multiple times, only the last time works 147 | // let wifi = ChinaDNSRunner.checkWiFiNetwork() 148 | // if wifi != self.wifi { 149 | NSLog("Wi-Fi status changed") 150 | // self.wifi = wifi 151 | self.recreateUDP() 152 | // return 153 | // } 154 | 155 | } 156 | } 157 | } 158 | } 159 | } 160 | 161 | override func stopTunnel(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) { 162 | // Add code here to start the process of stopping the tunnel 163 | NSLog("stopTunnelWithReason") 164 | session?.cancel() 165 | completionHandler() 166 | super.stopTunnel(with: reason, completionHandler: completionHandler) 167 | // simply kill the extension process since it does no harm and ShadowVPN is expected to be always on 168 | exit(0) 169 | } 170 | 171 | override func handleAppMessage(_ messageData: Data, completionHandler: ((Data?) -> Void)? = nil) { 172 | // Add code here to handle the message 173 | if let handler = completionHandler { 174 | handler(messageData) 175 | } 176 | } 177 | 178 | override func sleep(completionHandler: @escaping () -> Void) { 179 | // Add code here to get ready to sleep 180 | completionHandler() 181 | } 182 | 183 | override func wake() { 184 | // Add code here to wake up 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /tunnel/iplist.txt: -------------------------------------------------------------------------------- 1 | 1.1.127.45 2 | 1.1.67.51 3 | 1.2.3.4 4 | 1.209.208.200 5 | 1.226.83.147 6 | 1.234.21.83 7 | 1.234.29.40 8 | 1.234.39.14 9 | 1.234.4.91 10 | 1.234.70.80 11 | 1.234.83.104 12 | 1.244.115.172 13 | 1.33.170.68 14 | 1.33.188.62 15 | 1.33.190.228 16 | 1.33.190.70 17 | 1.33.191.58 18 | 104.200.31.226 19 | 104.28.1.22 20 | 104.28.14.112 21 | 104.28.20.14 22 | 104.28.30.59 23 | 106.186.120.157 24 | 106.187.39.80 25 | 107.6.34.101 26 | 108.168.215.230 27 | 108.168.250.3 28 | 108.179.196.77 29 | 108.179.250.106 30 | 108.61.250.218 31 | 109.123.115.205 32 | 109.206.173.212 33 | 109.234.159.38 34 | 109.71.81.130 35 | 110.173.154.142 36 | 110.74.163.40 37 | 112.175.60.31 38 | 113.11.194.190 39 | 113.160.102.90 40 | 118.145.17.184 41 | 118.219.253.245 42 | 118.5.49.6 43 | 119.18.62.130 44 | 119.235.57.82 45 | 119.245.217.155 46 | 119.9.94.83 47 | 12.87.133.0 48 | 120.89.93.248 49 | 122.214.2.171 50 | 122.218.101.190 51 | 123.126.249.238 52 | 123.30.175.29 53 | 123.50.49.171 54 | 125.230.148.48 55 | 127.0.0.2 56 | 128.121.126.139 57 | 128.199.180.162 58 | 133.192.181.66 59 | 133.242.165.24 60 | 133.42.48.3 61 | 137.135.129.175 62 | 14.102.249.18 63 | 141.101.118.102 64 | 141.8.195.47 65 | 141.8.195.78 66 | 141.8.225.80 67 | 142.4.5.109 68 | 144.76.106.232 69 | 144.76.127.114 70 | 144.76.21.13 71 | 145.253.183.23 72 | 147.87.244.32 73 | 155.92.182.118 74 | 157.205.32.64 75 | 157.7.143.209 76 | 159.106.121.75 77 | 159.253.20.179 78 | 159.50.88.77 79 | 16.63.155.0 80 | 162.159.243.101 81 | 162.243.137.163 82 | 162.253.33.134 83 | 164.109.96.232 84 | 164.138.221.68 85 | 168.156.168.21 86 | 169.132.13.103 87 | 171.17.130.53 88 | 171.25.204.141 89 | 173.192.219.59 90 | 173.194.127.144 91 | 173.201.216.6 92 | 173.224.209.14 93 | 173.236.228.108 94 | 173.244.184.10 95 | 173.255.194.174 96 | 173.255.230.196 97 | 174.142.113.142 98 | 174.142.22.25 99 | 176.10.37.81 100 | 176.57.216.145 101 | 178.18.82.216 102 | 178.236.177.77 103 | 178.32.111.136 104 | 178.32.156.59 105 | 178.32.247.82 106 | 178.33.212.162 107 | 178.49.132.135 108 | 178.62.242.156 109 | 178.62.75.99 110 | 178.79.182.248 111 | 180.153.225.168 112 | 180.179.171.121 113 | 180.87.182.227 114 | 181.224.155.41 115 | 183.111.141.95 116 | 184.154.10.146 117 | 184.169.132.244 118 | 184.72.253.232 119 | 185.25.150.45 120 | 185.53.61.50 121 | 188.132.250.186 122 | 188.165.31.24 123 | 188.226.207.251 124 | 188.40.108.13 125 | 188.5.4.96 126 | 189.163.17.5 127 | 192.104.44.6 128 | 192.121.151.106 129 | 192.67.198.6 130 | 192.95.98.202 131 | 193.105.145.158 132 | 193.169.66.88 133 | 193.203.48.18 134 | 193.234.233.149 135 | 193.238.151.98 136 | 193.239.132.44 137 | 193.48.96.218 138 | 193.57.244.117 139 | 193.91.26.132 140 | 194.149.250.20 141 | 194.185.115.1 142 | 194.187.94.6 143 | 194.67.144.70 144 | 195.146.235.33 145 | 195.149.210.211 146 | 195.154.243.151 147 | 195.191.149.103 148 | 195.2.88.68 149 | 195.211.72.200 150 | 195.43.82.170 151 | 195.49.201.30 152 | 195.50.195.15 153 | 195.74.38.62 154 | 195.74.78.21 155 | 195.77.241.242 156 | 195.8.125.64 157 | 197.4.4.12 158 | 198.143.143.36 159 | 198.57.205.133 160 | 198.57.222.88 161 | 198.58.124.68 162 | 199.167.31.142 163 | 199.21.68.222 164 | 199.79.63.83 165 | 2.1.1.2 166 | 2.187.253.121 167 | 2.228.123.7 168 | 2.228.154.8 169 | 20.139.56.0 170 | 200.229.206.115 171 | 200.98.234.14 172 | 201.77.211.143 173 | 202.106.1.2 174 | 202.181.7.85 175 | 202.218.219.10 176 | 202.6.96.25 177 | 203.113.173.22 178 | 203.133.238.172 179 | 203.161.230.171 180 | 203.199.57.81 181 | 203.98.7.65 182 | 206.108.51.91 183 | 206.113.150.70 184 | 207.12.88.98 185 | 207.126.59.27 186 | 207.140.149.247 187 | 207.58.177.166 188 | 208.109.138.55 189 | 208.109.205.232 190 | 208.112.102.122 191 | 208.43.134.107 192 | 208.43.33.194 193 | 208.56.31.43 194 | 208.73.211.164 195 | 208.86.154.112 196 | 208.93.0.150 197 | 209.116.71.109 198 | 209.126.106.182 199 | 209.141.48.35 200 | 209.145.54.50 201 | 209.188.7.186 202 | 209.204.148.22 203 | 209.220.30.174 204 | 209.235.224.25 205 | 209.36.73.33 206 | 209.43.1.130 207 | 209.56.158.42 208 | 209.62.154.94 209 | 209.85.229.138 210 | 210.175.255.154 211 | 210.209.110.199 212 | 210.230.192.183 213 | 211.43.203.33 214 | 211.5.133.18 215 | 211.8.69.27 216 | 211.94.66.147 217 | 212.227.98.130 218 | 212.45.52.219 219 | 212.68.42.67 220 | 212.77.104.29 221 | 213.108.66.21 222 | 213.133.111.102 223 | 213.169.251.35 224 | 213.174.158.108 225 | 213.186.33.5 226 | 213.19.161.141 227 | 213.207.85.148 228 | 213.238.166.227 229 | 216.12.205.2 230 | 216.139.213.144 231 | 216.178.241.101 232 | 216.198.246.103 233 | 216.221.188.182 234 | 216.234.179.13 235 | 216.250.115.144 236 | 216.38.0.92 237 | 216.70.88.29 238 | 216.92.58.37 239 | 217.160.42.85 240 | 217.172.183.9 241 | 217.30.184.161 242 | 218.44.251.212 243 | 220.110.150.90 244 | 220.247.224.8 245 | 221.213.49.149 246 | 221.8.69.27 247 | 222.122.56.219 248 | 23.23.14.192 249 | 23.89.5.60 250 | 24.51.184.0 251 | 243.185.187.30 252 | 243.185.187.39 253 | 249.129.46.48 254 | 253.157.14.165 255 | 28.121.126.139 256 | 28.13.216.0 257 | 31.169.90.4 258 | 31.170.8.8 259 | 31.210.156.212 260 | 31.22.4.60 261 | 31.222.185.202 262 | 31.25.191.134 263 | 34.254.247.151 264 | 37.1.205.21 265 | 37.1.207.129 266 | 37.140.238.35 267 | 37.187.134.150 268 | 37.187.149.129 269 | 37.187.251.35 270 | 37.252.122.184 271 | 37.58.78.79 272 | 37.59.25.95 273 | 37.61.54.158 274 | 37.99.194.148 275 | 38.117.98.231 276 | 4.17.143.131 277 | 4.193.80.0 278 | 4.21.70.9 279 | 4.30.13.168 280 | 4.30.187.9 281 | 4.30.235.229 282 | 4.31.139.146 283 | 4.34.180.178 284 | 4.35.100.20 285 | 4.35.234.200 286 | 4.36.66.178 287 | 4.53.17.215 288 | 4.59.79.206 289 | 4.78.167.196 290 | 4.79.129.122 291 | 41.79.20.9 292 | 43.253.199.12 293 | 46.137.219.7 294 | 46.165.231.144 295 | 46.20.126.252 296 | 46.20.13.100 297 | 46.229.175.95 298 | 46.243.6.170 299 | 46.30.212.198 300 | 46.38.24.209 301 | 46.82.174.68 302 | 49.2.123.56 303 | 49.212.153.128 304 | 5.10.105.41 305 | 5.10.68.187 306 | 5.10.68.188 307 | 5.10.69.29 308 | 5.10.77.72 309 | 5.100.152.24 310 | 5.100.225.204 311 | 5.100.228.206 312 | 5.100.231.27 313 | 5.100.248.208 314 | 5.144.129.20 315 | 5.35.251.108 316 | 5.9.118.111 317 | 5.9.120.140 318 | 5.9.136.210 319 | 5.9.242.232 320 | 5.9.5.26 321 | 5.9.65.105 322 | 50.116.6.162 323 | 50.18.183.233 324 | 50.57.11.12 325 | 50.63.202.13 326 | 50.87.148.140 327 | 50.87.169.77 328 | 50.93.207.101 329 | 50.97.134.91 330 | 54.174.40.182 331 | 54.187.136.30 332 | 54.187.39.38 333 | 54.191.193.138 334 | 54.200.3.32 335 | 54.206.98.127 336 | 54.209.238.28 337 | 54.209.87.186 338 | 54.218.38.198 339 | 54.229.147.183 340 | 54.235.199.154 341 | 54.244.22.77 342 | 54.246.169.32 343 | 54.246.202.250 344 | 54.68.166.130 345 | 54.76.135.1 346 | 54.83.51.191 347 | 54.86.21.64 348 | 54.86.223.202 349 | 54.88.252.91 350 | 59.124.74.28 351 | 59.24.3.173 352 | 61.54.28.6 353 | 62.138.115.35 354 | 62.75.221.31 355 | 62.92.17.213 356 | 64.14.72.41 357 | 64.150.184.98 358 | 64.22.110.34 359 | 64.33.88.161 360 | 64.33.99.47 361 | 64.34.161.142 362 | 64.50.179.133 363 | 64.66.163.251 364 | 64.79.69.250 365 | 64.79.84.141 366 | 64.91.254.97 367 | 65.104.202.252 368 | 65.160.219.113 369 | 65.183.39.139 370 | 66.146.2.241 371 | 66.187.204.50 372 | 66.206.11.194 373 | 66.39.61.161 374 | 66.45.252.237 375 | 66.55.151.148 376 | 66.85.134.186 377 | 66.96.147.160 378 | 67.137.227.11 379 | 67.225.220.248 380 | 68.71.58.18 381 | 69.16.196.113 382 | 69.167.172.162 383 | 69.171.13.49 384 | 69.174.244.221 385 | 69.175.75.202 386 | 69.195.124.90 387 | 69.30.23.10 388 | 69.50.192.218 389 | 69.61.60.122 390 | 70.42.243.33 391 | 72.14.205.104 392 | 72.14.205.99 393 | 72.167.32.10 394 | 72.20.110.50 395 | 72.29.94.240 396 | 72.32.4.243 397 | 72.47.228.79 398 | 72.5.1.109 399 | 72.52.244.56 400 | 74.117.117.122 401 | 74.117.57.138 402 | 74.124.195.73 403 | 74.125.127.102 404 | 74.125.155.102 405 | 74.125.204.121 406 | 74.125.39.102 407 | 74.125.39.113 408 | 74.207.236.174 409 | 74.208.125.184 410 | 74.220.215.67 411 | 74.82.166.166 412 | 75.98.175.166 413 | 76.164.217.116 414 | 77.4.7.92 415 | 78.108.178.26 416 | 78.140.172.33 417 | 78.16.49.15 418 | 78.24.135.99 419 | 79.127.127.68 420 | 79.136.125.49 421 | 79.98.34.60 422 | 8.105.84.0 423 | 8.34.161.150 424 | 8.7.198.45 425 | 80.190.96.26 426 | 80.241.209.19 427 | 80.241.92.180 428 | 80.245.171.70 429 | 80.70.184.118 430 | 80.72.41.146 431 | 80.82.117.209 432 | 80.82.201.154 433 | 80.92.117.132 434 | 82.145.47.117 435 | 83.125.118.122 436 | 83.222.124.187 437 | 83.222.5.171 438 | 84.124.59.165 439 | 85.111.18.138 440 | 85.190.0.110 441 | 85.25.171.103 442 | 85.92.134.229 443 | 87.106.57.209 444 | 87.230.46.50 445 | 88.198.69.101 446 | 88.214.195.67 447 | 89.108.118.129 448 | 89.111.181.74 449 | 89.186.95.11 450 | 89.30.125.204 451 | 89.31.55.106 452 | 90.156.201.42 453 | 91.121.245.154 454 | 91.186.28.41 455 | 91.198.129.47 456 | 91.217.73.22 457 | 91.221.37.35 458 | 91.223.175.25 459 | 91.238.30.54 460 | 91.239.201.16 461 | 92.53.106.175 462 | 92.53.96.9 463 | 92.63.110.174 464 | 93.115.240.148 465 | 93.158.121.72 466 | 93.187.205.2 467 | 93.46.8.89 468 | 93.93.187.49 469 | 94.136.188.30 470 | 94.141.31.140 471 | 94.23.147.142 472 | 94.23.156.11 473 | 94.23.193.224 474 | 94.23.199.144 475 | 95.163.95.47 476 | 95.211.150.70 477 | 95.211.229.156 478 | 95.211.58.97 479 | 95.85.22.163 480 | 96.126.97.15 481 | 96.127.172.221 482 | 96.30.51.148 483 | 97.74.80.22 484 | 98.129.229.202 485 | 98.158.152.159 486 | 98.158.178.141 487 | -------------------------------------------------------------------------------- /ShadowVPN/ConfigurationViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConfigurationViewController.swift 3 | // ShadowVPN 4 | // 5 | // Created by clowwindy on 8/6/15. 6 | // Copyright © 2015 clowwindy. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import NetworkExtension 11 | 12 | 13 | class ConfigurationViewController: UITableViewController { 14 | var providerManager: NETunnelProviderManager? 15 | var bindMap: [String: UITextField] = [:] 16 | var configuration: [String: Any] = [:] 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(save)) 21 | self.title = providerManager?.protocolConfiguration?.serverAddress 22 | let conf = self.providerManager?.protocolConfiguration as? NETunnelProviderProtocol 23 | // Dictionary in Swift is a struct. This is a copy 24 | self.configuration = conf?.providerConfiguration ?? [:] 25 | } 26 | 27 | func updateConfiguration() { 28 | for (k, v) in self.bindMap { 29 | self.configuration[k] = v.text 30 | } 31 | // self.configuration["route"] = "chnroutes" 32 | } 33 | 34 | @objc func save() { 35 | updateConfiguration() 36 | if let result = ConfigurationValidator.validate(configuration: self.configuration) { 37 | let alertController = UIAlertController(title: "Error", message: result, preferredStyle: .alert) 38 | alertController.addAction(UIAlertAction(title: "OK", style: .cancel, handler: { (action) -> Void in 39 | })) 40 | self.present(alertController, animated: true, completion: { () -> Void in 41 | }) 42 | return 43 | } 44 | (self.providerManager?.protocolConfiguration as? NETunnelProviderProtocol)?.providerConfiguration = self.configuration 45 | self.providerManager?.protocolConfiguration?.serverAddress = self.configuration["server"] as? String 46 | self.providerManager?.localizedDescription = self.configuration["server"] as? String 47 | 48 | self.providerManager?.saveToPreferences { (error) -> Void in 49 | self.navigationController?.popViewController(animated: true) 50 | } 51 | } 52 | 53 | func bindData(textField: UITextField, property: String) { 54 | let val = configuration[property] 55 | if let val = val { 56 | textField.text = String(describing: val) 57 | } 58 | bindMap[property] = textField 59 | } 60 | 61 | 62 | override func numberOfSections(in tableView: UITableView) -> Int { 63 | return 2 64 | } 65 | 66 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 67 | switch section { 68 | case 0: 69 | return 10 70 | case 1: 71 | return 1 72 | default: 73 | return 0 74 | } 75 | } 76 | 77 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 78 | switch indexPath.section { 79 | case 0: 80 | let cell = ConfigurationTextCell() 81 | cell.selectionStyle = .none 82 | switch indexPath.row { 83 | case 0: 84 | cell.textLabel?.text = "Description" 85 | cell.textField.placeholder = "Optional" 86 | bindData(textField: cell.textField, property: "description") 87 | case 1: 88 | cell.textLabel?.text = "Server" 89 | cell.textField.placeholder = "Server IP" 90 | cell.textField.autocapitalizationType = .none 91 | cell.textField.autocorrectionType = .no 92 | bindData(textField: cell.textField, property: "server") 93 | case 2: 94 | cell.textLabel?.text = "Port" 95 | cell.textField.placeholder = "Server Port" 96 | cell.textField.text = "1123" 97 | cell.textField.autocapitalizationType = .none 98 | cell.textField.autocorrectionType = .no 99 | cell.textField.keyboardType = .numberPad 100 | bindData(textField: cell.textField, property: "port") 101 | case 3: 102 | cell.textLabel?.text = "Password" 103 | cell.textField.placeholder = "Required" 104 | cell.textField.text = "" 105 | cell.textField.isSecureTextEntry = true 106 | cell.textField.autocapitalizationType = .none 107 | cell.textField.autocorrectionType = .no 108 | bindData(textField: cell.textField, property: "password") 109 | case 4: 110 | cell.textLabel?.text = "User Token" 111 | cell.textField.placeholder = "Optional" 112 | cell.textField.text = "" 113 | cell.textField.autocapitalizationType = .none 114 | cell.textField.autocorrectionType = .no 115 | bindData(textField: cell.textField, property: "usertoken") 116 | case 5: 117 | cell.textLabel?.text = "IP" 118 | cell.textField.placeholder = "Required" 119 | cell.textField.text = "10.7.0.2" 120 | cell.textField.autocapitalizationType = .none 121 | cell.textField.autocorrectionType = .no 122 | cell.textField.keyboardType = .decimalPad 123 | bindData(textField: cell.textField, property: "ip") 124 | case 6: 125 | cell.textLabel?.text = "Subnet" 126 | cell.textField.placeholder = "Required" 127 | cell.textField.text = "255.255.255.0" 128 | cell.textField.autocapitalizationType = .none 129 | cell.textField.autocorrectionType = .no 130 | cell.textField.keyboardType = .decimalPad 131 | bindData(textField: cell.textField, property: "subnet") 132 | case 7: 133 | cell.textLabel?.text = "DNS" 134 | cell.textField.placeholder = "DNS Server Address" 135 | cell.textField.text = "114.114.114.114,223.5.5.5,8.8.8.8,8.8.4.4,208.67.222.222" 136 | cell.textField.autocapitalizationType = .none 137 | cell.textField.autocorrectionType = .no 138 | bindData(textField: cell.textField, property: "dns") 139 | case 8: 140 | cell.textLabel?.text = "MTU" 141 | cell.textField.placeholder = "MTU" 142 | cell.textField.text = "1350" 143 | cell.textField.autocapitalizationType = .none 144 | cell.textField.autocorrectionType = .no 145 | cell.textField.keyboardType = .numberPad 146 | bindData(textField: cell.textField, property: "mtu") 147 | case 9: 148 | cell.textLabel?.text = "Route" 149 | cell.textField.text = "chnroutes" 150 | cell.textField.isEnabled = false 151 | cell.accessoryType = .disclosureIndicator 152 | cell.selectionStyle = .default 153 | bindData(textField: cell.textField, property: "route") 154 | return cell 155 | default: 156 | break 157 | } 158 | return cell 159 | case 1: 160 | let cell = UITableViewCell() 161 | cell.textLabel?.text = "Delete This Configuration" 162 | cell.textLabel?.textColor = UIColor.red 163 | return cell 164 | default: 165 | return UITableViewCell() 166 | } 167 | } 168 | 169 | override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 170 | tableView.deselectRow(at: indexPath, animated: true) 171 | if (indexPath.section == 0) { 172 | if (indexPath.row == 9) { 173 | let controller = SimpleTableViewController(labels: ["Default", "CHNRoutes"], values: ["default", "chnroutes"], initialValue: self.configuration["route"] as? String, selectionHandler: { [weak self] (result) -> Void in 174 | guard let `self` = self else { return } 175 | // else we'll lost unsaved modifications 176 | self.updateConfiguration() 177 | self.configuration["route"] = result 178 | self.tableView.reloadData() 179 | }) 180 | self.navigationController?.pushViewController(controller, animated: true) 181 | } 182 | } else if (indexPath.section == 1) { 183 | let alertController = UIAlertController(title: nil, message: "Delete this configuration?", preferredStyle: .alert) 184 | alertController.addAction(UIAlertAction(title: "Delete", style: .destructive, handler: { (action) in 185 | self.providerManager?.removeFromPreferences(completionHandler: { (error) in 186 | self.navigationController?.popViewController(animated: true) 187 | }) 188 | })) 189 | alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil)) 190 | self.present(alertController, animated: true, completion: nil) 191 | } 192 | } 193 | 194 | 195 | } 196 | -------------------------------------------------------------------------------- /tunnel/chinadns.m: -------------------------------------------------------------------------------- 1 | /* ChinaDNS 2 | Copyright (C) 2015 clowwindy 3 | 4 | This program is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #import "chinadns.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | typedef struct { 36 | uint16_t id; 37 | struct timeval ts; 38 | char *buf; 39 | size_t buflen; 40 | struct sockaddr *addr; 41 | socklen_t addrlen; 42 | } delay_buf_t; 43 | 44 | typedef struct { 45 | uint16_t id; 46 | uint16_t old_id; 47 | struct sockaddr *addr; 48 | socklen_t addrlen; 49 | } id_addr_t; 50 | 51 | typedef struct { 52 | int entries; 53 | struct in_addr *ips; 54 | } ip_list_t; 55 | 56 | typedef struct { 57 | struct in_addr net; 58 | in_addr_t mask; 59 | } net_mask_t; 60 | 61 | typedef struct { 62 | int entries; 63 | net_mask_t *nets; 64 | } net_list_t; 65 | 66 | 67 | // avoid malloc and free 68 | #define BUF_SIZE 512 69 | static char global_buf[BUF_SIZE]; 70 | static char compression_buf[BUF_SIZE]; 71 | static int verbose = 0; 72 | static int compression = 0; 73 | static int bidirectional = 0; 74 | 75 | static const char *default_dns_servers = 76 | "114.114.114.114,223.5.5.5,8.8.8.8,8.8.4.4,208.67.222.222:443,208.67.222.222:5353"; 77 | static char *dns_servers = NULL; 78 | static int dns_servers_len; 79 | static int has_chn_dns; 80 | static id_addr_t *dns_server_addrs; 81 | 82 | static int parse_args(int argc, char **argv); 83 | 84 | static int setnonblock(int sock); 85 | static int resolve_dns_servers(); 86 | 87 | static const char *default_listen_addr = "127.0.0.1"; 88 | static const char *default_listen_port = "53"; 89 | 90 | static char *listen_addr = NULL; 91 | static char *listen_port = NULL; 92 | 93 | static char *ip_list_file = NULL; 94 | static ip_list_t ip_list; 95 | static int parse_ip_list(); 96 | 97 | static char *chnroute_file = NULL; 98 | static net_list_t chnroute_list; 99 | static int parse_chnroute(); 100 | static int test_ip_in_list(struct in_addr ip, const net_list_t *netlist); 101 | 102 | int remote_recreate_required; 103 | 104 | static int dns_init_sockets(); 105 | static void dns_handle_local(); 106 | static void dns_handle_remote(); 107 | 108 | static const char *hostname_from_question(ns_msg msg); 109 | static int should_filter_query(ns_msg msg, struct in_addr dns_addr); 110 | 111 | static void queue_add(id_addr_t id_addr); 112 | static id_addr_t *queue_lookup(uint16_t id); 113 | 114 | #define ID_ADDR_QUEUE_LEN 128 115 | // use a queue instead of hash here since it's not long 116 | static id_addr_t id_addr_queue[ID_ADDR_QUEUE_LEN]; 117 | static int id_addr_queue_pos = 0; 118 | 119 | #define EMPTY_RESULT_DELAY 0.3f 120 | #define DELAY_QUEUE_LEN 128 121 | static delay_buf_t delay_queue[DELAY_QUEUE_LEN]; 122 | static void schedule_delay(uint16_t query_id, const char *buf, size_t buflen, 123 | struct sockaddr *addr, socklen_t addrlen); 124 | static void check_and_send_delay(); 125 | static void free_delay(int pos); 126 | // next position for first, not used 127 | static int delay_queue_first = 0; 128 | // current position for last, used 129 | static int delay_queue_last = 0; 130 | static float empty_result_delay = EMPTY_RESULT_DELAY; 131 | 132 | static int local_sock; 133 | static int remote_sock; 134 | 135 | static void usage(void); 136 | 137 | static int recreate_remote_sock(); 138 | 139 | #define LOG(s...) NSLog(@s) 140 | #define DLOG(s...) 141 | #define ERR(s) NSLog(@s) 142 | #define VERR(s...) NSLog(@s) 143 | 144 | int chinadns_main(int argc, char **argv) { 145 | fd_set readset, errorset; 146 | int max_fd; 147 | 148 | memset(&id_addr_queue, 0, sizeof(id_addr_queue)); 149 | if (0 != parse_args(argc, argv)) 150 | return EXIT_FAILURE; 151 | if (!compression) 152 | memset(&delay_queue, 0, sizeof(delay_queue)); 153 | if (0 != parse_ip_list()) 154 | return EXIT_FAILURE; 155 | if (0 != parse_chnroute()) 156 | return EXIT_FAILURE; 157 | if (0 != resolve_dns_servers()) 158 | return EXIT_FAILURE; 159 | if (0 != dns_init_sockets()) 160 | return EXIT_FAILURE; 161 | 162 | max_fd = MAX(local_sock, remote_sock) + 1; 163 | while (1) { 164 | FD_ZERO(&readset); 165 | FD_ZERO(&errorset); 166 | FD_SET(local_sock, &readset); 167 | FD_SET(local_sock, &errorset); 168 | FD_SET(remote_sock, &readset); 169 | FD_SET(remote_sock, &errorset); 170 | struct timeval timeout = { 171 | .tv_sec = 0, 172 | .tv_usec = 50 * 1000, 173 | }; 174 | if (-1 == select(max_fd, &readset, NULL, &errorset, &timeout)) { 175 | ERR("select"); 176 | return EXIT_FAILURE; 177 | } 178 | check_and_send_delay(); 179 | if (FD_ISSET(local_sock, &errorset)) { 180 | // TODO getsockopt(..., SO_ERROR, ...); 181 | VERR("local_sock error\n"); 182 | return EXIT_FAILURE; 183 | } 184 | if (FD_ISSET(remote_sock, &errorset)) { 185 | // TODO getsockopt(..., SO_ERROR, ...); 186 | VERR("remote_sock error\n"); 187 | return EXIT_FAILURE; 188 | } 189 | if (FD_ISSET(local_sock, &readset)) 190 | dns_handle_local(); 191 | if (FD_ISSET(remote_sock, &readset)) 192 | dns_handle_remote(); 193 | 194 | if (remote_recreate_required) { 195 | remote_recreate_required = 0; 196 | LOG("recreating ChinaDNS remote socket"); 197 | recreate_remote_sock(); 198 | } 199 | } 200 | return EXIT_SUCCESS; 201 | } 202 | 203 | static int setnonblock(int sock) { 204 | int flags; 205 | flags = fcntl(sock, F_GETFL, 0); 206 | if (flags == -1) { 207 | ERR("fcntl"); 208 | return -1; 209 | } 210 | if (-1 == fcntl(sock, F_SETFL, flags | O_NONBLOCK)) { 211 | ERR("fcntl"); 212 | return -1; 213 | } 214 | return 0; 215 | } 216 | 217 | static int parse_args(int argc, char **argv) { 218 | int ch; 219 | dns_servers = strdup(default_dns_servers); 220 | listen_addr = strdup(default_listen_addr); 221 | listen_port = strdup(default_listen_port); 222 | while ((ch = getopt(argc, argv, "hb:p:s:l:c:y:dmvV")) != -1) { 223 | switch (ch) { 224 | case 'h': 225 | usage(); 226 | exit(0); 227 | case 'b': 228 | listen_addr = strdup(optarg); 229 | break; 230 | case 'p': 231 | listen_port = strdup(optarg); 232 | break; 233 | case 's': 234 | dns_servers = strdup(optarg); 235 | break; 236 | case 'c': 237 | chnroute_file = strdup(optarg); 238 | break; 239 | case 'l': 240 | ip_list_file = strdup(optarg); 241 | break; 242 | case 'y': 243 | empty_result_delay = atof(optarg); 244 | break; 245 | case 'd': 246 | bidirectional = 1; 247 | break; 248 | case 'm': 249 | compression = 1; 250 | break; 251 | case 'v': 252 | verbose = 1; 253 | break; 254 | case 'V': 255 | // LOG("ChinaDNS %s\n", PACKAGE_VERSION); 256 | exit(0); 257 | default: 258 | usage(); 259 | exit(1); 260 | } 261 | } 262 | argc -= optind; 263 | argv += optind; 264 | return 0; 265 | } 266 | 267 | static int resolve_dns_servers() { 268 | struct addrinfo hints; 269 | struct addrinfo *addr_ip; 270 | char* token; 271 | int r; 272 | int i = 0; 273 | char *pch = strchr(dns_servers, ','); 274 | has_chn_dns = 0; 275 | int has_foreign_dns = 0; 276 | dns_servers_len = 1; 277 | if (compression) { 278 | if (!chnroute_file) { 279 | VERR("Chnroutes are necessary when using DNS compression pointer mutation\n"); 280 | return -1; 281 | } 282 | } 283 | while (pch != NULL) { 284 | dns_servers_len++; 285 | pch = strchr(pch + 1, ','); 286 | } 287 | dns_server_addrs = calloc(dns_servers_len, sizeof(id_addr_t)); 288 | 289 | memset(&hints, 0, sizeof(hints)); 290 | hints.ai_family = AF_INET; 291 | hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */ 292 | token = strtok(dns_servers, ","); 293 | while (token) { 294 | char *port; 295 | memset(global_buf, 0, BUF_SIZE); 296 | strncpy(global_buf, token, BUF_SIZE - 1); 297 | port = (strrchr(global_buf, ':')); 298 | if (port) { 299 | *port = '\0'; 300 | port++; 301 | } else { 302 | port = "53"; 303 | } 304 | if (0 != (r = getaddrinfo(global_buf, port, &hints, &addr_ip))) { 305 | VERR("%s:%s\n", gai_strerror(r), token); 306 | return -1; 307 | } 308 | if (compression) { 309 | if (test_ip_in_list(((struct sockaddr_in *)addr_ip->ai_addr)->sin_addr, 310 | &chnroute_list)) { 311 | dns_server_addrs[has_chn_dns].addr = addr_ip->ai_addr; 312 | dns_server_addrs[has_chn_dns].addrlen = addr_ip->ai_addrlen; 313 | has_chn_dns++; 314 | } else { 315 | has_foreign_dns++; 316 | dns_server_addrs[dns_servers_len - has_foreign_dns].addr = addr_ip->ai_addr; 317 | dns_server_addrs[dns_servers_len - has_foreign_dns].addrlen = addr_ip->ai_addrlen; 318 | } 319 | token = strtok(0, ","); 320 | } else { 321 | dns_server_addrs[i].addr = addr_ip->ai_addr; 322 | dns_server_addrs[i].addrlen = addr_ip->ai_addrlen; 323 | i++; 324 | token = strtok(0, ","); 325 | if (chnroute_file) { 326 | if (test_ip_in_list(((struct sockaddr_in *)addr_ip->ai_addr)->sin_addr, 327 | &chnroute_list)) { 328 | has_chn_dns = 1; 329 | } else { 330 | has_foreign_dns = 1; 331 | } 332 | } 333 | } 334 | } 335 | if (chnroute_file) { 336 | if (!(has_chn_dns && has_foreign_dns)) { 337 | if (compression) { 338 | VERR("You should have at least one Chinese DNS and one foreign DNS when " 339 | "using DNS compression pointer mutation\n"); 340 | return -1; 341 | } else { 342 | VERR("You should have at least one Chinese DNS and one foreign DNS when " 343 | "chnroutes is enabled\n"); 344 | return 0; 345 | } 346 | } 347 | } 348 | return 0; 349 | } 350 | 351 | static int cmp_in_addr(const void *a, const void *b) { 352 | struct in_addr *ina = (struct in_addr *)a; 353 | struct in_addr *inb = (struct in_addr *)b; 354 | if (ina->s_addr == inb->s_addr) 355 | return 0; 356 | if (ina->s_addr > inb->s_addr) 357 | return 1; 358 | return -1; 359 | } 360 | 361 | static int parse_ip_list() { 362 | FILE *fp; 363 | char line_buf[32]; 364 | char *line = NULL; 365 | size_t len = sizeof(line_buf); 366 | ssize_t read; 367 | ip_list.entries = 0; 368 | int i = 0; 369 | 370 | if (ip_list_file == NULL) 371 | return 0; 372 | 373 | fp = fopen(ip_list_file, "rb"); 374 | if (fp == NULL) { 375 | ERR("fopen"); 376 | VERR("Can't open ip list: %s\n", ip_list_file); 377 | return -1; 378 | } 379 | while ((line = fgets(line_buf, len, fp))) { 380 | ip_list.entries++; 381 | } 382 | 383 | ip_list.ips = calloc(ip_list.entries, sizeof(struct in_addr)); 384 | if (0 != fseek(fp, 0, SEEK_SET)) { 385 | VERR("fseek"); 386 | return -1; 387 | } 388 | while ((line = fgets(line_buf, len, fp))) { 389 | char *sp_pos; 390 | sp_pos = strchr(line, '\r'); 391 | if (sp_pos) *sp_pos = 0; 392 | sp_pos = strchr(line, '\n'); 393 | if (sp_pos) *sp_pos = 0; 394 | inet_aton(line, &ip_list.ips[i]); 395 | i++; 396 | } 397 | 398 | qsort(ip_list.ips, ip_list.entries, sizeof(struct in_addr), cmp_in_addr); 399 | fclose(fp); 400 | return 0; 401 | } 402 | 403 | static int cmp_net_mask(const void *a, const void *b) { 404 | net_mask_t *neta = (net_mask_t *)a; 405 | net_mask_t *netb = (net_mask_t *)b; 406 | if (neta->net.s_addr == netb->net.s_addr) 407 | return 0; 408 | // TODO: pre ntohl 409 | if (ntohl(neta->net.s_addr) > ntohl(netb->net.s_addr)) 410 | return 1; 411 | return -1; 412 | } 413 | 414 | static int parse_chnroute() { 415 | FILE *fp; 416 | char line_buf[32]; 417 | char *line; 418 | size_t len = sizeof(line_buf); 419 | ssize_t read; 420 | char net[32]; 421 | chnroute_list.entries = 0; 422 | int i = 0; 423 | 424 | if (chnroute_file == NULL) { 425 | VERR("CHNROUTE_FILE not specified, CHNRoute is disabled\n"); 426 | return 0; 427 | } 428 | 429 | fp = fopen(chnroute_file, "rb"); 430 | if (fp == NULL) { 431 | ERR("fopen"); 432 | VERR("Can't open chnroute: %s\n", chnroute_file); 433 | return -1; 434 | } 435 | while ((line = fgets(line_buf, len, fp))) { 436 | chnroute_list.entries++; 437 | } 438 | 439 | chnroute_list.nets = calloc(chnroute_list.entries, sizeof(net_mask_t)); 440 | if (0 != fseek(fp, 0, SEEK_SET)) { 441 | VERR("fseek"); 442 | return -1; 443 | } 444 | while ((line = fgets(line_buf, len, fp))) { 445 | char *sp_pos; 446 | sp_pos = strchr(line, '\r'); 447 | if (sp_pos) *sp_pos = 0; 448 | sp_pos = strchr(line, '\n'); 449 | if (sp_pos) *sp_pos = 0; 450 | sp_pos = strchr(line, '/'); 451 | if (sp_pos) { 452 | *sp_pos = 0; 453 | chnroute_list.nets[i].mask = (1 << (32 - atoi(sp_pos + 1))) - 1; 454 | } else { 455 | chnroute_list.nets[i].mask = UINT32_MAX; 456 | } 457 | if (0 == inet_aton(line, &chnroute_list.nets[i].net)) { 458 | VERR("invalid addr %s in %s:%d\n", line, chnroute_file, i + 1); 459 | return 1; 460 | } 461 | i++; 462 | } 463 | 464 | qsort(chnroute_list.nets, chnroute_list.entries, sizeof(net_mask_t), 465 | cmp_net_mask); 466 | 467 | fclose(fp); 468 | return 0; 469 | } 470 | 471 | static int test_ip_in_list(struct in_addr ip, const net_list_t *netlist) { 472 | // binary search 473 | int l = 0, r = netlist->entries - 1; 474 | int m, cmp; 475 | if (netlist->entries == 0) 476 | return 0; 477 | net_mask_t ip_net; 478 | ip_net.net = ip; 479 | while (l != r) { 480 | m = (l + r) / 2; 481 | cmp = cmp_net_mask(&ip_net, &netlist->nets[m]); 482 | if (cmp == -1) { 483 | if (r != m) 484 | r = m; 485 | else 486 | break; 487 | } else { 488 | if (l != m) 489 | l = m; 490 | else 491 | break; 492 | } 493 | DLOG("l=%d, r=%d\n", l, r); 494 | DLOG("%s, %d\n", inet_ntoa(netlist->nets[m].net), 495 | netlist->nets[m].mask); 496 | } 497 | DLOG("result: %x\n", 498 | (ntohl(netlist->nets[l].net.s_addr) ^ ntohl(ip.s_addr))); 499 | DLOG("mask: %x\n", (UINT32_MAX - netlist->nets[l].mask)); 500 | if ((ntohl(netlist->nets[l].net.s_addr) ^ ntohl(ip.s_addr)) & 501 | (UINT32_MAX ^ netlist->nets[l].mask)) { 502 | return 0; 503 | } 504 | return 1; 505 | } 506 | 507 | static int recreate_remote_sock() { 508 | if (remote_sock) { 509 | close(remote_sock); 510 | } 511 | remote_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 512 | return remote_sock; 513 | } 514 | 515 | static int dns_init_sockets() { 516 | struct addrinfo hints; 517 | struct addrinfo *addr_ip; 518 | int r; 519 | 520 | local_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 521 | if (0 != setnonblock(local_sock)) 522 | return -1; 523 | memset(&hints, 0, sizeof(hints)); 524 | hints.ai_family = AF_INET; 525 | hints.ai_socktype = SOCK_DGRAM; 526 | if (0 != (r = getaddrinfo(listen_addr, listen_port, &hints, &addr_ip))) { 527 | VERR("%s:%s:%s\n", gai_strerror(r), listen_addr, listen_port); 528 | return -1; 529 | } 530 | int yes = 1; 531 | if (0 != setsockopt(local_sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))) { 532 | perror("setsockopt"); 533 | return -1; 534 | } 535 | if (0 != bind(local_sock, addr_ip->ai_addr, addr_ip->ai_addrlen)) { 536 | ERR("bind"); 537 | VERR("Can't bind address %s:%s\n", listen_addr, listen_port); 538 | return -1; 539 | } 540 | freeaddrinfo(addr_ip); 541 | remote_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 542 | if (0 != setnonblock(remote_sock)) 543 | return -1; 544 | return 0; 545 | } 546 | 547 | static void dns_handle_local() { 548 | struct sockaddr *src_addr = malloc(sizeof(struct sockaddr)); 549 | socklen_t src_addrlen = sizeof(struct sockaddr); 550 | uint16_t query_id; 551 | ssize_t len; 552 | int i; 553 | int sended = 0; 554 | const char *question_hostname; 555 | ns_msg msg; 556 | len = recvfrom(local_sock, global_buf, BUF_SIZE, 0, src_addr, &src_addrlen); 557 | if (len > 0) { 558 | if (ns_initparse((const u_char *)global_buf, len, &msg) < 0) { 559 | ERR("ns_initparse"); 560 | free(src_addr); 561 | return; 562 | } 563 | // parse DNS query id 564 | // TODO generate id for each request to avoid conflicts 565 | query_id = ns_msg_id(msg); 566 | question_hostname = hostname_from_question(msg); 567 | LOG("request %s\n", question_hostname); 568 | 569 | // assign a new id 570 | uint16_t new_id; 571 | do { 572 | struct timeval tv; 573 | gettimeofday(&tv, 0); 574 | int randombits = (tv.tv_sec << 8) ^ tv.tv_usec; 575 | new_id = randombits & 0xffff; 576 | } while (queue_lookup(new_id)); 577 | 578 | uint16_t ns_new_id = htons(new_id); 579 | memcpy(global_buf, &ns_new_id, 2); 580 | 581 | id_addr_t id_addr; 582 | id_addr.id = new_id; 583 | id_addr.old_id = query_id; 584 | 585 | id_addr.addr = src_addr; 586 | id_addr.addrlen = src_addrlen; 587 | queue_add(id_addr); 588 | if (compression) { 589 | if (len > 16) { 590 | size_t off = 12; 591 | int ended = 0; 592 | while (off < len - 4) { 593 | if (global_buf[off] & 0xc0) 594 | break; 595 | if (global_buf[off] == 0) { 596 | ended = 1; 597 | off ++; 598 | break; 599 | } 600 | off += 1 + global_buf[off]; 601 | } 602 | if (ended) { 603 | memcpy(compression_buf, global_buf, off-1); 604 | memcpy(compression_buf + off + 1, global_buf + off, len - off); 605 | compression_buf[off-1] = '\xc0'; 606 | compression_buf[off] = '\x04'; 607 | for (i = 0; i < has_chn_dns; i++) { 608 | if (-1 == sendto(remote_sock, global_buf, len, 0, 609 | dns_server_addrs[i].addr, 610 | dns_server_addrs[i].addrlen)) { 611 | ERR("sendto"); 612 | recreate_remote_sock(); 613 | } 614 | } 615 | for (i = has_chn_dns; i < dns_servers_len; i++) { 616 | if (-1 == sendto(remote_sock, compression_buf, len + 1, 0, 617 | dns_server_addrs[i].addr, 618 | dns_server_addrs[i].addrlen)) { 619 | ERR("sendto"); 620 | recreate_remote_sock(); 621 | sended = 1; 622 | } 623 | } 624 | } 625 | } 626 | } 627 | if (!sended) { 628 | for (i = 0; i < dns_servers_len; i++) { 629 | if (-1 == sendto(remote_sock, global_buf, len, 0, 630 | dns_server_addrs[i].addr, 631 | dns_server_addrs[i].addrlen)) { 632 | ERR("sendto"); 633 | recreate_remote_sock(); 634 | } 635 | } 636 | } 637 | } 638 | else 639 | ERR("recvfrom"); 640 | } 641 | 642 | static void dns_handle_remote() { 643 | struct sockaddr *src_addr = malloc(sizeof(struct sockaddr)); 644 | socklen_t src_len = sizeof(struct sockaddr); 645 | uint16_t query_id; 646 | ssize_t len; 647 | const char *question_hostname; 648 | int r; 649 | ns_msg msg; 650 | len = recvfrom(remote_sock, global_buf, BUF_SIZE, 0, src_addr, &src_len); 651 | if (len > 0) { 652 | if (ns_initparse((const u_char *)global_buf, len, &msg) < 0) { 653 | ERR("ns_initparse"); 654 | free(src_addr); 655 | return; 656 | } 657 | // parse DNS query id 658 | query_id = ns_msg_id(msg); 659 | question_hostname = hostname_from_question(msg); 660 | if (question_hostname) { 661 | LOG("response %s from %s:%d - ", question_hostname, 662 | inet_ntoa(((struct sockaddr_in *)src_addr)->sin_addr), 663 | htons(((struct sockaddr_in *)src_addr)->sin_port)); 664 | } 665 | id_addr_t *id_addr = queue_lookup(query_id); 666 | if (id_addr) { 667 | id_addr->addr->sa_family = AF_INET; 668 | uint16_t ns_old_id = htons(id_addr->old_id); 669 | memcpy(global_buf, &ns_old_id, 2); 670 | r = should_filter_query(msg, ((struct sockaddr_in *)src_addr)->sin_addr); 671 | if (r == 0) { 672 | if (verbose) 673 | LOG("pass\n"); 674 | if (-1 == sendto(local_sock, global_buf, len, 0, id_addr->addr, 675 | id_addr->addrlen)) { 676 | ERR("sendto local_sock"); 677 | } 678 | } else if (r == -1) { 679 | schedule_delay(query_id, global_buf, len, id_addr->addr, 680 | id_addr->addrlen); 681 | if (verbose) 682 | LOG("delay\n"); 683 | } else { 684 | if (verbose) 685 | LOG("filter\n"); 686 | } 687 | } else { 688 | if (verbose) 689 | LOG("skip\n"); 690 | } 691 | free(src_addr); 692 | } 693 | else 694 | ERR("recvfrom"); 695 | } 696 | 697 | static void queue_add(id_addr_t id_addr) { 698 | id_addr_queue_pos = (id_addr_queue_pos + 1) % ID_ADDR_QUEUE_LEN; 699 | // free next hole 700 | id_addr_t old_id_addr = id_addr_queue[id_addr_queue_pos]; 701 | free(old_id_addr.addr); 702 | id_addr_queue[id_addr_queue_pos] = id_addr; 703 | } 704 | 705 | static id_addr_t *queue_lookup(uint16_t id) { 706 | int i; 707 | for (i = 0; i < ID_ADDR_QUEUE_LEN; i++) { 708 | if (id_addr_queue[i].id == id) 709 | return id_addr_queue + i; 710 | } 711 | return NULL; 712 | } 713 | 714 | static char *hostname_buf = NULL; 715 | static size_t hostname_buflen = 0; 716 | static const char *hostname_from_question(ns_msg msg) { 717 | ns_rr rr; 718 | int rrnum, rrmax; 719 | const char *result; 720 | int result_len; 721 | rrmax = ns_msg_count(msg, ns_s_qd); 722 | if (rrmax == 0) 723 | return NULL; 724 | for (rrnum = 0; rrnum < rrmax; rrnum++) { 725 | if (ns_parserr(&msg, ns_s_qd, rrnum, &rr)) { 726 | ERR("ns_parserr"); 727 | return NULL; 728 | } 729 | result = ns_rr_name(rr); 730 | result_len = strlen(result) + 1; 731 | if (result_len > hostname_buflen) { 732 | hostname_buflen = result_len << 1; 733 | hostname_buf = realloc(hostname_buf, hostname_buflen); 734 | } 735 | memcpy(hostname_buf, result, result_len); 736 | return hostname_buf; 737 | } 738 | return NULL; 739 | } 740 | 741 | static int should_filter_query(ns_msg msg, struct in_addr dns_addr) { 742 | ns_rr rr; 743 | int rrnum, rrmax; 744 | void *r; 745 | // TODO cache result for each dns server 746 | int dns_is_chn = 0; 747 | int dns_is_foreign = 0; 748 | if (chnroute_file && (dns_servers_len > 1)) { 749 | dns_is_chn = test_ip_in_list(dns_addr, &chnroute_list); 750 | dns_is_foreign = !dns_is_chn; 751 | } 752 | rrmax = ns_msg_count(msg, ns_s_an); 753 | if (rrmax == 0) { 754 | if (compression) { 755 | // Wait for foreign dns 756 | if (dns_is_chn) { 757 | LOG("compression dns_is_chn"); 758 | return 1; 759 | } else { 760 | LOG("compression !dns_is_chn"); 761 | return 0; 762 | } 763 | } 764 | return -1; 765 | } 766 | for (rrnum = 0; rrnum < rrmax; rrnum++) { 767 | if (ns_parserr(&msg, ns_s_an, rrnum, &rr)) { 768 | ERR("ns_parserr"); 769 | return 0; 770 | } 771 | u_int type; 772 | const u_char *rd; 773 | type = ns_rr_type(rr); 774 | rd = ns_rr_rdata(rr); 775 | if (type == ns_t_a) { 776 | if (verbose) 777 | LOG("%s, ", inet_ntoa(*(struct in_addr *)rd)); 778 | if (!compression) { 779 | r = bsearch(rd, ip_list.ips, ip_list.entries, sizeof(struct in_addr), 780 | cmp_in_addr); 781 | if (r) { 782 | return 1; 783 | } 784 | } 785 | if (test_ip_in_list(*(struct in_addr *)rd, &chnroute_list)) { 786 | // result is chn 787 | if (dns_is_foreign) { 788 | if (bidirectional) { 789 | // filter DNS result from foreign dns if result is inside chn 790 | return 1; 791 | } 792 | } 793 | } else { 794 | // result is foreign 795 | if (dns_is_chn) { 796 | // filter DNS result from chn dns if result is outside chn 797 | return 1; 798 | } 799 | } 800 | } else if (type == ns_t_aaaa || type == ns_t_ptr) { 801 | // if we've got an IPv6 result or a PTR result, pass 802 | LOG("AAAA or PTR"); 803 | return 0; 804 | } 805 | } 806 | if (rrmax == 1) { 807 | if (compression) { 808 | return 0; 809 | } else { 810 | return -1; 811 | } 812 | } 813 | return 0; 814 | } 815 | 816 | static void schedule_delay(uint16_t query_id, const char *buf, size_t buflen, 817 | struct sockaddr *addr, socklen_t addrlen) { 818 | int i; 819 | int found = 0; 820 | struct timeval now; 821 | gettimeofday(&now, 0); 822 | 823 | delay_buf_t *delay_buf = &delay_queue[delay_queue_last]; 824 | 825 | // first search for existed item with query_id and replace it 826 | for (i = delay_queue_first; 827 | i != delay_queue_last; 828 | i = (i + 1) % DELAY_QUEUE_LEN) { 829 | delay_buf_t *delay_buf2 = &delay_queue[i]; 830 | if (delay_buf2->id == query_id) { 831 | free_delay(i); 832 | delay_buf = &delay_queue[i]; 833 | found = 1; 834 | } 835 | } 836 | 837 | delay_buf->id = query_id; 838 | delay_buf->ts = now; 839 | delay_buf->buf = malloc(buflen); 840 | memcpy(delay_buf->buf, buf, buflen); 841 | delay_buf->buflen = buflen; 842 | delay_buf->addr = malloc(addrlen); 843 | memcpy(delay_buf->addr, addr, addrlen); 844 | delay_buf->addrlen = addrlen; 845 | 846 | // then append to queue 847 | if (!found) { 848 | delay_queue_last = (delay_queue_last + 1) % DELAY_QUEUE_LEN; 849 | if (delay_queue_last == delay_queue_first) { 850 | free_delay(delay_queue_first); 851 | delay_queue_first = (delay_queue_first + 1) % DELAY_QUEUE_LEN; 852 | } 853 | } 854 | } 855 | 856 | float time_diff(struct timeval t0, struct timeval t1) { 857 | return (t1.tv_sec - t0.tv_sec) + 858 | (t1.tv_usec - t0.tv_usec) / 1000000.0f; 859 | } 860 | 861 | static void check_and_send_delay() { 862 | struct timeval now; 863 | int i; 864 | gettimeofday(&now, 0); 865 | for (i = delay_queue_first; 866 | i != delay_queue_last; 867 | i = (i + 1) % DELAY_QUEUE_LEN) { 868 | delay_buf_t *delay_buf = &delay_queue[i]; 869 | if (time_diff(delay_buf->ts, now) > empty_result_delay) { 870 | if (-1 == sendto(local_sock, delay_buf->buf, delay_buf->buflen, 0, 871 | delay_buf->addr, delay_buf->addrlen)) { 872 | ERR("sendto local_sock"); 873 | } 874 | free_delay(i); 875 | delay_queue_first = (delay_queue_first + 1) % DELAY_QUEUE_LEN; 876 | } else { 877 | break; 878 | } 879 | } 880 | } 881 | 882 | static void free_delay(int pos) { 883 | free(delay_queue[pos].buf); 884 | free(delay_queue[pos].addr); 885 | } 886 | 887 | static void usage() { 888 | LOG("%s\n", "\ 889 | usage: chinadns [-h] [-l IPLIST_FILE] [-b BIND_ADDR] [-p BIND_PORT]\n\ 890 | [-c CHNROUTE_FILE] [-s DNS] [-m] [-v] [-V]\n\ 891 | Forward DNS requests.\n\ 892 | \n\ 893 | -l IPLIST_FILE path to ip blacklist file\n\ 894 | -c CHNROUTE_FILE path to china route file\n\ 895 | if not specified, CHNRoute will be turned\n\ 896 | -d off enable bi-directional CHNRoute filter\n\ 897 | -y delay time for suspects, default: 0.3\n\ 898 | -b BIND_ADDR address that listens, default: 127.0.0.1\n\ 899 | -p BIND_PORT port that listens, default: 53\n\ 900 | -s DNS DNS servers to use, default:\n\ 901 | 114.114.114.114,208.67.222.222:443,8.8.8.8\n\ 902 | -m use DNS compression pointer mutation\n\ 903 | (backlist and delaying would be disabled)\n\ 904 | -v verbose logging\n\ 905 | -h show this help message and exit\n\ 906 | -V print version and exit\n\ 907 | \n\ 908 | Online help: \n"); 909 | } 910 | 911 | 912 | -------------------------------------------------------------------------------- /ShadowVPN.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 620629BC1B789A320034179B /* ConfigurationValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 620629BB1B789A320034179B /* ConfigurationValidator.swift */; }; 11 | 620629BD1B789DE50034179B /* NSData+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D8D26A1B771B63009FA6FE /* NSData+Hex.swift */; }; 12 | 620A5B881B5A9F1E00F98476 /* crypto_secretbox_salsa208poly1305.c in Sources */ = {isa = PBXBuildFile; fileRef = 620A5B841B5A9F1E00F98476 /* crypto_secretbox_salsa208poly1305.c */; }; 13 | 620A5B891B5A9F1E00F98476 /* crypto.c in Sources */ = {isa = PBXBuildFile; fileRef = 620A5B861B5A9F1E00F98476 /* crypto.c */; }; 14 | 620A5B901B5AA85800F98476 /* SVCrypto.m in Sources */ = {isa = PBXBuildFile; fileRef = 620A5B8F1B5AA85800F98476 /* SVCrypto.m */; }; 15 | 625E05051B73D3C30041A9D6 /* checkmark_empty@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 625E05031B73D3C30041A9D6 /* checkmark_empty@2x.png */; }; 16 | 625E05061B73D3C30041A9D6 /* checkmark@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 625E05041B73D3C30041A9D6 /* checkmark@2x.png */; }; 17 | 626520C21B73AB890064F653 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 626520C11B73AB890064F653 /* MainViewController.swift */; }; 18 | 626520C41B73ABA10064F653 /* ConfigurationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 626520C31B73ABA10064F653 /* ConfigurationViewController.swift */; }; 19 | 62A427511B5A3C9700BB4AD9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62A427501B5A3C9700BB4AD9 /* AppDelegate.swift */; }; 20 | 62A427581B5A3C9700BB4AD9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 62A427571B5A3C9700BB4AD9 /* Assets.xcassets */; }; 21 | 62A4275B1B5A3C9700BB4AD9 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 62A427591B5A3C9700BB4AD9 /* LaunchScreen.storyboard */; }; 22 | 62A427721B5A3ED800BB4AD9 /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62A427711B5A3ED800BB4AD9 /* PacketTunnelProvider.swift */; }; 23 | 62D8D2691B76286F009FA6FE /* ConfigurationTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D8D2681B76286F009FA6FE /* ConfigurationTextCell.swift */; }; 24 | 62D8D26B1B771B63009FA6FE /* NSData+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D8D26A1B771B63009FA6FE /* NSData+Hex.swift */; }; 25 | 62D8D2701B772C5A009FA6FE /* RouteManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D8D26F1B772C5A009FA6FE /* RouteManager.swift */; }; 26 | 62D8D2981B77342F009FA6FE /* chinadns.m in Sources */ = {isa = PBXBuildFile; fileRef = 62D8D2971B77342F009FA6FE /* chinadns.m */; }; 27 | 62D8D29B1B773622009FA6FE /* chnroutes.txt in Resources */ = {isa = PBXBuildFile; fileRef = 62D8D29A1B773622009FA6FE /* chnroutes.txt */; }; 28 | 62D8D29E1B77433E009FA6FE /* ChinaDNSRunner.m in Sources */ = {isa = PBXBuildFile; fileRef = 62D8D29D1B77433E009FA6FE /* ChinaDNSRunner.m */; }; 29 | 62D8D2A01B7748CA009FA6FE /* iplist.txt in Resources */ = {isa = PBXBuildFile; fileRef = 62D8D29F1B7748CA009FA6FE /* iplist.txt */; }; 30 | 62D8D2A21B774A2F009FA6FE /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 62D8D2A11B774A2F009FA6FE /* libresolv.tbd */; }; 31 | 62F7E9891BB58DBE007A19E7 /* tunnel.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 62A4276D1B5A3ED800BB4AD9 /* tunnel.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 32 | A60BD4C920B50B35003D6D61 /* SimpleTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A60BD4C820B50B35003D6D61 /* SimpleTableViewController.swift */; }; 33 | A6330D5520A076D900A11425 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A6330D5420A076D900A11425 /* NetworkExtension.framework */; }; 34 | AB2AE7814EC8A97680674F72 /* libPods-tunnel.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F7CBA318BF54382F1B5AF32F /* libPods-tunnel.a */; }; 35 | C26DCA8D7FB941CDEBB06F60 /* libPods-ShadowVPN.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 42096B0DD905FA971B402AB0 /* libPods-ShadowVPN.a */; }; 36 | /* End PBXBuildFile section */ 37 | 38 | /* Begin PBXContainerItemProxy section */ 39 | 6228E95B1B775DDB00581B0F /* PBXContainerItemProxy */ = { 40 | isa = PBXContainerItemProxy; 41 | containerPortal = 62A427451B5A3C9700BB4AD9 /* Project object */; 42 | proxyType = 1; 43 | remoteGlobalIDString = 62A4276C1B5A3ED800BB4AD9; 44 | remoteInfo = tunnel; 45 | }; 46 | /* End PBXContainerItemProxy section */ 47 | 48 | /* Begin PBXCopyFilesBuildPhase section */ 49 | 62A4277A1B5A3ED800BB4AD9 /* Embed App Extensions */ = { 50 | isa = PBXCopyFilesBuildPhase; 51 | buildActionMask = 12; 52 | dstPath = ""; 53 | dstSubfolderSpec = 13; 54 | files = ( 55 | 62F7E9891BB58DBE007A19E7 /* tunnel.appex in Embed App Extensions */, 56 | ); 57 | name = "Embed App Extensions"; 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | /* End PBXCopyFilesBuildPhase section */ 61 | 62 | /* Begin PBXFileReference section */ 63 | 42096B0DD905FA971B402AB0 /* libPods-ShadowVPN.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ShadowVPN.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 64 | 462DCB6C067AA9583774906C /* Pods-tunnel.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-tunnel.release.xcconfig"; path = "Pods/Target Support Files/Pods-tunnel/Pods-tunnel.release.xcconfig"; sourceTree = ""; }; 65 | 620629BB1B789A320034179B /* ConfigurationValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurationValidator.swift; sourceTree = ""; }; 66 | 620A5B821B5A9E3100F98476 /* tunnel-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "tunnel-Bridging-Header.h"; sourceTree = ""; }; 67 | 620A5B841B5A9F1E00F98476 /* crypto_secretbox_salsa208poly1305.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = crypto_secretbox_salsa208poly1305.c; sourceTree = ""; }; 68 | 620A5B851B5A9F1E00F98476 /* crypto_secretbox_salsa208poly1305.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypto_secretbox_salsa208poly1305.h; sourceTree = ""; }; 69 | 620A5B861B5A9F1E00F98476 /* crypto.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = crypto.c; sourceTree = ""; }; 70 | 620A5B871B5A9F1E00F98476 /* crypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypto.h; sourceTree = ""; }; 71 | 620A5B8E1B5AA85800F98476 /* SVCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVCrypto.h; sourceTree = ""; }; 72 | 620A5B8F1B5AA85800F98476 /* SVCrypto.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVCrypto.m; sourceTree = ""; }; 73 | 623DE1E31B78AAB100B1440F /* ShadowVPN-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ShadowVPN-Bridging-Header.h"; sourceTree = ""; }; 74 | 625E05031B73D3C30041A9D6 /* checkmark_empty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "checkmark_empty@2x.png"; sourceTree = ""; }; 75 | 625E05041B73D3C30041A9D6 /* checkmark@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "checkmark@2x.png"; sourceTree = ""; }; 76 | 626520C11B73AB890064F653 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; 77 | 626520C31B73ABA10064F653 /* ConfigurationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurationViewController.swift; sourceTree = ""; }; 78 | 62A4274D1B5A3C9700BB4AD9 /* ShadowVPN.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShadowVPN.app; sourceTree = BUILT_PRODUCTS_DIR; }; 79 | 62A427501B5A3C9700BB4AD9 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 80 | 62A427571B5A3C9700BB4AD9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 81 | 62A4275A1B5A3C9700BB4AD9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 82 | 62A4275C1B5A3C9700BB4AD9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 83 | 62A4276D1B5A3ED800BB4AD9 /* tunnel.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = tunnel.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 84 | 62A427701B5A3ED800BB4AD9 /* tunnel.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = tunnel.entitlements; sourceTree = ""; }; 85 | 62A427711B5A3ED800BB4AD9 /* PacketTunnelProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PacketTunnelProvider.swift; sourceTree = ""; }; 86 | 62A427731B5A3ED800BB4AD9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 87 | 62D8D2681B76286F009FA6FE /* ConfigurationTextCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConfigurationTextCell.swift; sourceTree = ""; }; 88 | 62D8D26A1B771B63009FA6FE /* NSData+Hex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSData+Hex.swift"; sourceTree = ""; }; 89 | 62D8D26F1B772C5A009FA6FE /* RouteManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RouteManager.swift; sourceTree = ""; }; 90 | 62D8D2971B77342F009FA6FE /* chinadns.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = chinadns.m; sourceTree = ""; }; 91 | 62D8D2991B77345C009FA6FE /* chinadns.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = chinadns.h; sourceTree = ""; }; 92 | 62D8D29A1B773622009FA6FE /* chnroutes.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = chnroutes.txt; sourceTree = ""; }; 93 | 62D8D29C1B77433E009FA6FE /* ChinaDNSRunner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChinaDNSRunner.h; sourceTree = ""; }; 94 | 62D8D29D1B77433E009FA6FE /* ChinaDNSRunner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChinaDNSRunner.m; sourceTree = ""; }; 95 | 62D8D29F1B7748CA009FA6FE /* iplist.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = iplist.txt; sourceTree = ""; }; 96 | 62D8D2A11B774A2F009FA6FE /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; }; 97 | 8C36F9C5C8118C5BB6BF7967 /* Pods-ShadowVPN.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowVPN.release.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowVPN/Pods-ShadowVPN.release.xcconfig"; sourceTree = ""; }; 98 | 92EA19448C55590FCF3E36ED /* Pods-ShadowVPN.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowVPN.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowVPN/Pods-ShadowVPN.debug.xcconfig"; sourceTree = ""; }; 99 | A60BD4C820B50B35003D6D61 /* SimpleTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleTableViewController.swift; sourceTree = ""; }; 100 | A6330D5420A076D900A11425 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; }; 101 | A6330D5620A0779F00A11425 /* ShadowVPN.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ShadowVPN.entitlements; sourceTree = ""; }; 102 | DA156D19BD3CF872917EB4F1 /* Pods-tunnel.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-tunnel.debug.xcconfig"; path = "Pods/Target Support Files/Pods-tunnel/Pods-tunnel.debug.xcconfig"; sourceTree = ""; }; 103 | F7CBA318BF54382F1B5AF32F /* libPods-tunnel.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-tunnel.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 104 | /* End PBXFileReference section */ 105 | 106 | /* Begin PBXFrameworksBuildPhase section */ 107 | 62A4274A1B5A3C9700BB4AD9 /* Frameworks */ = { 108 | isa = PBXFrameworksBuildPhase; 109 | buildActionMask = 2147483647; 110 | files = ( 111 | A6330D5520A076D900A11425 /* NetworkExtension.framework in Frameworks */, 112 | C26DCA8D7FB941CDEBB06F60 /* libPods-ShadowVPN.a in Frameworks */, 113 | ); 114 | runOnlyForDeploymentPostprocessing = 0; 115 | }; 116 | 62A4276A1B5A3ED800BB4AD9 /* Frameworks */ = { 117 | isa = PBXFrameworksBuildPhase; 118 | buildActionMask = 2147483647; 119 | files = ( 120 | 62D8D2A21B774A2F009FA6FE /* libresolv.tbd in Frameworks */, 121 | AB2AE7814EC8A97680674F72 /* libPods-tunnel.a in Frameworks */, 122 | ); 123 | runOnlyForDeploymentPostprocessing = 0; 124 | }; 125 | /* End PBXFrameworksBuildPhase section */ 126 | 127 | /* Begin PBXGroup section */ 128 | 0EEFC1CABB0A90BEA3E66B08 /* Pods */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | 92EA19448C55590FCF3E36ED /* Pods-ShadowVPN.debug.xcconfig */, 132 | 8C36F9C5C8118C5BB6BF7967 /* Pods-ShadowVPN.release.xcconfig */, 133 | DA156D19BD3CF872917EB4F1 /* Pods-tunnel.debug.xcconfig */, 134 | 462DCB6C067AA9583774906C /* Pods-tunnel.release.xcconfig */, 135 | ); 136 | name = Pods; 137 | sourceTree = ""; 138 | }; 139 | 486E76D16A13A84BC2514505 /* Frameworks */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | A6330D5420A076D900A11425 /* NetworkExtension.framework */, 143 | 62D8D2A11B774A2F009FA6FE /* libresolv.tbd */, 144 | 42096B0DD905FA971B402AB0 /* libPods-ShadowVPN.a */, 145 | F7CBA318BF54382F1B5AF32F /* libPods-tunnel.a */, 146 | ); 147 | name = Frameworks; 148 | sourceTree = ""; 149 | }; 150 | 620A5B831B5A9F0E00F98476 /* Crypto */ = { 151 | isa = PBXGroup; 152 | children = ( 153 | 620A5B841B5A9F1E00F98476 /* crypto_secretbox_salsa208poly1305.c */, 154 | 620A5B851B5A9F1E00F98476 /* crypto_secretbox_salsa208poly1305.h */, 155 | 620A5B861B5A9F1E00F98476 /* crypto.c */, 156 | 620A5B871B5A9F1E00F98476 /* crypto.h */, 157 | 620A5B8E1B5AA85800F98476 /* SVCrypto.h */, 158 | 620A5B8F1B5AA85800F98476 /* SVCrypto.m */, 159 | 62D8D26A1B771B63009FA6FE /* NSData+Hex.swift */, 160 | ); 161 | name = Crypto; 162 | sourceTree = ""; 163 | }; 164 | 625E05021B73D3B70041A9D6 /* Resources */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | 625E05031B73D3C30041A9D6 /* checkmark_empty@2x.png */, 168 | 625E05041B73D3C30041A9D6 /* checkmark@2x.png */, 169 | ); 170 | name = Resources; 171 | sourceTree = ""; 172 | }; 173 | 62A427441B5A3C9700BB4AD9 = { 174 | isa = PBXGroup; 175 | children = ( 176 | 62A4274F1B5A3C9700BB4AD9 /* ShadowVPN */, 177 | 62A4276E1B5A3ED800BB4AD9 /* tunnel */, 178 | 62A4274E1B5A3C9700BB4AD9 /* Products */, 179 | 486E76D16A13A84BC2514505 /* Frameworks */, 180 | 0EEFC1CABB0A90BEA3E66B08 /* Pods */, 181 | ); 182 | sourceTree = ""; 183 | }; 184 | 62A4274E1B5A3C9700BB4AD9 /* Products */ = { 185 | isa = PBXGroup; 186 | children = ( 187 | 62A4274D1B5A3C9700BB4AD9 /* ShadowVPN.app */, 188 | 62A4276D1B5A3ED800BB4AD9 /* tunnel.appex */, 189 | ); 190 | name = Products; 191 | sourceTree = ""; 192 | }; 193 | 62A4274F1B5A3C9700BB4AD9 /* ShadowVPN */ = { 194 | isa = PBXGroup; 195 | children = ( 196 | 625E05021B73D3B70041A9D6 /* Resources */, 197 | 62D48D7F1B73952D003E4FEE /* Misc */, 198 | 62D48D7E1B739528003E4FEE /* UI */, 199 | ); 200 | path = ShadowVPN; 201 | sourceTree = ""; 202 | }; 203 | 62A4276E1B5A3ED800BB4AD9 /* tunnel */ = { 204 | isa = PBXGroup; 205 | children = ( 206 | 62D8D2961B7733ED009FA6FE /* Route */, 207 | 62D8D2951B7733EA009FA6FE /* VPN */, 208 | 62D8D2941B7733E2009FA6FE /* DNS */, 209 | 620A5B831B5A9F0E00F98476 /* Crypto */, 210 | 62A427731B5A3ED800BB4AD9 /* Info.plist */, 211 | 62A4276F1B5A3ED800BB4AD9 /* Supporting Files */, 212 | ); 213 | path = tunnel; 214 | sourceTree = ""; 215 | }; 216 | 62A4276F1B5A3ED800BB4AD9 /* Supporting Files */ = { 217 | isa = PBXGroup; 218 | children = ( 219 | 620A5B821B5A9E3100F98476 /* tunnel-Bridging-Header.h */, 220 | 62A427701B5A3ED800BB4AD9 /* tunnel.entitlements */, 221 | ); 222 | name = "Supporting Files"; 223 | sourceTree = ""; 224 | }; 225 | 62D48D7E1B739528003E4FEE /* UI */ = { 226 | isa = PBXGroup; 227 | children = ( 228 | A60BD4C820B50B35003D6D61 /* SimpleTableViewController.swift */, 229 | 626520C11B73AB890064F653 /* MainViewController.swift */, 230 | 626520C31B73ABA10064F653 /* ConfigurationViewController.swift */, 231 | 62D8D2681B76286F009FA6FE /* ConfigurationTextCell.swift */, 232 | 620629BB1B789A320034179B /* ConfigurationValidator.swift */, 233 | ); 234 | name = UI; 235 | sourceTree = ""; 236 | }; 237 | 62D48D7F1B73952D003E4FEE /* Misc */ = { 238 | isa = PBXGroup; 239 | children = ( 240 | 623DE1E31B78AAB100B1440F /* ShadowVPN-Bridging-Header.h */, 241 | A6330D5620A0779F00A11425 /* ShadowVPN.entitlements */, 242 | 62A427501B5A3C9700BB4AD9 /* AppDelegate.swift */, 243 | 62A427571B5A3C9700BB4AD9 /* Assets.xcassets */, 244 | 62A427591B5A3C9700BB4AD9 /* LaunchScreen.storyboard */, 245 | 62A4275C1B5A3C9700BB4AD9 /* Info.plist */, 246 | ); 247 | name = Misc; 248 | sourceTree = ""; 249 | }; 250 | 62D8D2941B7733E2009FA6FE /* DNS */ = { 251 | isa = PBXGroup; 252 | children = ( 253 | 62D8D29F1B7748CA009FA6FE /* iplist.txt */, 254 | 62D8D2991B77345C009FA6FE /* chinadns.h */, 255 | 62D8D2971B77342F009FA6FE /* chinadns.m */, 256 | 62D8D29C1B77433E009FA6FE /* ChinaDNSRunner.h */, 257 | 62D8D29D1B77433E009FA6FE /* ChinaDNSRunner.m */, 258 | ); 259 | name = DNS; 260 | sourceTree = ""; 261 | }; 262 | 62D8D2951B7733EA009FA6FE /* VPN */ = { 263 | isa = PBXGroup; 264 | children = ( 265 | 62A427711B5A3ED800BB4AD9 /* PacketTunnelProvider.swift */, 266 | ); 267 | name = VPN; 268 | sourceTree = ""; 269 | }; 270 | 62D8D2961B7733ED009FA6FE /* Route */ = { 271 | isa = PBXGroup; 272 | children = ( 273 | 62D8D29A1B773622009FA6FE /* chnroutes.txt */, 274 | 62D8D26F1B772C5A009FA6FE /* RouteManager.swift */, 275 | ); 276 | name = Route; 277 | sourceTree = ""; 278 | }; 279 | /* End PBXGroup section */ 280 | 281 | /* Begin PBXNativeTarget section */ 282 | 62A4274C1B5A3C9700BB4AD9 /* ShadowVPN */ = { 283 | isa = PBXNativeTarget; 284 | buildConfigurationList = 62A4275F1B5A3C9700BB4AD9 /* Build configuration list for PBXNativeTarget "ShadowVPN" */; 285 | buildPhases = ( 286 | 4E90FD687AC735D85FE8B14F /* [CP] Check Pods Manifest.lock */, 287 | 62A427491B5A3C9700BB4AD9 /* Sources */, 288 | 62A4274A1B5A3C9700BB4AD9 /* Frameworks */, 289 | 62A4274B1B5A3C9700BB4AD9 /* Resources */, 290 | 62A4277A1B5A3ED800BB4AD9 /* Embed App Extensions */, 291 | ); 292 | buildRules = ( 293 | ); 294 | dependencies = ( 295 | 6228E95C1B775DDB00581B0F /* PBXTargetDependency */, 296 | ); 297 | name = ShadowVPN; 298 | productName = ShadowVPN; 299 | productReference = 62A4274D1B5A3C9700BB4AD9 /* ShadowVPN.app */; 300 | productType = "com.apple.product-type.application"; 301 | }; 302 | 62A4276C1B5A3ED800BB4AD9 /* tunnel */ = { 303 | isa = PBXNativeTarget; 304 | buildConfigurationList = 62A427771B5A3ED800BB4AD9 /* Build configuration list for PBXNativeTarget "tunnel" */; 305 | buildPhases = ( 306 | 238937FB3210206E336553EF /* [CP] Check Pods Manifest.lock */, 307 | 62A427691B5A3ED800BB4AD9 /* Sources */, 308 | 62A4276A1B5A3ED800BB4AD9 /* Frameworks */, 309 | 62A4276B1B5A3ED800BB4AD9 /* Resources */, 310 | ); 311 | buildRules = ( 312 | ); 313 | dependencies = ( 314 | ); 315 | name = tunnel; 316 | productName = tunnel; 317 | productReference = 62A4276D1B5A3ED800BB4AD9 /* tunnel.appex */; 318 | productType = "com.apple.product-type.app-extension"; 319 | }; 320 | /* End PBXNativeTarget section */ 321 | 322 | /* Begin PBXProject section */ 323 | 62A427451B5A3C9700BB4AD9 /* Project object */ = { 324 | isa = PBXProject; 325 | attributes = { 326 | LastSwiftUpdateCheck = 0700; 327 | LastUpgradeCheck = 0700; 328 | ORGANIZATIONNAME = clowwindy; 329 | TargetAttributes = { 330 | 62A4274C1B5A3C9700BB4AD9 = { 331 | CreatedOnToolsVersion = 7.0; 332 | DevelopmentTeam = 77M64ZZJGP; 333 | LastSwiftMigration = 0930; 334 | ProvisioningStyle = Automatic; 335 | SystemCapabilities = { 336 | com.apple.ApplicationGroups.iOS = { 337 | enabled = 0; 338 | }; 339 | com.apple.Keychain = { 340 | enabled = 0; 341 | }; 342 | com.apple.NetworkExtensions.iOS = { 343 | enabled = 1; 344 | }; 345 | com.apple.VPNLite = { 346 | enabled = 1; 347 | }; 348 | }; 349 | }; 350 | 62A4276C1B5A3ED800BB4AD9 = { 351 | CreatedOnToolsVersion = 7.0; 352 | DevelopmentTeam = 77M64ZZJGP; 353 | LastSwiftMigration = 0930; 354 | ProvisioningStyle = Automatic; 355 | }; 356 | }; 357 | }; 358 | buildConfigurationList = 62A427481B5A3C9700BB4AD9 /* Build configuration list for PBXProject "ShadowVPN" */; 359 | compatibilityVersion = "Xcode 3.2"; 360 | developmentRegion = English; 361 | hasScannedForEncodings = 0; 362 | knownRegions = ( 363 | English, 364 | en, 365 | Base, 366 | ); 367 | mainGroup = 62A427441B5A3C9700BB4AD9; 368 | productRefGroup = 62A4274E1B5A3C9700BB4AD9 /* Products */; 369 | projectDirPath = ""; 370 | projectRoot = ""; 371 | targets = ( 372 | 62A4274C1B5A3C9700BB4AD9 /* ShadowVPN */, 373 | 62A4276C1B5A3ED800BB4AD9 /* tunnel */, 374 | ); 375 | }; 376 | /* End PBXProject section */ 377 | 378 | /* Begin PBXResourcesBuildPhase section */ 379 | 62A4274B1B5A3C9700BB4AD9 /* Resources */ = { 380 | isa = PBXResourcesBuildPhase; 381 | buildActionMask = 2147483647; 382 | files = ( 383 | 625E05051B73D3C30041A9D6 /* checkmark_empty@2x.png in Resources */, 384 | 62A4275B1B5A3C9700BB4AD9 /* LaunchScreen.storyboard in Resources */, 385 | 625E05061B73D3C30041A9D6 /* checkmark@2x.png in Resources */, 386 | 62A427581B5A3C9700BB4AD9 /* Assets.xcassets in Resources */, 387 | ); 388 | runOnlyForDeploymentPostprocessing = 0; 389 | }; 390 | 62A4276B1B5A3ED800BB4AD9 /* Resources */ = { 391 | isa = PBXResourcesBuildPhase; 392 | buildActionMask = 2147483647; 393 | files = ( 394 | 62D8D29B1B773622009FA6FE /* chnroutes.txt in Resources */, 395 | 62D8D2A01B7748CA009FA6FE /* iplist.txt in Resources */, 396 | ); 397 | runOnlyForDeploymentPostprocessing = 0; 398 | }; 399 | /* End PBXResourcesBuildPhase section */ 400 | 401 | /* Begin PBXShellScriptBuildPhase section */ 402 | 238937FB3210206E336553EF /* [CP] Check Pods Manifest.lock */ = { 403 | isa = PBXShellScriptBuildPhase; 404 | buildActionMask = 2147483647; 405 | files = ( 406 | ); 407 | inputPaths = ( 408 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 409 | "${PODS_ROOT}/Manifest.lock", 410 | ); 411 | name = "[CP] Check Pods Manifest.lock"; 412 | outputPaths = ( 413 | "$(DERIVED_FILE_DIR)/Pods-tunnel-checkManifestLockResult.txt", 414 | ); 415 | runOnlyForDeploymentPostprocessing = 0; 416 | shellPath = /bin/sh; 417 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 418 | showEnvVarsInLog = 0; 419 | }; 420 | 4E90FD687AC735D85FE8B14F /* [CP] Check Pods Manifest.lock */ = { 421 | isa = PBXShellScriptBuildPhase; 422 | buildActionMask = 2147483647; 423 | files = ( 424 | ); 425 | inputPaths = ( 426 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 427 | "${PODS_ROOT}/Manifest.lock", 428 | ); 429 | name = "[CP] Check Pods Manifest.lock"; 430 | outputPaths = ( 431 | "$(DERIVED_FILE_DIR)/Pods-ShadowVPN-checkManifestLockResult.txt", 432 | ); 433 | runOnlyForDeploymentPostprocessing = 0; 434 | shellPath = /bin/sh; 435 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 436 | showEnvVarsInLog = 0; 437 | }; 438 | /* End PBXShellScriptBuildPhase section */ 439 | 440 | /* Begin PBXSourcesBuildPhase section */ 441 | 62A427491B5A3C9700BB4AD9 /* Sources */ = { 442 | isa = PBXSourcesBuildPhase; 443 | buildActionMask = 2147483647; 444 | files = ( 445 | 620629BD1B789DE50034179B /* NSData+Hex.swift in Sources */, 446 | 62D8D2691B76286F009FA6FE /* ConfigurationTextCell.swift in Sources */, 447 | A60BD4C920B50B35003D6D61 /* SimpleTableViewController.swift in Sources */, 448 | 62A427511B5A3C9700BB4AD9 /* AppDelegate.swift in Sources */, 449 | 626520C41B73ABA10064F653 /* ConfigurationViewController.swift in Sources */, 450 | 620629BC1B789A320034179B /* ConfigurationValidator.swift in Sources */, 451 | 626520C21B73AB890064F653 /* MainViewController.swift in Sources */, 452 | ); 453 | runOnlyForDeploymentPostprocessing = 0; 454 | }; 455 | 62A427691B5A3ED800BB4AD9 /* Sources */ = { 456 | isa = PBXSourcesBuildPhase; 457 | buildActionMask = 2147483647; 458 | files = ( 459 | 62A427721B5A3ED800BB4AD9 /* PacketTunnelProvider.swift in Sources */, 460 | 620A5B891B5A9F1E00F98476 /* crypto.c in Sources */, 461 | 62D8D29E1B77433E009FA6FE /* ChinaDNSRunner.m in Sources */, 462 | 620A5B881B5A9F1E00F98476 /* crypto_secretbox_salsa208poly1305.c in Sources */, 463 | 62D8D2981B77342F009FA6FE /* chinadns.m in Sources */, 464 | 620A5B901B5AA85800F98476 /* SVCrypto.m in Sources */, 465 | 62D8D2701B772C5A009FA6FE /* RouteManager.swift in Sources */, 466 | 62D8D26B1B771B63009FA6FE /* NSData+Hex.swift in Sources */, 467 | ); 468 | runOnlyForDeploymentPostprocessing = 0; 469 | }; 470 | /* End PBXSourcesBuildPhase section */ 471 | 472 | /* Begin PBXTargetDependency section */ 473 | 6228E95C1B775DDB00581B0F /* PBXTargetDependency */ = { 474 | isa = PBXTargetDependency; 475 | target = 62A4276C1B5A3ED800BB4AD9 /* tunnel */; 476 | targetProxy = 6228E95B1B775DDB00581B0F /* PBXContainerItemProxy */; 477 | }; 478 | /* End PBXTargetDependency section */ 479 | 480 | /* Begin PBXVariantGroup section */ 481 | 62A427591B5A3C9700BB4AD9 /* LaunchScreen.storyboard */ = { 482 | isa = PBXVariantGroup; 483 | children = ( 484 | 62A4275A1B5A3C9700BB4AD9 /* Base */, 485 | ); 486 | name = LaunchScreen.storyboard; 487 | sourceTree = ""; 488 | }; 489 | /* End PBXVariantGroup section */ 490 | 491 | /* Begin XCBuildConfiguration section */ 492 | 62A4275D1B5A3C9700BB4AD9 /* Debug */ = { 493 | isa = XCBuildConfiguration; 494 | buildSettings = { 495 | ALWAYS_SEARCH_USER_PATHS = NO; 496 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 497 | CLANG_CXX_LIBRARY = "libc++"; 498 | CLANG_ENABLE_MODULES = YES; 499 | CLANG_ENABLE_OBJC_ARC = YES; 500 | CLANG_WARN_BOOL_CONVERSION = YES; 501 | CLANG_WARN_CONSTANT_CONVERSION = YES; 502 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 503 | CLANG_WARN_EMPTY_BODY = YES; 504 | CLANG_WARN_ENUM_CONVERSION = YES; 505 | CLANG_WARN_INT_CONVERSION = YES; 506 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 507 | CLANG_WARN_UNREACHABLE_CODE = YES; 508 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 509 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 510 | COPY_PHASE_STRIP = NO; 511 | DEBUG_INFORMATION_FORMAT = dwarf; 512 | ENABLE_STRICT_OBJC_MSGSEND = YES; 513 | ENABLE_TESTABILITY = YES; 514 | GCC_C_LANGUAGE_STANDARD = gnu99; 515 | GCC_DYNAMIC_NO_PIC = NO; 516 | GCC_NO_COMMON_BLOCKS = YES; 517 | GCC_OPTIMIZATION_LEVEL = 0; 518 | GCC_PREPROCESSOR_DEFINITIONS = ( 519 | "DEBUG=1", 520 | "$(inherited)", 521 | ); 522 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 523 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 524 | GCC_WARN_UNDECLARED_SELECTOR = YES; 525 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 526 | GCC_WARN_UNUSED_FUNCTION = YES; 527 | GCC_WARN_UNUSED_VARIABLE = YES; 528 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 529 | MTL_ENABLE_DEBUG_INFO = YES; 530 | ONLY_ACTIVE_ARCH = YES; 531 | SDKROOT = iphoneos; 532 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 533 | SWIFT_VERSION = 3.0; 534 | TARGETED_DEVICE_FAMILY = "1,2"; 535 | }; 536 | name = Debug; 537 | }; 538 | 62A4275E1B5A3C9700BB4AD9 /* Release */ = { 539 | isa = XCBuildConfiguration; 540 | buildSettings = { 541 | ALWAYS_SEARCH_USER_PATHS = NO; 542 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 543 | CLANG_CXX_LIBRARY = "libc++"; 544 | CLANG_ENABLE_MODULES = YES; 545 | CLANG_ENABLE_OBJC_ARC = YES; 546 | CLANG_WARN_BOOL_CONVERSION = YES; 547 | CLANG_WARN_CONSTANT_CONVERSION = YES; 548 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 549 | CLANG_WARN_EMPTY_BODY = YES; 550 | CLANG_WARN_ENUM_CONVERSION = YES; 551 | CLANG_WARN_INT_CONVERSION = YES; 552 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 553 | CLANG_WARN_UNREACHABLE_CODE = YES; 554 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 555 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 556 | COPY_PHASE_STRIP = NO; 557 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 558 | ENABLE_NS_ASSERTIONS = NO; 559 | ENABLE_STRICT_OBJC_MSGSEND = YES; 560 | GCC_C_LANGUAGE_STANDARD = gnu99; 561 | GCC_NO_COMMON_BLOCKS = YES; 562 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 563 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 564 | GCC_WARN_UNDECLARED_SELECTOR = YES; 565 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 566 | GCC_WARN_UNUSED_FUNCTION = YES; 567 | GCC_WARN_UNUSED_VARIABLE = YES; 568 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 569 | MTL_ENABLE_DEBUG_INFO = NO; 570 | SDKROOT = iphoneos; 571 | SWIFT_VERSION = 3.0; 572 | TARGETED_DEVICE_FAMILY = "1,2"; 573 | VALIDATE_PRODUCT = YES; 574 | }; 575 | name = Release; 576 | }; 577 | 62A427601B5A3C9700BB4AD9 /* Debug */ = { 578 | isa = XCBuildConfiguration; 579 | baseConfigurationReference = 92EA19448C55590FCF3E36ED /* Pods-ShadowVPN.debug.xcconfig */; 580 | buildSettings = { 581 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 582 | CLANG_ENABLE_MODULES = YES; 583 | CODE_SIGN_ENTITLEMENTS = ShadowVPN/ShadowVPN.entitlements; 584 | CODE_SIGN_IDENTITY = "iPhone Developer"; 585 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 586 | CODE_SIGN_STYLE = Automatic; 587 | DEVELOPMENT_TEAM = 77M64ZZJGP; 588 | EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; 589 | ENABLE_BITCODE = NO; 590 | INFOPLIST_FILE = ShadowVPN/Info.plist; 591 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 592 | PRODUCT_BUNDLE_IDENTIFIER = com.FlyKite.ShadowVPN; 593 | PRODUCT_NAME = "$(TARGET_NAME)"; 594 | PROVISIONING_PROFILE = ""; 595 | PROVISIONING_PROFILE_SPECIFIER = ""; 596 | SKIP_INSTALL = NO; 597 | SWIFT_OBJC_BRIDGING_HEADER = "ShadowVPN/ShadowVPN-Bridging-Header.h"; 598 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 599 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 600 | SWIFT_VERSION = 5.0; 601 | }; 602 | name = Debug; 603 | }; 604 | 62A427611B5A3C9700BB4AD9 /* Release */ = { 605 | isa = XCBuildConfiguration; 606 | baseConfigurationReference = 8C36F9C5C8118C5BB6BF7967 /* Pods-ShadowVPN.release.xcconfig */; 607 | buildSettings = { 608 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 609 | CLANG_ENABLE_MODULES = YES; 610 | CODE_SIGN_ENTITLEMENTS = ShadowVPN/ShadowVPN.entitlements; 611 | CODE_SIGN_IDENTITY = "iPhone Developer"; 612 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 613 | CODE_SIGN_STYLE = Automatic; 614 | DEVELOPMENT_TEAM = 77M64ZZJGP; 615 | EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; 616 | ENABLE_BITCODE = NO; 617 | INFOPLIST_FILE = ShadowVPN/Info.plist; 618 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 619 | PRODUCT_BUNDLE_IDENTIFIER = com.FlyKite.ShadowVPN; 620 | PRODUCT_NAME = "$(TARGET_NAME)"; 621 | PROVISIONING_PROFILE = ""; 622 | PROVISIONING_PROFILE_SPECIFIER = ""; 623 | SKIP_INSTALL = NO; 624 | SWIFT_OBJC_BRIDGING_HEADER = "ShadowVPN/ShadowVPN-Bridging-Header.h"; 625 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 626 | SWIFT_VERSION = 5.0; 627 | }; 628 | name = Release; 629 | }; 630 | 62A427781B5A3ED800BB4AD9 /* Debug */ = { 631 | isa = XCBuildConfiguration; 632 | baseConfigurationReference = DA156D19BD3CF872917EB4F1 /* Pods-tunnel.debug.xcconfig */; 633 | buildSettings = { 634 | CODE_SIGN_ENTITLEMENTS = tunnel/tunnel.entitlements; 635 | CODE_SIGN_IDENTITY = "iPhone Developer"; 636 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 637 | CODE_SIGN_STYLE = Automatic; 638 | DEVELOPMENT_TEAM = 77M64ZZJGP; 639 | ENABLE_BITCODE = NO; 640 | INFOPLIST_FILE = tunnel/Info.plist; 641 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; 642 | PRODUCT_BUNDLE_IDENTIFIER = com.FlyKite.ShadowVPN.tunnel; 643 | PRODUCT_NAME = "$(TARGET_NAME)"; 644 | PROVISIONING_PROFILE = ""; 645 | PROVISIONING_PROFILE_SPECIFIER = ""; 646 | SKIP_INSTALL = YES; 647 | SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/tunnel/tunnel-Bridging-Header.h"; 648 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 649 | SWIFT_VERSION = 4.0; 650 | }; 651 | name = Debug; 652 | }; 653 | 62A427791B5A3ED800BB4AD9 /* Release */ = { 654 | isa = XCBuildConfiguration; 655 | baseConfigurationReference = 462DCB6C067AA9583774906C /* Pods-tunnel.release.xcconfig */; 656 | buildSettings = { 657 | CODE_SIGN_ENTITLEMENTS = tunnel/tunnel.entitlements; 658 | CODE_SIGN_IDENTITY = "iPhone Developer"; 659 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 660 | CODE_SIGN_STYLE = Automatic; 661 | DEVELOPMENT_TEAM = 77M64ZZJGP; 662 | ENABLE_BITCODE = NO; 663 | INFOPLIST_FILE = tunnel/Info.plist; 664 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; 665 | PRODUCT_BUNDLE_IDENTIFIER = com.FlyKite.ShadowVPN.tunnel; 666 | PRODUCT_NAME = "$(TARGET_NAME)"; 667 | PROVISIONING_PROFILE = ""; 668 | PROVISIONING_PROFILE_SPECIFIER = ""; 669 | SKIP_INSTALL = YES; 670 | SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/tunnel/tunnel-Bridging-Header.h"; 671 | SWIFT_SWIFT3_OBJC_INFERENCE = On; 672 | SWIFT_VERSION = 4.0; 673 | }; 674 | name = Release; 675 | }; 676 | /* End XCBuildConfiguration section */ 677 | 678 | /* Begin XCConfigurationList section */ 679 | 62A427481B5A3C9700BB4AD9 /* Build configuration list for PBXProject "ShadowVPN" */ = { 680 | isa = XCConfigurationList; 681 | buildConfigurations = ( 682 | 62A4275D1B5A3C9700BB4AD9 /* Debug */, 683 | 62A4275E1B5A3C9700BB4AD9 /* Release */, 684 | ); 685 | defaultConfigurationIsVisible = 0; 686 | defaultConfigurationName = Release; 687 | }; 688 | 62A4275F1B5A3C9700BB4AD9 /* Build configuration list for PBXNativeTarget "ShadowVPN" */ = { 689 | isa = XCConfigurationList; 690 | buildConfigurations = ( 691 | 62A427601B5A3C9700BB4AD9 /* Debug */, 692 | 62A427611B5A3C9700BB4AD9 /* Release */, 693 | ); 694 | defaultConfigurationIsVisible = 0; 695 | defaultConfigurationName = Release; 696 | }; 697 | 62A427771B5A3ED800BB4AD9 /* Build configuration list for PBXNativeTarget "tunnel" */ = { 698 | isa = XCConfigurationList; 699 | buildConfigurations = ( 700 | 62A427781B5A3ED800BB4AD9 /* Debug */, 701 | 62A427791B5A3ED800BB4AD9 /* Release */, 702 | ); 703 | defaultConfigurationIsVisible = 0; 704 | defaultConfigurationName = Release; 705 | }; 706 | /* End XCConfigurationList section */ 707 | }; 708 | rootObject = 62A427451B5A3C9700BB4AD9 /* Project object */; 709 | } 710 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------