Skip to content

crypto/tls: ConnectionState isn't properly initialized until read or write from *tls.Conn #79828

Description

@flrdv

Go version

go1.26.3-X:nodwarf5 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/pavlo/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/pavlo/.config/go/env'
GOEXE=''
GOEXPERIMENT='nodwarf5'
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build805846040=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/pavlo/go/indigo/go.mod'
GOMODCACHE='/home/pavlo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/pavlo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/golang'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/pavlo/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib/golang/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26.3-X:nodwarf5'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

I tried calling *tls.Conn.ConnectionState() immediately after accepting a connection (using standard tls.NewListener(...))

I tested my assumption with the following server-example: https://go.dev/play/p/p_lxvj1RcTv
I used curl to connect. In fact, I only needed anything that can TLS.

What did you see happen?

ConnectionState is zeroed (except for NegotiatedProtocolIsMutual and ekm fields). Also enabling ALPN results in empty NegotiatedProtocol. The connection state is properly initialized only after the first read or write. Read([]byte(nil)) makes the job as a workaround.

What did you expect to see?

Completely initialized and not zeroed ConnectionState immediately after Accept() on tls.NewListener().

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions