Tor.framework is the easiest way to embed Tor in your iOS application. The API is not stable yet, and subject to change.
Currently, the framework compiles in the following versions of tor
, libevent
, openssl
, and liblzma
:
Component | Version |
---|---|
tor | 0.4.8.13 |
libevent | 2.1.12 |
OpenSSL | 3.4.0 |
liblzma | 5.6.3 |
Onionmasq | 0.6.2 |
To run the example project, clone the repo, and run pod install
from the Example directory first.
- iOS 12.0 or later
- MacOS 10.13 or later
- Xcode 13.0 or later
autoconf
,automake
,libtool
andgettext
in yourPATH
Install build tools via Homebrew:
brew install automake autoconf libtool gettext
Tor is available through CocoaPods. To install it, simply add the following line to your Podfile:
If you use dynamic frameworks, use the root spec:
use_frameworks!
pod 'Tor', '~> 408'
(or Tor/GeoIP
- see below.)
If you need to add it as a static library, you will need to add it from a modified podspec:
pod 'Tor', :podspec => 'https://raw.githubusercontent.com/iCepa/Tor.framework/pure_pod/TorStatic.podspec'
Currently static library support is unstable. You might encounter build issues. Every contribution to fix this is welcome!
(or Tor/GeoIP
- see below.)
If you check out this repository directly, you will also need to fetch the submodules:
git submodule update --init --recursive
If you use it as a normal CocoaPods dependency, that will be done by CocoaPods.
For maintainers/contributors of Tor.framework, a new release should be prepared by doing the following:
Ensure that you have committed changes to the submodule trees for tor, libevent, openssl, and xz.
Also update info and version numbers in README.md
and Tor.podspec
!
Then lint like this:
pod lib lint --verbose --allow-warnings
(Use verbose
, otherwise you'll get very bored.)
If the linting went well, create a git tag for the version, push to GitHub and then publish to CocoaPods:
pod trunk push Tor.podspec --verbose --allow-warnings --skip-import-validation --skip-tests
(Unfortunately, you can not not lint on publish, so you might skip the first lint. However, pod trunk push
will take even longer, because it will clone everything fresh, too.)
Then create a release in GitHub which corresponds to the tag, and attach latest info as per older releases.
To upgrade Tor:
cd Tor/tor
git fetch
git checkout tor-0.4.8.13 # Find latest versions with git tag -l
rm -r * && git checkout . # Get rid of all autogenerated configuration files, which may not work with the newest version anymore.
git submodule update --init --recursive # Later Tor has submodules.
-> Test build by running the Example apps.
Check build output in the Report Navigator. (Last tab in the left pane.)
For a headache-free start into the world of Tor on iOS and macOS, check out
the new TorManager
project!
Starting an instance of Tor involves using three classes: TORThread
, TORConfiguration
and TORController
.
Here is an example of integrating Tor with NSURLSession
:
TORConfiguration *configuration = [TORConfiguration new];
configuration.ignoreMissingTorrc = YES;
configuration.cookieAuthentication = YES;
configuration.dataDirectory = [NSURL fileURLWithPath:NSTemporaryDirectory()];
configuration.controlSocket = [configuration.dataDirectory URLByAppendingPathComponent:@"control_port"];
TORThread *thread = [[TORThread alloc] initWithConfiguration:configuration];
[thread start];
NSData *cookie = configuration.cookie;
TORController *controller = [[TORController alloc] initWithSocketURL:configuration.controlSocket];
NSError *error;
[controller connect:&error];
if (error) {
NSLog(@"Error: %@", error);
return;
}
[controller authenticateWithData:cookie completion:^(BOOL success, NSError *error) {
if (!success)
return;
[controller addObserverForCircuitEstablished:^(BOOL established) {
if (!established)
return;
[controller getSessionConfiguration:^(NSURLSessionConfiguration *configuration) {
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
...
}];
}];
}];
In your Podfile
use the subspec GeoIP
or StaticGeoIP
instead of the root spec:
use_frameworks!
pod 'Tor/GeoIP'
or
pod 'Tor/GeoIP', :podspec => 'https://raw.githubusercontent.com/iCepa/Tor.framework/pure_pod/TorStatic.podspec'
The subspec will create a "GeoIP" bundle with the appropriate GeoIP files.
To use it with Tor, add this to your configuration:
TORConfiguration *configuration = [TORConfiguration new];
configuration.geoipFile = NSBundle.geoIpBundle.geoipFile;
configuration.geoip6File = NSBundle.geoIpBundle.geoip6File;
Since I while, this project also contains a podspec, which uses Arti (A Rust Tor Implementation) or Onionmasq (Arti with a wrapper taking in IP packets, useful for VPN-style apps.)
pod 'Tor/Arti', :podspec => 'https://raw.githubusercontent.com/iCepa/Tor.framework/pure_pod/Arti.podspec'
or
pod 'Tor/Onionmasq', :podspec => 'https://raw.githubusercontent.com/iCepa/Tor.framework/pure_pod/Arti.podspec'
There's currently a known issue: Onionmasq won't compile if you build for iOS or an iOS simulator right away, since some Rust dependencies use custom build scripts which need to get compiled for MacOS, but will try to use the wrong platform (iOS) in this case. This can be fixed, if you compile for your machine first:
cd Pods/Tor/Tor/onionmasq
make macos-debug-aarch64-apple-darwin # If you run on Apple Silicon
make macos-debug-x86_64-apple-darwin # If you're still on Intel
Then, the Rust dependency build scripts will be compiled correctly and the Xcode build will run correctly.
You can also precompile your debug and release targets on the command line, if you like:
make macos-release-universal-macos # Release build for MacOS as universal binary
make ios-release-aarch64-apple-ios # Release build for iOS
make ios-debug-aarch64-apple-ios # Debug build for iOS device
make ios-debug-aarch64-apple-ios-sim # Debug build for iOS simulator running on Apple Silicon
make ios-debug-x86_64-apple-ios # Debug build for iOS simulator running on Intel
https://tordev.guardianproject.info
- Conrad Kramer, [email protected]
- Chris Ballinger, [email protected]
- Mike Tigas, [email protected]
- Benjamin Erhart, [email protected]
Tor.framework is available under the MIT license. See the
LICENSE
file for more info.