Documentation
¶
Index ¶
- func Error(format string, v ...interface{})
- func Fatal(format string, v ...interface{}) error
- func InitLogger(level LogLevel)
- func InitLoggerOutput(level LogLevel, output io.Writer)
- func InitLoggerOutputWithFormat(level LogLevel, format string, output io.Writer)
- func InitLoggerWithFormat(level LogLevel, format string)
- func Log(format string, v ...interface{})
- func ResetErrorHandler()
- func SetErrorHandler(handler ErrorHandler)
- func Verbose(format string, v ...interface{})
- type CredentialVerifier
- type DefaultErrorHandler
- type ErrorHandler
- type LogLevel
- type TestErrorHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(format string, v ...interface{})
Error prints an error message (always shown).
func Fatal ¶
Fatal logs a fatal error via the error handler (returns error in tests, exits in production).
func InitLogger ¶
func InitLogger(level LogLevel)
InitLogger initializes the global logger. Holds the lock for the whole call so it does not race with Log/Verbose/Error: logger.New() writes zerolog globals, and Msg() reads them.
func InitLoggerOutput ¶
InitLoggerOutput initializes the global console logger on a selected stream. Stdio protocols use stderr so logs cannot corrupt protocol messages.
func InitLoggerOutputWithFormat ¶
InitLoggerOutputWithFormat initializes the global logger in console or JSON form on a selected stream.
func InitLoggerWithFormat ¶
InitLoggerWithFormat initializes the global logger in console or JSON form.
func Log ¶
func Log(format string, v ...interface{})
Log prints a log message at info level (normal and verbose).
func ResetErrorHandler ¶
func ResetErrorHandler()
ResetErrorHandler resets to the default error handler
func SetErrorHandler ¶
func SetErrorHandler(handler ErrorHandler)
SetErrorHandler sets the error handler (used for testing)
Types ¶
type CredentialVerifier ¶ added in v0.10.0
type CredentialVerifier struct {
// contains filtered or unexported fields
}
CredentialVerifier compares a presented credential against a configured one in time that does not depend on the configured value. Go's own string comparison is not safe for a secret: it returns as soon as two bytes differ, so the time a rejection takes grows with the length of the shared prefix, and an attacker who can measure it recovers the secret one byte at a time instead of guessing it whole.
Three separate leaks have to be closed, and closing only the obvious one leaves a working oracle:
- The prefix leak. subtle.ConstantTimeCompare reads both operands to the end regardless of where they differ.
- The length leak. subtle.ConstantTimeCompare does not close this one: it returns immediately when the lengths differ, so a wrong-length guess is still measurably faster and the secret's length stays readable. Hashing to a fixed-size tag first removes it, because every candidate -- one byte or one megabyte -- is compared as the same 32 bytes.
- The short-circuit leak. Rejecting on the username before looking at the password lets the two secrets be attacked one after the other rather than jointly. Both tags are therefore always computed and always compared, and the two results are combined with a bitwise & rather than &&.
The tag is keyed with a random value drawn once at startup, so an attacker cannot precompute the tag of a guess and mount the same search against the tags themselves. The expected tags are computed once at construction, so per-request work does not depend on the configured username or password length either.
func NewCredentialVerifier ¶ added in v0.10.0
func NewCredentialVerifier(username, password string) (*CredentialVerifier, error)
NewCredentialVerifier binds a verifier to the configured credential pair.
func (*CredentialVerifier) CredentialsEqual ¶ added in v0.10.0
func (v *CredentialVerifier) CredentialsEqual(username, password string) bool
CredentialsEqual reports whether both presented values match the configured pair. It does the same work for every input.
func (*CredentialVerifier) StringsEqual ¶ added in v0.10.0
func (v *CredentialVerifier) StringsEqual(value, expected string) bool
StringsEqual compares two values that are not the configured credentials -- an SMTP authorization identity, say -- under the same tag construction, so a differing length is not distinguishable from a differing first byte.
type DefaultErrorHandler ¶
type DefaultErrorHandler struct{}
DefaultErrorHandler is the default error handler for production environments
func (*DefaultErrorHandler) Fatal ¶
func (h *DefaultErrorHandler) Fatal(format string, v ...interface{}) error
type ErrorHandler ¶
ErrorHandler defines the error handling interface
func GetErrorHandler ¶
func GetErrorHandler() ErrorHandler
GetErrorHandler returns the global error handler
type LogLevel ¶
type LogLevel int
LogLevel represents the logging level (owlmail legacy: silent / normal / verbose).
type TestErrorHandler ¶
type TestErrorHandler struct {
LastError error
}
TestErrorHandler is a test error handler for testing environments
func (*TestErrorHandler) Fatal ¶
func (h *TestErrorHandler) Fatal(format string, v ...interface{}) error