-
Notifications
You must be signed in to change notification settings - Fork 10
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
VerifySignature returning TPM_RC_SIGNATURE #10
Comments
FWIW here is doing what I think should be the same steps using the tpm2-tools scripts by hand:
|
The main issue is that the digest that is signed for TPM2_PolicyAuthorize contains both the approved policy digest and the policy reference, so VerifySignature fails because it is verifying the wrong digest. You can use https://pkg.go.dev/github.com/canonical/go-tpm2@v0.1.1-0.20220823192114-7a7993f0fa1f/util#ComputePolicyAuthorizeDigest to compute the digest that VerifySignature expects, which takes the approved policy digest (in this case, the current session digest read back with TPM2_PolicyGetDigest) and the policy reference used when creating the original policy (the one passed to https://pkg.go.dev/github.com/canonical/go-tpm2@v0.1.1-0.20220823192114-7a7993f0fa1f/util#TrialAuthPolicy.PolicyAuthorize if you're using that). Also, you can use https://pkg.go.dev/github.com/canonical/go-tpm2@v0.1.1-0.20220823192114-7a7993f0fa1f/mu to serialize and unserialize any TPM type (even types defined outside of this package) - so rather than reading in some bytes and then manually constructing the tpm2.Signature, you can use https://pkg.go.dev/github.com/canonical/go-tpm2@v0.1.1-0.20220823192114-7a7993f0fa1f/mu#MarshalToWriter to save the entire structure, and then https://pkg.go.dev/github.com/canonical/go-tpm2@v0.1.1-0.20220823192114-7a7993f0fa1f/mu#UnmarshalFromReader to read it back again. |
Sorry, I obviously have a wrong mental model on how some of this is implemented... What is "the policy reference"? Is that actually a reference to the policy calculated thus far on the tpm itself? Since this is not a trial policy, I need the TPM to perform the policypcr and policynv actions "for real", naturally. Then I need to pass the policy signature verification pubkey, and the policy signature, to the TPM, so it can verify this is a legit policy. Are you saying I should use util/ComputePolicyAuthorizeDigest in place of tpm.PolicyGetDigest and pass that result to tpm.VerifySignature? If so, what should the policyRef Nonce be? |
I tried simply doing
After calculating |
Oh - I think you might be saying that I should change the signature that I calculated in the first place? That would be unfortunate, but I can try that... Currently we do these steps: https://github.com/puzzleos/tpm_eapol_scripts/blob/master/read/tpm-read-secret.sh and this works, so the concatting of the 'policyref' is not strictly required by the TPM, at least. |
So just to be sure this is clear, at https://github.com/project-machine/trust/blob/master/lib/tpm2.go#L542 I have written out the digest to a file, and verified it is identical to the policy file which I signed, which signature is then (assigned to 's' and) passed into tpm2.VerifySignature. |
The policy reference can be used to reduce the scope of an authorized policy in the scenario where the person signing them might sign digests that have different uses. It's a static value that is chosen when the authorization policy associated with an object is created, and can be empty. Eg:
This creates an authorization policy that allows an entity with the private key to authorize policies with the policy reference "PCR-POLICY". The value of the policy reference is incorporated into the computed policy digest.
The signed policy is a signature over a digest that includes both the approved policy and the policy reference (this digest is computed by
The returned digest is the actual digest that was signed, and the one that should be passed to VerifySignature. You can either save this digest, or construct it again later on before calling VerifySignature:
You'll need to do this even for an empty policy reference because this is what TPM2_PolicyAuthorize does when verifying that the ticket matches the supplied parameters. In the case where the reference is empty, the digest is just becomes The reason this works with https://github.com/puzzleos/tpm_eapol_scripts/blob/master/read/tpm-read-secret.sh is because |
Thanks, and sorry for taking your time. Just to be clear, passing []byte("") for policyref should be the same as not having a policy ref at all? I do believe I tried that, but it sounds like I may be getting tripped up needing to do one more digest. I think the most promising approach for me will be to start with a minimal standalone test program until I get that right. |
Sorry, I missed this reply. You don't have to pass |
I'm doing basically the following code:
and getting
I've written 'digest' to disk, and verified it's identical to the policy
I had pre-generated, as well as that the signature read by t.readSignature(),
using the public key loaded into key, verifies correctly with:
Given that the signature file being read from disk is the binary blob,
should I be parsing it somehow rather than simply reading it into a []byte
and casting that to tpm2.Digest ?
The text was updated successfully, but these errors were encountered: