Skip to content

crypto/tls: don't close tcp-session if TLS-handshake fails #46735

Description

@eglinux

What version of Go are you using (go version)?

$ go version
go version go1.16.5 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/src/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/src/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1581134579=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Use crypto/tls package
https://github.com/golang/go/blob/master/src/crypto/tls/tls.go#L157-L159

What did you expect to see?

Not nil if tls-handshake fails.

I use blackbox_exporter (https://github.com/prometheus/blackbox_exporter) for the ssl-certificates monitoring. Due to the current implementation it is not possible to check hosts with having 2 way SSL enabled. Because tls-handshake always fails for those and conn structure is nil - the calling code cannot properly intercept this case.

The one way to fix it I can see is to add extra optional boolean parameter to the function which will let Rawconn structure to be returned to the caller and don't close tcp-connection in this case.

It should be possible to split TLS and TCP layers as their states should be independent from each other. In this case caller might be aware about TLS-layer errors (via err: ), but still be able to use TCP-connection on its own. In this case for instance the client will be able to grab ssl-certificate of the server even if tls-handshake fails.

What did you see instead?

Function returns nil and closes tcp-connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions