clarify peek() code

This commit is contained in:
nervuri 2022-06-12 00:00:00 +00:00
parent 3e8d967595
commit a37d9a5198
1 changed files with 8 additions and 5 deletions

View File

@ -129,21 +129,24 @@ _____________________
=> https://tildegit.org/nervuri/client-hello-mirror Source (contributions welcome)
=> https://www.gnu.org/licenses/agpl-3.0.en.html License: AGPL-3.0-or-later`
// Copy the Client Hello message before starting the TLS handshake.
func peek(conn net.Conn, tlsConfig *tls.Config) {
// Copy the Client Hello before starting the TLS handshake.
defer conn.Close()
var buf bytes.Buffer
_, err := io.CopyN(&buf, conn, 5) // TLS record header
// Copy TLS record header.
_, err := io.CopyN(&buf, conn, 5)
if err != nil {
log.Println(err)
return
}
// Check if this is a TLS handshake record.
if buf.Bytes()[0] != 0x16 {
// Not a Client Hello message.
return
}
length := binary.BigEndian.Uint16(buf.Bytes()[3:5])
_, err = io.CopyN(&buf, conn, int64(length))
// Extract handshake message length.
handshakeMessageLength := binary.BigEndian.Uint16(buf.Bytes()[3:5])
// Copy handshake message (should be a Client Hello).
_, err = io.CopyN(&buf, conn, int64(handshakeMessageLength))
if err != nil {
log.Println(err)
return