python - ssl.wrap_socket 在go中的实现

标签 python ssl go

在 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/

相关文章:

Python数组转换为字符串

go - 我可以在一个函数上使用两个 for 循环还是有更好的方法?

reflection - 去吧,为什么不应该使用 "this"作为方法接收者名称

python - numpy - 二维数组索引

python - 如何在 python 中使用 re 模块匹配模式之间的行

linux - Python简单的SSL通信

firefox - 通过 HTTPS 的 Firefox 上的灰色三角形

unit-testing - 忽略 Golang 测试覆盖率计算中的代码块

Python错误加载google API的JSON代码

amazon-web-services - 为 HTTP 和 HTTPS 打开不同的站点