From ba70d1d9485b03b55186f727f13dff114fe439a2 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sun, 25 Aug 2024 12:16:20 -0400 Subject: [PATCH] crypto/tls: expose extensions presented by client to GetCertificate This enables JA3 and JA4 TLS fingerprinting to be implemented from the GetCertificate callback, similar to what BoringSSL provides with its SSL_CTX_set_dos_protection_cb hook. fixes #32936 Change-Id: Idb54ebcb43075582fcef0ac6438727f494543424 Reviewed-on: https://go-review.googlesource.com/c/go/+/471396 Reviewed-by: Dmitri Shuralyov Reviewed-by: Roland Shoemaker LUCI-TryBot-Result: Go LUCI --- common.go | 4 ++++ handshake_messages.go | 3 +++ handshake_server.go | 1 + 3 files changed, 8 insertions(+) diff --git a/common.go b/common.go index f628ba3..895ee85 100644 --- a/common.go +++ b/common.go @@ -446,6 +446,10 @@ type ClientHelloInfo struct { // might be rejected if used. SupportedVersions []uint16 + // Extensions lists the IDs of the extensions presented by the client + // in the client hello. + Extensions []uint16 + // Conn is the underlying net.Conn for the connection. Do not read // from, or write to, this connection; that will cause the TLS // connection to fail. diff --git a/handshake_messages.go b/handshake_messages.go index f5b0897..7ae20ea 100644 --- a/handshake_messages.go +++ b/handshake_messages.go @@ -97,6 +97,8 @@ type clientHelloMsg struct { pskBinders [][]byte quicTransportParameters []byte encryptedClientHello []byte + // extensions are only populated on the server-side of a handshake + extensions []uint16 } func (m *clientHelloMsg) marshalMsg(echInner bool) ([]byte, error) { @@ -467,6 +469,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool { return false } seenExts[extension] = true + m.extensions = append(m.extensions, extension) switch extension { case extensionServerName: diff --git a/handshake_server.go b/handshake_server.go index 46bd06d..dbc0551 100644 --- a/handshake_server.go +++ b/handshake_server.go @@ -949,6 +949,7 @@ func clientHelloInfo(ctx context.Context, c *Conn, clientHello *clientHelloMsg) SignatureSchemes: clientHello.supportedSignatureAlgorithms, SupportedProtos: clientHello.alpnProtocols, SupportedVersions: supportedVersions, + Extensions: clientHello.extensions, Conn: c.conn, config: c.config, ctx: ctx,