繁体   English   中英

低级 TLS 握手?

[英]Low level TLS handshake?

我想拦截ALPN选择和 select 我想要的而不是客户端和服务器之间的第一个公共选项。

代码:

// we have some ALPN protocols and certificates for TLS/SSL
tlsConfig := &tls.Config {
    Certificates: serverCertificates,
    NextProtos  : serverALPN,
}
// a simple TCP server
server, err := net.Listen("tcp", serverHost+":"+serverPort) 
...
for {
    // we accept a connection
    conn, err := ln.Accept()
    ...
    // wrap it in TLS
    tlsConn := tls.Server(conn, &tlsConfig)
    // and pass it to the handler
    go handleConnection(tlsConn)
}

到目前为止,我们还没有进行任何 TLS 握手,所以连接是空闲的、纯粹的。 func handleConnection(conn *tls.Conn)中,我们会err:= conn.Handshake()自动为我们执行握手,但是如何手动执行呢? 我似乎没有在tls模块文档中找到任何相关信息。 我想做这样的事情:

// we communicate with client until he's told us all the ALPNs they support
state := conn.HandshakeUntilALPN()
// we got the list, now we use some algorithm to choose the ALPN
ALPN := myALPNAlgorithm(state.listOfALPNsFromClient)
// after that we tell the client which algo we've chosen
conn.SendALPN(ALPN)
// and we continue the handshake
conn.ContinueHandshake()
...

当然这是愚蠢的伪伪代码,但希望你明白了:)

理想情况下,我想知道对于ServerClient来说,如果可能的话。

答案在加密库中: https://pkg.go.dev/crypto/tls

这些论文可能有用:

https://developpaper.com/the-principle-of-https-and-golang-specifies-the-https-cipher-suite/

https://eli.thegreenplace.net/2021/go-https-servers-with-tls/

您将需要构建自己的服务器和客户端。 TLSlistenandserve 是一种抽象。 你将不得不建立自己的倾听和服务。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM