Skip to content
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

[Bug] [HTTP Authentication][V 2.5.1] #266

Closed
2 tasks done
engageub opened this issue Jun 18, 2023 · 11 comments
Closed
2 tasks done

[Bug] [HTTP Authentication][V 2.5.1] #266

engageub opened this issue Jun 18, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@engageub
Copy link

engageub commented Jun 18, 2023

Verify steps

  • Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
  • I have searched on the issue tracker for a related issue.

Version

2.5.1

What OS are you seeing the problem on?

Linux

Description

After the recent docker update to v2.5.1 http authentication issues are seen while using http protocol with username and password. However socks5 protocol is working fine.

Switching back to v2.5.0 in docker, http proxies with username and password work fine.

Thank you

CLI or Config

Working Version with http username and password: xjasonlyu/tun2socks:v2.5.0
Buggy Version: xjasonlyu/tun2socks:v2.5.1

Logs

time="2023-06-18T13:18:25Z" level=warning msg="[TCP] dial 136.243.150.101:443: HTTP auth required by proxy"
time="2023-06-18T13:18:28Z" level=warning msg="[TCP] dial 144.76.194.78:443: HTTP auth required by proxy"
time="2023-06-18T13:18:30Z" level=warning msg="[TCP] dial 168.119.91.41:443: HTTP auth required by proxy"
time="2023-06-18T13:18:32Z" level=warning msg="[TCP] dial 144.76.194.78:443: HTTP auth required by proxy"
time="2023-06-18T13:18:33Z" level=warning msg="[TCP] dial 168.119.91.41:443: HTTP auth required by proxy"
time="2023-06-18T13:18:35Z" level=warning msg="[TCP] dial 168.119.91.41:443: HTTP auth required by proxy"
time="2023-06-18T13:18:37Z" level=warning msg="[TCP] dial 168.119.91.41:443: HTTP auth required by proxy"

How to Reproduce

Register to traffmonetizer from https://github.com/engageub/InternetIncome and input your token below.
If v.2.5.0 is used in the container version, it works fine without any Auth issues.

sudo docker run --name tuntraffmon --restart=always  -e PROXY=YOUR_HTTP_PROXY -v '/dev/net/tun:/dev/net/tun' --cap-add=NET_ADMIN -d xjasonlyu/tun2socks:v2.5.1
sudo  docker run -d  --restart=always --network="container:tuntraffmon " traffmonetizer/cli start accept  --token YOUR_TOKEN

@engageub
Copy link
Author

engageub commented Jun 18, 2023

Looks like the changes in the following file is throwing this error message.
Looking at the difference in two lines for headers "Basic" keyword is missing in the headers for Proxy-Authorization.

v 2.5.0
req.Header.Add("Proxy-Authorization",
			fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(auth))))
v 2.5.1
req.Header.Set("Proxy-Authorization", basicAuth(h.user, h.pass))

func basicAuth(username, password string) string {
	auth := username + ":" + password
	return base64.StdEncoding.EncodeToString([]byte(auth))
}

8e20770

v2.5.0...v2.5.1
Thank you

@xjasonlyu
Copy link
Owner

Thanks! Would you like to submit a PR to fix this? 🤗

@xjasonlyu xjasonlyu added the bug Something isn't working label Jun 19, 2023
@engageub
Copy link
Author

I have limited access to the resources and have not setup anything yet so far on this code. I just had a look at the code with the difference in the files from github. This requires lot of testing since there are other files in the code where changes have been made, so the functionality of them also needs to be tested just in case there is a dependency on this file directly or indirectly.

Thank you

@xjasonlyu
Copy link
Owner

No worries about the dependency or anything else.

Basically, there's only one-line code change required, from

req.Header.Set("Proxy-Authorization", basicAuth(h.user, h.pass))

to

req.Header.Set("Proxy-Authorization", fmt.Sprintf("Basic %s", basicAuth(h.user, h.pass)))

@engageub
Copy link
Author

engageub commented Jun 19, 2023

Yes, I think the return statement should be changed this way for basicAuth function. But you may have your own coding standards, so it can be written in different ways.

	return "Basic " + base64.StdEncoding.EncodeToString([]byte(auth))

@xjasonlyu
Copy link
Owner

The basicAuth function was copied from the go std net/http package, so I think it's better to keep it untouched.

@xjasonlyu
Copy link
Owner

Anyway, a PR is always welcome!

@xjasonlyu
Copy link
Owner

I'm gonna close this issue. Reopen if this bug still exists.

@blechschmidt
Copy link

Could you please draft a new release for this change to become available to packages and third-parties that do not build from source?

Thanks a lot in advance.

@xjasonlyu
Copy link
Owner

@blechschmidt no problem! just released a minor fixed version.

@blechschmidt
Copy link

Awesome, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants