tls

package
v1.7.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServerTLSNotConfigured = errors.New("client started a TLS handshake but no TLS certificate is configured")
	ErrPlainTextNotAllowed    = errors.New("client sent plain text but TLS is required")
)

Errors for accepting server connections that may use TLS or plain text.

View Source
var (
	ErrTLSALPNHandshakeFailed = errors.New("alpn handshake failed, retrying with ALPN disabled")
	ErrNoTLSHandshakeFailed   = errors.New("no TLS handshake")
)

Functions

func AsTLSHandshakeError

func AsTLSHandshakeError(err error) error

AsTLSHandshakeError maps specific error strings to their corresponding TLS handshake error constants.

func LoadServerConfig

func LoadServerConfig(logger *zap.Logger, settings ServerSettings) (*tls.Config, error)

LoadServerConfig loads the server certificate. It returns a nil config when no certificate files are configured.

The returned config re-reads the certificate files on each TLS handshake, so a created or renewed certificate, such as a Secret mounted as an optional volume, is used for new connections without a restart. Until the files exist, TLS handshakes fail and plain-text connections are still accepted, unless TLS is required. The certificate is loaded once here, so that an invalid certificate is reported at startup.

func NewTLSWithALPNDisabled

func NewTLSWithALPNDisabled(c *tls.Config, logger *zap.Logger) credentials.TransportCredentials

NewTLSWithALPNDisabled uses c to construct a TransportCredentials based on TLS. ALPN verification is disabled.

func PrepareServerConn

func PrepareServerConn(ctx context.Context, conn net.Conn, opts ServerConnOptions) (net.Conn, error)

PrepareServerConn peeks at the first byte of a newly accepted connection and returns a connection that yields the plain-text stream: the TLS connection after a successful handshake if the client started one, or the plain connection otherwise.

Types

type AuthProperties

type AuthProperties struct {
	DisableALPN bool
	DisableTLS  bool
}

type ServerConnOptions

type ServerConnOptions struct {
	// Config is the server TLS configuration, or nil to accept plain text only.
	Config *tls.Config
	// Required rejects plain-text connections.
	Required bool
	// FirstByteTimeout bounds how long a new connection may stay silent.
	FirstByteTimeout time.Duration
	// HandshakeTimeout bounds the TLS handshake.
	HandshakeTimeout time.Duration
}

ServerConnOptions configures PrepareServerConn.

type ServerSettings

type ServerSettings struct {
	CertFile string
	KeyFile  string
	Required bool
}

ServerSettings configures TLS for a server that may accept both TLS and plain-text connections on the same port. With a certificate configured, each connection may use TLS or plain text unless Required is set; without one, only plain text is accepted.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL