Skip to content

Commit

Permalink
Use 32 byte salt by default (gopasspw#1690)
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 gopasspw#1688

RELEASE_NOTES=[ENHANCEMENT] Use 32 byte salt by default

Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
  • Loading branch information
dominikschulz authored Jan 12, 2021
1 parent f966884 commit 8d227c9
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 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,52 @@ func sha1sum() func(...string) (string, error) {
}
}

// saltLen tries to parse the given string into a numeric salt length.
// NOTE: This is on of the rare cases where I think named returns
// are useful.
func saltLen(s []string) (saltLen int) {
defer func() {
debug.Log("using saltLen %d", saltLen)
}()

// default should be 32bit
saltLen = 32

if len(s) < 2 {
return
}

i, err := strconv.Atoi(s[0])
if err == nil && i > 0 {
saltLen = i
}
if err != nil {
debug.Log("failed to parse saltLen %+v: %q", s, err)
}
return
}

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 8d227c9

Please sign in to comment.