Skip to content

Commit

Permalink
Merge pull request #428 from smallstep/mariano/parent
Browse files Browse the repository at this point in the history
Do not overflow default handle on 32 bits architectures
  • Loading branch information
maraino committed Feb 15, 2024
2 parents 4967ab9 + 0d9fd4e commit e352efd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tpm/internal/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const (
nvramEkNonceIndex = 0x1c00003

// Defined in "Registry of reserved TPM 2.0 handles and localities", and checked on a glinux machine.
commonSrkEquivalentHandle = 0x81000001
commonEkEquivalentHandle = 0x81010001
commonSrkEquivalentHandle = tpmutil.Handle(0x81000001)
commonEkEquivalentHandle = tpmutil.Handle(0x81010001)
)

// Key encodings
Expand Down
4 changes: 3 additions & 1 deletion tpm/tss2.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tpm
import (
"context"

"github.com/google/go-tpm/tpmutil"

"go.step.sm/crypto/tpm/tss2"
)

Expand All @@ -11,7 +13,7 @@ const (
// and checked on a glinux machine. This is the default parent handle
// used by go-tpm and go-attestation, and thus also the default handle
// set when marshaling to the TSS2 format.
commonSrkEquivalentHandle = 0x81000001
commonSrkEquivalentHandle = tpmutil.Handle(0x81000001)
)

// ToTSS2 gets the public and private blobs and returns a [*tss2.TPMKey].
Expand Down
10 changes: 6 additions & 4 deletions tpm/tss2/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package tss2

import (
"encoding/pem"

"github.com/google/go-tpm/tpmutil"
)

// handleOwner is the reserved handle TPM_RH_OWNER.
const handleOwner = 0x40000001
const handleOwner = tpmutil.Handle(0x40000001)

// TPMOption is the type used to modify a [TPMKey].
type TPMOption func(*TPMKey)

// WithParent sets the [TPMKey] parent handle.
func WithParent(parent int) TPMOption {
func WithParent(parent tpmutil.Handle) TPMOption {
return func(t *TPMKey) {
t.Parent = parent
t.Parent = int(parent)
}
}

Expand All @@ -22,7 +24,7 @@ func New(pub, priv []byte, opts ...TPMOption) *TPMKey {
key := &TPMKey{
Type: oidLoadableKey,
EmptyAuth: true,
Parent: handleOwner,
Parent: int(handleOwner),
PublicKey: addPrefixLength(pub),
PrivateKey: addPrefixLength(priv),
}
Expand Down

0 comments on commit e352efd

Please sign in to comment.