Skip to content

Commit

Permalink
Use 32 byte salt by default
Browse files Browse the repository at this point in the history
This changes the salted hash funcs for the template feature to
use 32 salts by default and accept a parameter to choose the
desired salt length.

Fixes #1688

RELEASE_NOTES=[ENHANCEMENT] Use 32 byte salt by default

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz committed Jan 7, 2021
1 parent 004eaa4 commit e24143c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions internal/tpl/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"crypto/md5"
"crypto/sha1"
"fmt"
"strconv"
"text/template"

"github.com/gopasspw/gopass/internal/debug"
"github.com/jsimonetti/pwscheme/md5crypt"
"github.com/jsimonetti/pwscheme/ssha"
"github.com/jsimonetti/pwscheme/ssha256"
Expand Down Expand Up @@ -39,27 +41,43 @@ func sha1sum() func(...string) (string, error) {
}
}

func saltLen(s []string) int {
defLen := 32
if len(s) < 2 {
debug.Log("using saltLen %d", defLen)
return defLen
}
if i, err := strconv.Atoi(s[0]); err == nil && i > 0 {
debug.Log("using saltLen %d", i)
return i
} else {
debug.Log("failed to parse saltLen %+v: %q", s, err)
}
debug.Log("using saltLen %d", defLen)
return defLen
}

func md5cryptFunc() func(...string) (string, error) {
return func(s ...string) (string, error) {
return md5crypt.Generate(s[0], 4)
return md5crypt.Generate(s[0], uint8(saltLen(s)))
}
}

func sshaFunc() func(...string) (string, error) {
return func(s ...string) (string, error) {
return ssha.Generate(s[0], 4)
return ssha.Generate(s[0], uint8(saltLen(s)))
}
}

func ssha256Func() func(...string) (string, error) {
return func(s ...string) (string, error) {
return ssha256.Generate(s[0], 4)
return ssha256.Generate(s[0], uint8(saltLen(s)))
}
}

func ssha512Func() func(...string) (string, error) {
return func(s ...string) (string, error) {
return ssha512.Generate(s[0], 4)
return ssha512.Generate(s[0], uint8(saltLen(s)))
}
}

Expand Down

0 comments on commit e24143c

Please sign in to comment.