Documentation
¶
Overview ¶
Package tls provides hardened, opinionated TLS plumbing for Go servers and clients: a curated default crypto/tls.Config (TLS 1.2 floor, AEAD cipher suites, modern curve preferences), the typed Pair enabled/cert/key shape with a pure per-field merge (ResolvePair), the Pair.ServerConfig and ClientConfig builders, and the CertPool helper for trusting private CAs.
The package is framework-free: it works entirely from typed Pair values, so callers own how those values are sourced (flags, environment, a config file). A single certificate can serve multiple transports by resolving a shared Pair against per-transport overrides with ResolvePair.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CertPool ¶
CertPool builds an x509 certificate pool seeded with the given PEM CA/cert files, so clients can trust certificates that are not in the system roots (self-signed or private CA). Pass the same cert files the servers present to share one trust anchor across gRPC, HTTP and the gateway.
func ClientConfig ¶
ClientConfig returns a hardened client TLS config (DefaultConfig) that trusts the given CA/cert files via a custom pool. With no files it returns the default config, which trusts the system roots.
func DefaultConfig ¶
DefaultConfig returns the hardened TLS configuration shared across HTTP and gRPC servers and the HTTP client. It enforces TLS 1.2 minimum with curated AEAD cipher suites and modern curve preferences.
Example ¶
package main
import (
"fmt"
"gitlab.com/phpboyscout/go/tls"
)
func main() {
// DefaultConfig returns the shared hardened TLS configuration used by the
// HTTP, gRPC and gateway transports.
cfg := tls.DefaultConfig()
fmt.Println("Min TLS version:", cfg.MinVersion)
fmt.Println("Cipher suites:", len(cfg.CipherSuites))
}
Output: Min TLS version: 771 Cipher suites: 6
Types ¶
type Pair ¶
type Pair struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Cert string `mapstructure:"cert" yaml:"cert" json:"cert"`
Key string `mapstructure:"key" yaml:"key" json:"key"`
}
Pair is the typed enabled/cert/key triple used to configure TLS for any transport. It carries struct tags so the same shape marshals to and from config consistently wherever it is used.
func ResolvePair ¶
func ResolvePair(shared Pair, transport Pair, overrides PairOverrides) Pair
ResolvePair resolves TLS settings from already-materialised typed values. It starts from the shared pair and overrides individual fields when the transport section explicitly supplied them.
func (Pair) Certificate ¶
func (p Pair) Certificate() (cryptotls.Certificate, error)
Certificate loads the X509 key pair described by the pair.
func (Pair) ServerConfig ¶
ServerConfig returns the hardened DefaultConfig with this pair's certificate loaded. Pass nextProtos to advertise ALPN protocols (e.g. "h2" for a raw gRPC TLS listener); when empty the config's defaults are left as-is.
type PairOverrides ¶
PairOverrides records which fields a transport-specific TLS section set. ResolvePair uses it to merge per-transport config without requiring a config lookup interface.