Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change hashing algorithm from SHA-512 to bcrypt #638

Merged
merged 2 commits into from
Nov 11, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
make hash difficulty configurable
David Christofas authored and phil-davis committed Nov 11, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 14063508bb32606dd5f600f5add952ac4333994c
2 changes: 2 additions & 0 deletions .drone.star
Original file line number Diff line number Diff line change
@@ -1411,6 +1411,8 @@ def ocisServer(storage):
'KONNECTD_IDENTIFIER_REGISTRATION_CONF': '/drone/src/ocis/tests/config/drone/identifier-registration.yml',
'KONNECTD_ISS': 'https://ocis-server:9200',
'KONNECTD_TLS': 'true',
# 4 is the lowest possible value. ONLY FOR TESTS
'ACCOUNTS_HASH_DIFFICULTY': 4,
},
'commands': [
'apk add mailcap', # install /etc/mime.types
1 change: 1 addition & 0 deletions accounts/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ type Server struct {
Version string
Name string
AccountsDataPath string
HashDifficulty int
}

// Asset defines the available asset configuration.
7 changes: 7 additions & 0 deletions accounts/pkg/flagset/flagset.go
Original file line number Diff line number Diff line change
@@ -85,6 +85,13 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
EnvVars: []string{"ACCOUNTS_DATA_PATH"},
Destination: &cfg.Server.AccountsDataPath,
},
&cli.IntFlag{
Name: "accounts-hash-difficulty",
Value: 11,
Usage: "accounts password hash difficulty",
EnvVars: []string{"ACCOUNTS_HASH_DIFFICULTY"},
Destination: &cfg.Server.HashDifficulty,
},
&cli.StringFlag{
Name: "asset-path",
Value: "",
8 changes: 2 additions & 6 deletions accounts/pkg/service/v0/accounts.go
Original file line number Diff line number Diff line change
@@ -29,10 +29,6 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

const (
_hashDifficulty = 11
)

// accLock mutually exclude readers from writers on account files
var accLock sync.Mutex

@@ -315,7 +311,7 @@ func (s Service) CreateAccount(ctx context.Context, in *proto.CreateAccountReque
if out.PasswordProfile != nil {
if out.PasswordProfile.Password != "" {
// encrypt password
hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), _hashDifficulty)
hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.Server.HashDifficulty)
if err != nil {
s.log.Error().Err(err).Str("id", id).Msg("could not hash password")
return merrors.InternalServerError(s.id, "could not hash password: %v", err.Error())
@@ -499,7 +495,7 @@ func (s Service) UpdateAccount(ctx context.Context, in *proto.UpdateAccountReque
}
if in.Account.PasswordProfile.Password != "" {
// encrypt password
hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), _hashDifficulty)
hashed, err := bcrypt.GenerateFromPassword([]byte(in.Account.PasswordProfile.Password), s.Config.Server.HashDifficulty)
if err != nil {
in.Account.PasswordProfile.Password = ""
s.log.Error().Err(err).Str("id", id).Msg("could not hash password")