-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Package to setup system wide HTTP(S) Proxy on Desktop Platforms #190
Changes from 56 commits
e793764
bbd9f82
ba98871
bcb602e
4cb44eb
c11ab04
fdf398f
6a5680c
f48a095
cc694c9
044d794
422ca10
e2247d5
f91cafc
65db63e
f48f419
ed4c93b
ceec53f
5952a45
0faac88
7339b23
7b895a5
b6f3c97
6c59ad8
a04317e
7dd57d0
75ea37c
bdc6d2d
f8906a1
2826419
d3020d3
34ce3c3
0522adb
7cf4822
1ef992a
029a9c4
3f736c9
1baff92
3c593f9
9d8c9c9
b6558e2
2594efb
984833e
66658ac
1dedbf7
630fc56
4765b77
3f15492
4700f68
8855f10
8d5f311
c7e805c
4405b78
38e2535
9cfad5f
4fd18a6
428f291
7490cd1
00f414c
17aeeb7
b3c6f61
e49e0da
136c2db
3fbb4ed
e5b3ad1
7d22038
235ad1d
7e4abd9
d9c10c8
3da2ff2
05e3d14
d71b726
7cdec08
77faf78
b34db8e
35273de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,32 @@ | ||||||||||
# Platform support | ||||||||||
|
||||||||||
The table below summarizes system-wide support this package offers for various types of proxies on desktop platforms. | ||||||||||
|
||||||||||
| Proxy Type | Windows | MacOS | Linux | | ||||||||||
| --- | ----------- | ------ | ------ | | ||||||||||
| HTTP | Yes | Yes | Yes | ||||||||||
| HTTPS | Yes | Yes | Yes | ||||||||||
| SOCKS | No | Yes | Yes | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you do support Windows, but it's SOCKS4? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found this socks server package that implements sock4, 4a, and 5: https://github.com/cybozu-go/usocksd?tab=readme-ov-file I wanted to test socks proxy on all platforms and see what versions they support in reality. I have tested linux and mac with socks 5 and they work fine. I could not get windows working with socks5 and it only worked with sock4 server in my tests. I have not tested mac and linux against socks4 though...Maybe we can do this later as TODO item. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have updated doc.go to reflect this in the documentation language |
||||||||||
|
||||||||||
|
||||||||||
`SetupWebProxy` implementation in this package setups both HTTP and HTTPS proxy when they distinguished by the platform. `SetupSOCKSProxy` sets up SOCKS proxy that proxies all TCP-based connections. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to explain what setting a HTTP proxy and setting a HTTPS proxy mean. |
||||||||||
|
||||||||||
For example, on MacOS, if you have HTTP Proxy setup and visit a website over HTTPS, your traffic does NOT go through the proxy. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you rearrange the notes. Perhaps in a "Platform considerations" section. Then group each OS and pull the "other notes". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fortuna I rewrote the godoc and rearranged the notes. |
||||||||||
|
||||||||||
However, if only HTTPS proxy is setup, both HTTP and HTTPS requests go through the HTTPS proxy. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you set HTTPS, HTTP will use it? That's very counter intuitive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fortuna The proxy server running locally is HTTP proxy server in both cases. In the first experiment, I only setup system's client HTTP proxy settings. In this case, only HTTP requests get routed through the proxy. If I setup system's client HTTPS proxy settings, both HTTP and HTTPS requests get routed through the proxy. I believe this is just the way the system decides which type of request to route to the proxy. HTTPS is basically the super set in this design. In our case, we don't care much about this since we are settings up both at the same time on all platforms and call it WebProxy which ends up routing both HTTP and HTTPS requests through the proxy. |
||||||||||
|
||||||||||
If SOCKS is setup, both HTTP and HTTPS requests go through the proxy since it is performed at the TCP layer. SOCKS does not support UDP. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SOCKS5 does support UDP. Please rephrase. Did you mean the OS implementation doesn't support it? Did you test on all platforms? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. Sock5 does support UDP. I will update the language |
||||||||||
|
||||||||||
On Windows, The client only supports SOCKS4 spec and cannot connecto SOCKS5 proxy. | ||||||||||
amircybersec marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
Support for FTP Proxy setting was not included due lack of adoption and usage. Username and password authentication was not included due to potential unreliability and untestd behavior. Please note that in SOCKS and HTTP proxy, credentials are communicated in plain text. | ||||||||||
amircybersec marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say that authentication is not supported because the intended usage it to connect to a proxy running on localhost. |
||||||||||
|
||||||||||
If you have a need for any of those, feel free to open an issue and let me know about the use case. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can delete this.
Suggested change
|
||||||||||
|
||||||||||
## Other notes | ||||||||||
|
||||||||||
1. Windows does not explicitly distinguish between HTTP and HTTPS proxy. Also, username/password support authentication is not supported. | ||||||||||
|
||||||||||
2. MacOS SOCKS client does not seems to correctly support authentication even thoguh it accepts credentials [[ref](https://discussions.apple.com/thread/255394737?sortBy=best)]. | ||||||||||
|
||||||||||
3. On GNOME, username/Pass authenticartion is not currently supported for HTTPS proxy [[ref](https://gitlab.gnome.org/GNOME/gsettings-desktop-schemas/-/issues/42)]. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,80 @@ | ||||||||||||||
// Copyright 2024 Jigsaw Operations LLC | ||||||||||||||
// | ||||||||||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||
// you may not use this file except in compliance with the License. | ||||||||||||||
// You may obtain a copy of the License at | ||||||||||||||
// | ||||||||||||||
// https://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||
// | ||||||||||||||
// Unless required by applicable law or agreed to in writing, software | ||||||||||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||
// See the License for the specific language governing permissions and | ||||||||||||||
// limitations under the License. | ||||||||||||||
|
||||||||||||||
/* | ||||||||||||||
jyyi1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
Package sysproxy provides a simple interface to set/unset system-wide proxy settings. | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is cleaner:
Suggested change
|
||||||||||||||
|
||||||||||||||
# Platform Support | ||||||||||||||
|
||||||||||||||
Currently this package supports desktop platforms only. The following platforms are supported: | ||||||||||||||
amircybersec marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
- macOS | ||||||||||||||
amircybersec marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
- Linux (Gnome) | ||||||||||||||
- Windows | ||||||||||||||
|
||||||||||||||
# macOS | ||||||||||||||
|
||||||||||||||
To configure proxy settings on macOS, we use networksetup utility with following options. To set web proxy: | ||||||||||||||
|
||||||||||||||
networksetup -setwebproxy <networkservice> <domain> <portnumber> | ||||||||||||||
|
||||||||||||||
To set secure web proxy: | ||||||||||||||
|
||||||||||||||
networksetup -setsecurewebproxy <networkservice> <domain> <portnumber> | ||||||||||||||
|
||||||||||||||
For more information, see the link [here]. | ||||||||||||||
|
||||||||||||||
# Linux | ||||||||||||||
|
||||||||||||||
Currently only GNOME is supported. This package uses gsettings untility to setup proxy settings. The following commands are used to set proxy settings: | ||||||||||||||
|
||||||||||||||
gsetting set org.gnome.system.proxy.http host 'proxy.example.com' | ||||||||||||||
gsetting set org.gnome.system.proxy.http port 8080 | ||||||||||||||
|
||||||||||||||
The following parameters can be set for other types of proxies: | ||||||||||||||
|
||||||||||||||
org.gnome.system.proxy.https | ||||||||||||||
org.gnome.system.proxy.ftp | ||||||||||||||
org.gnome.system.proxy.socks | ||||||||||||||
|
||||||||||||||
For more information, you can checkout the documentation for [gsettings] and its [configuration]. | ||||||||||||||
|
||||||||||||||
# Windows | ||||||||||||||
|
||||||||||||||
On Windows, the package uses HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings + InternetSetOptionW | ||||||||||||||
to setup proxy settings. For more information, you can checkout the documentation for [InternetSetOptionW]. | ||||||||||||||
|
||||||||||||||
# Usage | ||||||||||||||
|
||||||||||||||
To set up system-wide proxy settings, use the [SetWebProxy] or [SetSOCKSProxy] methods to connect to a Web (HTTP & HTTPS) or SOCKS proxy. | ||||||||||||||
This function takes two arguments: the IP address / hostname and the port of the proxy server. | ||||||||||||||
|
||||||||||||||
To clear system-wide proxy settings, use the [ClearWebProxy] or [ClearSOCKSProxy] function. | ||||||||||||||
This will set the address and port to "127.0.0.1:0" and disable the proxy. | ||||||||||||||
|
||||||||||||||
To ensure that the system-wide proxy settings are unset upon program termination, it is recommended to call: | ||||||||||||||
|
||||||||||||||
defer ClearWebProxy() | ||||||||||||||
|
||||||||||||||
// or | ||||||||||||||
|
||||||||||||||
defer ClearSOCKSProxy() | ||||||||||||||
|
||||||||||||||
after the setting the proxy. | ||||||||||||||
|
||||||||||||||
[here]: https://keith.github.io/xcode-man-pages/networksetup.8.html | ||||||||||||||
[gsettings]: https://github.com/GNOME/gsettings-desktop-schemas/blob/master/schemas/org.gnome.system.proxy.gschema.xml.in | ||||||||||||||
[configuration]: https://developer-old.gnome.org/ProxyConfiguration/ | ||||||||||||||
[InternetSetOptionW]: https://learn.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetsetoptionw | ||||||||||||||
*/ | ||||||||||||||
package sysproxy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to the Go doc instead. No one will read the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed README and merged content with Godoc