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

fix MakeCredential return value error #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Zha0Chan
Copy link

Return value in
func MakeCredential(rand io.Reader, key *tpm2.Public, credential tpm2.Digest, objectName tpm2.Name) (credentialBlob tpm2.IDObject, secret tpm2.EncryptedSecret, err error)

The prototypes of credentialBlob tpm2.IDObject and secret tpm2.EncryptedSecret are respectively IDObject corresponding to the TPM2B_ID_OBJECT type. EncryptedSecret corresponds to the TPM2B_ENCRYPTED_SECRET type.
The prototypes of these two types are as follows

/* Definition of TPM2B_ID_OBJECT Structure <INOUT> */
typedef struct {
    UINT16 size;
    BYTE credential[sizeof(TPMS_ID_OBJECT)];
} TPM2B_ID_OBJECT;
/* Definition of TPM2B_ENCRYPTED_SECRET Structure */
typedef struct {
    UINT16 size;
    BYTE secret[sizeof(TPMU_ENCRYPTED_SECRET)];
} TPM2B_ENCRYPTED_SECRET;

The first two bytes in each structure identify the length of the content, which is not included in the original code, so the fix is as follows:

func MakeCredential(rand io.Reader, key *tpm2.Public, credential tpm2.Digest, objectName tpm2.Name) (credentialBlob tpm2.IDObject, secret tpm2.EncryptedSecret, err error) {
...
credentialBlob, err = mu.MarshalToBytes(credentialBlob)
if err != nil {
return nil, nil, fmt.Errorf("cannot marshal credential bytes: %w", err)
}
	
secret, err = mu.MarshalToBytes(secret)
if err != nil {
return nil, nil, fmt.Errorf("cannot marshal secret bytes: %w", err)
}
return credentialBlob, secret, nil
}

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.

1 participant