TLS Config With Minimum Version

Pin a minimum TLS version, supply an explicit root pool, and set handshake timeouts so clients fail closed instead of negotiating weak protocols.

GoSecurity Boundaries

Code

snippet
package main

import (
	"crypto/tls"
	"crypto/x509"
	"fmt"
	"net/http"
	"time"
)

func main() {
	// 信任池显式构造:生产环境应装入已知 CA,而不是留空
	roots := x509.NewCertPool()

	cfg := &tls.Config{
		MinVersion: tls.VersionTLS12, // 拒绝 TLS 1.0/1.1
		RootCAs:    roots,
		ServerName: "api.example.test",
	}

	transport := &http.Transport{
		TLSClientConfig:     cfg,
		TLSHandshakeTimeout: 5 * time.Second,
		ForceAttemptHTTP2:   true,
	}
	client := &http.Client{
		Transport: transport,
		Timeout:   10 * time.Second,
	}

	fmt.Println("minimum version:", tls.VersionName(cfg.MinVersion))
	fmt.Println("server name:", cfg.ServerName)
	fmt.Println("client timeout:", client.Timeout)
	fmt.Println("root pool empty:", roots.Equal(x509.NewCertPool()))
}

How it works

Count the function main as the entire surface area of TLS Config With Minimum Version.

Using it

The demo output is labeled (minimum version:, server name:, client timeout:), so the printed lines read as a trace of the operations that ran.

Key statements

MinVersion: tls.VersionTLS12, // 拒绝 TLS 1.0/1.1

Interactive Tools for This Topic

FAQ

What does TLS Config With Minimum Version print when run?
Running the file directly is enough — expect labeled output lines such as `minimum version:`, `server name:`, `client timeout:`.