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:
- 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
- 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
- func FormatCrud(ctx context.Context, name string, cfg *Config) error
- func GenHash(password []byte) string
- func GenHashFromPassword(password string, cost int) (string, error)
- func GeneratePasswordHash(password string, algorithm string, params HashParams) (string, error)
- func NewBasicAuthWebdavHandler(a *App) http.Handler
- func Resolve(ctx context.Context, name string, d Dir) string
- func SayUnauthorized(w http.ResponseWriter, realm string)
- func VerifyPasswordHash(password, hash string) error
- type App
- type Argon2Algorithm
- type AuthInfo
- type BcryptAlgorithm
- type Config
- type Cors
- type CrudType
- type Dir
- func (d Dir) Mkdir(ctx context.Context, name string, perm os.FileMode) error
- func (d Dir) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error)
- func (d Dir) RemoveAll(ctx context.Context, name string) error
- func (d Dir) Rename(ctx context.Context, oldName, newName string) error
- func (d Dir) Stat(ctx context.Context, name string) (os.FileInfo, error)
- type HashAlgorithm
- type HashConfig
- type HashParams
- type Logging
- type ScryptAlgorithm
- type TLS
- type UserInfo
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func FormatCrud ¶
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 GenHashFromPassword ¶
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 ¶
NewBasicAuthWebdavHandler creates a new http handler with basic auth features. The handler will use the application config for user and password lookups.
func SayUnauthorized ¶
func SayUnauthorized(w http.ResponseWriter, realm string)
func VerifyPasswordHash ¶
VerifyPasswordHash verifies a password against a hash using auto-detection
Types ¶
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 ¶
AuthInfo holds the username and authentication status
func AuthFromContext ¶
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 ¶
ParseConfig parses the application configuration an sets defaults.
func (*Config) AuthenticationNeeded ¶
AuthenticationNeeded returns whether users are defined and authentication is required
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) 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 ¶
RemoveAll removes a file or directory at the resolved physical path based on user permissions.
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
Directories
¶
| Path | Synopsis |
|---|---|
|
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 |