Skip to content

Commit 4b0e42c

Browse files
authored
Merge pull request #360 from dgarske/get_ek_certs
Support for getting TPM EK Certificates
2 parents fb7e321 + 8f1e35a commit 4b0e42c

File tree

16 files changed

+1400
-57
lines changed

16 files changed

+1400
-57
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ examples/boot/secret_seal
7979
examples/boot/secret_unseal
8080
examples/firmware/ifx_fw_extract
8181
examples/firmware/ifx_fw_update
82+
examples/endorsement/get_ek_certs
8283

8384
# Generated Cert Files
8485
certs/ca-*.pem

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Portable TPM 2.0 project designed for embedded use.
3434
* Parameter encryption support using AES-CFB or XOR.
3535
* Support for salted unbound authenticated sessions.
3636
* Support for HMAC Sessions.
37+
* Support for reading Endorsement certificates (EK Credential Profile).
3738

3839
Note: See [examples/README.md](examples/README.md) for details on using the examples.
3940

@@ -168,7 +169,7 @@ make install
168169
# then for some other library such as wolfTPM:
169170

170171
# cd /your-wolftpm-repo
171-
./configure --enable-swtpm --with-wolfcrypt=~/workspace/my_wolfssl_bin
172+
./configure --enable-swtpm --with-wolfcrypt=~/workspace/my_wolfssl_bin
172173
```
173174

174175
### Build options and defines
@@ -823,9 +824,15 @@ Connection: close
823824
```
824825

825826

827+
### TPM Endorsement Key Certificates
828+
829+
The TCG EK Credential Profile defines how manufacturers provision endorsement certificates in the TCG NV index range (see TPM_20_TCG_NV_SPACE).
830+
The `get_ek_certs` example shows how to retrieve those EK cerificates, validate them and create a primary EK handle for signing.
831+
See `./examples/endorsement/get_ek_certs`.
832+
833+
826834
## Todo
827835

828-
* Add support for Endorsement certificates (EK Credential Profile).
829836
* Update to v1.59 of specification (adding CertifyX509).
830837
* Inner wrap support for SensitiveToPrivate.
831838
* Add support for IRQ (interrupt line)

examples/endorsement/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# TPM Endorsement Certificates
2+
3+
TPM manufactures provision Endorsement Certificates based on a TPM key. This certificate can be used for signing/endorsement.
4+
5+
The `get_ek_certs` example will enumerate and validate the Endorsement Key Certificates stored in the NV TCG region.
6+
7+
We have loaded some of the root and intermediate CA's into the trusted_certs.h file.
8+
9+
## Example Detail
10+
11+
1) Get handles in the TCG NV range using `wolfTPM2_GetHandles` with `TPM_20_TCG_NV_SPACE`.
12+
2) Get size of the certificate by reading the public NV information using `wolfTPM2_NVReadPublic`.
13+
3) Read the NV data (certificate DER/ASN.1) from the NV index using `wolfTPM2_NVReadAuth`.
14+
4) Get the EK public template using the NV index by calling `wolfTPM2_GetKeyTemplate_EKIndex` or `wolfTPM2_GetKeyTemplate_EK`.
15+
5) Create the primary endorsement key with public template and TPM_RH_ENDORSEMENT hierarchy using `wolfTPM2_CreatePrimaryKey`.
16+
6) Parse the ASN.1/DER certificate using `wc_ParseCert` to extract issuer, serial number, etc...
17+
7) The URI for the CA issuer certificate can be obtained in `extAuthInfoCaIssuer`.
18+
8) Import the certificate public key and compare it against the primary EK public unique area.
19+
9) Use the wolfSSL Certificate Manager to validate the EK certificate. Trusted certificates are loaded using `wolfSSL_CertManagerLoadCABuffer` and the EK certificate is validated using `wolfSSL_CertManagerVerifyBuffer`.
20+
10) Optionally covert to PEM and export using `wc_DerToPem`.
21+
22+
## Example certificate chains
23+
24+
### Infineon SLB9672
25+
26+
Infineon certificates for TPM 2.0 can be downloaded from the following URLs (replace xxx with 3-digit CA number):
27+
28+
https://pki.infineon.com/OptigaRsaMfrCAxxx/OptigaRsaMfrCAxxx.crt
29+
https://pki.infineon.com/OptigaEccMfrCAxxx/OptigaEccMfrCAxxx.crt
30+
31+
32+
Examples:
33+
34+
- Infineon OPTIGA(TM) RSA Root CA 2
35+
- Infineon OPTIGA(TM) TPM 2.0 RSA CA 059
36+
- Infineon OPTIGA(TM) ECC Root CA 2
37+
- Infineon OPTIGA(TM) TPM 2.0 ECC CA 059
38+
39+
### STMicro ST33KTPM
40+
41+
Example:
42+
43+
- STSAFE RSA root CA 02 (http://sw-center.st.com/STSAFE/STSAFERsaRootCA02.crt)
44+
- STSAFE-TPM RSA intermediate CA 10 (http://sw-center.st.com/STSAFE/stsafetpmrsaint10.crt)
45+
- STSAFE ECC root CA 02 (http://sw-center.st.com/STSAFE/STSAFEEccRootCA02.crt)
46+
- STSAFE-TPM ECC intermediate CA 10 (http://sw-center.st.com/STSAFE/stsafetpmeccint10.crt)

examples/endorsement/endorsement.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* endorsement.h
2+
*
3+
* Copyright (C) 2006-2024 wolfSSL Inc.
4+
*
5+
* This file is part of wolfTPM.
6+
*
7+
* wolfTPM is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfTPM is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
22+
#ifndef _WOLFTPM_ENDORSEMENT_H_
23+
#define _WOLFTPM_ENDORSEMENT_H_
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
int TPM2_EndorsementCert_Example(void* userCtx, int argc, char *argv[]);
30+
31+
#ifdef __cplusplus
32+
} /* extern "C" */
33+
#endif
34+
35+
#endif /* _WOLFTPM_ENDORSEMENT_H_ */

0 commit comments

Comments
 (0)