summaryrefslogtreecommitdiff
path: root/bin/sm-ipmi-key.go
blob: 7477e89c00c5679bfaa0b04235d4ff2d5aea0fda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main

// A key generator that generates magic keys
// go run sm-ipmi-key.go

import (
	"crypto/hmac"
	"crypto/sha1"
	"encoding/hex"
	"fmt"
	"os"
	"strings"
)

const secretKey = "8544E3B47ECA58F9583043F8"

func mustUnhex(s string) []byte {
	o, err := hex.DecodeString(s)
	if err != nil {
		panic(err)
	}
	return o
}

func main() {
	// Cleanup mac
	mac := strings.ReplaceAll(strings.ToLower(os.Args[1]), ":", "")

	// Create hash
	hash := hmac.New(sha1.New, mustUnhex(secretKey))
	hash.Write(mustUnhex(mac))
	res := hex.EncodeToString(hash.Sum(nil))

	// Cut into groups of 4 characters
	out := make([]string, 24/4)
	for i := 0; i < 24/4; i++ {
		out[i] = res[:24][i*4 : i*4+4]
	}

	// Print the groups with spaces between them
	fmt.Println(strings.Join(out, " "))
}