Skip to content

Implement TCP TPM protocol #387

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

Merged
merged 2 commits into from
Feb 3, 2025
Merged

Implement TCP TPM protocol #387

merged 2 commits into from
Feb 3, 2025

Conversation

chrisfenner
Copy link
Member

This change implements the basic TCP TPM protocol, which is useful for connecting to a running TPM simulator. It also introduces some tests which are skipped if the --cmd_addr or --plat_addr flags aren't provided.

To aid in testing, this change also implements ReadClock.

A number of TCP commands aren't implemented and left for a future change.

Tested against a recent build of the TCG TPM simulator from https://github.com/trustedcomputinggroup/tpm

@chrisfenner chrisfenner requested review from alexmwu, jkl73 and a team as code owners January 24, 2025 16:43
@chrisfenner chrisfenner force-pushed the tcp-tpm branch 3 times, most recently from 74770b9 to c6153e6 Compare January 24, 2025 17:04
This change implements the basic TCP TPM protocol, which is useful for
connecting to a running TPM simulator. It also introduces some tests
which are skipped if the --cmd_addr or --plat_addr flags aren't
provided.

A number of TCP commands aren't implemented and left for a future
change.

Tested against a recent build of the TCG TPM simulator from
https://github.com/trustedcomputinggroup/tpm

use the closeTPM helper, caught by linter

Co-authored-by: anamendes23 <anamendes@google.com>
"github.com/google/go-tpm/tpm2"
)

var (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful for future contributors to give some clear instructions on testing

# get TGC ref impl
# build sim
./TPMCmd/Simulator/src/tpm2-simulator
go test blah

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion, added this.

} else if n != len(rsp) {
return nil, fmt.Errorf("%w: could not read full TPM response: only got %v out of %v bytes", ErrTransport, n, len(rsp))
}
// The server also provides a TCP error code at the end.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this in the implementation? I couldn't find it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// The de-facto TPM-over-TCP protocol is defined by the Reference Implementation.
// See https://github.com/TrustedComputingGroup/TPM/blob/main/TPMCmd/Simulator/include/TpmTcpProtocol.h

type regularCommand uint32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume there's no other way to differentiate regular and plat commands other than reading https://github.com/TrustedComputingGroup/TPM/blob/main/TPMCmd/Simulator/src/TcpServer.c?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, they are in the same namespace together in the C code.

}
if clock2.CurrentTime.ClockInfo.ResetCount != clock1.CurrentTime.ClockInfo.ResetCount {
t.Errorf("resetCount after Restart was %v, want %v",
clock1.CurrentTime.ClockInfo.ResetCount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Errorf("resetCount after Restart was %v, want %v",
clock2.CurrentTime.ClockInfo.ResetCount, clock1.CurrentTime.ClockInfo.ResetCount)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed. Thanks!

@chrisfenner chrisfenner merged commit f37a5ca into google:main Feb 3, 2025
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants