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

Implement some additional hierarchy control and dictionary attack functions for TPM2 #109

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

chrisccoulson
Copy link

This adds API's for clearing the TPM, disabling the ability to clear the TPM with owner authorization, changing the hierarchy authorization values and configuring dictionary attack parameters.

This adds an API for calling TPM2_Clear with password authentication
This adds a simple API that wraps the TPM2_DictionaryAttackParameters command.
This adds an API that wraps around the TPM2_HierarchyChangeAuth command
so that authorization values for the various hierarchies can be set.
This adds an API that wraps around TPM2_ClearControl to disable the
ability to clear the TPM with owner authorization. As re-enabling owner
clear requires platform authorization, the API only supports disabling
owner clear (ie, TPM2_ClearControl called with disable=YES")
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

cmatsuoka added a commit to cmatsuoka/snapd that referenced this pull request Jul 9, 2019
Execute TPM provisioning on install using Chris Coulson's FDE utils code
from https://github.com/chrisccoulson/ubuntu-core-fde-utils. This also
requires google/go-tpm#109.

Try to provision the TPM as late as possible to prevent a situation
where the installation fails after the TPM is provisioned. Provisioning
happens just before sealing the LUKS device keyfile and the lockout
authorization value is stored inside the encrypted partition.

Signed-off-by: Claudio Matsuoka <[email protected]>
cmatsuoka added a commit to cmatsuoka/snapd that referenced this pull request Jul 9, 2019
Execute TPM provisioning on install using Chris Coulson's FDE utils code
from https://github.com/chrisccoulson/ubuntu-core-fde-utils. This also
requires google/go-tpm#109 which has been added
to vendored packages.

Try to provision the TPM as late as possible to prevent a situation
where the installation fails after the TPM is provisioned. Provisioning
happens just before sealing the LUKS device keyfile and the lockout
authorization value is stored inside the encrypted partition.

Signed-off-by: Claudio Matsuoka <[email protected]>
Copy link
Contributor

@awly awly left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.
Please also sign the CLA per the above comment

cmdIncrementNVCounter tpmutil.Command = 0x00000134
cmdWriteNV tpmutil.Command = 0x00000137
cmdPCREvent tpmutil.Command = 0x0000013C
cmdDictionaryAttackParameters tpmutil.Command = 0x0000013A
Copy link
Contributor

Choose a reason for hiding this comment

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

Move it one line higher, to keep sorted order

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I've done that now.

return concat(ha, auth)
}

func Clear(rw io.ReadWriter, hierarchy tpmutil.Handle, password string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add doc comments to all exported funcs

Copy link
Author

Choose a reason for hiding this comment

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

Done.

tpm2/tpm2.go Outdated
}

func encodeDisableOwnerClear(password string) ([]byte, error) {
lockout, err := tpmutil.Pack(HandleLockout)
Copy link
Contributor

Choose a reason for hiding this comment

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

Pass the handle as argument

tpm2/tpm2.go Outdated
if err != nil {
return nil, err
}
param, err := tpmutil.Pack(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Pass this as argument

tpm2/tpm2.go Outdated
return concat(lockout, auth, param)
}

func DisableOwnerClear(rw io.ReadWriter, password string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Change this to ClearControl and take hierarchy and enable/disable as arguments

Copy link
Author

Choose a reason for hiding this comment

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

I've updated this now.

}
defer FlushContext(rw, rootHandle)

persistentHandle := tpmutil.Handle(0x817FFFFF)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment explaining where this value comes from

Copy link
Author

Choose a reason for hiding this comment

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

I just copied this value from other tests in tpm2_test.go.

@awly awly added the kokoro:run Enable presubmit tests for non-org members label Jul 10, 2019
@kokoro-team kokoro-team removed the kokoro:run Enable presubmit tests for non-org members label Jul 10, 2019
@chrisccoulson
Copy link
Author

Thanks for the PR.
Please also sign the CLA per the above comment

I've hit this issue in the past, but I should be part of Canonical's corporate CLA with Google now.

@awly
Copy link
Contributor

awly commented Jul 11, 2019

Thanks for the PR.
Please also sign the CLA per the above comment

I've hit this issue in the past, but I should be part of Canonical's corporate CLA with Google now.

Did you add your Canonical email address to the GitHub account? You can check it under https://github.com/settings/emails. It doesn't need to be primary, but needs to be added there.

tpm2/tpm2.go Outdated
return concat(handle, auth, param)
}

// Control whether the TPM can be cleared with the Clear() API. Calling this with the third parameter set to
Copy link
Contributor

Choose a reason for hiding this comment

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

Per https://golang.org/doc/effective_go.html#commentary, the comment must start with // ClearControl ...

Copy link
Author

Choose a reason for hiding this comment

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

Done

tpm2/tpm2.go Outdated
return concat(lockout, auth, params)
}

// Change the dictionary attack lockout parameters. The first parameter is the number of authorization failures
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, start comment with // SetDictionaryAttackParameters ...

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the PR.
Please also sign the CLA per the above comment

I've hit this issue in the past, but I should be part of Canonical's corporate CLA with Google now.

Did you add your Canonical email address to the GitHub account? You can check it under https://github.com/settings/emails. It doesn't need to be primary, but needs to be added there.

My Canonical email address is registered with my github account. Note that I was only added to the CCLA after submitting this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I don't see anything wrong.
One last thing to check - did you change your github username since getting added to the CLA? Or perhaps there was a typo in it?

I've emailed our internal team responsible for this CLA github bot, will let you know when we figure out the problem.

Copy link
Member

@josephlr josephlr left a comment

Choose a reason for hiding this comment

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

LGTM from the perspective of properly encoding the auth areas and decoding the responses (fairly easy as none of these commands return anything).

My only concern is that all of these commands use passwords for their authentication. We're trying to avoid having two methods for each command (Foo and FooWithAuth). However, I think this is actually fine, because these commands only use the Hierarchy handles, and those handles can only use password-based authorization.

@awly, do you know if this is actually true? It shouldn't be possible/necessary to do policy auth with things like HandleEndorsement or HandlePlatform.

@josephlr
Copy link
Member

@chrisccoulson I know we have a CLA on file w/ Cannonical, so if you can resolve the merge conflicts, I can just override the CLA check.

@awly
Copy link
Contributor

awly commented Jul 22, 2019

@awly, do you know if this is actually true? It shouldn't be possible/necessary to do policy auth with things like HandleEndorsement or HandlePlatform.

Sorry, I don't know.
But I think it's a good idea to standardize on taking AuthCommand as argument everywhere instead of password strings.

@chrisccoulson I know we have a CLA on file w/ Cannonical, so if you can resolve the merge conflicts, I can just override the CLA check.

I have a few email threads going about this, with @chrisccoulson and our internal CLA team.
Let's not override the CLA check if we can resolve this.

@Grazfather
Copy link

Grazfather commented Mar 5, 2020

Just poking here, 'cause I had hacked in some of the same functionality, and it would be nice to have these officially supported!

EDIT: Looks like it's partially implemented in #163

@langbeck
Copy link
Contributor

@awly and @josephlr, do you have any updates on this CLA issue?
I will need this functionality soon and, as @Grazfather said, it would be nice to have these officially supported.

@josephlr
Copy link
Member

The CLA stuff shouldn't be a problem, as Cannonical has singed a new CLA w/ Google since the last update here. If there's still an issue, I'll manually override the CI if a rebase doesn't get the check to work correctly.

If @chrisccoulson is willing to rebase this on latest master (see #163 which implemented some of this functionality), I'd merge it.

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.

7 participants