Skip to content

Commit

Permalink
Derive TPM seed from system UUID (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
Itxaka committed Dec 16, 2022
1 parent 1fe8838 commit 76d2bb3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/register/register.go
Expand Up @@ -21,6 +21,7 @@ import (
"crypto/x509"
"fmt"
"io"
"math/big"
"math/rand"
"net/http"
"strings"
Expand All @@ -37,13 +38,26 @@ import (
)

func Register(url string, caCert []byte, smbios bool, emulateTPM bool, emulatedSeed int64) ([]byte, error) {

tpmAuth := &tpm.AuthClient{}
if emulateTPM {
logrus.Info("Enable TPM emulation")
if emulatedSeed == -1 {
emulatedSeed = rand.Int63()
logrus.Debugf("TPM emulation set to -1, setting random seed: %d", emulatedSeed)
data, err := ghw.Product(ghw.WithDisableWarnings())
if err != nil {
emulatedSeed = rand.Int63()
logrus.Debugf("TPM emulation using random seed: %d", emulatedSeed)
} else {
uuid := strings.Replace(data.UUID, "-", "", -1)
var i big.Int
_, converted := i.SetString(uuid, 16)
if !converted {
emulatedSeed = rand.Int63()
logrus.Debugf("TPM emulation using random seed: %d", emulatedSeed)
} else {
emulatedSeed = i.Int64()
logrus.Debugf("TPM emulation using system UUID %s, resulting in seed: %d", uuid, emulatedSeed)
}
}
}
tpmAuth.EmulateTPM(emulatedSeed)
}
Expand Down

0 comments on commit 76d2bb3

Please sign in to comment.