mirror of
https://github.com/xcat2/confluent.git
synced 2026-01-11 10:32:31 +00:00
Add a go version of genpasshmac
This commit is contained in:
10
confluent_osdeploy/utils/gopasshmac/go.mod
Normal file
10
confluent_osdeploy/utils/gopasshmac/go.mod
Normal file
@@ -0,0 +1,10 @@
|
||||
module genpasshmac
|
||||
|
||||
go 1.22
|
||||
|
||||
toolchain go1.23.6
|
||||
|
||||
require (
|
||||
github.com/go-crypt/crypt v0.3.2 // indirect
|
||||
github.com/go-crypt/x v0.3.2 // indirect
|
||||
)
|
||||
4
confluent_osdeploy/utils/gopasshmac/go.sum
Normal file
4
confluent_osdeploy/utils/gopasshmac/go.sum
Normal file
@@ -0,0 +1,4 @@
|
||||
github.com/go-crypt/crypt v0.3.2 h1:I4i0u2g8X9bxCXIjvv19BDVXqQbddDQrURCJrOyyJos=
|
||||
github.com/go-crypt/crypt v0.3.2/go.mod h1:U0YhpCizEtaVC4gVfUUN0qGn1Z6+e3at+B5uLYx/sV0=
|
||||
github.com/go-crypt/x v0.3.2 h1:m2wn2+8tp28V4yDiW5NSTiyNSXnCoTs1R1+H+cAJA3M=
|
||||
github.com/go-crypt/x v0.3.2/go.mod h1:uelN9rbD2e2eqE8KA26B9R6OQ0TdM6msWdPsoMM1ZFk=
|
||||
49
confluent_osdeploy/utils/gopasshmac/main.go
Normal file
49
confluent_osdeploy/utils/gopasshmac/main.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
//"fmt"
|
||||
"github.com/go-crypt/crypt/algorithm/shacrypt"
|
||||
"os"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
)
|
||||
|
||||
func main() {
|
||||
hmackeyfile := flag.String("k", "", "Key file for HMAC calculation")
|
||||
passfile := flag.String("p", "", "File to write generated password to")
|
||||
cryptfile := flag.String("c", "", "File to write crypted form of key to")
|
||||
hmacfile := flag.String("m", "", "File to write HMAC value to")
|
||||
flag.Parse()
|
||||
randbytes := make([]byte, 36)
|
||||
_, err := rand.Read(randbytes)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
newpasswd := base64.StdEncoding.EncodeToString(randbytes)
|
||||
hasher, err := shacrypt.New(shacrypt.WithVariant(shacrypt.VariantSHA256), shacrypt.WithIterations(5000))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
digest, err := hasher.Hash(newpasswd)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cryptdata := []byte(digest.Encode())
|
||||
err = os.WriteFile(*passfile, []byte(newpasswd), 0600)
|
||||
if err != nil { panic(err )}
|
||||
err = os.WriteFile(*cryptfile, cryptdata, 0600)
|
||||
if err != nil { panic(err )}
|
||||
keydata, err := os.ReadFile(*hmackeyfile)
|
||||
if err != nil { panic(err )}
|
||||
hmacer := hmac.New(sha256.New, keydata)
|
||||
hmacer.Write(cryptdata)
|
||||
hmacresult := hmacer.Sum(nil)
|
||||
hmacout := []byte(base64.StdEncoding.EncodeToString(hmacresult))
|
||||
err = os.WriteFile(*hmacfile, hmacout, 0600)
|
||||
if err != nil { panic(err )}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user