mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-27 21:38:01 +01:00
Validate bcrypt-cost config value to prevent silent errors
This commit is contained in:
parent
3c4c5dde4d
commit
462e568f00
@ -2337,7 +2337,7 @@ func (ac *AccountCredentials) Serialize() (result string, err error) {
|
|||||||
return string(credText), nil
|
return string(credText), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *AccountCredentials) SetPassphrase(passphrase string, bcryptCost uint) (err error) {
|
func (ac *AccountCredentials) SetPassphrase(passphrase string, bcryptCost int) (err error) {
|
||||||
if passphrase == "" {
|
if passphrase == "" {
|
||||||
ac.PassphraseHash = nil
|
ac.PassphraseHash = nil
|
||||||
ac.SCRAMCreds = SCRAMCreds{}
|
ac.SCRAMCreds = SCRAMCreds{}
|
||||||
@ -2348,7 +2348,7 @@ func (ac *AccountCredentials) SetPassphrase(passphrase string, bcryptCost uint)
|
|||||||
return errAccountBadPassphrase
|
return errAccountBadPassphrase
|
||||||
}
|
}
|
||||||
|
|
||||||
ac.PassphraseHash, err = passwd.GenerateFromPassword([]byte(passphrase), int(bcryptCost))
|
ac.PassphraseHash, err = passwd.GenerateFromPassword([]byte(passphrase), bcryptCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errAccountBadPassphrase
|
return errAccountBadPassphrase
|
||||||
}
|
}
|
||||||
|
|||||||
@ -375,7 +375,7 @@ type AccountRegistrationConfig struct {
|
|||||||
Mailto email.MailtoConfig
|
Mailto email.MailtoConfig
|
||||||
} `yaml:"callbacks"`
|
} `yaml:"callbacks"`
|
||||||
VerifyTimeout custime.Duration `yaml:"verify-timeout"`
|
VerifyTimeout custime.Duration `yaml:"verify-timeout"`
|
||||||
BcryptCost uint `yaml:"bcrypt-cost"`
|
BcryptCost int `yaml:"bcrypt-cost"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VHostConfig struct {
|
type VHostConfig struct {
|
||||||
@ -1595,6 +1595,12 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
if config.Accounts.Registration.BcryptCost == 0 {
|
if config.Accounts.Registration.BcryptCost == 0 {
|
||||||
config.Accounts.Registration.BcryptCost = passwd.DefaultCost
|
config.Accounts.Registration.BcryptCost = passwd.DefaultCost
|
||||||
}
|
}
|
||||||
|
if config.Accounts.Registration.BcryptCost < passwd.MinCost || config.Accounts.Registration.BcryptCost > passwd.MaxCost {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"invalid bcrypt-cost %d (require %d <= cost <= %d)",
|
||||||
|
config.Accounts.Registration.BcryptCost, passwd.MinCost, passwd.MaxCost,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if config.Channels.MaxChannelsPerClient == 0 {
|
if config.Channels.MaxChannelsPerClient == 0 {
|
||||||
config.Channels.MaxChannelsPerClient = 100
|
config.Channels.MaxChannelsPerClient = 100
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
MinCost = bcrypt.MinCost
|
MinCost = bcrypt.MinCost
|
||||||
|
MaxCost = bcrypt.MaxCost
|
||||||
DefaultCost = 12 // ballpark: 250 msec on a modern Intel CPU
|
DefaultCost = 12 // ballpark: 250 msec on a modern Intel CPU
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user