Documentation
¶
Index ¶
- Variables
- func ConfigureClientTLS(provider ClientTLSProvider) (*tls.Config, Error)
- func ConfigureServerTLS(provider ServerTLSProvider, customizers ...ServerTLSCustomizer) (*tls.Config, Error)
- type ACMECertificateProvider
- type ClientCertificateProvider
- type ClientTLSProvider
- type MutualTLSCustomizer
- type MutualTLSWithCRLCustomizer
- type MutualTLSWithOCSPCustomizer
- type ServerCertificateProvider
- type ServerTLSCustomizer
- type ServerTLSProvider
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnsupportedTLSVersion is returned when a TLS version other than TLS 1.2 or TLS 1.3 is specified. ErrUnsupportedTLSVersion Error = NewError("tls", "unsupported TLS version, please use tls.VersionTLS12 or tls.VersionTLS13") // ErrAppendRootCertificates is returned when root certificates cannot be appended to the certificate pool. ErrAppendRootCertificates Error = NewError("clienttls", "failed to append root certificates") // ErrUnableToLoadRootCert is returned when a root certificate cannot be parsed or loaded. ErrUnableToLoadRootCert Error = NewError("clienttls", "unable to load root certificate") // ErrCertificateRevoked is returned during peer verification when a certificate is identified as revoked. ErrCertificateRevoked Error = NewError("tls", "the certificate was revoked") // ErrCertificateUnknownOCSP is returned when the OCSP responder does not recognize the certificate. ErrCertificateUnknownOCSP Error = NewError("tls", "the certificate is unknown to OCSP server") // ErrTLSProviderRequiredHTTPS is returned when querying an HTTPS OCSP server without a configured TLSProvider. ErrTLSProviderRequiredHTTPS Error = NewError("mtls", "TLSProvider is required for https OCSP server") // ErrMissingPeerCertificate is returned when a TLS connection has no peer certificates. ErrMissingPeerCertificate Error = NewError("tls", "missing peer certificate") // ErrCRLExpired is returned when a CRL's NextUpdate date is in the past. ErrCRLExpired Error = NewError("tls", "CRL has expired") // ErrNoCertificatePEMBlock is returned when no PEM CERTIFICATE block is found in the certificate string or file. ErrNoCertificatePEMBlock Error = NewError("tls", "no PEM certificate block found in configured certificate") // ErrCertificateNotCA is returned when the configured certificate is not a CA certificate. ErrCertificateNotCA Error = NewError("tls", "certificate is not a CA certificate") // ErrIncompleteCertKeyFile is returned when exactly one of CertFile and CertKeyFile is configured. ErrIncompleteCertKeyFile Error = NewError("tls", "both CertFile and CertKeyFile must be provided") // ErrNoUsableCRL is returned when CRL discovery cannot find or fetch any usable CRL. ErrNoUsableCRL Error = NewError("tls", "no usable CRL found") // ErrDelegatedOCSPMissingSigning is returned when a delegated OCSP responder lacks the OCSPSigning extended key usage. ErrDelegatedOCSPMissingSigning Error = NewError("tls", "delegated OCSP responder certificate is missing OCSPSigning extended key usage") // ErrOCSPResponseTooOld is returned when an OCSP response's ThisUpdate exceeds the maximum allowed age. ErrOCSPResponseTooOld Error = NewError("tls", "OCSP response is too old") // ErrOCSPResponseExpired is returned when an OCSP response has expired past its NextUpdate date. ErrOCSPResponseExpired Error = NewError("tls", "OCSP response has expired") // ErrDelegatedOCSPInvalidValidity is returned when the current time is outside a delegated OCSP responder's validity period. ErrDelegatedOCSPInvalidValidity Error = NewError("tls", "delegated OCSP responder certificate is not valid at the current time") // ErrOCSPThisUpdateInFuture is returned when an OCSP response's ThisUpdate is in the future. ErrOCSPThisUpdateInFuture Error = NewError("tls", "OCSP response ThisUpdate is in the future") )
Functions ¶
func ConfigureClientTLS ¶
func ConfigureClientTLS(provider ClientTLSProvider) (*tls.Config, Error)
ConfigureClientTLS creates a *tls.Config from a ClientTLSProvider.
func ConfigureServerTLS ¶
func ConfigureServerTLS(provider ServerTLSProvider, customizers ...ServerTLSCustomizer) (*tls.Config, Error)
ConfigureServerTLS creates a *tls.Config from a ServerTLSProvider and applies any ServerTLSCustomizer.
Types ¶
type ACMECertificateProvider ¶
type ACMECertificateProvider struct {
// AutoCertManager manages TLS certificates automatically using the ACME protocol,
// Enables integration with Let's Encrypt or other ACME-compatible providers.
//
// Default: nil
AutoCertManager *autocert.Manager `json:"auto_cert_manager"`
// TLSMinVersion allows to set TLS minimum version.
//
// Default: tls.VersionTLS12
// WARNING: TLS1.0 and TLS1.1 versions are not supported.
TLSMinVersion uint16 `json:"tls_min_version"`
}
ACMECertificateProvider is a struct implementing the ServerTLSProvider interface.
func (*ACMECertificateProvider) ProvideServerTLS ¶
func (p *ACMECertificateProvider) ProvideServerTLS() (*tls.Config, Error)
ProvideServerTLS implements ServerTLSProvider.
type ClientCertificateProvider ¶
type ClientCertificateProvider struct {
// Certificate is either a path to a file or the content of the file instead.
//
// It must contain, in order, in PEM format the certificate, key and any additional
// intermediate CA certificate signing this certificate.
//
// Default: ""
Certificate string `json:"certificate"`
// RootCertificates is either a path to a file or the content of the file instead.
//
// It must contain in PEM format a list of CA certificates to add to the certificate pool,
// permitting to authenticate a remote server.
//
// Default: ""
RootCertificates string `json:"root_certificates"`
// IncludeSystemCertificates allows to inherit CA certificates from the system.
//
// Default: false
IncludeSystemCertificates bool `json:"include_system_certificates"`
// TLSMinVersion allows to set TLS minimum version.
//
// Default: tls.VersionTLS12
TLSMinVersion uint16 `json:"tls_min_version"`
}
ClientCertificateProvider is a struct implementing ClientTLSProvider.
func (*ClientCertificateProvider) ProvideClientTLS ¶
func (p *ClientCertificateProvider) ProvideClientTLS() (*tls.Config, Error)
ProvideClientTLS implements ClientTLSProvider.
type ClientTLSProvider ¶
type ClientTLSProvider interface {
// ProvideClientTLS provides possibly a *tls.Config object to be used by a client or
// an error if it fails to do so.
//
// NOTE: Implementations may return (nil, nil) if no tls.Config can be provided and no error occurred.
// For example when no path to a certificate is provided (empty string), instead of a wrong
// path which will generate an error.
ProvideClientTLS() (*tls.Config, Error)
}
ClientTLSProvider provides an interface for creating a *tls.Config to be used by a client.
type MutualTLSCustomizer ¶
type MutualTLSCustomizer struct {
// Certificate is either a path to a file or the content of the file instead.
// It must be a PEM encoded CA certificate.
//
// Default: ""
Certificate string `json:"certificate"`
}
MutualTLSCustomizer is a struct implementing ServerTLSCustomizer.
func (*MutualTLSCustomizer) ClientCertificate ¶
func (c *MutualTLSCustomizer) ClientCertificate() (*x509.Certificate, Error)
ClientCertificate provides a way to retrieve the configured Client CA certificate.
func (*MutualTLSCustomizer) CustomizeServerTLS ¶
func (c *MutualTLSCustomizer) CustomizeServerTLS(cfg *tls.Config) Error
CustomizeServerTLS implements ServerTLSCustomizer.
It parses the Certificate, either a file path or its content, a PEM encoded CA certificate. It will add the certificate to config.ClientCAs and set config.ClientAuth to tls.RequireAndVerifyClientCert.
type MutualTLSWithCRLCustomizer ¶
type MutualTLSWithCRLCustomizer struct {
// TLSProvider is an optional ClientTLSProvider to configure the HTTP client that will fetch a CRL.
//
// Default: nil
TLSProvider ClientTLSProvider `json:"tls_provider"`
// Client is an optional resty.Client to use for fetching the CRL.
// If nil, a new resty client will be created.
Client *resty.Client `json:"-"`
// Certificate is either a path to a file or the content of the file instead.
// It must be a PEM encoded CA certificate.
//
// Default: ""
Certificate string `json:"certificate"`
// RevocationList is either a URL to, a path to or a CRL directly.
//
// Default: ""
RevocationList string `json:"revocation_list"`
// Timeout specifies the HTTP request timeout when fetching a CRL.
// Default: 10 * time.Second
Timeout time.Duration `json:"timeout"`
}
MutualTLSWithCRLCustomizer is a struct implementing ServerTLSCustomizer.
It provides MutualTLS configuration with Certificate Revocation List check to a tls.Config object.
CRL can be provided via a URL, a file path or directly. If none is provided, the CRL can be fetched from the URL defined in the CRL Distribution Endpoints. See: https://docs.openssl.org/3.5/man5/x509v3_config/#crl-distribution-points
NOTE: Only CRL version 2 in PEM format is supported. See: https://docs.openssl.org/3.5/man1/openssl-ca/#crl-options
func (*MutualTLSWithCRLCustomizer) CustomizeServerTLS ¶
func (m *MutualTLSWithCRLCustomizer) CustomizeServerTLS(config *tls.Config) Error
CustomizeServerTLS implements ServerTLSCustomizer.
type MutualTLSWithOCSPCustomizer ¶
type MutualTLSWithOCSPCustomizer struct {
TLSProvider ClientTLSProvider `json:"tls_provider"`
Client *resty.Client `json:"-"`
Certificate string `json:"certificate"`
OCSPServer string `json:"ocsp_server"`
Timeout time.Duration `json:"timeout"`
MaxResponseAge time.Duration `json:"max_response_age"`
// contains filtered or unexported fields
}
MutualTLSWithOCSPCustomizer is a struct implementing ServerTLSCustomizer.
func (*MutualTLSWithOCSPCustomizer) CustomizeServerTLS ¶
func (m *MutualTLSWithOCSPCustomizer) CustomizeServerTLS(config *tls.Config) Error
CustomizeServerTLS implements ServerTLSCustomizer.
type ServerCertificateProvider ¶
type ServerCertificateProvider struct {
// Certificate is either a path to a file or the content of the file instead.
//
// It must contain, in order, in PEM format the certificate, key and any additional
// intermediate CA certificate signing this certificate.
//
// Default: ""
Certificate string `json:"certificate"`
// CertFile is a path of certificate file.
// If you want to use TLS, you should enter this field or use "Certificate".
//
// Default: ""
//
// Deprecated: Use Certificate instead.
CertFile string `json:"cert_file"`
// KeyFile is a path of certificate's private key.
// If you want to use TLS, you should enter this field or use "Certificate".
//
// Default: ""
//
// Deprecated: Use Certificate instead.
CertKeyFile string `json:"cert_key_file"`
// TLSMinVersion allows to set TLS minimum version.
//
// Default: tls.VersionTLS12
// WARNING: TLS1.0 and TLS1.1 versions are not supported.
TLSMinVersion uint16 `json:"tls_min_version"`
}
ServerCertificateProvider is a struct implementing ServerTLSProvider.
func (*ServerCertificateProvider) ProvideServerTLS ¶
func (p *ServerCertificateProvider) ProvideServerTLS() (*tls.Config, Error)
ProvideServerTLS implements ServerTLSProvider.
type ServerTLSCustomizer ¶
ServerTLSCustomizer provides an interface for customizing an existing *tls.Config object configured for a server.
type ServerTLSProvider ¶
type ServerTLSProvider interface {
// ProvideServerTLS provides possibly a *tls.Config object to be used by a server or
// an error if it fails to do so.
//
// NOTE: Implementations may return (nil, nil) if no tls.Config can be provided and no error occurred.
// For example when no path to a certificate is provided (empty string), instead of a wrong
// path which will generate an error.
ProvideServerTLS() (*tls.Config, Error)
}
ServerTLSProvider provides an interface for creating a *tls.Config to be used by a server.