-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add method to obtain TPM capabilities #580
Conversation
|
1d37a0b
to
45647ae
Compare
@hslatman Any examples on how I would go about testing the |
45647ae
to
c786adc
Compare
3820749
to
858f286
Compare
858f286
to
44310bb
Compare
var ( | ||
v algorithmAttributes | ||
ok bool | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defining these here seems unnecessary if you make them assignments in both parts below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v
is used further down, I could refactor more of this code if you feel strongly.
I take it you mean the The test would be limited to what the TPM simulator returns in terms of supported algorithms, which would always be the same, unless recompiled per test case, which doesn't sound enticing to me 😅 AFAIK there's no way to reconfigure the TPM simulator at runtime. To have more test variability we could look into mocking TPM responses on the |
Co-authored-by: Herman Slatman <[email protected]>
Co-authored-by: Herman Slatman <[email protected]>
Co-authored-by: Herman Slatman <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Just a linting issue left
kms/tpmkms/tpmkms_simulator_test.go
Outdated
@@ -59,10 +59,19 @@ func withKey(name string) newSimulatedTPMOption { | |||
} | |||
} | |||
|
|||
func newSimulatedTPM(t *testing.T, opts ...newSimulatedTPMOption) *tpmp.TPM { | |||
func newSimulatedTPM(t *testing.T, caps *tpmp.Capabilities, opts ...newSimulatedTPMOption) *tpmp.TPM { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you turn the capabilities into a newSimulatedTPMOption
, like withAK
and withKey
, only not operating on the tpm.TPM
instance? Then it can remain variadic, and won't require changing it in the tests where you're now passing nil
. It'll still need the special case to properly create the TPM instance, so there's still some logic needed to switch between "initialization" and "preparation" options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I'll work on this more - I wanted to do that originally, but I think I'll have to change how options work between this package and the tpm
package to be able to actually modify the capabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it can be done by changing the newSimulatedTPMOption
to also return a type or bool (or to rework that into a struct), and to use that to differentiate between initialization and preparation options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hslatman Unless I'm not following you, I can't change this behavior without either exporting something from the tpm
package to control the capabilities while under test (eg: either a helper Option
setter, the options
struct and field, etc.). I've removed that test code for now: what do you think about either mocking the tpm
package itself or adding support to the Simulator
to override the capabilities, eg (in the simulator
package):
// the packed command buffer for CmdGetCapability (0x17A)
var getCapabilityAlgs = []byte{128, 1, 0, 0, 0, 22, 0, 0, 1, 122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
func (s *WrappingSimulator) Write(p []byte) (int, error) {
if bytes.Equal(p, getCapabilityAlgs) {
// ...
}
return s.wrapped.Write(p)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you don't mind, I'll keep working on better tests for this after merging, so we can unblock work depending on these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the test you had back in #590 and merged that into this branch. You're right we'll need that WithCapabilities
method exported; didn't think about the package boundary. I've marked it experimental, and noted that it's primarily used for testing.
Some form of emulating responses from a TPM might be useful for future tests, and it would be great to have that available in plain Go, but I think it would be best in a new package, and not (partially) reliant on the C simulator (or at least separate from the current simulator code). I know Panos has looked a bit into generating Go code from the spec, so that might be a way to do it.
v algorithmAttributes | ||
ok bool | ||
) | ||
if !properties.ak && req.SignatureAlgorithm == apiv1.UnspecifiedSignAlgorithm && len(preferredSignatureAlgorithms) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw the usage of withAK
and was thinking how that could succeed, and then found that the algorithm is ignored here. I think that's fine for now, but we may want to add the capability check for AK creation too at some point. But IIRC AKs have stricter requirements, so there might be algorithms that will just fail at the TPM level.
e0ff582
to
3f1a5d6
Compare
Change the simulated TPM options to accept initializers and preparers
This PR adds support for interrogating the TPM capabilities. The capabilities currently reported are the supported algorithms of the TPM.
As well, the TPMKMS will now:
Future improvements may also ensure that the TPM supports the relevant hash/curve functions during sign operations.
💔Thank you!