Qv2ray: Obj-C API for macOS system proxy

Created on 18 Dec 2019  ·  25Comments  ·  Source: Qv2ray/Qv2ray

In MacOSX Client, Set System Proxy is checked but still system proxy is not set

In MacOSX Client Preference > Inbound settings > Set System Proxy is checked, but still system proxy for both Ethernet network and WiFi network is not set.

Is this the desired behaviour, bug or am I missing something ?

NewFeature help wanted platformacOS

All 25 comments

Currently, there's no support to set up macOS system settings in version 2.
Apple only provides objective-c or swift API, but not c++.

It already on the schedule, but I didn't expect to implement this feature in the near future (I need to learn ObjC)

It already on the schedule, but I didn't expect to implement this feature in the near future (I need to learn ObjC)

I know bit of ObjC I could maybe help you guys with that... 🥂

Yes sure! The interfaces are here:

https://github.com/lhy0403/Qv2ray/blob/dev/src/components/QvSystemProxyConfigurator.hpp

I may write a better doc soon.

You may just send the obj-c code directly here since integrating these to Qt might be tricky.

You may just send the obj-c code directly here since integrating these to Qt might be tricky.

Yes Cool! Also If you need any more MacOS related API Implementation feel free to bug me.

Let's reopen this for tracking.

The code for the SetSystemProxy for MacOSX can be located here

I changed the function signature a bit, for accepting the list of network interface to apply these settings to and also which address is for which protocol (i am not sure how to access that, its part of QString & address maybe?

THanks, I will go and check your repo, since I don't have much free time recently, I might reply you in a few days.

I may have found a relatively easy way to set system proxies on macOS:
why not run networksetup command on macOS, if it's hard to integrate Obj-C code?
Here's a reference:

https://richardkmiller.com/925/script-to-enabledisable-socks-proxy-on-mac-os-x

cc @lhy0403


updates: this can be used to temporarily implement this, which, later can be replaced with native Obj-C calls.

A tricky way implementing this is to .....

"but one thing seems to work for me … changing the proxy tool permission and chown to root …. Then it won’t ask for a password … maybe we can ask for permission once and install that tool as root and all the future run can be run as root’s permission"

Quoted.

Yeah maybe we can set this file @DuckSoft you mentioned as chown root:root and call it directly?
What do you think? @DuckSoft @SoumeshBanerjee

If so, I still need some API (or something else) that allows me to show a sudo password prompt.

If so, I still need some API (or something else) that allows me to show a sudo password prompt.

You can run this using apple script calling with administrator privileges .. like this example

So we can embed an AppleScript and call it to set our “setProxy.sh” as owned by root:root.
Once that is done, each time we just need to call that “setProxy.sh -myArgs” without prompting current user password?

Where should we place that “setProxy.sh”?
It needs to be somewhere that cannot be deleted by the user accidentally.

In Qv2ray config dir?

Where should we place that “setProxy.sh”?

Well Apple apps are just a folder ... so in XCode you can create Copy Build Phase and place that file there (not sure how you're building the application though!)
To view the folder structure of Qv2ray app you can do $ ls qv2ray.app

or

/Library/Application\ Support/Qv2ray folder for the application maybe!

Merry Christmas 🎄

Merry Christmas everyone!
I'd love to put it into "/Library/Application Support/Qv2ray" since app folder content and permission will be replaced (and reset as well) when upgrading Qv2ray. However, by using the system application support path, we only need to update the script whenever needed.

So final confirmation: "setProxy" will be inside /Library/Application\ Support/Qv2ray right?

I'll setup a VM and test this feature soon.

I tried on my VM, I'm able to call networksetup setsocksfirewallproxystate Ethernet off and set the proxy without root permission, I wonder if it only happen to me or it's a new feature in the recent macOS update.

macOS Catalina 10.15.3 Beta (19D49f)
cc @SoumeshBanerjee

Also need to mention, the Interface name (or Apple calls it "Service name") may be changed by user and varies in different languages (maybe?).

For ref only

➜  ~ networksetup -listallnetworkservices 
An asterisk (*) denotes that a network service is disabled.
Ethernetxxx
Bluetooth PAN

I tried on my VM, I'm able to call networksetup setsocksfirewallproxystate Ethernet off and set the proxy without root permission, I wonder if it only happen to me or it's a new feature in the recent macOS update

I am not sure but seems like networksetup CLI tool don't prompt for sudo permission/ password to run (at least in my user account which is a Admin account)... just like if you manually edit from the Settings app

Also need to mention, the Interface name (or Apple calls it "Service name") may be changed by user and varies in different languages (maybe?).

Yes, sorry for not making this clearer, the Interface name (service name) can be changed by the user / program
In the ObjC API program we can set the proxy for all the interfaces... if we remove this check

@SoumeshBanerjee To make it simple, I chose to directly execute the networksetup process.
Thanks for your contributions.

Feature added, we will enumerate all network interfaces except the disabled ones, and set proxy settings to all of the enabled ones.

Later, maybe we can utilize this helper from @SoumeshBanerjee and include it within our macOS distribution. networksetup maybe too tricky for a stable release.

For information: This is temporarily fixed and will be closed.
Future migrations to use @SoumeshBanerjee 's repo will be discussed whenever needed.

Was this page helpful?
0 / 5 - 0 ratings