All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [tpm2] Issues experimenting with tpm2-tools and keyctl trusted keys
@ 2019-01-23 13:56 Thibaut Sautereau
  0 siblings, 0 replies; 5+ messages in thread
From: Thibaut Sautereau @ 2019-01-23 13:56 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 580 bytes --]

On Wed, Jan 23, 2019 at 01:11:20PM +0000, Fuchs, Andreas wrote:
> have you tried running the same sequences but using tpm2_create
> instead of "keyctl new" and tpm2_unseal instead of "keyctl load" ?
> Just to make sure that the TPM side of things is working ok ?

Yes, using tpm2_create instead of "keyctl new" and tpm2_load+tpm2_unseal
(exclusively with handles) instead of "keyctl load" works perfectly.

> Then it would be narrowed down to finding the diff between the basic
> commands and how keyctl uses them.

Right.

-- 
Thibaut Sautereau
CLIP OS developer

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [tpm2] Issues experimenting with tpm2-tools and keyctl trusted keys
@ 2019-01-23 13:11 Fuchs, Andreas
  0 siblings, 0 replies; 5+ messages in thread
From: Fuchs, Andreas @ 2019-01-23 13:11 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 3258 bytes --]

have you tried running the same sequences but using tpm2_create instead of "keyctl new" and tpm2_unseal instead of "keyctl load" ?
Just to make sure that the TPM side of things is working ok ?

Then it would be narrowed down to finding the diff between the basic commands and how keyctl uses them.
________________________________________
From: tpm2 [tpm2-bounces(a)lists.01.org] on behalf of Thibaut Sautereau [thibaut.sautereau(a)clip-os.org]
Sent: Monday, January 21, 2019 09:16
To: tpm2
Subject: [tpm2] Issues experimenting with tpm2-tools and keyctl trusted keys

Hello folks,

I'm experimenting with TPM 2.0 (using swtpm 0.1.0), tpm2-tools 3.1.3,
tpm2-tss 2.1.0 and the Linux 4.19.16 kernel's trusted keys. I found this
thread [1] about the "policydigest" and "policyhandle" options added to
keyctl but I cannot reproduce the given example [2] using tpm2-tools
instead of the author's Python testing scripts [3]. I wonder if I do
something wrong by executing the following commands:

export TPM2TOOLS_TCTI="device:/dev/tpmrm0"
tpm2_takeownership --clear
# I tried fiddling with the object attributes in the following command
# but AIUI the default ones should be OK
tpm2_createprimary --hierarchy=o --halg=sha256 --kalg=rsa \
        --context=/tmp/primary.context
tpm2_evictcontrol --auth=o --context=/tmp/primary.context \
        --handle=0x80ffffff --persistent=0x81010001
tpm2_createpolicy --policy-file=/tmp/policy.digest --policy-pcr \
        --set-list=sha256:0 --policy-digest-alg=sha256
policydigest=$(xxd -p /tmp/policy.digest | tr -d '\n')
keyid=$(keyctl add trusted test \
        "new 32 keyhandle=0x81010001 hash=sha256 policydigest=$policydigest" @u)
keyctl link @us @s
keyctl pipe $keyid > /tmp/blob.hex

Until here, everything works fine.

Now for testing I want to reimport the key from the blob file, but I
need a handle to a TPM_SE_POLICY and thus need to directly use the TPM
device, as the in-kernel resource manager I was using so far would
prevent me from keeping a policy session "opened". So I re-export
TPM2TOOLS_TCTI just as Javier Martinez Canillas showed on GitHub [4]:

export TPM2TOOLS_TCTI="device:/dev/tpm0"
# --auth-policy-session implies --extend-policy-session
tpm2_createpolicy --policy-pcr --set-list=sha256:0 \
        --policy-digest-alg=sha256 --auth-policy-session
keyctl add trusted test2 \
        "load $(cat /tmp/blob.hex) keyhandle=0x81010001 policyhandle=0x03000000" @u

This last command causes: "add_key: Operation not permitted".
In kernel logs, I have:
        [ 1350.287556] tpm tpm0: A TPM error (2466) occurred unsealing
        [ 1350.289856] trusted_key: key_unseal failed (-1)

The TPM error is 0x9a2, i.e. TPM2_RC_BAD_AUTH. I cannot see what I'm
doing wrong. Do you see something obvious?

[1] https://lkml.org/lkml/2015/11/17/520
[2] https://lkml.org/lkml/2015/11/21/125
[3] https://github.com/jsakkine-intel/tpm2-scripts
[4] https://github.com/tpm2-software/tpm2-tools/issues/510#issuecomment-331385565

Thanks a lot for your time and your work!

--
Thibaut Sautereau
CLIP OS developper
_______________________________________________
tpm2 mailing list
tpm2(a)lists.01.org
https://lists.01.org/mailman/listinfo/tpm2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [tpm2] Issues experimenting with tpm2-tools and keyctl trusted keys
@ 2019-01-23 12:59 Thibaut Sautereau
  0 siblings, 0 replies; 5+ messages in thread
From: Thibaut Sautereau @ 2019-01-23 12:59 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2627 bytes --]

Hello Javier,

On Wed, Jan 23, 2019 at 10:36:22AM +0100, Javier Martinez Canillas wrote:
> Hello Thibaut,
> 
> On 1/21/19 9:16 AM, Thibaut Sautereau wrote:
> > Hello folks,
> > 
> > I'm experimenting with TPM 2.0 (using swtpm 0.1.0), tpm2-tools 3.1.3,
> > tpm2-tss 2.1.0 and the Linux 4.19.16 kernel's trusted keys. I found this
> > thread [1] about the "policydigest" and "policyhandle" options added to
> > keyctl but I cannot reproduce the given example [2] using tpm2-tools
> > instead of the author's Python testing scripts [3]. I wonder if I do
> > something wrong by executing the following commands:
> >
> 
> Did it work for you when using Jarkko's test scripts?

Yes, it did.

> > export TPM2TOOLS_TCTI="device:/dev/tpmrm0"
> > tpm2_takeownership --clear
> > # I tried fiddling with the object attributes in the following command
> > # but AIUI the default ones should be OK
> > tpm2_createprimary --hierarchy=o --halg=sha256 --kalg=rsa \
> > 	--context=/tmp/primary.context 
> > tpm2_evictcontrol --auth=o --context=/tmp/primary.context \
> > 	--handle=0x80ffffff --persistent=0x81010001
> > tpm2_createpolicy --policy-file=/tmp/policy.digest --policy-pcr \
> > 	--set-list=sha256:0 --policy-digest-alg=sha256
> > policydigest=$(xxd -p /tmp/policy.digest | tr -d '\n')
> > keyid=$(keyctl add trusted test \
> > 	"new 32 keyhandle=0x81010001 hash=sha256 policydigest=$policydigest" @u)
> > keyctl link @us @s
> > keyctl pipe $keyid > /tmp/blob.hex
> > 
> > Until here, everything works fine.
> > 
> > Now for testing I want to reimport the key from the blob file, but I
> > need a handle to a TPM_SE_POLICY and thus need to directly use the TPM
> > device, as the in-kernel resource manager I was using so far would
> > prevent me from keeping a policy session "opened". So I re-export
> > TPM2TOOLS_TCTI just as Javier Martinez Canillas showed on GitHub [4]:
> > 
> > export TPM2TOOLS_TCTI="device:/dev/tpm0"
> > # --auth-policy-session implies --extend-policy-session
> > tpm2_createpolicy --policy-pcr --set-list=sha256:0 \
> > 	--policy-digest-alg=sha256 --auth-policy-session
> > keyctl add trusted test2 \
> > 	"load $(cat /tmp/blob.hex) keyhandle=0x81010001 policyhandle=0x03000000" @u
> > 
> 
> You have the policy handle hardcoded to 0x03000000 here, I guess that's correct
> and is the value printed by tpm2_createpolicy in EXTENDED_POLICY_SESSION_HANDLE?

Yes.

> Sorry for saying the obvious, but just in case since I don't see anything wrong
> with your commands.

No worries. Thanks for your help!

-- 
Thibaut Sautereau
CLIP OS developer

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [tpm2] Issues experimenting with tpm2-tools and keyctl trusted keys
@ 2019-01-23  9:36 Javier Martinez Canillas
  0 siblings, 0 replies; 5+ messages in thread
From: Javier Martinez Canillas @ 2019-01-23  9:36 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 3058 bytes --]

Hello Thibaut,

On 1/21/19 9:16 AM, Thibaut Sautereau wrote:
> Hello folks,
> 
> I'm experimenting with TPM 2.0 (using swtpm 0.1.0), tpm2-tools 3.1.3,
> tpm2-tss 2.1.0 and the Linux 4.19.16 kernel's trusted keys. I found this
> thread [1] about the "policydigest" and "policyhandle" options added to
> keyctl but I cannot reproduce the given example [2] using tpm2-tools
> instead of the author's Python testing scripts [3]. I wonder if I do
> something wrong by executing the following commands:
>

Did it work for you when using Jarkko's test scripts?
 
> export TPM2TOOLS_TCTI="device:/dev/tpmrm0"
> tpm2_takeownership --clear
> # I tried fiddling with the object attributes in the following command
> # but AIUI the default ones should be OK
> tpm2_createprimary --hierarchy=o --halg=sha256 --kalg=rsa \
> 	--context=/tmp/primary.context 
> tpm2_evictcontrol --auth=o --context=/tmp/primary.context \
> 	--handle=0x80ffffff --persistent=0x81010001
> tpm2_createpolicy --policy-file=/tmp/policy.digest --policy-pcr \
> 	--set-list=sha256:0 --policy-digest-alg=sha256
> policydigest=$(xxd -p /tmp/policy.digest | tr -d '\n')
> keyid=$(keyctl add trusted test \
> 	"new 32 keyhandle=0x81010001 hash=sha256 policydigest=$policydigest" @u)
> keyctl link @us @s
> keyctl pipe $keyid > /tmp/blob.hex
> 
> Until here, everything works fine.
> 
> Now for testing I want to reimport the key from the blob file, but I
> need a handle to a TPM_SE_POLICY and thus need to directly use the TPM
> device, as the in-kernel resource manager I was using so far would
> prevent me from keeping a policy session "opened". So I re-export
> TPM2TOOLS_TCTI just as Javier Martinez Canillas showed on GitHub [4]:
> 
> export TPM2TOOLS_TCTI="device:/dev/tpm0"
> # --auth-policy-session implies --extend-policy-session
> tpm2_createpolicy --policy-pcr --set-list=sha256:0 \
> 	--policy-digest-alg=sha256 --auth-policy-session
> keyctl add trusted test2 \
> 	"load $(cat /tmp/blob.hex) keyhandle=0x81010001 policyhandle=0x03000000" @u
> 

You have the policy handle hardcoded to 0x03000000 here, I guess that's correct
and is the value printed by tpm2_createpolicy in EXTENDED_POLICY_SESSION_HANDLE?

Sorry for saying the obvious, but just in case since I don't see anything wrong
with your commands.

> This last command causes: "add_key: Operation not permitted".
> In kernel logs, I have:
> 	[ 1350.287556] tpm tpm0: A TPM error (2466) occurred unsealing
> 	[ 1350.289856] trusted_key: key_unseal failed (-1)
> 
> The TPM error is 0x9a2, i.e. TPM2_RC_BAD_AUTH. I cannot see what I'm
> doing wrong. Do you see something obvious?
> 
> [1] https://lkml.org/lkml/2015/11/17/520
> [2] https://lkml.org/lkml/2015/11/21/125
> [3] https://github.com/jsakkine-intel/tpm2-scripts
> [4] https://github.com/tpm2-software/tpm2-tools/issues/510#issuecomment-331385565
> 
> Thanks a lot for your time and your work!
> 

Best regards,
-- 
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tpm2] Issues experimenting with tpm2-tools and keyctl trusted keys
@ 2019-01-21  8:16 Thibaut Sautereau
  0 siblings, 0 replies; 5+ messages in thread
From: Thibaut Sautereau @ 2019-01-21  8:16 UTC (permalink / raw)
  To: tpm2

[-- Attachment #1: Type: text/plain, Size: 2492 bytes --]

Hello folks,

I'm experimenting with TPM 2.0 (using swtpm 0.1.0), tpm2-tools 3.1.3,
tpm2-tss 2.1.0 and the Linux 4.19.16 kernel's trusted keys. I found this
thread [1] about the "policydigest" and "policyhandle" options added to
keyctl but I cannot reproduce the given example [2] using tpm2-tools
instead of the author's Python testing scripts [3]. I wonder if I do
something wrong by executing the following commands:

export TPM2TOOLS_TCTI="device:/dev/tpmrm0"
tpm2_takeownership --clear
# I tried fiddling with the object attributes in the following command
# but AIUI the default ones should be OK
tpm2_createprimary --hierarchy=o --halg=sha256 --kalg=rsa \
	--context=/tmp/primary.context 
tpm2_evictcontrol --auth=o --context=/tmp/primary.context \
	--handle=0x80ffffff --persistent=0x81010001
tpm2_createpolicy --policy-file=/tmp/policy.digest --policy-pcr \
	--set-list=sha256:0 --policy-digest-alg=sha256
policydigest=$(xxd -p /tmp/policy.digest | tr -d '\n')
keyid=$(keyctl add trusted test \
	"new 32 keyhandle=0x81010001 hash=sha256 policydigest=$policydigest" @u)
keyctl link @us @s
keyctl pipe $keyid > /tmp/blob.hex

Until here, everything works fine.

Now for testing I want to reimport the key from the blob file, but I
need a handle to a TPM_SE_POLICY and thus need to directly use the TPM
device, as the in-kernel resource manager I was using so far would
prevent me from keeping a policy session "opened". So I re-export
TPM2TOOLS_TCTI just as Javier Martinez Canillas showed on GitHub [4]:

export TPM2TOOLS_TCTI="device:/dev/tpm0"
# --auth-policy-session implies --extend-policy-session
tpm2_createpolicy --policy-pcr --set-list=sha256:0 \
	--policy-digest-alg=sha256 --auth-policy-session
keyctl add trusted test2 \
	"load $(cat /tmp/blob.hex) keyhandle=0x81010001 policyhandle=0x03000000" @u

This last command causes: "add_key: Operation not permitted".
In kernel logs, I have:
	[ 1350.287556] tpm tpm0: A TPM error (2466) occurred unsealing
	[ 1350.289856] trusted_key: key_unseal failed (-1)

The TPM error is 0x9a2, i.e. TPM2_RC_BAD_AUTH. I cannot see what I'm
doing wrong. Do you see something obvious?

[1] https://lkml.org/lkml/2015/11/17/520
[2] https://lkml.org/lkml/2015/11/21/125
[3] https://github.com/jsakkine-intel/tpm2-scripts
[4] https://github.com/tpm2-software/tpm2-tools/issues/510#issuecomment-331385565

Thanks a lot for your time and your work!

-- 
Thibaut Sautereau
CLIP OS developper

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-23 13:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-23 13:56 [tpm2] Issues experimenting with tpm2-tools and keyctl trusted keys Thibaut Sautereau
  -- strict thread matches above, loose matches on Subject: below --
2019-01-23 13:11 Fuchs, Andreas
2019-01-23 12:59 Thibaut Sautereau
2019-01-23  9:36 Javier Martinez Canillas
2019-01-21  8:16 Thibaut Sautereau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.