|
|
|
|
@ -11,7 +11,6 @@ import (
|
|
|
|
|
"github.com/hashicorp/boundary/internal/auth/password/store"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/oplog"
|
|
|
|
|
random "github.com/hashicorp/boundary/internal/securerandom"
|
|
|
|
|
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
|
|
|
|
|
"github.com/hashicorp/go-kms-wrapping/v2/extras/structwrapping"
|
|
|
|
|
"golang.org/x/crypto/argon2"
|
|
|
|
|
@ -153,7 +152,7 @@ type Argon2Credential struct {
|
|
|
|
|
tableName string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func newArgon2Credential(ctx context.Context, accountId string, password string, conf *Argon2Configuration) (*Argon2Credential, error) {
|
|
|
|
|
func newArgon2Credential(ctx context.Context, accountId string, password string, conf *Argon2Configuration, opt ...Option) (*Argon2Credential, error) {
|
|
|
|
|
const op = "password.newArgon2Credential"
|
|
|
|
|
if accountId == "" {
|
|
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing accountId")
|
|
|
|
|
@ -165,6 +164,8 @@ func newArgon2Credential(ctx context.Context, accountId string, password string,
|
|
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing argon2 configuration")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opts := GetOpts(opt...)
|
|
|
|
|
|
|
|
|
|
id, err := newArgon2CredentialId(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.Wrap(ctx, err, op)
|
|
|
|
|
@ -181,7 +182,7 @@ func newArgon2Credential(ctx context.Context, accountId string, password string,
|
|
|
|
|
|
|
|
|
|
// Generate a random salt
|
|
|
|
|
salt := make([]byte, conf.SaltLength)
|
|
|
|
|
if _, err := io.ReadFull(random.SecureRandomReader(), salt); err != nil {
|
|
|
|
|
if _, err := io.ReadFull(opts.withRandomReader, salt); err != nil {
|
|
|
|
|
return nil, errors.Wrap(ctx, err, op, errors.WithCode(errors.Io))
|
|
|
|
|
}
|
|
|
|
|
c.Salt = salt
|
|
|
|
|
|