Documentation ¶
Index ¶
- Constants
- Variables
- func CheckUntil(interval time.Duration, timeout time.Duration, predicate func() (bool, error)) error
- func Command(name string, args ...string) *exec.Cmd
- func CommandWithStdout(name string, args ...string) *exec.Cmd
- func ConvertDERToPEM(der []byte, blockType PEMBlockType) ([]byte, error)
- func Decrypt(ciphertext []byte, key *[32]byte) (plaintext []byte, err error)
- func DirectoryExists(path string) (exists bool, err error)
- func Encrypt(plaintext []byte, key *[32]byte) (ciphertext []byte, err error)
- func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string
- func ExportRsaPublicKeyAsPemStr(pubkey *rsa.PublicKey) (string, error)
- func FileExists(path string) (exists bool, err error)
- func GenerateCertificate(privateKeyBuilder PrivateKeyBuilder, hosts []string, validFrom time.Time, ...) ([]byte, []byte, error)
- func GenerateRsaKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey)
- func GetExpectedErrTxt(err string) string
- func HashSHA256FromPath(path string) (output string, err error)
- func HashSHA256FromString(input string) (output string)
- func IsBoolCountLessThanN(n int, v bool, vals ...bool) bool
- func IsRedirectionSafe(url url.URL, protectedDomain string) bool
- func IsRedirectionURISafe(uri, protectedDomain string) (bool, error)
- func IsStringAbsURL(input string) (err error)
- func IsStringAlphaNumeric(input string) bool
- func IsStringInSlice(needle string, haystack []string) (inSlice bool)
- func IsStringInSliceContains(needle string, haystack []string) (inSlice bool)
- func IsStringInSliceFold(needle string, haystack []string) (inSlice bool)
- func IsStringInSliceSuffix(needle string, haystack []string) (hasSuffix bool)
- func IsStringSliceContainsAll(needles []string, haystack []string) (inSlice bool)
- func IsStringSliceContainsAny(needles []string, haystack []string) (inSlice bool)
- func IsStringSlicesDifferent(a, b []string) (different bool)
- func IsStringSlicesDifferentFold(a, b []string) (different bool)
- func IsURLHostComponent(u url.URL) (isHostComponent bool)
- func IsURLHostComponentWithPort(u url.URL) (isHostComponentWithPort bool)
- func IsURLInSlice(needle url.URL, haystack []url.URL) (has bool)
- func JoinAndCanonicalizeHeaders(sep []byte, headers ...string) (joined []byte)
- func NewTLSConfig(config *schema.TLSConfig, defaultMinVersion uint16, certPool *x509.CertPool) (tlsConfig *tls.Config)
- func NewX509CertPool(directory string) (certPool *x509.CertPool, warnings []error, errors []error)
- func OriginFromURL(u url.URL) (origin url.URL)
- func ParseDurationString(input string) (duration time.Duration, err error)
- func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error)
- func ParseRsaPublicKeyFromPemStr(pubPEM string) (*rsa.PublicKey, error)
- func PathExists(path string) (exists bool, err error)
- func RandomBytes(n int, characters string, crypto bool) (bytes []byte)
- func RandomString(n int, characters string, crypto bool) (randomString string)
- func RunCommandAndReturnOutput(command string) (output string, exitCode int, err error)
- func RunCommandUntilCtrlC(cmd *exec.Cmd)
- func RunCommandWithTimeout(cmd *exec.Cmd, timeout time.Duration) error
- func RunFuncUntilCtrlC(fn func() error) error
- func RunFuncWithRetry(attempts int, sleep time.Duration, f func() error) (err error)
- func Shell(command string) *exec.Cmd
- func SliceString(s string, d int) (array []string)
- func StandardizeDurationString(input string) (output string, err error)
- func StringHTMLEscape(input string) (output string)
- func StringJoinDelimitedEscaped(value []string, delimiter rune) string
- func StringSliceFromURLs(urls []url.URL) []string
- func StringSlicesDelta(before, after []string) (added, removed []string)
- func StringSplitDelimitedEscaped(value string, delimiter rune) (out []string)
- func TLSStringToTLSConfigVersion(input string) (version uint16, err error)
- func URLsFromStringSlice(urls []string) []url.URL
- func Version() (versionString string)
- type Clock
- type ECDSAKeyBuilder
- type Ed25519KeyBuilder
- type ErrSliceSortAlphabetical
- type PEMBlockType
- type PrivateKeyBuilder
- type RSAKeyBuilder
- type RealClock
Constants ¶
const ( // RFC3339Zero is the default value for time.Time.Unix(). RFC3339Zero = int64(-62135596800) // TLS13 is the textual representation of TLS 1.3. TLS13 = "1.3" // TLS12 is the textual representation of TLS 1.2. TLS12 = "1.2" // TLS11 is the textual representation of TLS 1.1. TLS11 = "1.1" // TLS10 is the textual representation of TLS 1.0. TLS10 = "1.0" )
const ( // Hour is an int based representation of the time unit. Hour = time.Minute * 60 //nolint:revive // Day is an int based representation of the time unit. Day = Hour * 24 // Week is an int based representation of the time unit. Week = Day * 7 // Year is an int based representation of the time unit. Year = Day * 365 // Month is an int based representation of the time unit. Month = Year / 12 )
const ( DurationUnitDays = "d" DurationUnitWeeks = "w" DurationUnitMonths = "M" DurationUnitYears = "y" )
Duration unit types.
const ( HoursInDay = 24 HoursInWeek = HoursInDay * 7 HoursInMonth = HoursInDay * 30 HoursInYear = HoursInDay * 365 )
Number of hours in particular measurements of time.
Variables ¶
var (
// AlphaNumericCharacters are literally just valid alphanumeric chars.
AlphaNumericCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
var BuildBranch = "master"
BuildBranch is replaced by LDFLAGS at build time with the current branch.
var BuildCommit = "unknown"
BuildCommit is replaced by LDFLAGS at build time with the current commit.
var BuildDate = ""
BuildDate is replaced by LDFLAGS at build time with the date the build started.
var BuildExtra = ""
BuildExtra is replaced by LDFLAGS at build time with a blank string by default. People porting Authelia can use this to add a suffix to their versions.
var BuildNumber = "0"
BuildNumber is replaced by LDFLAGS at build time with the CI build number.
var BuildState = "untagged dirty"
BuildState is replaced by LDFLAGS at build time with `tagged` or `untagged` depending on if the commit is tagged, and `clean` or `dirty` depending on the working tree state. For example if the commit was tagged and the working tree was dirty it would be "tagged dirty". This is used to determine the version string output mode.
var BuildTag = "unknown"
BuildTag is replaced by LDFLAGS at build time with the latest tag at or before the current commit.
var ErrTLSVersionNotSupported = errors.New("supplied tls version isn't supported")
ErrTLSVersionNotSupported returned when an unknown TLS version supplied.
var ErrTimeoutReached = errors.New("timeout reached")
ErrTimeoutReached error thrown when a timeout is reached.
Functions ¶
func CheckUntil ¶
func CheckUntil(interval time.Duration, timeout time.Duration, predicate func() (bool, error)) error
CheckUntil regularly check a predicate until it's true or time out is reached.
func CommandWithStdout ¶
CommandWithStdout create a command forwarding stdout and stderr to the OS streams.
func ConvertDERToPEM ¶ added in v4.35.0
func ConvertDERToPEM(der []byte, blockType PEMBlockType) ([]byte, error)
ConvertDERToPEM convert certificate in DER format into PEM format.
func Decrypt ¶
Decrypt decrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag where '|' indicates concatenation.
func DirectoryExists ¶
DirectoryExists returns true if the given path exists and is a directory.
func Encrypt ¶
Encrypt encrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Output takes the form nonce|ciphertext|tag where '|' indicates concatenation.
func ExportRsaPrivateKeyAsPemStr ¶
func ExportRsaPrivateKeyAsPemStr(privkey *rsa.PrivateKey) string
ExportRsaPrivateKeyAsPemStr marshal a rsa private key into PEM string.
func ExportRsaPublicKeyAsPemStr ¶
ExportRsaPublicKeyAsPemStr marshal a RSA public into a PEM string.
func FileExists ¶
FileExists returns true if the given path exists and is a file.
func GenerateCertificate ¶ added in v4.35.0
func GenerateCertificate(privateKeyBuilder PrivateKeyBuilder, hosts []string, validFrom time.Time, validFor time.Duration, isCA bool) ([]byte, []byte, error)
GenerateCertificate generate a certificate given a private key. RSA, Ed25519 and ECDSA are officially supported.
func GenerateRsaKeyPair ¶
func GenerateRsaKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey)
GenerateRsaKeyPair generate an RSA key pair. bits can be 2048 or 4096.
func GetExpectedErrTxt ¶
GetExpectedErrTxt returns error text for expected errs.
func HashSHA256FromPath ¶
HashSHA256FromPath takes a path string and calculates the SHA256 checksum of the file at the path returning it as a base16 hash string.
func HashSHA256FromString ¶
HashSHA256FromString takes an input string and calculates the SHA256 checksum returning it as a base16 hash string.
func IsBoolCountLessThanN ¶ added in v4.35.0
IsBoolCountLessThanN takes an int (n), bool (v), and then a variadic slice of bool (vals). If the number of bools in vals with the value v is more than n, it returns false, otherwise it returns true.
func IsRedirectionSafe ¶
IsRedirectionSafe determines whether the URL is safe to be redirected to.
func IsRedirectionURISafe ¶
IsRedirectionURISafe determines whether the URI is safe to be redirected to.
func IsStringAbsURL ¶
IsStringAbsURL checks a string can be parsed as a URL and that is IsAbs and if it can't it returns an error describing why.
func IsStringAlphaNumeric ¶
IsStringAlphaNumeric returns false if any rune in the string is not alpha-numeric.
func IsStringInSlice ¶
IsStringInSlice checks if a single string is in a slice of strings.
func IsStringInSliceContains ¶
IsStringInSliceContains checks if a single string is in an array of strings.
func IsStringInSliceFold ¶
IsStringInSliceFold checks if a single string is in a slice of strings but uses strings.EqualFold to compare them.
func IsStringInSliceSuffix ¶
IsStringInSliceSuffix checks if the needle string has one of the suffixes in the haystack.
func IsStringSliceContainsAll ¶ added in v4.33.0
IsStringSliceContainsAll checks if the haystack contains all strings in the needles.
func IsStringSliceContainsAny ¶ added in v4.33.0
IsStringSliceContainsAny checks if the haystack contains any of the strings in the needles.
func IsStringSlicesDifferent ¶
IsStringSlicesDifferent checks two slices of strings and on the first occurrence of a string item not existing in the other slice returns true, otherwise returns false.
func IsStringSlicesDifferentFold ¶
IsStringSlicesDifferentFold checks two slices of strings and on the first occurrence of a string item not existing in the other slice (case insensitive) returns true, otherwise returns false.
func IsURLHostComponent ¶ added in v4.35.0
IsURLHostComponent returns true if the provided url.URL that was parsed from a string to a url.URL via url.Parse is just a hostname. This is needed because of the way this function parses such strings.
func IsURLHostComponentWithPort ¶ added in v4.35.0
IsURLHostComponentWithPort returns true if the provided url.URL that was parsed from a string to a url.URL via url.Parse is just a hostname with a port. This is needed because of the way this function parses such strings.
func IsURLInSlice ¶ added in v4.35.0
IsURLInSlice returns true if the needle url.URL is in the []url.URL haystack.
func JoinAndCanonicalizeHeaders ¶ added in v4.35.0
JoinAndCanonicalizeHeaders join header strings by a given sep.
func NewTLSConfig ¶
func NewTLSConfig(config *schema.TLSConfig, defaultMinVersion uint16, certPool *x509.CertPool) (tlsConfig *tls.Config)
NewTLSConfig generates a tls.Config from a schema.TLSConfig and a x509.CertPool.
func NewX509CertPool ¶
NewX509CertPool generates a x509.CertPool from the system PKI and the directory specified.
func OriginFromURL ¶ added in v4.35.0
OriginFromURL returns an origin url.URL given another url.URL.
func ParseDurationString ¶
ParseDurationString standardizes a duration string with StandardizeDurationString then uses time.ParseDuration to convert it into a time.Duration.
func ParseRsaPrivateKeyFromPemStr ¶
func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error)
ParseRsaPrivateKeyFromPemStr parse a RSA private key from PEM string.
func ParseRsaPublicKeyFromPemStr ¶
ParseRsaPublicKeyFromPemStr parse RSA public key from a PEM string.
func PathExists ¶
PathExists returns true if the given path exists.
func RandomBytes ¶ added in v4.33.0
RandomBytes returns a random []byte with a given length with values from the provided characters. When crypto is set to false we use math/rand and when it's set to true we use crypto/rand. The crypto option should always be set to true excluding when the task is time sensitive and would not benefit from extra randomness.
func RandomString ¶
RandomString returns a random string with a given length with values from the provided characters. When crypto is set to false we use math/rand and when it's set to true we use crypto/rand. The crypto option should always be set to true excluding when the task is time sensitive and would not benefit from extra randomness.
func RunCommandAndReturnOutput ¶
RunCommandAndReturnOutput runs a shell command then returns the stdout and the exit code.
func RunCommandUntilCtrlC ¶
RunCommandUntilCtrlC run a command until ctrl-c is hit.
func RunCommandWithTimeout ¶
RunCommandWithTimeout run a command with timeout.
func RunFuncUntilCtrlC ¶
RunFuncUntilCtrlC run a function until ctrl-c is hit.
func RunFuncWithRetry ¶
RunFuncWithRetry run a function for n attempts with a sleep of n duration between each attempt.
func SliceString ¶
SliceString splits a string s into an array with each item being a max of int d d = denominator, n = numerator, q = quotient, r = remainder.
func StandardizeDurationString ¶ added in v4.34.0
StandardizeDurationString converts units of time that stdlib is unaware of to hours.
func StringHTMLEscape ¶
StringHTMLEscape escapes chars for a HTML body.
func StringJoinDelimitedEscaped ¶ added in v4.35.0
StringJoinDelimitedEscaped joins a string with a specified rune delimiter after escaping any instance of that string in the string slice. Used with StringSplitDelimitedEscaped.
func StringSliceFromURLs ¶ added in v4.35.0
StringSliceFromURLs returns a []string from a []url.URL.
func StringSlicesDelta ¶
StringSlicesDelta takes a before and after []string and compares them returning a added and removed []string.
func StringSplitDelimitedEscaped ¶ added in v4.35.0
StringSplitDelimitedEscaped splits a string with a specified rune delimiter after unescaping any instance of that string in the string slice that has been escaped. Used with StringJoinDelimitedEscaped.
func TLSStringToTLSConfigVersion ¶
TLSStringToTLSConfigVersion returns a go crypto/tls version for a tls.Config based on string input.
func URLsFromStringSlice ¶ added in v4.35.0
URLsFromStringSlice returns a []url.URL from a []string.
func Version ¶
func Version() (versionString string)
Version returns the Authelia version.
The format of the string is dependent on the values in BuildState. If tagged and clean are present it returns the BuildTag i.e. v1.0.0. If dirty and tagged are present it returns <BuildTag>-dirty. Otherwise the following is the format: untagged-<BuildTag>-dirty-<BuildExtra> (<BuildBranch>, <BuildCommit>).
Types ¶
type ECDSAKeyBuilder ¶ added in v4.35.0
type ECDSAKeyBuilder struct {
// contains filtered or unexported fields
}
ECDSAKeyBuilder builder of ECDSA private key.
func (ECDSAKeyBuilder) Build ¶ added in v4.35.0
func (ekb ECDSAKeyBuilder) Build() (interface{}, error)
Build an ECDSA private key.
func (ECDSAKeyBuilder) WithCurve ¶ added in v4.35.0
func (ekb ECDSAKeyBuilder) WithCurve(curve elliptic.Curve) ECDSAKeyBuilder
WithCurve configure the curve to use for the ECDSA private key.
type Ed25519KeyBuilder ¶ added in v4.35.0
type Ed25519KeyBuilder struct{}
Ed25519KeyBuilder builder of Ed25519 private key.
func (Ed25519KeyBuilder) Build ¶ added in v4.35.0
func (ekb Ed25519KeyBuilder) Build() (interface{}, error)
Build an Ed25519 private key.
type ErrSliceSortAlphabetical ¶
type ErrSliceSortAlphabetical []error
ErrSliceSortAlphabetical is a helper type that can be used with sort.Sort to sort a slice of errors in alphabetical order. Usage is simple just do sort.Sort(ErrSliceSortAlphabetical([]error{})).
func (ErrSliceSortAlphabetical) Len ¶
func (s ErrSliceSortAlphabetical) Len() int
func (ErrSliceSortAlphabetical) Less ¶
func (s ErrSliceSortAlphabetical) Less(i, j int) bool
func (ErrSliceSortAlphabetical) Swap ¶
func (s ErrSliceSortAlphabetical) Swap(i, j int)
type PEMBlockType ¶ added in v4.35.0
type PEMBlockType int
PEMBlockType represent an enum of the existing PEM block types.
const ( // Certificate block type. Certificate PEMBlockType = iota // PrivateKey block type. PrivateKey )
type PrivateKeyBuilder ¶ added in v4.35.0
type PrivateKeyBuilder interface {
Build() (interface{}, error)
}
PrivateKeyBuilder interface for a private key builder.
type RSAKeyBuilder ¶ added in v4.35.0
type RSAKeyBuilder struct {
// contains filtered or unexported fields
}
RSAKeyBuilder builder of RSA private key.
func (RSAKeyBuilder) Build ¶ added in v4.35.0
func (rkb RSAKeyBuilder) Build() (interface{}, error)
Build a RSA private key.
func (RSAKeyBuilder) WithKeySize ¶ added in v4.35.0
func (rkb RSAKeyBuilder) WithKeySize(bits int) RSAKeyBuilder
WithKeySize configure the key size to use with RSA.