google / google/go-tpm-tools

Validate max size of import blob.

Open
#559 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
309
Forks
118
Avg merge
1d 16h
Merged PRs (30d)
33

Description

Import blob appears to only handle sensitive data with a max of 128 bytes. See this test:

```go
package client_test

import (
"fmt"
"io"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
tpmclient "github.com/google/go-tpm-tools/client"
tpmserver "github.com/google/go-tpm-tools/server"
"github.com/google/go-tpm-tools/simulator"
)

func TestImportE2E(t *testing.T) {
sim, err := simulator.Get()
if err != nil {
t.Fatal(err)
}
defer sim.Close()

for i := 0; i < 256; i++ {
t.Run(fmt.Sprint(i), func(t *testing.T) {
testImport(t, sim, i)
})
}

}

func testImport(t *testing.T, tpmDev io.ReadWriteCloser, size int) {
ek, err := tpmclient.EndorsementKeyRSA(tpmDev)
if err != nil {
t.Fatal(err)
}
defer ek.Close()

secret := strings.Repeat("s", size)
blob, err := tpmserver.CreateImportBlob(ek.PublicKey(), []byte(secret), nil)
if err != nil {
t.Fatal(err)
}

out, err := ek.Import(blob)
if err != nil {
t.Fatalf("Import failed: size=%v, err=%v", size, err)
}
if diff := cmp.Diff(string(out), secret); diff != "" {
t.Errorf("unexpected output (-got +want): %s", diff)
}
}
```

At message size of 129 bytes and beyond, this test starts failing with:
```
Import failed: size=129, err=import failed: parameter 3, error code 0x15 : structure is the wrong size
```

Is that by the TPM spec or is there a something wrong with the encoding?

Contributor guide

Open the contributing guide

Research direction

Start with the provided TestImportE2E reproduction, then trace CreateImportBlob and ek.Import to inspect how the sensitive data size is encoded and passed to the TPM. Compare the behavior at 128 and 129 bytes with the TPM specification. Done means establishing whether the limit is specified or an encoding defect, then adding regression coverage and fixing or documenting the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.