mtls

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const H2TLSProto = "h2"

Variables

View Source
var (
	// DefaultCurve represent the supported TLS curves.
	DefaultCurve = []tls.CurveID{tls.CurveP256, tls.X25519}

	// DefaultCipher represent the accepted ciphers.
	DefaultCipher = []uint16{
		tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
		tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
		tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
		tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
		tls.TLS_AES_128_GCM_SHA256,
		tls.TLS_AES_256_GCM_SHA384,
		tls.TLS_CHACHA20_POLY1305_SHA256,

		tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
	}

	// ErrParseUserCA error is returned in case of invalid ca cert path.
	ErrParseUserCA = errors.New("failed to parse root certificate")
)

Functions

func GetTLSCfg

func GetTLSCfg(cfg Config, http2 ...bool) (*tls.Config, error)

GetTLSCfg return a tls config ready for mTLS. Optional support for http can be specified via the http2 variadic argument. Enabling http2 add 'h2' to the NextProto list. thx to https://dev.to/living_syn/validating-client-certificate-sans-in-go-i5p see example/http2/main.go for more.

func LoadListner

func LoadListner(addr string, cfg *tls.Config) (net.Listener, error)

LoadTLSListener return a tls listner ready for mTLS and/or http2.

Types

type Config

type Config struct {
	Cert     string `json:"cert"     mapstructure:"cert"`
	Key      string `json:"key"      mapstructure:"key"`
	Ca       string `json:"ca"       mapstructure:"ca"`
	Level    Level  `json:"level"    mapstructure:"level"`
	Insecure bool   `json:"insecure"    mapstructure:"insecure"`
}

Config contain the tls config passed by the config file.

func (Config) AsAttrs

func (cfg Config) AsAttrs() []any

func (Config) Empty

func (cfg Config) Empty() bool

Empty implemte Config.

func (Config) SameAs

func (cfg Config) SameAs(in Config) bool

type Level

type Level tls.ClientAuthType
const (

	// NoClientCert indicates that no client certificate should be requested
	// during the handshake, and if any certificates are sent they will not
	// be verified.
	NoClientCert Level = iota
	// RequestClientCert indicates that a client certificate should be requested
	// during the handshake, but does not require that the client send any
	// certificates.
	RequestClientCert
	// RequireAnyClientCert indicates that a client certificate should be requested
	// during the handshake, and that at least one certificate is required to be
	// sent by the client, but that certificate is not required to be valid.
	RequireAnyClientCert
	// VerifyClientCertIfGiven indicates that a client certificate should be requested
	// during the handshake, but does not require that the client sends a
	// certificate. If the client does send a certificate it is required to be
	// valid.
	VerifyClientCertIfGiven
	// RequireAndVerifyClientCert indicates that a client certificate should be requested
	// during the handshake, and that at least one valid certificate is required
	// to be sent by the client.
	RequireAndVerifyClientCert
	// RequireAndVerifyClientCertAndSAN is the same as RequireAndVerifyClientCert
	// with an extra check to the certificate SAN.
	RequireAndVerifyClientCertAndSAN
)

func (Level) MarshalJSON

func (lv Level) MarshalJSON() ([]byte, error)

func (Level) STD

func (lv Level) STD() tls.ClientAuthType

func (*Level) Set

func (lv *Level) Set(val string) error

func (Level) String

func (lv Level) String() string

func (*Level) UnmarshalJSON

func (lv *Level) UnmarshalJSON(b []byte) error

type LevelError

type LevelError struct {
	// contains filtered or unexported fields
}

func (LevelError) Error

func (e LevelError) Error() string

Directories

Path Synopsis
Package webfmwk/v6/tls/cmd hold function destined to be used for command line implementation.
Package webfmwk/v6/tls/cmd hold function destined to be used for command line implementation.

Jump to

Keyboard shortcuts

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