mirror of
https://github.com/kairos-io/tpm-helpers.git
synced 2025-09-19 16:29:45 +00:00
Add EmulatedHostSeed option
Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
This commit is contained in:
23
config.go
23
config.go
@@ -1,7 +1,9 @@
|
|||||||
package tpm
|
package tpm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"hash/fnv"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/google/go-attestation/attest"
|
"github.com/google/go-attestation/attest"
|
||||||
)
|
)
|
||||||
@@ -67,6 +69,27 @@ func WithCommandChannel(cc attest.CommandChannelTPM20) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hashit(s string) uint32 {
|
||||||
|
h := fnv.New32a()
|
||||||
|
h.Write([]byte(s))
|
||||||
|
return h.Sum32()
|
||||||
|
}
|
||||||
|
|
||||||
|
func tokenize() int64 {
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int64(hashit(hostname))
|
||||||
|
}
|
||||||
|
|
||||||
|
var EmulatedHostSeed = func() Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.seed = tokenize()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *config) apply(opts ...Option) error {
|
func (c *config) apply(opts ...Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
if err := o(c); err != nil {
|
if err := o(c); err != nil {
|
||||||
|
Reference in New Issue
Block a user