diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-07-19 10:35:14 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-07-19 10:35:14 +0200 |
commit | 3c846b6a59c1e725b56b7784c30cfbd5a3dc080b (patch) | |
tree | c5c3353f3b5332e0477a3a376192d206d6e79faf /ssha.go | |
parent | 216e175eafd50b977e132ca0055df9fed9e83a6a (diff) | |
download | guichet-3c846b6a59c1e725b56b7784c30cfbd5a3dc080b.tar.gz guichet-3c846b6a59c1e725b56b7784c30cfbd5a3dc080b.zip |
Inclusive + Fix checks + Fix SSHAbetter_login
Diffstat (limited to 'ssha.go')
-rw-r--r-- | ssha.go | 33 |
1 files changed, 3 insertions, 30 deletions
@@ -1,37 +1,10 @@ package main import ( - "crypto/rand" - "crypto/sha1" - "encoding/base64" - "fmt" - - log "github.com/sirupsen/logrus" + "github.com/jsimonetti/pwscheme/ssha512" ) // Encode encodes the []byte of raw password -func SSHAEncode(rawPassPhrase []byte) string { - hash := makeSSHAHash(rawPassPhrase, makeSalt()) - b64 := base64.StdEncoding.EncodeToString(hash) - return fmt.Sprintf("{ssha}%s", b64) -} - -// makeSalt make a 32 byte array containing random bytes. -func makeSalt() []byte { - sbytes := make([]byte, 32) - _, err := rand.Read(sbytes) - if err != nil { - log.Panicf("Could not read random bytes: %s", err) - } - return sbytes -} - -// makeSSHAHash make hasing using SHA-1 with salt. This is not the final output though. You need to append {SSHA} string with base64 of this hash. -func makeSSHAHash(passphrase, salt []byte) []byte { - sha := sha1.New() - sha.Write(passphrase) - sha.Write(salt) - - h := sha.Sum(nil) - return append(h, salt...) +func SSHAEncode(rawPassPhrase string) (string, error) { + return ssha512.Generate(rawPassPhrase, 16) } |