gpt4 book ai didi

python - 通过代理的 HTTPS 完全加密,包括 SSL CONNECT

转载 作者:IT王子 更新时间:2023-10-29 01:15:28 26 4
gpt4 key购买 nike

我正在尝试测试一个期望立即进行 SSL 握手的代理,即使客户端将使用 SSL CONNECT 方法也是如此。问题是我的 Golang 和 Python 测试代码似乎都有同样的缺陷。他们以明文方式连接到代理,然后发出 CONNECT,但代理拒绝此操作,因为它期待 SSL 握手。

有谁知道如何使用可用的标准库强制这两种技术对代理使用 SSL?

谢谢。

示例代码如下:

#!/usr/bin/python

try:
import urllib2

proxy = urllib2.ProxyHandler({'https': "myproxyip:6881"})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
print urllib2.urlopen('https://www.google.ca').read()

except Exception as err:
print err


try:
import httplib

c = httplib.HTTPSConnection('myproxyip', 6881)
c.set_tunnel('google.ca', 443)
c.request('GET', '/')
res = c.getresponse()
print res.status, res.reason

except Exception as err:
print err

和戈兰

// vim: ft=go ts=4 sw=4 et ai:
package main

import (
"net/http"
"log"
"io/ioutil"
"time"
"crypto/tls"
"net/url"
)

var use_proxy = true
var proxy = "https://myproxyip:6881"
var req_url = "https://google.ca"
var n_seconds time.Duration = 15
var period = time.Second * n_seconds
var n_threads = 50
var thread_start_delay time.Duration = 1

func http_fetch(req_url string) {
tr := http.Transport {
TLSClientConfig: &tls.Config {
InsecureSkipVerify: true,
},
}
proxy_url, err := url.Parse(proxy)
if err != nil {
log.Fatal(err)
}
if use_proxy {
tr.Proxy = http.ProxyURL(proxy_url)
}
client := &http.Client{}
client.Transport = &tr

req, err := http.NewRequest("GET", req_url, nil)
if err != nil {
log.Fatal(err)
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36")

res, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
defer res.Body.Close()
document := string(body)
print(document)
}


func main() {
println("main: Starting", n_threads, "threads to hammer", req_url, "every", n_seconds, "seconds, ctrl-c to quit...")
done := make(<-chan bool)
for i:= 0; i < n_threads; i++ {
go func(thread_id int) {
println("thread", thread_id, ": starting periodic_hammer")
for {
println("thread", thread_id, ": fetching", req_url)
http_fetch(req_url)
println("thread", thread_id, ": done, sleeping for", n_seconds, "seconds")
time.Sleep(period)
}
}(i+1)
println("main: delaying", thread_start_delay, "seconds before starting next thread")
time.Sleep(thread_start_delay * time.Second)
}
<-done
}

最佳答案

仅从 Go 1.10 开始支持使用 https 代理。来自draft release notes :

On the client side, an HTTP proxy (most commonly configured by ProxyFromEnvironment) can now be specified as an https:// URL, meaning that the client connects to the proxy over HTTPS before issuing a standard, proxied HTTP request. (Previously, HTTP proxy URLs were required to begin with http:// or socks5://.)

关于python - 通过代理的 HTTPS 完全加密,包括 SSL CONNECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45037328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com