app

package
v1.0.0-caldav Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package app provides all app related stuff like config parsing, serving, etc.

Useful information: http://www.webdav.org/specs/#dav and http://www.webdav.org/specs/rfc4918.html

HashAlgorithm interface and implementations

This package implements secure password hashing algorithms for david. We support bcrypt, argon2id, and scrypt - all memory-hard algorithms.

Why we don't use SHA-256/SHA-512 for password hashing:

SHA algorithms (SHA-256, SHA-512) are designed for general-purpose hashing and are intentionally fast. This makes them unsuitable for password hashing because:

  1. Speed is a security risk: Fast hashes can be brute-forced quickly using GPU/ASIC clusters (see: https://github.com/audstanley/david/issues/2)

2. No built-in salting: SHA doesn't include salt, requiring manual implementation

3. No adaptive work factor: SHA can't be slowed down as hardware improves

  1. Vulnerable to rainbow tables: Without proper salting, common passwords can be pre-computed and looked up

Instead, we use memory-hard algorithms (bcrypt, argon2id, scrypt) that: - Are intentionally slow (~65-85ms per hash) - Require significant memory (~4KB-128MB), making GPU attacks expensive - Include built-in salting - Have configurable work factors that can be increased over time

For more information on password hashing, see: - OWASP Password Storage Cheat Sheet - RFC 9106 (Argon2) - RFC 7914 (scrypt)

Index

Constants

View Source
const (
	Propfind string = "PROPFIND"
	Mkol     string = "MKOL"
	Move     string = "MOVE"
	Lock     string = "LOCK"
	Unlock   string = "UNLOCK"
	Propatch string = "PROPPATCH"
	Copy     string = "COPY"
)

Variables

This section is empty.

Functions

func FormatCrud

func FormatCrud(ctx context.Context, name string, cfg *Config) error

FormatCrud formats and validates a CRUD type string based on the provided context, user name, configuration. This function takes a context (`ctx`), user name (`name`), configuration (`c`), and a `CrudType` object (`crud`) as input.

func GenHash

func GenHash(password []byte) string

GenHash generates a hashed password string using bcrypt (default algorithm)

func GenHashFromPassword

func GenHashFromPassword(password string, cost int) (string, error)

GenHashFromPassword generates a hashed password string with specified algorithm and cost

func GeneratePasswordHash

func GeneratePasswordHash(password string, algorithm string, params HashParams) (string, error)

GeneratePasswordHash generates a hash using the specified algorithm

func NewBasicAuthWebdavHandler

func NewBasicAuthWebdavHandler(a *App) http.Handler

NewBasicAuthWebdavHandler creates a new http handler with basic auth features. The handler will use the application config for user and password lookups.

func Resolve

func Resolve(ctx context.Context, name string, d Dir) string

Resolve returns the physical path for the given name.

func SayUnauthorized

func SayUnauthorized(w http.ResponseWriter, realm string)

func VerifyPasswordHash

func VerifyPasswordHash(password, hash string) error

VerifyPasswordHash verifies a password against a hash using auto-detection

Types

type App

type App struct {
	Config  *Config
	Handler *webdav.Handler
}

App holds configuration information and the webdav handler.

type Argon2Algorithm

type Argon2Algorithm struct{}

Argon2Algorithm implements Argon2id hashing

func (*Argon2Algorithm) Generate

func (a *Argon2Algorithm) Generate(password string, params interface{}) (string, error)

func (*Argon2Algorithm) Name

func (a *Argon2Algorithm) Name() string

func (*Argon2Algorithm) Prefix

func (a *Argon2Algorithm) Prefix() string

func (*Argon2Algorithm) Verify

func (a *Argon2Algorithm) Verify(password, hash string) error

type AuthInfo

type AuthInfo struct {
	Username      string
	Authenticated bool
	CrudType      *CrudType
}

AuthInfo holds the username and authentication status

func AuthFromContext

func AuthFromContext(ctx context.Context) *AuthInfo

AuthFromContext returns information about the authentication state of the current user.

type BcryptAlgorithm

type BcryptAlgorithm struct{}

BcryptAlgorithm implements bcrypt hashing

func (*BcryptAlgorithm) Generate

func (b *BcryptAlgorithm) Generate(password string, params interface{}) (string, error)

func (*BcryptAlgorithm) Name

func (b *BcryptAlgorithm) Name() string

func (*BcryptAlgorithm) Prefix

func (b *BcryptAlgorithm) Prefix() string

func (*BcryptAlgorithm) Verify

func (b *BcryptAlgorithm) Verify(password, hash string) error

type Config

type Config struct {
	Address string               `default:"127.0.0.1"`
	Port    string               `default:"8000"`
	Prefix  string               `default:""`
	Dir     string               `default:"/tmp"`
	TLS     *TLS                 `default:"nil"`
	Log     Logging              `default:"{error:true, create:false, read:false, update:false, delete:false}"`
	Realm   string               `default:"david"`
	Users   map[string]*UserInfo `default:"nil"`
	Cors    Cors                 `default:"{origin:*, credentials:false}"`
	Hash    HashConfig           `default:"{algorithm:bcrypt,bcrypt_cost:10}"`
}

Config represents the configuration of the server application.

func ParseConfig

func ParseConfig(path string) *Config

ParseConfig parses the application configuration an sets defaults.

func (*Config) AuthenticationNeeded

func (cfg *Config) AuthenticationNeeded() bool

AuthenticationNeeded returns whether users are defined and authentication is required

type Cors

type Cors struct {
	Origin      string
	Credentials bool
}

Cors contains settings related to Cross-Origin Resource Sharing (CORS)

type CrudType

type CrudType struct {
	// Create, Read, Update, Delete
	Crud   string
	Create bool
	Read   bool
	Update bool
	Delete bool
}

type Dir

type Dir struct {
	Config *Config
}

Dir is a custom webdav directory implementation that allows user configuration access for authentication. It extends the functionalities of the standard Dir by resolving paths based on user information and logging actions based on configuration settings.

func (Dir) Mkdir

func (d Dir) Mkdir(ctx context.Context, name string, perm os.FileMode) error

Mkdir attempts to create a directory at the resolved physical path.

func (Dir) OpenFile

func (d Dir) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error)

OpenFile opens a file at the resolved physical path based on user permissions and returns a webdav.File object.

This function takes a context (`ctx`), a file name (`name`), a flag (`flag`) indicating the access mode, and a permission mode (`perm`) for the file as input.

func (Dir) RemoveAll

func (d Dir) RemoveAll(ctx context.Context, name string) error

RemoveAll removes a file or directory at the resolved physical path based on user permissions.

func (Dir) Rename

func (d Dir) Rename(ctx context.Context, oldName, newName string) error

Rename resolves the physical file and delegates this to an os.Rename execution

func (Dir) Stat

func (d Dir) Stat(ctx context.Context, name string) (os.FileInfo, error)

Stat resolves the physical file and delegates this to an os.Stat execution

type HashAlgorithm

type HashAlgorithm interface {
	// Generate creates a hash from the password with given cost/params
	Generate(password string, params interface{}) (string, error)
	// Verify checks if the password matches the hash
	Verify(password, hash string) error
	// Name returns the algorithm name
	Name() string
	// Prefix returns the hash prefix for detection
	Prefix() string
}

HashAlgorithm defines the interface for password hashing algorithms

func DetectHashAlgorithm

func DetectHashAlgorithm(hash string) (HashAlgorithm, error)

DetectHashAlgorithm returns the algorithm based on hash prefix

func GetHashAlgorithm

func GetHashAlgorithm(name string) (HashAlgorithm, error)

GetHashAlgorithm returns the appropriate hash algorithm based on name

type HashConfig

type HashConfig struct {
	Algorithm string     `yaml:"algorithm" default:"bcrypt"`
	Params    HashParams `yaml:"params"`
}

HashConfig contains configuration for password hashing

type HashParams

type HashParams struct {
	BcryptCost        int    `yaml:"bcrypt_cost" default:"10"`
	Argon2Memory      uint32 `yaml:"memory" default:"65536"` // KiB
	Argon2Iterations  uint   `yaml:"iterations" default:"3"`
	Argon2Parallelism uint   `yaml:"parallelism" default:"4"`
	ScryptN           uint   `yaml:"scrypt_n" default:"16384"` // CPU/memory cost
	ScryptR           uint   `yaml:"scrypt_r" default:"8"`     // Block size
	ScryptP           uint   `yaml:"scrypt_p" default:"1"`     // Parallelism
}

HashParams contains configuration for all hash algorithms

type Logging

type Logging struct {
	Production bool `default:"false"`
	Debug      bool `default:"true"`
	Error      bool
	Create     bool
	Read       bool
	Update     bool
	Delete     bool
}

Logging allows definition for logging each CRUD method.

type ScryptAlgorithm

type ScryptAlgorithm struct{}

ScryptAlgorithm implements scrypt hashing

func (*ScryptAlgorithm) Generate

func (s *ScryptAlgorithm) Generate(password string, params interface{}) (string, error)

func (*ScryptAlgorithm) Name

func (s *ScryptAlgorithm) Name() string

func (*ScryptAlgorithm) Prefix

func (s *ScryptAlgorithm) Prefix() string

func (*ScryptAlgorithm) Verify

func (s *ScryptAlgorithm) Verify(password, hash string) error

type TLS

type TLS struct {
	CertFile string
	KeyFile  string
}

TLS allows specification of a certificate and private key file.

type UserInfo

type UserInfo struct {
	Password    string
	Subdir      *string
	Permissions string
	Crud        *CrudType
}

UserInfo allows storing of a password and user directory.

Directories

Path Synopsis
api
jwt
Package config provides configuration management using Viper
Package config provides configuration management using Viper
Package icalendar provides parsing and generation of iCalendar files per RFC 2445
Package icalendar provides parsing and generation of iCalendar files per RFC 2445
component
Package component provides iCalendar component types Note: Component files should be in the parent icalendar package for proper imports
Package component provides iCalendar component types Note: Component files should be in the parent icalendar package for proper imports
Package log provides centralized logging infrastructure
Package log provides centralized logging infrastructure
Package storage provides LevelDB-based storage for iCalendar data
Package storage provides LevelDB-based storage for iCalendar data

Jump to

Keyboard shortcuts

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