Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing Name for 'SignHandle' parameter #361

Open
jeremyhahn opened this issue Jun 26, 2024 · 3 comments
Open

missing Name for 'SignHandle' parameter #361

jeremyhahn opened this issue Jun 26, 2024 · 3 comments

Comments

@jeremyhahn
Copy link

jeremyhahn commented Jun 26, 2024

I'm running into strange behavior. I'm getting this error when I invoke my remote attestation process via grpc to issue a quote, but when I run the same method the grpc service is calling via a unit test, it passes without the error.

The test is here:
https://github.com/jeremyhahn/go-trusted-platform/blob/fdcdbf0f626afb7c9a80311fbdcd2ccb3bcb3a55/tpm2/tpm_test.go#L59

The quote method is here:
https://github.com/jeremyhahn/go-trusted-platform/blob/fdcdbf0f626afb7c9a80311fbdcd2ccb3bcb3a55/tpm2/tpm.go#L1081

To run the remote attestation service, from the project root:

Attestor

make attestor

Verifier

make verifier

Verifier log:
rpc error: code = Unknown desc = missing Name for 'SignHandle' parameter

If I change the KnownName() method in tpm2/structures.go to the include TPMIDHSavedTransientClear in the Empty Buffer return, the error goes away and the service runs as expected.

func (h TPMHandle) KnownName() *TPM2BName {
	switch (TPMHT)(h >> 24) {
	case TPMHTPCR, TPMHTHMACSession, TPMHTPolicySession, TPMHTPermanent:
		result := make([]byte, 4)
		binary.BigEndian.PutUint32(result, h.HandleValue())
		return &TPM2BName{Buffer: result}
	case TPMHTTransient:
		// The Name of a sequence object is an Empty Buffer
		// See part 1: Architecture, section 32.4.5
		if h == TPMIDHSavedSequence || h == TPMIDHSavedTransientClear {
			return &TPM2BName{
				Buffer: []byte{},
			}
		}
	}
	return nil
}

I'm just getting my feet wet with the tpm2 library and don't fully understand the implications of this change. It appears this code is intentionally ignoring transient handles with the stClear attribute set (which seems to make sense). I've scoured the internet and TCG docs trying to find anything that specifies whether the stClear attribute should also default to an Empty Buffer but I haven't had any luck.

Is this a bug in the KnownName method that needs to be fixed or am I barking up the wrong tree? Any insights into why the code works fine in the unit tests but fails during the grpc calls?

@chrisfenner
Copy link
Member

Thanks for filing this @jeremyhahn! I suspect you've found an edge-case in object naming that's not handled well by KnownName. Let me see if I can reproduce your error and come to a working theory of the issue.

Is your device/TPM undergoing any type of power state transition?

@jeremyhahn
Copy link
Author

jeremyhahn commented Jun 27, 2024

The tests are using the simulator but I get the same error on a real TPM. No power state transitions.

@nckrss
Copy link
Contributor

nckrss commented Sep 20, 2024

@jeremyhahn you may have been seeing a false positive in the test related to #370.

In your example you need to use a NamedHandle or AuthHandle to provide the Name because CreateLoadedResponse returns a transient handle, which means that the Name is calculated and not known based on the Most Significant Octet of the handle. Since it is calculated (Part 1 Architecture Section 16 Table 3) you must provide it from the response, hence the CreateLoadedResponse.Name field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants