Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto/tls: VerifyConnection is called twice by tls 1.3 servers if connection is resumed #39012

rolandshoemaker opened this issue May 12, 2020 · 4 comments


Copy link

@rolandshoemaker rolandshoemaker commented May 12, 2020

When using session resumption on a TLS 1.3 server with VerifyConnection set it will be called twice when a session is resumed. This looks like it's happening because it gets called once in checkForResumption, which calls processCertsFromClient, and then again when readClientCertificate calls VerifyConnection if ClientAuth is set to ignore client certs (also because PSK resumption). This appears to work as expected in 1.2.

It seems like perhaps VerifyConnection should be decoupled from processCertsFromClient and handled somewhere else in handshake? (I don't have any concrete suggestion of where would be better though.)

Minimal(ish) repro:

package main

import (

func main() {
	tlsVer := uint16(tls.VersionTLS13)
	clientConf := &tls.Config{
		ClientSessionCache: tls.NewLRUClientSessionCache(5),
		MinVersion:         tlsVer,
		MaxVersion:         tlsVer,
		InsecureSkipVerify: true,
	tr := &http.Transport{
		TLSClientConfig: clientConf,
	hc := &http.Client{Transport: tr}

	k, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
	if err != nil {
	tmpl := &x509.Certificate{
		SerialNumber: big.NewInt(1),
		Subject:      pkix.Name{CommonName: "localhost"},
		DNSNames:     []string{"localhost"},
	c, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, k.Public(), k)
	if err != nil {

	serverConf := &tls.Config{
		MinVersion: tlsVer,
		MaxVersion: tlsVer,
		VerifyConnection: func(_ tls.ConnectionState) error {
			fmt.Println("server verify connection")
			return nil
		Certificates: []tls.Certificate{
				Certificate: [][]byte{c},
				PrivateKey:  k,

	l, err := net.Listen("tcp", "localhost:8181")
	if err != nil {
	tl := tls.NewListener(l, serverConf)
	s := http.Server{Handler: http.NotFoundHandler()}

	go func() {


	resp, err := hc.Get("https://localhost:8181")
	if err != nil {
	fmt.Println("resumed?", resp.TLS.DidResume)

cc @FiloSottile @katiehockman

Copy link

@katiehockman katiehockman commented May 12, 2020

Thanks for filing this @rolandshoemaker. Will take a look this week.

@katiehockman katiehockman self-assigned this May 12, 2020
@katiehockman katiehockman added this to the Go1.15 milestone May 12, 2020
Copy link

@gopherbot gopherbot commented May 13, 2020

Change mentions this issue: crypto/tls: fix duplicate calls to VerifyConnection

Copy link

@networkimprov networkimprov commented May 13, 2020

Backport candidate?

Copy link

@katiehockman katiehockman commented May 14, 2020

VerifyConnection was a new feature for 1.15, so this will just be merged to master and included in that release. No backport needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.