我想攔截ALPN選擇并選擇我想要的,而不是客戶端和服務器之間的第一個常見的。
代碼:
// 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()
...
當然這是愚蠢的偽偽代碼,但希望你明白:)
理想情況下,如果可能的話,我想知道對于Server和。Client
uj5u.com熱心網友回復:
答案在加密庫中: 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 是一種抽象。你將不得不建立自己的聆聽和服務。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/438844.html
上一篇:io/ioutil的問題
