Skip to contentSkip to conversation

openssl_tpm2_engine: Add attestation functions for primary keys

PATCH Superseded James Bottomley 3 participants 20 messages Aug 2, 2024 – Aug 5, 2024 Keys-trusted

lore
Share & tools
lore

James Bottomley

author maintainer
#0 lore raw

cover openssl_tpm2_engine: Add attestation functions for primary keys

The first 5 patches add supporting infrastructure and the next three add the actually attestation command, its man page and its tests.

The design is to be able to store a stable copy of the signing EK (done by name) in /etc/eksign.name, which can then be used to verify any on the fly creation of the signing key. The reason for using a signing EK not an AK as the specs usually require is to have the simplicity of a stable key that never changes as the attesting key and because there are no privacy issues in the machine owner knowing it. The command then provides a way to attest this key against the EK certificate (if the TPM has one). If there is no EK certificate, the signing EK name is used on a trust on first use (TOFU) basis.

attest_tpm2_primary --eksign > /etc/eksign.name

Will create this file once. If an EK certificate exists, the eksign.name file can be attested to that certificate with

attest_tpm2_primary --attest tpm-cert.crt --name /etc/eksign.name

The above commands should only need to be done once per TPM.

Once the Signing EK is known, it can be used on every boot to create and certify the NULL key, which is what the kernel uses and exports from version 6.10 onwards and thus proves to the user that the kernel's reliance on the NULL key during boot was cryptographically justifed. This can be done from a boot script as:

attest_tpm2_primary --certify null --name /etc/eksign.name /sys/class/tpm/tpm0/null_name

Which will return true if the certification succeeds. If the certification fails, all TPM functions should be considered compromised. Whether boot should continue even with a compromised TPM is a user policy decision.

James

---

James Bottomley (8):
tss: Fix handling of TPM_RH_NULL in intel-tss
libcommon: add ability to create a signing primary key
libcommon: add bin2hex and tmp2_get_hexname
libcommon: add primary creation from template
tss: add tpm2_Certify, tpm2_ActivateCredential and tpm2_PolicyOR
tools: add new attest_tpm2_primary command
attest_tpm2_primary: add man page
tests: add tests for attest_tpm2_primary

 src/include/ibm-tss.h              |  84 +++
 src/include/intel-tss.h            |  95 +++-
 src/include/tpm2-common.h          |   9 +
 src/libcommon/tpm2-common.c        |  93 +++-
 src/tools/Makefile.am              |  11 +-
 src/tools/attest_tpm2_primary.1.in | 103 ++++
 src/tools/attest_tpm2_primary.c    | 842 +++++++++++++++++++++++++++++
 tests/attestation.sh               |  30 +
 tests/check_importable.sh          |   3 +-
 tests/engine/Makefile.am           |   3 +-
 tests/provider/Makefile.am         |   3 +-
 tests/seal_unseal.sh               |   3 +-
 tests/start_sw_tpm.sh              |   2 +
 13 files changed, 1230 insertions(+), 51 deletions(-)
 create mode 100644 src/tools/attest_tpm2_primary.1.in
 create mode 100644 src/tools/attest_tpm2_primary.c
 create mode 100755 tests/attestation.sh
Signature · 1 line
2.35.3
author maintainer
#1 lore raw

PATCH 1/8 tss: Fix handling of TPM_RH_NULL in intel-tss

Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with this. In the Intel TSS, there are two internal handles representing NULL: ESYS_TR_NONE and ESYS_TR_RH_NULL. We translate TPM_RH_NULL to ESYS_TR_NONE because most of the time it does mean no value. However, for the NULL primary handle we must use ESYS_TR_RH_NULL, so check for that specific case and fix it. Additionally remove the intel_handle() code which was supposed to do this: it's unused because 0 is never passed in as a handle number.

---
 src/include/intel-tss.h | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
src/include/intel-tss.h +5 -13
index 1870b4e..5b8db20 100644
@@ -251,14 +251,6 @@ intel_sess_helper(TSS_CONTEXT *tssContext, TPM_HANDLE auth, TPMA_SESSION flags)
 				  TPMA_SESSION_CONTINUESESSION | flags);
 }
 
-static inline TPM_HANDLE
-intel_handle(TPM_HANDLE h)
-{
-	if (h == 0)
-		return ESYS_TR_NONE;
-	return h;
-}
-
 static inline void
 TSS_Delete(TSS_CONTEXT *tssContext)
 {
@@ -937,8 +929,10 @@ tpm2_CreatePrimary(TSS_CONTEXT *tssContext, TPM_HANDLE primaryHandle,
 	TPM2B_PUBLIC *opub;
 	TPM_RC rc;
 
-	/* FIXME will generate wrong value for NULL hierarchy */
-	primaryHandle = intel_handle(primaryHandle);
+
+	/* TPM_RH_NULL is mapped to ESYS_TR_NONE, which won't work here */
+	if (primaryHandle == TPM_RH_NULL)
+		primaryHandle = INT_TPM_RH_NULL;
 
 	outsideInfo.size = 0;
 	creationPcr.count = 0;
@@ -993,9 +987,7 @@ tpm2_StartAuthSession(TSS_CONTEXT *tssContext, TPM_HANDLE tpmKey,
 		      TPM_HANDLE *sessionHandle,
 		      const char *bindPassword)
 {
-	bind = intel_handle(bind);
-	tpmKey = intel_handle(tpmKey);
-	if (bind != ESYS_TR_NONE)
+	if (bind != TPM_RH_NULL)
 		intel_auth_helper(tssContext, bind, bindPassword);
 
 	return Esys_StartAuthSession(tssContext, tpmKey, bind, ESYS_TR_NONE,
Signature · 1 line
2.35.3
#2 lore raw

Re: [PATCH 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

Quoted 4 lines · James Bottomley

Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with this. In the Intel TSS, there are two internal handles representing NULL: ESYS_TR_NONE and ESYS_TR_RH_NULL. We translate TPM_RH_NULL to ESYS_TR_NONE because

Can you split this into two paragraphs.

I'm lost why it has two representations.

Quoted 31 lines

most of the time it does mean no value. However, for the NULL primary handle we must use ESYS_TR_RH_NULL, so check for that specific case and fix it. Additionally remove the intel_handle() code which was supposed to do this: it's unused because 0 is never passed in as a handle number.

---
 src/include/intel-tss.h | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
src/include/intel-tss.h +0 -8
index 1870b4e..5b8db20 100644
@@ -251,14 +251,6 @@ intel_sess_helper(TSS_CONTEXT *tssContext, TPM_HANDLE auth, TPMA_SESSION flags)
 				  TPMA_SESSION_CONTINUESESSION | flags);
 }
 
-static inline TPM_HANDLE
-intel_handle(TPM_HANDLE h)
-{
-	if (h == 0)
-		return ESYS_TR_NONE;
-	return h;
-}
-
 static inline void
 TSS_Delete(TSS_CONTEXT *tssContext)
 {

src/include/intel-tss.h tpm2_CreatePrimary(TSS_CONTEXT *tssContext, TPM_HANDLE primaryHandle, · line 933

Quoted 7 lines
src/include/intel-tss.h +2 -2
@@ -937,8 +929,10 @@ tpm2_CreatePrimary(TSS_CONTEXT *tssContext, TPM_HANDLE primaryHandle,
 	TPM2B_PUBLIC *opub;
 	TPM_RC rc;
 
-	/* FIXME will generate wrong value for NULL hierarchy */
-	primaryHandle = intel_handle(primaryHandle);
+
+	/* TPM_RH_NULL is mapped to ESYS_TR_NONE, which won't work here */

I simply don't understand what E

Quoted 6 lines
src/include/intel-tss.h +2 -0
+	if (primaryHandle == TPM_RH_NULL)
+		primaryHandle = INT_TPM_RH_NULL;
 
 	outsideInfo.size = 0;
 	creationPcr.count = 0;

src/include/intel-tss.h tpm2_StartAuthSession(TSS_CONTEXT *tssContext, TPM_HANDLE tpmKey, · line 993

Quoted 10 lines
src/include/intel-tss.h +1 -3
@@ -993,9 +987,7 @@ tpm2_StartAuthSession(TSS_CONTEXT *tssContext, TPM_HANDLE tpmKey,
 		      TPM_HANDLE *sessionHandle,
 		      const char *bindPassword)
 {
-	bind = intel_handle(bind);
-	tpmKey = intel_handle(tpmKey);
-	if (bind != ESYS_TR_NONE)
+	if (bind != TPM_RH_NULL)
 		intel_auth_helper(tssContext, bind, bindPassword);
 
 	return Esys_StartAuthSession(tssContext, tpmKey, bind, ESYS_TR_NONE,

BR, Jarkko

author maintainer
#3 lore raw

Re: [PATCH 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

Quoted 10 lines · Jarkko Sakkinen
Quoted 5 lines · James Bottomley

Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with this.  In the Intel TSS, there are two internal handles representing NULL: ESYS_TR_NONE and ESYS_TR_RH_NULL.  We translate TPM_RH_NULL to ESYS_TR_NONE because

Can you split this into two paragraphs.

I'm lost why it has two representations.

Well, I actually have no idea why the Intel TSS has two representations for *every* handle: an internal one (specific to the TSS) and an external one that everyone uses, like 81000001 or 40000007. As far as I can see it just adds pointless complexity to the coding. The IBM TSS only has one, so for code which works with both, the shim has to transform between internal and external handle representations before sending the command onward to the Intel TSS.

Even more mysteriously the Intel TSS has three representations for the NULL handle: an internal one, an external one (40000007) and one you use for an empty session (ESYS_TR_NONE). The IBM TSS uses TPM_RH_NULL for all three so you can't just translate from external to internal you have to know if you're using the handle for a session or a hierarchy as well.

James

maintainer
#4 lore raw

Re: [PATCH 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

Quoted 12 lines · James Bottomley
Quoted 10 lines · Jarkko Sakkinen
Quoted 5 lines · James Bottomley

Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with this.  In the Intel TSS, there are two internal handles representing NULL: ESYS_TR_NONE and ESYS_TR_RH_NULL.  We translate TPM_RH_NULL to ESYS_TR_NONE because

Can you split this into two paragraphs.

I'm lost why it has two representations.

Quoted 7 lines

Well, I actually have no idea why the Intel TSS has two representations for *every* handle: an internal one (specific to the TSS) and an external one that everyone uses, like 81000001 or 40000007. As far as I can see it just adds pointless complexity to the coding. The IBM TSS only has one, so for code which works with both, the shim has to transform between internal and external handle representations before sending the command onward to the Intel TSS.

Is it possible to address this complexity and move into a single representation? I.e. use external presentation all the way.

Quoted 7 lines

Even more mysteriously the Intel TSS has three representations for the NULL handle: an internal one, an external one (40000007) and one you use for an empty session (ESYS_TR_NONE). The IBM TSS uses TPM_RH_NULL for all three so you can't just translate from external to internal you have to know if you're using the handle for a session or a hierarchy as well.

Same question applies to this too.

Quoted 1 line

James

I'm doing my own TPM2 stack with Rust, which just re-implements the functionality of my old tpm2-scripts and tpm2.py module as nice small app called tpm2-cli.

It will be more use case based interface than than protocol spec as a software interface. Main goal for now is to get this whole flow into it (with varying parameters for the key) as single function:

tpm2_createprimary --hierarchy o -G ecc -c owner.txt tpm2_evictcontrol -c owner.txt 0x81000001
openssl ecparam -name prime256v1 -genkey -noout -out private.pem tpm2_import -C 0x81000001 -G ecc -i private.pem -u key.pub -r key.priv tpm2_encodeobject -C 0x81000001 -u key.pub -r key.priv -o key.priv.pem openssl asn1parse -inform pem -in key.priv.pem -noout -out key.priv.der

BR, Jarkko

author maintainer
#5 lore raw

Re: [PATCH 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

Quoted 22 lines · Jarkko Sakkinen
Quoted 12 lines · James Bottomley
Quoted 10 lines · Jarkko Sakkinen
Quoted 5 lines · James Bottomley

Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with this. In the Intel TSS, there are two internal handles representing
NULL: ESYS_TR_NONE and ESYS_TR_RH_NULL.  We translate TPM_RH_NULL to ESYS_TR_NONE because

Can you split this into two paragraphs.

I'm lost why it has two representations.

Quoted 8 lines

Well, I actually have no idea why the Intel TSS has two representations for *every* handle: an internal one (specific to the TSS) and an external one that everyone uses, like 81000001 or 40000007. As far as I can see it just adds pointless complexity to the coding.  The IBM TSS only has one, so for code which works with both, the shim has to transform between internal and external handle representations before sending the command onward to the Intel TSS.

Quoted 2 lines

Is it possible to address this complexity and move into a single representation? I.e. use external presentation all the way.

Yes, that's what the current code does. It began life as pure IBM TSS so it used what the Intel TSS would consider as all external handle representations. The external to internal shift (and back) happens inside the TSS shim.

Quoted 8 lines
Quoted 6 lines

Even more mysteriously the Intel TSS has three representations for the NULL handle: an internal one, an external one (40000007) and one you use for an empty session (ESYS_TR_NONE).  The IBM TSS uses TPM_RH_NULL for all three so you can't just translate from external to internal you have to know if you're using the handle for a session or a hierarchy as well.

Same question applies to this too.

Remember this is just fixing the Intel TSS Shim. The fact that we have to use three different handles for NULL isn't visible outside the shim, so a consumer of these APIs just uses TPM_RH_NULL everywhere. The fix is that the Intel TSS Shim was using the wrong handle for some operations.

Quoted 11 lines
Quoted 2 lines

James

I'm doing my own TPM2 stack with Rust, which just re-implements the functionality of my old tpm2-scripts and tpm2.py module as nice small app called tpm2-cli.

It will be more use case based interface than than protocol spec as a software interface. Main goal for now is to get this whole flow into it (with varying parameters for the key) as single function:

Quoted 9 lines

tpm2_createprimary --hierarchy o -G ecc -c owner.txt tpm2_evictcontrol -c owner.txt 0x81000001
openssl ecparam -name prime256v1 -genkey -noout -out private.pem tpm2_import -C 0x81000001 -G ecc -i private.pem -u key.pub -r key.priv
tpm2_encodeobject -C 0x81000001 -u key.pub -r key.priv -o key.priv.pem
openssl asn1parse -inform pem -in key.priv.pem -noout -out key.priv.der

Well, that's simply the library API. That's actually what the IBM TSS uses.  I think the Library API is by far the simplest TPM API to use, so beyond trying to sort out the complexity of getting a compatibility shim I've not really used the Intel TSS. I think the Intel TSS is based on the ESAPI document which introduces the handle conversion complexity. I haven't read the ESAPI spec, I just tried to reverse engineer it (from the source) into supporting an API which can be compatible with the library spec/IBM TSS.

James

maintainer
#6 lore raw

Re: [PATCH 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

Quoted 23 lines · James Bottomley
Quoted 22 lines · Jarkko Sakkinen
Quoted 20 lines · James Bottomley
Quoted 10 lines · Jarkko Sakkinen
Quoted 5 lines · James Bottomley

Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with this. In the Intel TSS, there are two internal handles representing
NULL: ESYS_TR_NONE and ESYS_TR_RH_NULL.  We translate TPM_RH_NULL to ESYS_TR_NONE because

Can you split this into two paragraphs.

I'm lost why it has two representations.

Well, I actually have no idea why the Intel TSS has two representations for *every* handle: an internal one (specific to the TSS) and an external one that everyone uses, like 81000001 or 40000007. As far as I can see it just adds pointless complexity to the coding.  The IBM TSS only has one, so for code which works with both, the shim has to transform between internal and external handle representations before sending the command onward to the Intel TSS.

Quoted 7 lines
Quoted 2 lines

Is it possible to address this complexity and move into a single representation? I.e. use external presentation all the way.

Yes, that's what the current code does. It began life as pure IBM TSS so it used what the Intel TSS would consider as all external handle representations. The external to internal shift (and back) happens inside the TSS shim.

Ah, right, OK now I'm on page, thank you.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Even more mysteriously the Intel TSS has three representations for the NULL handle: an internal one, an external one (40000007) and one you use for an empty session (ESYS_TR_NONE).  The IBM TSS uses TPM_RH_NULL for all three so you can't just translate from external to internal you have to know if you're using the handle for a session or a hierarchy as well.

Quoted 7 lines
Quoted 1 line

Same question applies to this too.

Remember this is just fixing the Intel TSS Shim. The fact that we have to use three different handles for NULL isn't visible outside the shim, so a consumer of these APIs just uses TPM_RH_NULL everywhere. The fix is that the Intel TSS Shim was using the wrong handle for some operations.

OK, got it, thanks.

BR, Jarkko

author maintainer
#7 lore raw

PATCH v2 1/8 tss: Fix handling of TPM_RH_NULL in intel-tss

The design of the intel-tss shim is to hide the difference between the internal and the external handles by doing the internal to external transform on entry. Unfortunately, the NULL handle (TPM_RH_NULL, 40000007) has two possible internal representations depending on whether it's used to indicate no session or the null hierarcy.

There is a bug in the intel-tss in that it uses the wrong internal NULL handle to try to create the NULL seed primary (and thus fails). Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with thi correctly.

The fix is to do the correct transform to the internal hierarchy representation on NULL hierarchy creation and to do the session handle conversion everywhere else. Additionally remove the intel_handle() code which was supposed to do this: it's unused because 0 is never passed in as a handle number.

---
v2: reword commit message

---
 src/include/intel-tss.h | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
src/include/intel-tss.h +0 -0
index 1870b4e..5b8db20 100644
@@ -251,14 +251,6 @@ intel_sess_helper(TSS_CONTEXT *tssContext,

TPM_HANDLE auth, TPMA_SESSION flags)
TPMA_SESSION_CONTINUESESSION |
flags);
}

-static inline TPM_HANDLE
-intel_handle(TPM_HANDLE h)
-{
- if (h == 0)
- return ESYS_TR_NONE;
- return h;
-}
-
static inline void
TSS_Delete(TSS_CONTEXT *tssContext)
{
@@ -937,8 +929,10 @@ tpm2_CreatePrimary(TSS_CONTEXT *tssContext, TPM_HANDLE primaryHandle,
TPM2B_PUBLIC *opub;
TPM_RC rc;

- /* FIXME will generate wrong value for NULL hierarchy */
- primaryHandle = intel_handle(primaryHandle);
+
+ /* TPM_RH_NULL is mapped to ESYS_TR_NONE, which won't work
here */
+ if (primaryHandle == TPM_RH_NULL)
+ primaryHandle = INT_TPM_RH_NULL;

outsideInfo.size = 0;
creationPcr.count = 0;
@@ -993,9 +987,7 @@ tpm2_StartAuthSession(TSS_CONTEXT *tssContext, TPM_HANDLE tpmKey,
TPM_HANDLE *sessionHandle,
const char *bindPassword)
{
- bind = intel_handle(bind);
- tpmKey = intel_handle(tpmKey);
- if (bind != ESYS_TR_NONE)
+ if (bind != TPM_RH_NULL)
intel_auth_helper(tssContext, bind, bindPassword);

return Esys_StartAuthSession(tssContext, tpmKey, bind,
ESYS_TR_NONE,

Signature · 1 line
2.35.3
author maintainer
#8 lore raw

Re: [openssl-tpm2-engine] [PATCH v2 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

Quoted 12 lines · James Bottomley

The design of the intel-tss shim is to hide the difference between the
internal and the external handles by doing the internal to external transform on entry.  Unfortunately, the NULL handle (TPM_RH_NULL, 40000007) has two possible internal representations depending on whether it's used to indicate no session or the null hierarcy.

There is a bug in the intel-tss in that it uses the wrong internal NULL handle to try to create the NULL seed primary (and thus fails). Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with thi correctly.

Quoted 6 lines

The fix is to do the correct transform to the internal hierarchy representation on NULL hierarchy creation and to do the session handle
conversion everywhere else.  Additionally remove the intel_handle() code which was supposed to do this: it's unused because 0 is never passed in as a handle number.

Going over all the internal to external handle conversions, I found one more use case that would produce a bug. This one isn't actually used in the openssl_tpm2_engine code, so it's an unmanifested bug but nevertheless it should be fixed to avoid problems later on. I'll fold the below fix into this patch.

Regards,

James

---

src/include/intel-tss.h +0 -0
index 3b8c18d..a2050ba 100644
@@ -1271,6 +1271,19 @@ tpm2_handle_ext(TSS_CONTEXT *tssContext,

TPM_HANDLE esysh)
{
TPM2_HANDLE realh = 0;

+ switch (esysh) {
+ case ESYS_TR_RH_OWNER:
+ return EXT_TPM_RH_OWNER;
+ case ESYS_TR_RH_PLATFORM:
+ return EXT_TPM_RH_PLATFORM;
+ case ESYS_TR_RH_ENDORSEMENT:
+ return EXT_TPM_RH_ENDORSEMENT;
+ case ESYS_TR_RH_NULL:
+ return EXT_TPM_RH_NULL;
+ case ESYS_TR_NONE:
+ return EXT_TPM_RH_NULL;
+ }
+
Esys_TR_GetTpmHandle(tssContext, esysh, &realh);

return realh;

maintainer
#9 lore raw

Re: [PATCH v2 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

In reply to James Bottomley
Quoted 63 lines · James Bottomley

The design of the intel-tss shim is to hide the difference between the internal and the external handles by doing the internal to external transform on entry. Unfortunately, the NULL handle (TPM_RH_NULL, 40000007) has two possible internal representations depending on whether it's used to indicate no session or the null hierarcy.

There is a bug in the intel-tss in that it uses the wrong internal NULL handle to try to create the NULL seed primary (and thus fails). Now that we're going to be using the NULL primary to salt sessions, the Intel TSS shim needs fixing to cope with thi correctly.

The fix is to do the correct transform to the internal hierarchy representation on NULL hierarchy creation and to do the session handle conversion everywhere else. Additionally remove the intel_handle() code which was supposed to do this: it's unused because 0 is never passed in as a handle number.

---
v2: reword commit message

---
 src/include/intel-tss.h | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
src/include/intel-tss.h +0 -8
index 1870b4e..5b8db20 100644
@@ -251,14 +251,6 @@ intel_sess_helper(TSS_CONTEXT *tssContext,
 TPM_HANDLE auth, TPMA_SESSION flags)
 				  TPMA_SESSION_CONTINUESESSION |
 flags);
 }
 
-static inline TPM_HANDLE
-intel_handle(TPM_HANDLE h)
-{
-	if (h == 0)
-		return ESYS_TR_NONE;
-	return h;
-}
-
 static inline void

TSS_Delete(TSS_CONTEXT *tssContext)
{

src/include/intel-tss.h +2 -2
@@ -937,8 +929,10 @@ tpm2_CreatePrimary(TSS_CONTEXT *tssContext,
 TPM_HANDLE primaryHandle,
 	TPM2B_PUBLIC *opub;
 	TPM_RC rc;
 
-	/* FIXME will generate wrong value for NULL hierarchy */
-	primaryHandle = intel_handle(primaryHandle);
+
+	/* TPM_RH_NULL is mapped to ESYS_TR_NONE, which won't work

here */

src/include/intel-tss.h +2 -0
+	if (primaryHandle == TPM_RH_NULL)
+		primaryHandle = INT_TPM_RH_NULL;
 
 	outsideInfo.size = 0;
 	creationPcr.count = 0;

src/include/intel-tss.h tpm2_StartAuthSession(TSS_CONTEXT *tssContext, · line 992

Quoted 9 lines
src/include/intel-tss.h +1 -3
@@ -993,9 +987,7 @@ tpm2_StartAuthSession(TSS_CONTEXT *tssContext,
 TPM_HANDLE tpmKey,
 		      TPM_HANDLE *sessionHandle,
 		      const char *bindPassword)
 {
-	bind = intel_handle(bind);
-	tpmKey = intel_handle(tpmKey);
-	if (bind != ESYS_TR_NONE)
+	if (bind != TPM_RH_NULL)
 		intel_auth_helper(tssContext, bind, bindPassword);

Not blaming the patch but just have hard time coping this.

The most basic question is probably this: what is the application for INT_TPM_RH_NULL?

Let's imagine that we have a flow chart describing Intel shim as a state machine. I decide to shoot it with these three stimulus:

1. INT_TPM_RH_NULL
2. TPM_RH_NULL
3. A valid handle

What happens in each case to its state?

Quoted 3 lines
src/include/intel-tss.h +0 -0
 	return Esys_StartAuthSession(tssContext, tpmKey, bind,

ESYS_TR_NONE,

BR, Jarkko

author maintainer
#10 lore raw

Re: [openssl-tpm2-engine] [PATCH v2 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

On Mon, 2024-08-05 at 00:28 +0300, Jarkko Sakkinen wrote:
[...]

Quoted 47 lines
Quoted 35 lines
src/include/intel-tss.h +0 -0
@@ -251,14 +251,6 @@ intel_sess_helper(TSS_CONTEXT *tssContext,
 TPM_HANDLE auth, TPMA_SESSION flags)

                                  TPMA_SESSION_CONTINUESESSION | flags);
 }

src/include/intel-tss.h +0 -8
-static inline TPM_HANDLE
-intel_handle(TPM_HANDLE h)
-{
-       if (h == 0)
-               return ESYS_TR_NONE;
-       return h;
-}
-

 static inline void
 TSS_Delete(TSS_CONTEXT *tssContext)
 {

src/include/intel-tss.h +0 -0
@@ -937,8 +929,10 @@ tpm2_CreatePrimary(TSS_CONTEXT *tssContext,
 TPM_HANDLE primaryHandle,
         TPM2B_PUBLIC *opub;
         TPM_RC rc;


-       /* FIXME will generate wrong value for NULL hierarchy */ -       primaryHandle = intel_handle(primaryHandle);
+
+       /* TPM_RH_NULL is mapped to ESYS_TR_NONE, which won't work here */
+       if (primaryHandle == TPM_RH_NULL)
+               primaryHandle = INT_TPM_RH_NULL;

        outsideInfo.size = 0;
        creationPcr.count = 0;

src/include/intel-tss.h tpm2_StartAuthSession(TSS_CONTEXT *tssContext, · line 992

Quoted 9 lines
src/include/intel-tss.h +1 -3
@@ -993,9 +987,7 @@ tpm2_StartAuthSession(TSS_CONTEXT *tssContext,
 TPM_HANDLE tpmKey,
                       TPM_HANDLE *sessionHandle,
                       const char *bindPassword)
  {
-       bind = intel_handle(bind);
-       tpmKey = intel_handle(tpmKey);
-       if (bind != ESYS_TR_NONE)
+       if (bind != TPM_RH_NULL)
                 intel_auth_helper(tssContext, bind, bindPassword);

Not blaming the patch but just have hard time coping this.

Quoted 2 lines

The most basic question is probably this: what is the application for INT_TPM_RH_NULL?

Ah, well, it turns out that the Intel TSS also isn't very performant and part of the performance loss is using a memory database for translating external TPM objects into internal ones. Some of the performance can be recovered by not doing this.

It turns out that the engine code never uses volatile external handles, so the switch from volatile internal -> external and vice versa (which occurs on load followed by key operation) was eliminated and the code uses internal representation for volatile handles and external representation for all other handles. This scheme worked fine until non-volatile key indexes were introduced and then it broke down a bit. It would be logically very nice to redo the internal representation to be entirely contained within the intel tss shim, but then that would reintroduce the performance problem (although on the other hand, the Intel TSS is still twice as slow as the IBM TSS so perhaps this wouldn't be such a huge addition).

Regards,

James

maintainer
#11 lore raw

Re: [openssl-tpm2-engine] [PATCH v2 1/8] tss: Fix handling of TPM_RH_NULL in intel-tss

Quoted 49 lines · James Bottomley

On Mon, 2024-08-05 at 00:28 +0300, Jarkko Sakkinen wrote:
[...]

Quoted 47 lines
Quoted 35 lines
src/include/intel-tss.h +0 -0
@@ -251,14 +251,6 @@ intel_sess_helper(TSS_CONTEXT *tssContext,
 TPM_HANDLE auth, TPMA_SESSION flags)

                                  TPMA_SESSION_CONTINUESESSION | flags);
 }

src/include/intel-tss.h +0 -8
-static inline TPM_HANDLE
-intel_handle(TPM_HANDLE h)
-{
-       if (h == 0)
-               return ESYS_TR_NONE;
-       return h;
-}
-

 static inline void
 TSS_Delete(TSS_CONTEXT *tssContext)
 {

src/include/intel-tss.h +0 -0
@@ -937,8 +929,10 @@ tpm2_CreatePrimary(TSS_CONTEXT *tssContext,
 TPM_HANDLE primaryHandle,
         TPM2B_PUBLIC *opub;
         TPM_RC rc;


-       /* FIXME will generate wrong value for NULL hierarchy */ -       primaryHandle = intel_handle(primaryHandle);
+
+       /* TPM_RH_NULL is mapped to ESYS_TR_NONE, which won't work here */
+       if (primaryHandle == TPM_RH_NULL)
+               primaryHandle = INT_TPM_RH_NULL;

        outsideInfo.size = 0;
        creationPcr.count = 0;

src/include/intel-tss.h tpm2_StartAuthSession(TSS_CONTEXT *tssContext, · line 992

Quoted 9 lines
src/include/intel-tss.h +1 -3
@@ -993,9 +987,7 @@ tpm2_StartAuthSession(TSS_CONTEXT *tssContext,
 TPM_HANDLE tpmKey,
                       TPM_HANDLE *sessionHandle,
                       const char *bindPassword)
  {
-       bind = intel_handle(bind);
-       tpmKey = intel_handle(tpmKey);
-       if (bind != ESYS_TR_NONE)
+       if (bind != TPM_RH_NULL)
                 intel_auth_helper(tssContext, bind, bindPassword);

Not blaming the patch but just have hard time coping this.

Quoted 7 lines
Quoted 2 lines

The most basic question is probably this: what is the application for INT_TPM_RH_NULL?

Ah, well, it turns out that the Intel TSS also isn't very performant and part of the performance loss is using a memory database for translating external TPM objects into internal ones. Some of the performance can be recovered by not doing this.

So INT_RH_NULL is a flag that translates to "do not translate to internal object if it is derived from the nulll seed?". I.e. is it some kind of skip flag?

External presentation is any TPM object I guess, but what is conceptually the internal representation we are talking about here?

I wonder why nobody ever got idea that all kinds of TPM daemons could use u64 for handles, and have future-proof robustness as in TPM2 handles are u32.

BR, Jarkko

author maintainer
#12 lore raw

PATCH 2/8 libcommon: add ability to create a signing primary key

In reply to James Bottomley

Having a primary key that can sign things is useful for conducting certification and quoting operations without having to go through the makecredential/activatecredential dance, which is unnecessary for a local TPM where you don't need privacy separated attestation keys. Add the ability to use the signing key template to tpm2_load_srk().

---
 src/include/tpm2-common.h   |  1 +
 src/libcommon/tpm2-common.c | 23 ++++++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)
src/include/tpm2-common.h +1 -0
index 4520f76..97b60f2 100644
@@ -23,6 +23,7 @@ enum tpm2_type {
 	TPM2_LOADABLE = 1,
 	TPM2_IMPORTABLE = 2,
 	TPM2_SEALED = 3,
+	TPM2_SIGNING = 4,
 };
 
 struct policies {
src/libcommon/tpm2-common.c +18 -5
index 3b9f785..b70ac27 100644
@@ -743,17 +743,30 @@ TPM_RC tpm2_load_srk(TSS_CONTEXT *tssContext, TPM_HANDLE *h, const char *auth,
 		TPMA_OBJECT_NODA |
 		TPMA_OBJECT_SENSITIVEDATAORIGIN |
 		TPMA_OBJECT_USERWITHAUTH |
-		TPMA_OBJECT_DECRYPT |
 		TPMA_OBJECT_RESTRICTED;
+	if (type == TPM2_SIGNING)
+		VAL(inPublic.publicArea.objectAttributes) |=
+			TPMA_OBJECT_SIGN;
+	else
+		VAL(inPublic.publicArea.objectAttributes) |=
+			TPMA_OBJECT_DECRYPT;
 	if (type != TPM2_LEGACY)
 		VAL(inPublic.publicArea.objectAttributes) |=
 			TPMA_OBJECT_FIXEDPARENT |
 			TPMA_OBJECT_FIXEDTPM;
 
-	inPublic.publicArea.parameters.eccDetail.symmetric.algorithm = TPM_ALG_AES;
-	inPublic.publicArea.parameters.eccDetail.symmetric.keyBits.aes = 128;
-	inPublic.publicArea.parameters.eccDetail.symmetric.mode.aes = TPM_ALG_CFB;
-	inPublic.publicArea.parameters.eccDetail.scheme.scheme = TPM_ALG_NULL;
+	if (type != TPM2_SIGNING) {
+		inPublic.publicArea.parameters.eccDetail.symmetric.algorithm = TPM_ALG_AES;
+		inPublic.publicArea.parameters.eccDetail.symmetric.keyBits.aes = 128;
+		inPublic.publicArea.parameters.eccDetail.symmetric.mode.aes = TPM_ALG_CFB;
+		inPublic.publicArea.parameters.eccDetail.scheme.scheme = TPM_ALG_NULL;
+	} else {
+		inPublic.publicArea.parameters.eccDetail.symmetric.algorithm = TPM_ALG_NULL;
+		inPublic.publicArea.parameters.eccDetail.symmetric.keyBits.aes = 0;
+		inPublic.publicArea.parameters.eccDetail.symmetric.mode.aes = TPM_ALG_NULL;
+		inPublic.publicArea.parameters.eccDetail.scheme.scheme = TPM_ALG_ECDSA;
+		inPublic.publicArea.parameters.eccDetail.scheme.details.ecdsa.hashAlg = TPM_ALG_SHA256;
+	}
 	inPublic.publicArea.parameters.eccDetail.curveID = TPM_ECC_NIST_P256;
 	inPublic.publicArea.parameters.eccDetail.kdf.scheme = TPM_ALG_NULL;
 
Signature · 1 line
2.35.3
author maintainer
#13 lore raw

PATCH 3/8 libcommon: add bin2hex and tmp2_get_hexname

In reply to James Bottomley
---
 src/include/tpm2-common.h   |  5 +++++
 src/libcommon/tpm2-common.c | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)
src/include/tpm2-common.h +5 -0
index 97b60f2..0e0f28a 100644
@@ -9,6 +9,9 @@
  * not a TPM error, so don't process the rc as one */
 #define NOT_TPM_ERROR (0xffffffff)
 
+/* maximum space for a sha256 name in ascii */
+#define MAX_HEXNAME 132
+
 extern TPM_ALG_ID name_alg;
 
 struct policy_command {
@@ -141,4 +144,6 @@ int tpm2_rsa_decrypt(const struct app_data *ad, PUBLIC_KEY_RSA_2B *cipherText,
 		     char *srk_auth);
 int tpm2_rm_signed_policy(char *tpmkey, int rmnum);
 int tpm2_get_signed_policy(char *tpmkey, STACK_OF(TSSAUTHPOLICY) **sk);
+void bin2hex(char *dst, const unsigned char *src, size_t count);
+void tpm2_get_hexname(char hexname[MAX_HEXNAME], TPM2B_PUBLIC *pub);
 #endif
src/libcommon/tpm2-common.c +16 -0
index b70ac27..3ffa773 100644
@@ -2320,6 +2320,14 @@ int hex2bin(unsigned char *dst, const char *src, size_t count)
 	return 0;
 }
 
+void bin2hex(char *dst, const unsigned char *src, size_t count)
+{
+	int i;
+
+	for (i = 0; i < count; i++)
+		sprintf(&dst[i<<1], "%02x", src[i]);
+}
+
 TPM_RC tpm2_parse_policy_file(const char *policy_file,
 			      STACK_OF(TSSOPTPOLICY) *sk,
 			      char *auth, TPMT_HA *digest)
@@ -3376,6 +3384,14 @@ openssl_print_errors()
 	ERR_print_errors_fp(stderr);
 }
 
+void tpm2_get_hexname(char hexname[MAX_HEXNAME], TPM2B_PUBLIC *pub)
+{
+	NAME_2B n;
+
+	tpm2_ObjectPublic_GetName(&n, &pub->publicArea);
+	bin2hex(hexname, (unsigned char *)n.name, n.size);
+}
+
 IMPLEMENT_ASN1_FUNCTIONS(TSSOPTPOLICY)
 IMPLEMENT_ASN1_FUNCTIONS(TSSAUTHPOLICY)
 IMPLEMENT_ASN1_FUNCTIONS(TSSLOADABLE)
Signature · 1 line
2.35.3
maintainer
#14 lore raw

Re: [PATCH 3/8] libcommon: add bin2hex and tmp2_get_hexname

Quoted 5 lines · James Bottomley
---
 src/include/tpm2-common.h   |  5 +++++
 src/libcommon/tpm2-common.c | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

Would not hurt to introduce them in the commit message.

Quoted 46 lines
src/include/tpm2-common.h +5 -0
index 97b60f2..0e0f28a 100644
@@ -9,6 +9,9 @@
  * not a TPM error, so don't process the rc as one */
 #define NOT_TPM_ERROR (0xffffffff)
 
+/* maximum space for a sha256 name in ascii */
+#define MAX_HEXNAME 132
+
 extern TPM_ALG_ID name_alg;
 
 struct policy_command {
@@ -141,4 +144,6 @@ int tpm2_rsa_decrypt(const struct app_data *ad, PUBLIC_KEY_RSA_2B *cipherText,
 		     char *srk_auth);
 int tpm2_rm_signed_policy(char *tpmkey, int rmnum);
 int tpm2_get_signed_policy(char *tpmkey, STACK_OF(TSSAUTHPOLICY) **sk);
+void bin2hex(char *dst, const unsigned char *src, size_t count);
+void tpm2_get_hexname(char hexname[MAX_HEXNAME], TPM2B_PUBLIC *pub);
 #endif
src/libcommon/tpm2-common.c +9 -0
index b70ac27..3ffa773 100644
@@ -2320,6 +2320,14 @@ int hex2bin(unsigned char *dst, const char *src, size_t count)
 	return 0;
 }
 
+void bin2hex(char *dst, const unsigned char *src, size_t count)
+{
+	int i;
+
+	for (i = 0; i < count; i++)
+		sprintf(&dst[i<<1], "%02x", src[i]);
+}
+
 TPM_RC tpm2_parse_policy_file(const char *policy_file,
 			      STACK_OF(TSSOPTPOLICY) *sk,
 			      char *auth, TPMT_HA *digest)
@@ -3376,6 +3384,14 @@ openssl_print_errors()
 	ERR_print_errors_fp(stderr);
 }
 
+void tpm2_get_hexname(char hexname[MAX_HEXNAME], TPM2B_PUBLIC *pub)

src/libcommon/tpm2-common.c openssl_print_errors() · line 3397

Quoted 10 lines
src/libcommon/tpm2-common.c +7 -0
+{
+	NAME_2B n;
+
+	tpm2_ObjectPublic_GetName(&n, &pub->publicArea);
+	bin2hex(hexname, (unsigned char *)n.name, n.size);
+}
+
 IMPLEMENT_ASN1_FUNCTIONS(TSSOPTPOLICY)
 IMPLEMENT_ASN1_FUNCTIONS(TSSAUTHPOLICY)
 IMPLEMENT_ASN1_FUNCTIONS(TSSLOADABLE)

BR, Jarkko

author maintainer
#15 lore raw

PATCH 4/8 libcommon: add primary creation from template

In reply to James Bottomley

Although for usual operation we only need the standard template to create the keys, for EK operations we need to create the EK from the exact EK template (of which there are a few), so add a new function to allow the creation of a primary from any given template.

---
 src/include/tpm2-common.h   |  3 +++
 src/libcommon/tpm2-common.c | 54 +++++++++++++++++++++----------------
 2 files changed, 34 insertions(+), 23 deletions(-)
src/include/tpm2-common.h +3 -0
index 0e0f28a..026a2ae 100644
@@ -59,6 +59,9 @@ struct app_data {
 void tpm2_error(TPM_RC rc, const char *reason);
 TPM_RC tpm2_load_srk(TSS_CONTEXT *tssContext, TPM_HANDLE *h, const char *auth,
 		     TPM2B_PUBLIC *pub, TPM_HANDLE handle, enum tpm2_type type);
+TPM_RC tpm2_load_srk_tmpl(TSS_CONTEXT *tssContext, TPM_HANDLE *h,
+			  const char *auth, TPM2B_PUBLIC *tmpl,
+			  TPM2B_PUBLIC *pub, TPM_HANDLE hierarchy);
 void tpm2_flush_handle(TSS_CONTEXT *tssContext, TPM_HANDLE h);
 EVP_PKEY *tpm2_to_openssl_public(TPMT_PUBLIC *pub);
 void tpm2_flush_srk(TSS_CONTEXT *tssContext, TPM_HANDLE hSRK);
src/libcommon/tpm2-common.c +31 -23

75 lines not on this page · raw message

Signature · 1 line
2.35.3
author maintainer
#16 lore raw

PATCH 5/8 tss: add tpm2_Certify, tpm2_ActivateCredential and tpm2_PolicyOR

In reply to James Bottomley

tpm2_Certify is used to verify that a given object is resident in the TPM. tpm2_ActivateCredential is used to decrypt a challenge from a privacyCA and constructing the high template for the EK to use with this requires PolicyOR.

---
 src/include/ibm-tss.h   | 84 +++++++++++++++++++++++++++++++++++++++++
 src/include/intel-tss.h | 77 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 160 insertions(+), 1 deletion(-)
src/include/ibm-tss.h +84 -0
index 1b53319..b5da340 100644
@@ -16,6 +16,7 @@
 #define VAL(X)			X.val
 #define VAL_2B(X, MEMBER)	X.b.MEMBER
 #define VAL_2B_P(X, MEMBER)	X->b.MEMBER
+#define VAL_T(X, MEMBER)	X.t.MEMBER
 
 static inline void
 tpm2_error(TPM_RC rc, const char *reason)
@@ -695,6 +696,26 @@ tpm2_PolicySecret(TSS_CONTEXT *tssContext, TPM_HANDLE authHandle,
 	return rc;
 }
 
+static inline TPM_RC
+tpm2_PolicyOR(TSS_CONTEXT *tssContext, TPM_HANDLE policySession,
+	      TPML_DIGEST *pHashList)
+{
+	PolicyOR_In in;
+	TPM_RC rc;
+
+	in.policySession = policySession;
+	in.pHashList = *pHashList;
+
+	rc = TSS_Execute(tssContext,
+			 NULL,
+			 (COMMAND_PARAMETERS *)&in,
+			 NULL,
+			 TPM_CC_PolicyOR,
+			 TPM_RH_NULL, NULL, 0);
+
+	return rc;
+}
+
 static inline TPM_RC
 tpm2_PolicyGetDigest(TSS_CONTEXT *tssContext, TPM_HANDLE policySession,
 		     DIGEST_2B *digest)
@@ -743,6 +764,69 @@ tpm2_PCR_Read(TSS_CONTEXT *tssContext, TPML_PCR_SELECTION *pcrSelectionIn,
 	return rc;
 }
 
+static inline TPM_RC
+tpm2_Certify(TSS_CONTEXT *tssContext, TPM_HANDLE objectHandle,
+	     TPM_HANDLE signHandle, DATA_2B *qualifyingData,
+	     ATTEST_2B *certifyInfo, TPMT_SIGNATURE *signature)
+{
+	Certify_In in;
+	Certify_Out out;
+	TPM_RC rc;
+
+	in.objectHandle = objectHandle;
+	in.signHandle = signHandle;
+	in.qualifyingData.t = *qualifyingData;
+	in.inScheme.scheme = TPM_ALG_NULL;
+
+	rc = TSS_Execute(tssContext,
+			 (RESPONSE_PARAMETERS *)&out,
+			 (COMMAND_PARAMETERS *)&in,
+			 NULL,
+			 TPM_CC_Certify,
+			 TPM_RS_PW, NULL, 0,
+			 TPM_RS_PW, NULL, 0,
+			 TPM_RH_NULL, NULL, 0);
+
+	if (rc)
+		return rc;
+
+	*certifyInfo = out.certifyInfo.t;
+	*signature = out.signature;
+
+	return rc;
+}
+
+static inline TPM_RC
+tpm2_ActivateCredential(TSS_CONTEXT *tssContext, TPM_HANDLE activateHandle,
+			TPM_HANDLE keyHandle, ID_OBJECT_2B *credentialBlob,
+			ENCRYPTED_SECRET_2B *secret, DIGEST_2B *certinfo,
+			TPM_HANDLE auth)
+{
+	ActivateCredential_In in;
+	ActivateCredential_Out out;
+	TPM_RC rc;
+
+	in.activateHandle = activateHandle;
+	in.keyHandle = keyHandle;
+	in.credentialBlob.t = *credentialBlob;
+	in.secret.t = *secret;
+
+	rc = TSS_Execute(tssContext,
+			 (RESPONSE_PARAMETERS *)&out,
+			 (COMMAND_PARAMETERS *)&in,
+			 NULL,
+			 TPM_CC_ActivateCredential,
+			 TPM_RS_PW, NULL, 0,
+			 auth, NULL, TPMA_SESSION_ENCRYPT,
+			 TPM_RH_NULL, NULL, 0);
+	if (rc)
+		return rc;
+
+	*certinfo = out.certInfo.t;
+
+	return rc;
+}
+
 static inline TPM_HANDLE
 tpm2_handle_int(TSS_CONTEXT *tssContext, TPM_HANDLE h)
 {
src/include/intel-tss.h +76 -1

127 lines not on this page · raw message

Signature · 1 line
2.35.3
author maintainer
#17 lore raw

PATCH 6/8 tools: add new attest_tpm2_primary command

In reply to James Bottomley

This command can be used for three things which allow a system to build an ongoing trust relationship with the TPM. For TPMs which don't have EK certificates (most fTPMs) it allows a trust on first use model where the EK is squirreled away in a permanent location on the filesystem as:

attest_tpm2_primary --ek > /etc/eksign.name

Which generates a signing EK that can be used to certify other objects and permanently stores the name in /etc (ideally this should be stored in an immutable location on OS install).

If the TPM does have a signing certificate, the next step is to verify the cert back to the manufacturer and bind it to the signing EK by doing

attest_tpm2_primary --attest --name /etc/eksign.name <ek cert file>

This will run a local makecredential/activatecredential on the signing EK using the public key in the <ek cert file>. Once this happens the TPM is proven to be a genuine discrete TPM.

Finally, having the permanent name file allows the signing EK to certify the NULL key used by the kernel on every boot via

attest_tpm2_primary --certify null --name /etc/eksign.name /sys/class/tpm/tpm0/null_name

Since the null_name changes on every boot this allows a user confidence that the TPM booted up correctly and isn't being snooped.

Additionally, the command can generate the public SRK for importable keys by running a certification against the signing EK to verify it isn't being spoofed:

attest_tpm2_primary --certify owner --name /etc/eksign.name --file srk.pub

---
 src/tools/Makefile.am           |   6 +-
 src/tools/attest_tpm2_primary.c | 842 ++++++++++++++++++++++++++++++++
 2 files changed, 847 insertions(+), 1 deletion(-)
 create mode 100644 src/tools/attest_tpm2_primary.c
src/tools/Makefile.am +5 -1
index 572847c..7cca442 100644
@@ -12,7 +12,7 @@ endif
 AM_CPPFLAGS = -I ../include ${DEPRECATION}
 
 bin_PROGRAMS=create_tpm2_key load_tpm2_key seal_tpm2_data unseal_tpm2_data \
-	signed_tpm2_policy
+	signed_tpm2_policy attest_tpm2_primary
 COMMONLIB = ../libcommon/libcommon.a
 
 create_tpm2_key_SOURCES=create_tpm2_key.c
@@ -35,6 +35,10 @@ signed_tpm2_policy_SOURCES=signed_tpm2_policy.c
 signed_tpm2_policy_LDADD=${COMMONLIB} ${DEPS_LIBS}
 signed_tpm2_policy_CFLAGS=${DEPS_CFLAGS}
 
+attest_tpm2_primary_SOURCES=attest_tpm2_primary.c
+attest_tpm2_primary_LDADD=${COMMONLIB} ${DEPS_LIBS}
+attest_tpm2_primary_CFLAGS=${DEPS_CFLAGS}
+
 $(builddir)/%.1: $(srcdir)/%.1.in $(builddir)/%
 	$(HELP2MAN) --no-info -i $< -o $@ $(builddir)/$*
 
src/tools/attest_tpm2_primary.c new file +842 -0

842 lines not on this page · raw message

Signature · 1 line
2.35.3
author maintainer
#18 lore raw

PATCH 7/8 attest_tpm2_primary: add man page

In reply to James Bottomley
---
 src/tools/Makefile.am              |   5 +-
 src/tools/attest_tpm2_primary.1.in | 103 +++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 2 deletions(-)
 create mode 100644 src/tools/attest_tpm2_primary.1.in
src/tools/Makefile.am +3 -2
index 7cca442..3012411 100644
@@ -1,9 +1,10 @@
 if NATIVE_BUILD
 EXTRA_DIST = create_tpm2_key.1 load_tpm2_key.1 seal_tpm2_data.1 \
-	unseal_tpm2_data.1 signed_tpm2_policy.1 openssl_tpm2_engine.7
+	unseal_tpm2_data.1 signed_tpm2_policy.1 openssl_tpm2_engine.7 \
+	attest_tpm2_primary.1
 
 man1_MANS = create_tpm2_key.1 load_tpm2_key.1 seal_tpm2_data.1 \
-	unseal_tpm2_data.1 signed_tpm2_policy.1
+	unseal_tpm2_data.1 signed_tpm2_policy.1 attest_tpm2_primary.1
 man7_MANS = openssl_tpm2_engine.7
 
 CLEANFILES = $(man1_MANS)
src/tools/attest_tpm2_primary.1.in new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.35.3
author maintainer
#19 lore raw

PATCH 8/8 tests: add tests for attest_tpm2_primary

In reply to James Bottomley
---
 tests/attestation.sh       | 30 ++++++++++++++++++++++++++++++
 tests/check_importable.sh  |  3 +--
 tests/engine/Makefile.am   |  3 ++-
 tests/provider/Makefile.am |  3 ++-
 tests/seal_unseal.sh       |  3 +--
 tests/start_sw_tpm.sh      |  2 ++
 6 files changed, 38 insertions(+), 6 deletions(-)
 create mode 100755 tests/attestation.sh
tests/attestation.sh new file +30 -0
new file mode 100755
index 0000000..bd927fa
@@ -0,0 +1,30 @@
+#!/bin/bash
+set -x
+
+##
+# We already created eksign.name and null.name, so check them first
+##
+${bindir}/attest_tpm2_primary --eksign --name ${testdir}/eksign.name || exit 1
+${bindir}/attest_tpm2_primary --eksign --name ${testdir}/null.name && exit 1
+${bindir}/attest_tpm2_primary --certify null --name ${testdir}/eksign.name ${testdir}/null.name || exit 1
+##
+# Run through certification of all the keys (already done null above
+##
+for h in owner endorsement platform; do
+    rm -f tmp.name
+    ${bindir}/attest_tpm2_primary -C ${h} -n ${testdir}/eksign.name -o > tmp.name || exit 1
+    ${bindir}/attest_tpm2_primary -C ${h} -n ${testdir}/eksign.name tmp.name || exit 1
+    ${bindir}/attest_tpm2_primary -C ${h} -n ${testdir}/eksign.name null.name && exit 1
+done
+##
+# attestation tests
+# 1. create both P-256 and RSA2048 attestation certs
+##
+openssl genrsa 2048 > ca.key || exit 1
+# several EK templates exist, so try RSA and EC for each
+for high in "" "-high"; do
+    for alg in "-rsa 2048" "-ecc nistp256"; do
+	tsscreateekcert ${high} ${alg} -cakey ca.key -of cert.der || exit 1
+	${bindir}/attest_tpm2_primary --attest cert.der --name ${testdir}/eksign.name || exit 1
+    done
+done
tests/check_importable.sh +1 -2
index eeafe03..ee84f16 100755
@@ -2,8 +2,7 @@
 
 
 # export the parent key as a EC and RSA public key
-prim=$(tsscreateprimary -ecc nistp256 -hi o -opem srk.pub | sed 's/Handle //') || exit 1
-tssflushcontext -ha ${prim} || exit 1
+${bindir}/attest_tpm2_primary --certify owner --name ${testdir}/eksign.name --file srk.pub || exit 1
 prim=$(tsscreateprimary -rsa 2048 -hi o -opem srkrsa.pub | sed 's/Handle //') || exit 1
 tssflushcontext -ha ${prim} || exit 1
 
tests/engine/Makefile.am +2 -1
index ec6f321..7bade2b 100644
@@ -30,6 +30,7 @@ TESTS += ../check_curves.sh \
 	../check_locality.sh \
 	../check_secret_policies.sh \
 	../dynamic_engine.sh \
+	../attestation.sh \
 	../stop_sw_tpm.sh
 
 fail_connect.sh: tpm_server_found
@@ -53,6 +54,6 @@ AM_TESTS_ENVIRONMENT = TPM_INTERFACE_TYPE=socsim; export TPM_INTERFACE_TYPE; \
 
 TEST_EXTENSIONS = .sh
 
-CLEANFILES = key*.tpm key*.pub key*.priv tmp.* NVChip h*.bin key*.der seal.* fifo tss2.*
+CLEANFILES = key*.tpm key*.pub key*.priv tmp.* NVChip h*.bin key*.der seal.* fifo tss2.* *.name
 clean-local:
 	rm -fr testdir
tests/provider/Makefile.am +2 -1
index 1080036..05bbee1 100644
@@ -31,6 +31,7 @@ TESTS += ../check_curves.sh \
 	../check_signed_policies.sh \
 	../check_locality.sh \
 	../check_secret_policies.sh \
+	../attestation.sh \
 	../stop_sw_tpm.sh
 
 fail_connect.sh: tpm_server_found
@@ -56,7 +57,7 @@ endif
 
 TEST_EXTENSIONS = .sh
 
-CLEANFILES = key*.tpm key*.pub key*.priv tmp.* NVChip h*.bin key*.der seal.* fifo tss2.*
+CLEANFILES = key*.tpm key*.pub key*.priv tmp.* NVChip h*.bin key*.der seal.* fifo tss2.* *.name
 clean-local:
 	rm -fr testdir
 
tests/seal_unseal.sh +1 -2
index 6d05a4c..2df3aa8 100755
@@ -48,8 +48,7 @@ for n in sha1 sha256 sha384; do
     else
 	POLICYFILE="${testdir}/policies/policy_pcr${n}.txt"
     fi
-    prim=$(tsscreateprimary -hi o -st -ecc nistp256 -opem srk.pub | sed 's/Handle //') || exit 1
-    tssflushcontext -ha $prim
+    ${bindir}/attest_tpm2_primary -C owner -n ${testdir}/eksign.name -f srk.pub || exit 1
     TPM_INTERFACE_TYPE= echo $DATA | ${bindir}/seal_tpm2_data -n ${n} -a -k ${AUTH} --import srk.pub seal.tpm || exit 1;
     ${bindir}/unseal_tpm2_data -k ${AUTH} seal.tpm | grep -q "${DATA}" || exit 1;
     rm seal.tpm
tests/start_sw_tpm.sh +2 -0
index 5f249a5..1e0e4db 100755
@@ -56,3 +56,5 @@ key=$(tsscreateprimary -hi o -st -rsa|sed 's/Handle //') && \
 tssevictcontrol -hi o -ho ${key} -hp 81000001 && \
 tssflushcontext -ha ${key}
 
+${bindir}/attest_tpm2_primary --ek > ${testdir}/eksign.name || exit 1
+${bindir}/attest_tpm2_primary --certify null --outname --name ${testdir}/eksign.name > ${testdir}/null.name || exit 1
Signature · 1 line
2.35.3