-x, -f, env vars, prepping for hashing
This commit is contained in:
@@ -7,6 +7,20 @@ const (
|
||||
DefMinLin uint = 1
|
||||
)
|
||||
|
||||
// Hash algorithms. TODO.
|
||||
const (
|
||||
HashNull pwHash = iota
|
||||
HashArgon2i
|
||||
HashScryptSha256
|
||||
HashCryptSha256
|
||||
HashCryptSha512
|
||||
HashBcrypt
|
||||
HashBcryptSha256
|
||||
HashPbkdf2Sha1
|
||||
HashPbkdf2Sha256
|
||||
HashPbkdf2Sha512
|
||||
)
|
||||
|
||||
// Pre-defined charsets.
|
||||
var (
|
||||
// upper contains the characters from 0x41 to 0x5a ([A-Z]).
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package pwgenerator
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"r00t2.io/goutils/multierr"
|
||||
)
|
||||
@@ -44,6 +46,61 @@ func (o *GenOpts) Generate() (passwords []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
GenerateCollection returns a PwCollection instead of a slice of password text.
|
||||
|
||||
It contains extended information about a password, hashes, etc.
|
||||
|
||||
Note: hashing support currently under construction and not implemented. TODO.
|
||||
*/
|
||||
func (o *GenOpts) GenerateCollection(hashAlgos []pwHash) (collection *PwCollection, err error) {
|
||||
|
||||
var charset CharSet
|
||||
var errs *multierr.MultiError = multierr.NewMultiError(nil)
|
||||
var passwd string
|
||||
|
||||
collection = &PwCollection{
|
||||
XMLName: xml.Name{
|
||||
Space: "", // TODO?
|
||||
Local: "collection",
|
||||
},
|
||||
Passwords: make([]*PwDef, o.Count),
|
||||
}
|
||||
|
||||
if o.Count == 0 {
|
||||
o.Count = DefCount
|
||||
}
|
||||
if o.LengthMax == 0 {
|
||||
o.LengthMax = DefMaxLen
|
||||
}
|
||||
|
||||
if err = o.sanChk(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if charset, err = o.Chars(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for idx, _ := range collection.Passwords {
|
||||
if passwd, err = o.generatePassword(charset); err != nil {
|
||||
errs.AddError(err)
|
||||
err = nil
|
||||
}
|
||||
collection.Passwords[idx] = &PwDef{
|
||||
XMLName: xml.Name{
|
||||
Space: "", // TODO?
|
||||
Local: "password",
|
||||
},
|
||||
Password: passwd,
|
||||
Generated: time.Now(),
|
||||
Hashes: nil, // TODO
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// generatePassword generates a single password from CharSet c (plus any minimum requirements).
|
||||
func (o *GenOpts) generatePassword(c CharSet) (password string, err error) {
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package pwgenerator
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"time"
|
||||
)
|
||||
|
||||
// pwHash is an explicit hash algorithm.
|
||||
type pwHash uint8
|
||||
|
||||
// cryptoShuffler is used to shuffle a slice in a cryptographically sane way.
|
||||
type cryptoShuffler struct{}
|
||||
|
||||
@@ -56,6 +64,28 @@ type GenOpts struct {
|
||||
explicitCharset CharSet
|
||||
}
|
||||
|
||||
// PwCollection contains the full series of generated passwords.
|
||||
type PwCollection struct {
|
||||
XMLName xml.Name `json:"-" yaml:"-"`
|
||||
Passwords []*PwDef `json:"password_defs" yaml:"Password Definitions" xml:"passwordDefs"`
|
||||
}
|
||||
|
||||
// PwDef contains a generated password and related metadata.
|
||||
type PwDef struct {
|
||||
XMLName xml.Name `json:"-" yaml:"-"`
|
||||
Password string `json:"password" yaml:"Password" xml:"password,attr"`
|
||||
Generated time.Time `json:"generated" yaml:"Generated" xml:"generated,attr"`
|
||||
Hashes []PwHashDef `json:"hashes,omitempty" yaml:"Hashes,omitempty" xml:"hashes,omitempty"`
|
||||
// Hashes []PwHashDef `json:"hashes" yaml:"Hashes" xml:"hashes"`
|
||||
}
|
||||
|
||||
// PwHashDef defines a hash for a PwDef (once we implement it).
|
||||
type PwHashDef struct {
|
||||
XMLName xml.Name `json:"-" yaml:"-"`
|
||||
HashType string `json:"hash_algo" yaml:"Hash Algorithm" xml:"hashAlgo,attr"`
|
||||
HashString string `json:"hash" yaml:"Hash" xml:",chardata"`
|
||||
}
|
||||
|
||||
// selectFilter is used to include specified number of characters.
|
||||
type selectFilter struct {
|
||||
upperCounter uint
|
||||
|
||||
Reference in New Issue
Block a user