gpt4 book ai didi

python - ssl.wrap_socket 在go中的实现

转载 作者:数据小太阳 更新时间:2023-10-29 03:42:20 26 4
gpt4 key购买 nike

在 python 中,您可以使用 ssl 包装标准套接字。可以在此处找到详细文档,https://docs.python.org/2/library/ssl.html

我想要类似的东西。这是我的尝试。

func GetSSLWrappedConnection() (SSLWrappedConnection net.Conn, err error){

fmt.Println("Initialiazing proxy connection")
rawConn, er_ := net.Dial("tcp", "127.0.0.1:8080")
if er_ != nil {
return nil, fmt.Errorf("Can't establish connection with remote server!")
} else {
// now we need to wrap the connection (SSL Wrap)
var TLSconfig *tls.Config
TLSconfig = &tls.Config{
InsecureSkipVerify: true}

ssl_wrapped_connection := tls.Client(rawConn, TLSconfig)
err = ssl_wrapped_connection.Handshake()

if err != nil {
fmt.Println(err)
rawConn.Close()
return nil, err
}
return ssl_wrapped_connection, nil
}

这是正确的实现方式吗?

最佳答案

问错了问题。

一个简单的 tls.Dial 就可以了!

关于python - ssl.wrap_socket 在go中的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46071843/

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