Documentation
¶
Index ¶
- Constants
- Variables
- func AddCertificate(certificate string) error
- func CalculateFingerprint(certDER []byte) string
- func ClientAuthTypeToString(t ClientAuthType) string
- func GetCertPool() *x509.CertPool
- func GetTLSConfig(opt Option) (tlsConfig *tls.Config, err error)
- func LoadCertificates(certificate string) (*x509.CertPool, error)
- func NewFingerprintVerifier(fingerprint string, time func() time.Time) (func(certs []*x509.Certificate, serverName string) error, error)
- func NewNameCertVerifier(dnsName string, roots *x509.CertPool, now func() time.Time) func([]*x509.Certificate) error
- func NewRandomTLSKeyPair(keyPairType KeyPairType) (certificate string, privateKey string, fingerprint string, err error)
- func NewTLSKeyPairLoader(certificate, privateKey string) (func() (*tls.Certificate, error), error)
- func ResetCertificate()
- func SetStore(store Store)
- type ClientAuthType
- type KeyPairType
- type Option
- type Store
Constants ¶
const ( NoClientCert = tls.NoClientCert RequestClientCert = tls.RequestClientCert RequireAnyClientCert = tls.RequireAnyClientCert VerifyClientCertIfGiven = tls.VerifyClientCertIfGiven RequireAndVerifyClientCert = tls.RequireAndVerifyClientCert )
Variables ¶
var DisableEmbedCa, _ = strconv.ParseBool(os.Getenv("DISABLE_EMBED_CA"))
var DisableSystemCa, _ = strconv.ParseBool(os.Getenv("DISABLE_SYSTEM_CA"))
Functions ¶
func AddCertificate ¶
func CalculateFingerprint ¶
CalculateFingerprint computes the SHA-256 fingerprint of the given DER-encoded certificate and returns it as a hex string.
func ClientAuthTypeToString ¶
func ClientAuthTypeToString(t ClientAuthType) string
func GetCertPool ¶
func NewFingerprintVerifier ¶
func NewFingerprintVerifier(fingerprint string, time func() time.Time) (func(certs []*x509.Certificate, serverName string) error, error)
NewFingerprintVerifier returns a function that verifies whether a certificate's SHA-256 fingerprint matches the given one.
func NewNameCertVerifier ¶
func NewNameCertVerifier(dnsName string, roots *x509.CertPool, now func() time.Time) func([]*x509.Certificate) error
NewNameCertVerifier returns a verifier for a certificate chain and an explicit DNSName.
func NewRandomTLSKeyPair ¶
func NewRandomTLSKeyPair(keyPairType KeyPairType) (certificate string, privateKey string, fingerprint string, err error)
NewRandomTLSKeyPair generates a random TLS key pair based on the specified KeyPairType and returns it with a SHA256 fingerprint. Note: Most browsers do not support KeyPairTypeEd25519 type of certificate, and utls.UConn will also reject this type of certificate.
func NewTLSKeyPairLoader ¶
func NewTLSKeyPairLoader(certificate, privateKey string) (func() (*tls.Certificate, error), error)
NewTLSKeyPairLoader creates a loader function for TLS key pairs from the provided certificate and private key data or file paths. If both certificate and privateKey are empty, generates a random TLS RSA key pair.
func ResetCertificate ¶
func ResetCertificate()
Types ¶
type ClientAuthType ¶
type ClientAuthType = tls.ClientAuthType
func ClientAuthTypeFromString ¶
func ClientAuthTypeFromString(s string) ClientAuthType
type KeyPairType ¶
type KeyPairType string
const ( KeyPairTypeRSA KeyPairType = "rsa" KeyPairTypeP256 KeyPairType = "p256" KeyPairTypeP384 KeyPairType = "p384" KeyPairTypeEd25519 KeyPairType = "ed25519" )