Documentation
¶
Index ¶
- Variables
- func AsTLSHandshakeError(err error) error
- func LoadServerConfig(logger *zap.Logger, settings ServerSettings) (*tls.Config, error)
- func NewTLSWithALPNDisabled(c *tls.Config, logger *zap.Logger) credentials.TransportCredentials
- func PrepareServerConn(ctx context.Context, conn net.Conn, opts ServerConnOptions) (net.Conn, error)
- type AuthProperties
- type ServerConnOptions
- type ServerSettings
Constants ¶
This section is empty.
Variables ¶
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.
var ( ErrTLSALPNHandshakeFailed = errors.New("alpn handshake failed, retrying with ALPN disabled") ErrNoTLSHandshakeFailed = errors.New("no TLS handshake") )
Functions ¶
func AsTLSHandshakeError ¶
AsTLSHandshakeError maps specific error strings to their corresponding TLS handshake error constants.
func LoadServerConfig ¶
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 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 ¶
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.