Home

Awesome

ATTENTION: This version of Tor.framework is discontinued, because it uses Carthage, which is incompatible with Apple Silicon Macs.

Releases after version 406.8.2 will be pure CocoaPods releases.

For the pure CocoaPods version, go here: https://github.com/iCepa/Tor.framework/tree/pure_pod

For the time being, the old Carthage stuff will stay here, to not break dependencies, but it will eventually go away! Use the CocoaPods version - you'll want the latest Tor version!

Tor.framework

Carthage Compatible Travis CI

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 static versions of tor, libevent, openssl, and liblzma:

tor0.4.6.8
libevent2.1.12
OpenSSL1.1.1l
liblzma5.2.5

Requirements

Installation

Embedded frameworks require a minimum deployment target of iOS 8 or OS X Mavericks (10.9).

If you use brew, make sure to install autoconf, automake, libtool and gettext:

brew install automake autoconf libtool gettext

Initial Setup

git clone git@github.com:iCepa/Tor.framework

cd Tor.framework

git submodule update --init --recursive

carthage build --no-skip-current

Carthage

To integrate Tor into your Xcode project using Carthage, specify it in your Cartfile:

github "iCepa/Tor.framework" "master"

The above method will configure Carthage to fetch and compile Tor.framework from source. Alternatively, you may use the following to use binary-compiled versions of Tor.framework that correspond to releases in GitHub:

binary "https://icepa.github.io/Tor.framework/Tor.json" == 406.8.2

For available precompiled versions, see docs/Tor.json. Since Tor 0.3.5.2, the Tor.framework release version numbers follow the format "ABB.C.X" for tor version "0.A.B.C" and Tor.framework release X (for that version of Tor). Note that the "BB" slot is a two-digit number, with a leading zero, if necessary. "305.2.1" is the first release from tor 0.3.5.2.

Building a Carthage Binary archive

For maintainers/contributors of Tor.framework, a new precompiled release can be generated by doing the following:

Ensure that you have committed changes to the submodule trees for tor, libevent, openssl, and xz.

In Tor/version.sh, increment the TOR_BUNDLE_SHORT_VERSION_STRING version per the format described above. Change TOR_BUNDLE_SHORT_VERSION_DATE to the current date. Commit these changes.

Also update info in README.md, Tor.podspec and docs/Tor.json!

Create a git tag for the version, and then build + archive the framework:

carthage build --no-skip-current

carthage archive Tor

(This generates a Tor.framework.zip file in the repo.)

Then create a release in GitHub which corresponds to the tag, attach the generated Tor.framework.zip to the release.

Add a corresponding entry to docs/Tor.json, commit & push that so that it becomes available at https://icepa.github.io/Tor.framework/Tor.json

Upgrading Tor

To upgrade Tor:

cd Tor/tor
git fetch
git checkout tor-0.4.6.8 # 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 building Tor-iOS and Tor-Mac targets in Xcode.

Check build output in the Report Navigator. (Last tab in the left pane.)

The tor.sh build script will call make show-libs, which outputs all libraries which are created by the Tor build. This is echoed with a "LIBRARIES: " header. Search for that in the build output and compare the list against the list of "Frameworks and Libraries" in the Tor-iOS and Tor-Mac targets. Add missing ones accordingly.

The typically can be found in ~/Library/Developer/Xcode/DerivedData/Tor-[random ID]/Build/Products/Debug[-iphonesimulator].

The project.pbxproj file may need manual editing to set the references to the built libraries in a way, which is independent of your personal setup. Check other entries for how that is done.

CocoaPods

Nowadays, Tor.framework can be found on the CocoaPods registry:

pod 'Tor', '~> 406.8.2'

If you want to directly use it, you need to reference the provided podspec like so:

pod 'Tor', podspec: 'https://raw.githubusercontent.com/iCepa/Tor.framework/v406.8.2/Tor.podspec'

You could also reference master, to always get the latest version:

pod 'Tor', podspec: 'https://raw.githubusercontent.com/iCepa/Tor.framework/master/Tor.podspec'

Usage

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];
[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];
            ...
        }];
    }];
}];

GeoIP

This works only with CocoaPods:

In your Podfile use subspec GeoIP instead of the root spec:

pod 'Tor/GeoIP'

The subspec will create a "GeoIP" bundle and install a run script phase which will download 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;

ATTENTION: You might need to build two times to acquire the geoip files, due to a limitation of CocoaPods!

Known Issues

License

Tor.framework is available under the MIT license. See the LICENSE file for more info.