Files
nym/nym-connect/native/ios/README.MD
T
Jon Häggblad ce380a6b0d Native nym-connect clients for iOS and Android (initial version) (#3452)
* initial crate

* foomp

* Make it work for x86_64-linux-android

* remove unused stuff

* Add header

* another layer of hacks

* additional target os locking

* cleanup

* bootstrap android app

* android jni function

* instructions + xcode project

* update jni name

* add native socks5 class

* typo

* gitkeep android native lib path

* add native socks5 class

* add socks5 native lib in java

* add build script

* fix jni dependency declaration

* wip

* Update build.sh

* Move build.sh to new subdir

* rename to build-android.sh

* fix typo in FFI function name

* use a good SP

* wip not crashing state

* add android network permissions

* android_logging

* starting client on button in swift + safer ffi

* set tag for libnyms5 logs

* testing callbacks

* android: start socks5 process in a separated thread

* non-blocking client with callbacks

* Remove the old non-working logger

* Restore commented out functionality in socks5 client

* basic file write/load + possible android fix

* Fully working state (minus task manager)

* Remove unused function

* data persistence + cb with address

* Remove stray old MyClass file from the merge

* Make storage_dir and Option

* Fix char_p for android

* Android now works with the new branch

* Tidy up a little in the jni code

* Move android mod to seperate file

* jni wrap start/stop

* Add android build to Makefile

* android: add basic UI and start/stop actions

* typo

* add nym word

* dirty persistence restored

* dirty android fixes

* even dirtier workaround

* Move rust crate to sdk/lib

* Update cargo.toml

* Strip release binary

* Update lib name in android project

* Move ios project to nym-connect directory

* remove old gitignore file

* Move ios client one step deeper

* fixed xcode lib paths

* removed old tracked file

* move android app under new path

* a bit of cleanup

* hopefully fixing the CI issues (🤞)

* Update Makefile

* android: add better support for persistent state

* updating ios UI on ffi callbacks

* missing dead code

* Added toggle button (wip)

* swapped connect and disconnect  methods around

* icon

* fixed android build

* reset button + reuse service provider

* disabling reset button

* android: run proxy in a worker as foreground service

* todo user cancel action

* android build script: add aarch64

* add stop action from notification

* add simple callbacks to the socks5 bridge

* pick a sp randomly

* pass stop cb to lib call

* add loading state support

* refactor(android): base connection state on callback calls

* android: add optimistic ui

* android: unique instance of libnym

* removing deadcode

---------

Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com>
Co-authored-by: pierre <dommerc.pierre@gmail.com>
Co-authored-by: Mark Sinclair <mmsinclair@users.noreply.github.com>
2023-05-25 15:45:40 +02:00

2.5 KiB

Socks5-c

Setting up dummy socks5 client in iOS (from scratch)

Based on https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-06-rust-on-ios.html

  1. Install xcode, iOS simulator, etc. (xcode-select --install)
  2. add rust targets: rustup target add aarch64-apple-ios x86_64-apple-ios
  3. get cargo-lipo: cargo install cargo-lipo
  4. build our library file. From inside cargo run cargo lipo --release
  5. go to General tab of the xcode project setting and under Linked Frameworks and Libraries import /cargo/target/universal/release/libsocks5_c.a
  6. link libresolv.tbd: in Linked Frameworks and Libraries search for and select libresolv.tbd
  7. import socks5_c.h header file into the project: File -> Add Files to "..."
  8. create bridging header: make new Socks5-Bridging-Header.h file and put the following inside:
    #ifndef Greetings_Bridging_Header_h
    #define Greetings_Bridging_Header_h
    
    #import "socks5_c.h"
    
    #endif
  1. tell xcode about the bridging header: go to Build Settings tab and set Objective-C Bridging Header to $(PROJECT_DIR)/Socks5/Socks5-Bridging-Header.h
  2. tell xcode where to look for libraries for linking: go to Build Settings tab and amend the Library Search Paths option value to $(PROJECT_DIR)/../../cargo/target/universal/release
  3. create a swift file to actually call our code (RustSocks5.swift)
// this is an example

class RustSocks5 {
    func runForever(serviceProvider: String) {
        run_client(serviceProvider)
    }
}
 
  1. call the new code however you want. I did it by setting onAppear:
struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
        .onAppear{
            let rustSocks5 = RustSocks5()
            rustSocks5.runForever(serviceProvider: "my-service-provider-address")
        }
    }
}
  1. note: the above requires passing a service provider address. The easiest (for testing) would be to just run a local network requester with open proxy and passing that address.
  2. fix iOS simulator: go to Build Settings and add Any iOS Simulator SDK with value arm64 inside Excluded Architecture.
  3. start the simulator!
  4. test it by sending some request, like curl -x socks5h://127.0.0.1:1080 https://nymtech.net