Skip to content

Adds the attest structures #293

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 17 commits into from
Dec 2, 2021

Conversation

Superhepper
Copy link
Collaborator

Adds the Attest type and all the different attest info types.

Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

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

🤯 That's a lot of new types, thanks!! Looks pretty good overall, had just a few comments/questions.

I'm also curious, I thought there was at least one place where one of the FFI types is used, TPM2B_ATTEST, I think. Did you not want to update that yet?

Copy link
Collaborator

@wiktor-k wiktor-k left a comment

Choose a reason for hiding this comment

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

Quite a nice collection of types.
They are currently not used by any context methods? Just curious how would they fit in the larger scheme of things here...

@Superhepper
Copy link
Collaborator Author

From a pure functionality point of view there is little difference. But the new traits are more explicit, the data they produce and consumes are not just any bytes it is specifically the bytes that are produced or consumed by the Tss2_MU_* functions for each individual type.

@wiktor-k
Copy link
Collaborator

Good point. Thanks for the explanation @Superhepper and @ionut-arm 👍!

@Superhepper
Copy link
Collaborator Author

The types will be used later by context method implementation of TPM2_Certify for example. I actually took some code from the @ionut-arm Certify PR and made the types more 'complete'.

@Superhepper
Copy link
Collaborator Author

🤯 That's a lot of new types, thanks!! Looks pretty good overall, had just a few comments/questions.

I'm also curious, I thought there was at least one place where one of the FFI types is used, TPM2B_ATTEST, I think. Did you not want to update that yet?

I was so focused on the Attest type and all the info types that I did not even think of to check if the TPM2B_ATTEST or TPMS_ATTEST was used any where. But I fixed that now.

Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

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

👍🏻

- Adds YesNo interface type that corresponds to the TPMI_YES_NO.
  It can be used to correct convert interface type to YseNo or to bool.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the AttestationType as a structure tags interface type.
  This corresponds to the TPMI_ST_ATTEST Type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the AttestBuffer strucuture this corresponds to the
  TPM2B_ATTEST structure.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the ClockInfo type this corresponds to the TPMS_CLOCK_INFO
  type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Added CertifyInfo type this corresponds to the
  TPMS_CERTIFY_INFO type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the QuoteInfo type, this corresponds to the TPMS_QUOTE_INFO
  type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the TimeInfo type, this corresponds to the TPMS_TIME_INFO
  type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the TimeAttestInfo type, this corresponds to the
  TPMS_TIME_ATTEST_INFO type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the CommandAuditInfo type, this corresponds to the
  TPMS_COMMAND_AUDIT_INFO type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the SessionAuditInfo type, this corresponds to the
  TPMS_SESSION_AUDIT_INFO structure.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the CreationInfo type, this corresponds to the
  TPMS_CREATION_INFO type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the NvCertifyInfo type, this corresponds to the
  TPMS_NV_CERTIFY_INFO type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the NvDigestCertifyInfo type, this corresponds to the
  TPMS_NV_DIGEST_CERTIFY_INFO type that was added in the 3.1.0
  version of the tpm2-tss library. And in the r1.59 version of the
  TPM 2.0 specification.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Adds the Attest and AttestInfo types. The Attest type corresponds
  to the TPMS_ATTEST and the AttestInfo type corresponds somewhat
  to the TPMU_ATTEST type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
@Superhepper
Copy link
Collaborator Author

@wiktor-k: Is there something you would like to be changed before this can be merged?

@wiktor-k
Copy link
Collaborator

wiktor-k commented Dec 2, 2021

I've re-read it all and the only place I'm less-than-super-positive is unsafe { buffer.set_len(offset as usize) };. I'm wondering if truncate is not sufficient in this case? Maybe I'm paranoid but I wouldn't want the vector to contain some random memory in case offset is bigger than the initial capacity.

If you think it's good as it is I won't block it though :)

@Superhepper
Copy link
Collaborator Author

I've re-read it all and the only place I'm less-than-super-positive is unsafe { buffer.set_len(offset as usize) };. I'm wondering if truncate is not sufficient in this case? Maybe I'm paranoid but I wouldn't want the vector to contain some random memory in case offset is bigger than the initial capacity.

If you think it's good as it is I won't block it though :)

Well truncate wont work here because the vector can in this case not know the number of bytes that have been written to it.

What can be done is to allocate an array with a maximum size and write the data to it and then convert a slice of that array into an vector. It would require some extra copying. But it might be worth it in order to avoid the unsafe part.

Copy link
Collaborator

@wiktor-k wiktor-k left a comment

Choose a reason for hiding this comment

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

Nah, I think it's fine it just looks weird on first sight. The same issue happens in cryptoki that you're supposed to pass a buffer big enough end then cut it. I was also thinking about running drop on elements outside of len but since this is just u8s then there's nothing to worry about.

This is good for me after your explanations, not sure if rewriting to use arrays would be the best use of your time :)

@Superhepper
Copy link
Collaborator Author

I actually come up with a way to use truncate instead. Will change it in one sec.

- Adds Marshall trait for types that can be marshalled
  into TPM marshalled data.

- Adds UnMarshall trait for types that can be un marshalled
  from TPM marshalled data.

- Implemented Marshall and UnMarshall trait for the Attest type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
- Changes the retur type of the Context method quote from
  TPM2B_ATTEST to the new Attest type.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
@wiktor-k
Copy link
Collaborator

wiktor-k commented Dec 2, 2021

Ha, very cool! One less unsafe thing to worry about. Thanks for taking the extra steps for safety @Superhepper. 👍

Fixed Clippy and compile errors that occured when upgrading
to version 1.57 of the rust compiler.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
@Superhepper Superhepper merged commit 5fcf5c8 into parallaxsecond:main Dec 2, 2021
@Superhepper Superhepper deleted the attest_structures branch July 3, 2022 09:47
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.

3 participants