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

https blocking does not take effect #501

Open
gitcfly opened this issue Jun 19, 2023 · 3 comments
Open

https blocking does not take effect #501

gitcfly opened this issue Jun 19, 2023 · 3 comments

Comments

@gitcfly
Copy link

gitcfly commented Jun 19, 2023

Thank you very much for this library, it works very well in http mode, however an error occurred when I was processing an https request , Here is my code:

func main() {
	proxy := goproxy.NewProxyHttpServer()
	proxy.Verbose = true
	proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm)
	proxy.OnResponse().DoFunc(func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
		glg.Println("OnResponse:", ctx.Req.Proto, ctx.Req.Method, ctx.Req.URL.String())
		return resp
	})
	glg.Fatal(http.ListenAndServe(":62222", proxy))
}

I want to get a response from https, but the proxy.OnResponse().DoFunc method is not executed, and the following error is found in the log:

2023/06/19 20:29:21 [003] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:21 [003] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:21 [003] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:21 [003] INFO: signing for m.baidu.com
2023/06/19 20:29:21 [003] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:21 [004] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:21 [004] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:21 [004] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:21 [004] INFO: signing for m.baidu.com
2023/06/19 20:29:21 [004] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:21 [005] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:21 [005] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:21 [005] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:21 [005] INFO: signing for m.baidu.com
2023/06/19 20:29:21 [005] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:21 [006] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:21 [006] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:21 [006] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:21 [006] INFO: signing for m.baidu.com
2023/06/19 20:29:22 [006] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:22 [007] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:22 [007] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:22 [007] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:22 [007] INFO: signing for m.baidu.com
2023/06/19 20:29:22 [007] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:22 [008] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:22 [008] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:22 [008] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:22 [008] INFO: signing for m.baidu.com
2023/06/19 20:29:22 [008] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:22 [009] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:22 [009] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:22 [009] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:22 [009] INFO: signing for m.baidu.com
2023/06/19 20:29:22 [009] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:22 [010] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:22 [010] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:22 [010] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:22 [010] INFO: signing for m.baidu.com
2023/06/19 20:29:22 [010] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:22 [011] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:22 [011] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:22 [011] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:22 [011] INFO: signing for m.baidu.com
2023/06/19 20:29:23 [011] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:23 [012] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:23 [012] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:23 [012] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:23 [012] INFO: signing for m.baidu.com
2023/06/19 20:29:23 [012] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:23 [013] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:23 [013] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:23 [013] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:23 [013] INFO: signing for m.baidu.com
2023/06/19 20:29:23 [013] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:23 [014] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:23 [014] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:23 [014] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:23 [014] INFO: signing for m.baidu.com
2023/06/19 20:29:23 [014] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:23 [015] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:23 [015] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:23 [015] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:23 [015] INFO: signing for m.baidu.com
2023/06/19 20:29:24 [015] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:24 [016] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:24 [016] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:24 [016] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:24 [016] INFO: signing for m.baidu.com
2023/06/19 20:29:24 [016] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:24 [017] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:24 [017] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:24 [017] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:24 [017] INFO: signing for m.baidu.com
2023/06/19 20:29:24 [017] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:24 [018] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:24 [018] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:24 [018] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:24 [018] INFO: signing for m.baidu.com
2023/06/19 20:29:24 [018] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:24 [019] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:24 [019] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:24 [019] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:24 [019] INFO: signing for m.baidu.com
2023/06/19 20:29:24 [019] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:24 [020] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:24 [020] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:24 [020] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:24 [020] INFO: signing for m.baidu.com
2023/06/19 20:29:25 [020] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:25 [021] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:25 [021] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:25 [021] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:25 [021] INFO: signing for m.baidu.com
2023/06/19 20:29:25 [021] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:25 [022] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:25 [022] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:25 [022] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:25 [022] INFO: signing for m.baidu.com
2023/06/19 20:29:25 [022] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:25 [023] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:25 [023] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:25 [023] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:25 [023] INFO: signing for m.baidu.com
2023/06/19 20:29:26 [023] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:26 [024] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:26 [024] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:26 [024] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:26 [024] INFO: signing for m.baidu.com
2023/06/19 20:29:26 [024] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:26 [025] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:26 [025] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:26 [025] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:26 [025] INFO: signing for m.baidu.com
2023/06/19 20:29:26 [025] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:26 [026] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:26 [026] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:26 [026] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:26 [026] INFO: signing for m.baidu.com
2023/06/19 20:29:26 [026] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:26 [027] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:26 [027] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:26 [027] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:26 [027] INFO: signing for m.baidu.com
2023/06/19 20:29:26 [027] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:27 [028] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:27 [028] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:27 [028] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:27 [028] INFO: signing for m.baidu.com
2023/06/19 20:29:27 [028] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:27 [029] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:27 [029] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:27 [029] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:27 [029] INFO: signing for m.baidu.com
2023/06/19 20:29:27 [029] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:27 [030] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:27 [030] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:27 [030] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:27 [030] INFO: signing for m.baidu.com
2023/06/19 20:29:28 [030] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:28 [031] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:28 [031] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:28 [031] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:28 [031] INFO: signing for m.baidu.com
2023/06/19 20:29:28 [031] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:28 [032] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:28 [032] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:28 [032] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:28 [032] INFO: signing for m.baidu.com
2023/06/19 20:29:28 [032] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:28 [033] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:28 [033] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:28 [033] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:28 [033] INFO: signing for m.baidu.com
2023/06/19 20:29:29 [033] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate
2023/06/19 20:29:29 [034] INFO: Running 1 CONNECT handlers
2023/06/19 20:29:29 [034] INFO: on 0th handler: &{2 <nil> 0x12b27c0} m.baidu.com:443
2023/06/19 20:29:29 [034] INFO: Assuming CONNECT is TLS, mitm proxying it
2023/06/19 20:29:29 [034] INFO: signing for m.baidu.com
2023/06/19 20:29:29 [034] WARN: Cannot handshake client m.baidu.com:443 remote error: tls: unknown certificate

Can you help me see what needs to be done?

@chekun
Copy link

chekun commented Nov 29, 2023

Hi @gitcfly , have you solved this ? I am facing this, no clue at all.

@chekun
Copy link

chekun commented Nov 29, 2023

@gitcfly tell you what , you need to get your os trust your ca cert , then everything is fine.

@gitcfly
Copy link
Author

gitcfly commented Nov 29, 2023

@gitcfly tell you what , you need to get your os trust your ca cert , then everything is fine.

Thank you for your answer. If I use this library in the future, I will try it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants