summaryrefslogtreecommitdiff
path: root/bin/sm-ipmi-key.go
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sm-ipmi-key.go')
-rw-r--r--bin/sm-ipmi-key.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/bin/sm-ipmi-key.go b/bin/sm-ipmi-key.go
new file mode 100644
index 0000000..7477e89
--- /dev/null
+++ b/bin/sm-ipmi-key.go
@@ -0,0 +1,42 @@
1package main
2
3// A key generator that generates magic keys
4// go run sm-ipmi-key.go
5
6import (
7 "crypto/hmac"
8 "crypto/sha1"
9 "encoding/hex"
10 "fmt"
11 "os"
12 "strings"
13)
14
15const secretKey = "8544E3B47ECA58F9583043F8"
16
17func mustUnhex(s string) []byte {
18 o, err := hex.DecodeString(s)
19 if err != nil {
20 panic(err)
21 }
22 return o
23}
24
25func main() {
26 // Cleanup mac
27 mac := strings.ReplaceAll(strings.ToLower(os.Args[1]), ":", "")
28
29 // Create hash
30 hash := hmac.New(sha1.New, mustUnhex(secretKey))
31 hash.Write(mustUnhex(mac))
32 res := hex.EncodeToString(hash.Sum(nil))
33
34 // Cut into groups of 4 characters
35 out := make([]string, 24/4)
36 for i := 0; i < 24/4; i++ {
37 out[i] = res[:24][i*4 : i*4+4]
38 }
39
40 // Print the groups with spaces between them
41 fmt.Println(strings.Join(out, " "))
42}