Migrat pkg/password to using pkglib package

This commit is contained in:
Tom Wiesing 2023-02-26 10:24:06 +01:00
parent 010fd536ea
commit aa3580c248
No known key found for this signature in database
11 changed files with 56 additions and 158 deletions

View file

@ -1,8 +1,13 @@
package config
import "github.com/FAU-CDI/wisski-distillery/pkg/password"
import (
"crypto/rand"
"github.com/FAU-CDI/wisski-distillery/internal/passwordx"
"github.com/tkw1536/pkglib/password"
)
// NewPassword returns a new password using the password settings from this configuration
func (cfg Config) NewPassword() (string, error) {
return password.Password(cfg.PasswordLength)
return password.Generate(rand.Reader, cfg.PasswordLength, passwordx.Charset)
}

View file

@ -1,13 +1,15 @@
package config
import (
"crypto/rand"
"path/filepath"
"time"
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
"github.com/FAU-CDI/wisski-distillery/internal/passwordx"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/password"
"github.com/tkw1536/pkglib/hostname"
"github.com/tkw1536/pkglib/password"
)
// Template is a template for the configuration file
@ -47,7 +49,7 @@ func (tpl *Template) SetDefaults(env environment.Environment) (err error) {
}
if tpl.TriplestoreAdminPassword == "" {
tpl.TriplestoreAdminPassword, err = password.Password(64)
tpl.TriplestoreAdminPassword, err = password.Generate(rand.Reader, 64, passwordx.Charset)
if err != nil {
return err
}
@ -58,14 +60,14 @@ func (tpl *Template) SetDefaults(env environment.Environment) (err error) {
}
if tpl.MysqlAdminPassword == "" {
tpl.MysqlAdminPassword, err = password.Password(64)
tpl.MysqlAdminPassword, err = password.Generate(rand.Reader, 64, passwordx.Charset)
if err != nil {
return err
}
}
if tpl.DockerNetworkName == "" {
tpl.DockerNetworkName, err = password.Password(10)
tpl.DockerNetworkName, err = password.Generate(rand.Reader, 10, passwordx.Charset)
if err != nil {
return err
}
@ -73,7 +75,7 @@ func (tpl *Template) SetDefaults(env environment.Environment) (err error) {
}
if tpl.SessionSecret == "" {
tpl.SessionSecret, err = password.Password(100)
tpl.SessionSecret, err = password.Generate(rand.Reader, 100, passwordx.Charset)
if err != nil {
return err
}

View file

@ -9,10 +9,11 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/pkg/password"
"github.com/FAU-CDI/wisski-distillery/internal/passwordx"
"github.com/pkg/errors"
"github.com/pquerna/otp"
"github.com/pquerna/otp/totp"
"github.com/tkw1536/pkglib/password"
"github.com/tkw1536/pkglib/pools"
"github.com/tkw1536/pkglib/reflectx"
"golang.org/x/crypto/bcrypt"
@ -263,7 +264,7 @@ func (auth *Auth) CheckPasswordPolicy(candidate string, username string) error {
return ErrPolicyTooShort
}
if err := password.CheckCommonPassword(func(common string) (bool, error) { return common == candidate, nil }); err != nil {
if err := password.CheckCommonPassword(func(common string) (bool, error) { return common == candidate, nil }, passwordx.Sources...); err != nil {
return ErrPolicyKnown
}

View file

@ -1,18 +1,19 @@
package exporter
import (
"crypto/rand"
"fmt"
"path/filepath"
"time"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter/logger"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/sql"
"github.com/FAU-CDI/wisski-distillery/internal/passwordx"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/password"
"github.com/tkw1536/pkglib/password"
)
// Exporter manages snapshots and backups
@ -59,7 +60,7 @@ func (dis *Exporter) NewArchivePath(prefix string) (path string) {
// newSnapshot name returns a new basename for a snapshot with the provided prefix.
// The name is guaranteed to be unique within this process.
func (*Exporter) newSnapshotName(prefix string) string {
suffix, _ := password.Password(10) // silently ignore any errors!
suffix, _ := password.Generate(rand.Reader, 10, passwordx.Snapshot) // silently ignore any errors!
if prefix == "" {
prefix = "backup"
} else {

View file

@ -0,0 +1,9 @@
package passwordx
import "github.com/tkw1536/pkglib/password"
// Charset is a Charset safe for usage within the distillery
const Charset = password.DefaultCharSet
// Snapshot is a charset to be used to generate snapshot ids
const Snapshot = password.DefaultCharSet

View file

@ -0,0 +1,23 @@
package passwordx
import (
"embed"
"github.com/tkw1536/pkglib/password"
)
//go:embed common
var commonEmbed embed.FS
var Sources []password.PasswordSource
func init() {
var err error
Sources, err = password.NewSources(commonEmbed, "**/*.txt")
if err != nil {
panic(err)
}
if len(Sources) == 0 {
panic("no sources")
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
// This file contains a list of common WissKI Passwords
W1ssk1.

View file

@ -6,8 +6,9 @@ import (
"fmt"
"io"
"github.com/FAU-CDI/wisski-distillery/internal/passwordx"
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
"github.com/FAU-CDI/wisski-distillery/pkg/password"
"github.com/tkw1536/pkglib/password"
)
var errGetValidator = errors.New("GetPasswordValidator: Unknown Error")
@ -64,7 +65,7 @@ func (pv PasswordValidator) CheckDictionary(ctx context.Context, writer io.Write
}
return errPasswordUsername
}
for candidate := range password.CommonPasswords() {
for candidate := range password.Passwords(passwordx.Sources...) {
if ctx.Err() != nil {
continue
}