configs

package
v0.0.0-...-7a4d71e Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package configs contains Readeck configuration.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSize is returned when an encoded string is not 128-bit long.
	ErrInvalidSize = errors.New("invalid encoded string size")
	// ErrInvalidData is returned when input data does not match its signature.
	ErrInvalidData = errors.New("invalid data")
)
View Source
var Config = config{
	Main: configMain{
		LogLevel:      slog.LevelInfo,
		DataDirectory: "data",
	},
	Server: configServer{
		Host: "127.0.0.1",
		Port: 8000,
		Session: configSession{
			CookieName: "sxid",
			MaxAge:     86400 * 30,
		},
		TrustedProxies: []configIPNet{
			newConfigIPNet("127.0.0.0/8"),
			newConfigIPNet("10.0.0.0/8"),
			newConfigIPNet("172.16.0.0/12"),
			newConfigIPNet("192.168.0.0/16"),
			newConfigIPNet("fd00::/8"),
			newConfigIPNet("::1/128"),
		},
	},
	Database: configDB{},
	Email: configEmail{
		Port: 25,
	},
	Auth: configAuth{
		Forwarded: configForwardedAuth{
			Enabled:             false,
			HeaderUser:          "Remote-User",
			HeaderEmail:         "Remote-Email",
			HeaderGroup:         "Remote-Groups",
			ProvisioningEnabled: true,
		},
	},
	Bookmarks: configBookmarks{
		PublicShareTTL: 24,
	},
	Worker: configWorker{
		DSN:         "memory://",
		NumWorkers:  max(1, runtime.NumCPU()-1),
		StartWorker: true,
	},
	Extractor: configExtractor{
		NumWorkers: runtime.NumCPU(),
		DeniedIPs: []configIPNet{
			newConfigIPNet("127.0.0.0/8"),
			newConfigIPNet("::1/128"),
		},
		ProxyMatch: []configProxyMatch{},
	},
	Metrics: configMetrics{
		Host: "127.0.0.1",
		Port: 0,
	},
}

Config holds the configuration data from configuration files or flags.

This variable sets some default values that might be overwritten by a configuration file.

View Source
var Keys = KeyMaterial{}

Keys contains the encryption and signin keys.

Functions

func BuildTime

func BuildTime() time.Time

BuildTime returns the build time or, if empty, the time when the application started.

func ExtractorDeniedIPs

func ExtractorDeniedIPs() []*net.IPNet

ExtractorDeniedIPs returns the value of Config.Extractor.DeniedIPs as a slice of *net.IPNet.

func GenerateKey

func GenerateKey() string

GenerateKey returns a random key.

func InitConfiguration

func InitConfiguration()

InitConfiguration applies some default computed values on the configuration.

func LoadConfiguration

func LoadConfiguration(configPath string) error

LoadConfiguration loads the configuration file.

func TrustedProxies

func TrustedProxies() []*net.IPNet

TrustedProxies returns the value of Config.Server.TrustedProxies as a slice of *net.IPNet.

func Version

func Version() string

Version returns the current readeck version.

func WriteConfig

func WriteConfig(filename string) error

WriteConfig writes configuration to a file.

Types

type EncodingKey

type EncodingKey []byte

EncodingKey is a key that can be used to encode and decode a variable that support JSON marshaling.

func (EncodingKey) Decode

func (k EncodingKey) Decode(encoded []byte) ([]byte, error)

Decode decodes the input data with chacha20-poly1305 using the key.

func (EncodingKey) DecodeJSON

func (k EncodingKey) DecodeJSON(encoded []byte, v any) error

DecodeJSON decodes an encoded value and unmarshals it into the variable v.

func (EncodingKey) Encode

func (k EncodingKey) Encode(data []byte) ([]byte, error)

Encode encodes the input data with chacha20-poly1305 using the key.

func (EncodingKey) EncodeJSON

func (k EncodingKey) EncodeJSON(v any) ([]byte, error)

EncodeJSON marshals a variable to JSON and encodes it using the key.

type KeyMaterial

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

KeyMaterial contains the signing and encryption keys.

func (KeyMaterial) Expand

func (km KeyMaterial) Expand(name string, keyLength int) ([]byte, error)

Expand call hkdf.Expand using the [KeyMaterial.prk] main key.

func (KeyMaterial) OauthRequestKey

func (km KeyMaterial) OauthRequestKey() EncodingKey

OauthRequestKey returns a 256-bit key used to encode the oauth authorization payload.

func (KeyMaterial) SessionKey

func (km KeyMaterial) SessionKey() []byte

SessionKey returns a 256-bit key used by the session's secure cookie.

func (KeyMaterial) TOTPKey

func (km KeyMaterial) TOTPKey() EncodingKey

TOTPKey returns a 256-bit key used to encrypt the TOTP secret information.

func (KeyMaterial) TokenKey

func (km KeyMaterial) TokenKey() SigningKey

TokenKey returns a 256-bit key used to genrate a token's MAC.

type SigningKey

type SigningKey []byte

SigningKey is a key that can be used to sign and verify a base58 payload.

func (SigningKey) Decode

func (s SigningKey) Decode(encoded string) (string, error)

Decode returns a token ID, using the signed, base58 encoded token. It checks its length and mac.

func (SigningKey) Encode

func (s SigningKey) Encode(raw string) (string, error)

Encode returns a base58 encoded token and its mac. The whole token is 280-bit long.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL