tls

package
v5.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 10 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(icfg IConfig, 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 added in v5.3.0

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"`
	Insecure bool   `json:"insecure" mapstructure:"insecure"`
	Level    Level  `json:"level"    mapstructure:"level"`
}

Config contain the tls config passed by the config file. It implement Config

func (Config) Empty

func (cfg Config) Empty() bool

Empty implemte Config.

func (Config) GetCa

func (cfg Config) GetCa() string

GetKey implemte Config.

func (Config) GetCert

func (cfg Config) GetCert() string

GetCert implemte Config.

func (Config) GetInsecure

func (cfg Config) GetInsecure() bool

GetInsecure implemte Config.

func (Config) GetKey

func (cfg Config) GetKey() string

GetKey implemte Config.

func (Config) GetLevel

func (cfg Config) GetLevel() Level

func (Config) SameAs added in v5.2.3

func (cfg Config) SameAs(in IConfig) bool

func (Config) String

func (cfg Config) String() string

String implement Stringer interface.

type IConfig

type IConfig interface {
	fmt.Stringer

	// GetCert return the full path to the server certificate file.
	GetCert() string

	// GetKey return the full path to the server key file.
	GetKey() string

	// GetCa return the full path to the server ca cert file.
	GetCa() string

	// GetInsecure return true if the TLS Certificate shouldn't be checked.
	GetInsecure() bool

	// GetLevel return
	GetLevel() Level

	// IsEmpty return true if the config is empty.
	Empty() bool

	// SameAs return true if both config are identique.
	SameAs(in IConfig) bool
}

IConfig is used to interface the TLS implemtation.

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 added in v5.3.0

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

func (LevelError) Error added in v5.3.0

func (e LevelError) Error() string

Directories

Path Synopsis
Package webfmwk/v5/tls/cmd hold function destined to be used for command line implementation.
Package webfmwk/v5/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