Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Restricted TPM keys, such as AKs, are usually used to sign objects generated within the TPM, such as quotes. However, they can also be used for signing data that was not generated within the TPM, if the data does not start with TPM_GENERATED_VALUE. This requires hashing the data to-be-signed by the TPM and retrieving a validation ticket together with the digest from the TPM.
It can be useful, e.g., to generate a self-signed Certificate Signing Request for the AK and then retrieve AK certificates from CAs (which are able to perform credential activation) via standard protocols such as Enrollment over Secure Transport (EST). EST mandates that the CSR is self-signed with the corresponding private key (RFC 7030, Section 4.2.1), so this is imho the only possibility to be EST compliant.
This pull request therefore adds a sign() method to the AK interface for signing arbitrary objects. Furthermore, it adds a hash() method to the TPM interface, as the data to-be-signed by a restricted key must be hashed within the TPM to retrieve a TPM validation ticket. The existing internal sign() method of the wrappedKey20 implementation was extended with a validation ticket parameter to be able to prove that the data was hashed within the TPM.
Note: currently, I only implemented this additional functionality for the Linux TPM2.0. The TPM1.2 and Windows TPM throw a "not implemented" error if the new methods are called.