Project

General

Profile

Trusted Platform Module 2.0 » History » Version 136

Andreas Steffen, 03.01.2021 11:22

1 17 Andreas Steffen
h1. Trusted Platform Module 2.0
2 1 Andreas Steffen
3 6 Andreas Steffen
{{>toc}}
4 6 Andreas Steffen
5 51 Andreas Steffen
h2. Connect to a TPM 2.0 Device
6 1 Andreas Steffen
7 131 Andreas Steffen
h3. Install TPM 2.0 Software Stack and Tools
8 51 Andreas Steffen
9 90 Andreas Steffen
In order to connect to a TPM 2.0 hardware or firmware device a software stack implementing the "TCG TSS 2.0 System Level API":https://trustedcomputinggroup.org/resource/tcg-tss-2-0-system-level-api-sapi-specification/ is needed. An excellent open source "tpm2-tss":https://github.com/tpm2-software/tpm2-tss library is available from the "tpm2-software":https://github.com/tpm2-software project which also offers a set of "tpm2-tools":https://github.com/tpm2-software/tpm2-tools which itself uses the "TCG TSS 2.0 Enhanced System Level API":https://trustedcomputinggroup.org/resource/tcg-tss-2-0-enhanced-system-api-esapi-specification/.
10 1 Andreas Steffen
11 89 Andreas Steffen
When using the latest *strongswan-5.9.1* version with a *Linux 5.4* kernel or newer, we recommend these latest versions:
12 1 Andreas Steffen
13 89 Andreas Steffen
* *tpm2-tss* version 3.0.3: https://github.com/tpm2-software/tpm2-tss/releases/tag/3.0.3
14 79 Andreas Steffen
15 89 Andreas Steffen
* *tpm2-tools* version 5.0: https://github.com/tpm2-software/tpm2-tools/releases/tag/5.0
16 79 Andreas Steffen
17 90 Andreas Steffen
Support for earlier strongSwan versions and Linux kernels can be found [[TpmPluginOld|here]].
18 71 Andreas Steffen
19 91 Andreas Steffen
In order to test if we can connect to the TPM 2.0 device we list all persistent keys stored in the Non-Volatile (NV) RAM:
20 3 Andreas Steffen
<pre>
21 91 Andreas Steffen
tpm2_getcap handles-persistent
22 91 Andreas Steffen
- 0x81000001
23 91 Andreas Steffen
- 0x81000002
24 91 Andreas Steffen
- 0x81010001
25 18 Andreas Steffen
</pre>
26 1 Andreas Steffen
27 93 Andreas Steffen
A manual showing all *tpm2-tools* functions with their arguments can be found "here":https://github.com/tpm2-software/tpm2-tools/tree/5.0/man. The access to the */dev/tpmrm0* TPM resource manager device requires *root* rights on most Linux platforms. But e.g. with Ubuntu, adding the user to the *tss* group enables direct access to the TPM device:
28 92 Andreas Steffen
<pre>
29 92 Andreas Steffen
sudo usermod -a -G tss <username>
30 92 Andreas Steffen
</pre>
31 96 Andreas Steffen
32 51 Andreas Steffen
h3. Enable the strongSwan tpm Plugin
33 51 Andreas Steffen
34 51 Andreas Steffen
The strongSwan libtpmtss *tpm* plugin and the TSS2 interface are enabled and built with the following options
35 51 Andreas Steffen
36 1 Andreas Steffen
  ./configure --enable-tss-tss2 --enable-tpm  ...
37 96 Andreas Steffen
38 117 Andreas Steffen
With the strongSwan [[IpsecPki|pki]] tool we can now list the persistent key stored under the handle *0x81010001*
39 96 Andreas Steffen
<pre>
40 96 Andreas Steffen
pki --print --type priv --keyid 0x81010001 --debug 2
41 97 Andreas Steffen
</pre>
42 98 Andreas Steffen
With debug level 2 some basic information on the TPM device is shown; A second generation Intel firmware TPM running on the Intel Management Engine is employed. Both SHA1 and SHA256 PCR banks are available:
43 97 Andreas Steffen
<pre>
44 96 Andreas Steffen
TPM 2.0 - manufacturer: INTC (Intel) rev: 01.38 2018 
45 96 Andreas Steffen
TPM 2.0 - algorithms: RSA SHA1 HMAC AES MGF1 KEYEDHASH XOR SHA256 RSASSA RSAES RSAPSS OAEP ECDSA ECDH ECDAA ECSCHNORR KDF1_SP800_56A KDF1_SP800_108 ECC SYMCIPHER CTR OFB CBC CFB ECB
46 96 Andreas Steffen
TPM 2.0 - ECC curves: NIST_P256 BN_P256
47 96 Andreas Steffen
TPM 2.0 - PCR banks: SHA1 SHA256
48 97 Andreas Steffen
</pre>
49 99 Andreas Steffen
Apparently the analyzed persistent key can be used for encryption only because no signature algorithm is defined:
50 97 Andreas Steffen
<pre>
51 96 Andreas Steffen
TPM 2.0 via TSS2 v2 available
52 96 Andreas Steffen
signature algorithm is NULL with ERROR hash
53 97 Andreas Steffen
</pre>
54 118 Andreas Steffen
Debug level 2 shows that [[IpsecPki|pki]] extracts the public key from the TPM and converts it into a standard PKCS#1 format:
55 97 Andreas Steffen
<pre>
56 96 Andreas Steffen
L0 - subjectPublicKeyInfo:
57 96 Andreas Steffen
L1 - algorithm:
58 96 Andreas Steffen
L2 - algorithmIdentifier:
59 96 Andreas Steffen
L3 - algorithm:
60 96 Andreas Steffen
  'rsaEncryption'
61 96 Andreas Steffen
L1 - subjectPublicKey:
62 96 Andreas Steffen
-- > --
63 96 Andreas Steffen
L0 - RSAPublicKey:
64 96 Andreas Steffen
L1 - modulus:
65 96 Andreas Steffen
L1 - publicExponent:
66 96 Andreas Steffen
-- < --
67 97 Andreas Steffen
</pre>
68 98 Andreas Steffen
At the end of the output the fingerprint of the 2048 bit RSA key is listed:
69 97 Andreas Steffen
<pre>
70 96 Andreas Steffen
  privkey:   RSA 2048 bits
71 96 Andreas Steffen
  keyid:     ee:c7:bf:5a:de:0f:11:84:2c:86:2b:69:84:ba:65:b9:81:d2:a9:45
72 1 Andreas Steffen
  subjkey:   df:f2:e9:e7:79:98:f0:d2:0b:62:db:c0:5c:2c:eb:45:73:85:e9:79
73 97 Andreas Steffen
</pre>
74 7 Andreas Steffen
75 128 Andreas Steffen
h2. Derive Persistent Endorsement Keys
76 1 Andreas Steffen
77 128 Andreas Steffen
h3. RSA Endorsement Key
78 128 Andreas Steffen
79 116 Andreas Steffen
The "tpm2_createek":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_createek.1.md command derives a 2048 bit RSA Endorsement Key (EK) in a deterministic way from the secret _Endorsement Primary Seed_ *unique* to each TPM device and makes the key persistent in the non-volatile memory of the TPM under the object handle *0x81010002*
80 11 Andreas Steffen
81 100 Andreas Steffen
 tpm2_createek -G rsa -c 0x81010002
82 1 Andreas Steffen
83 119 Andreas Steffen
Using the "tpm2_getcap":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_getcap.1.md command we can check that the newly derived Endorsement Key has been persisted in the NV RAM
84 100 Andreas Steffen
<pre>
85 100 Andreas Steffen
tpm2_getcap handles-persistent
86 100 Andreas Steffen
- 0x81000001
87 100 Andreas Steffen
- 0x81000002
88 100 Andreas Steffen
- 0x81010001
89 100 Andreas Steffen
- 0x81010002
90 100 Andreas Steffen
</pre>
91 101 Andreas Steffen
Listing the key properties shows that the 2048 bit Endorsement Key already exists under the handle *0x81010001* analyzed in the previous section
92 1 Andreas Steffen
<pre>
93 123 Andreas Steffen
pki --print --type priv --keyid 0x81010002
94 100 Andreas Steffen
TPM 2.0 via TSS2 v2 available
95 100 Andreas Steffen
signature algorithm is NULL with ERROR hash
96 100 Andreas Steffen
  privkey:   RSA 2048 bits
97 100 Andreas Steffen
  keyid:     ee:c7:bf:5a:de:0f:11:84:2c:86:2b:69:84:ba:65:b9:81:d2:a9:45
98 100 Andreas Steffen
  subjkey:   df:f2:e9:e7:79:98:f0:d2:0b:62:db:c0:5c:2c:eb:45:73:85:e9:79
99 1 Andreas Steffen
</pre>
100 1 Andreas Steffen
101 129 Andreas Steffen
h3. Delete Persisted Keys
102 126 Andreas Steffen
103 119 Andreas Steffen
We therefore delete the duplicate key with the following "tpm2_evictcontrol":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_evictcontrol.1.md command
104 100 Andreas Steffen
<pre>
105 100 Andreas Steffen
tpm2_evictcontrol -c 0x81010002
106 100 Andreas Steffen
persistent-handle: 0x81010002
107 100 Andreas Steffen
action: evicted
108 100 Andreas Steffen
</pre>
109 100 Andreas Steffen
The key removal can be verified with
110 100 Andreas Steffen
<pre>
111 100 Andreas Steffen
tpm2_getcap handles-persistent
112 100 Andreas Steffen
- 0x81000001
113 102 Andreas Steffen
- 0x81000002
114 1 Andreas Steffen
- 0x81010001
115 100 Andreas Steffen
</pre>
116 1 Andreas Steffen
117 128 Andreas Steffen
h3. ECC Endorsement Key
118 103 Andreas Steffen
119 120 Andreas Steffen
Again using the "tpm2_createek":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_createek.1.md command we derive a 256 bit ECC Endorsement Key (EK) in a deterministic way from the secret _Endorsement Primary Seed_ *unique* to each TPM device and make the key persistent in the non-volatile memory of the TPM under the object handle *0x81010002*:
120 103 Andreas Steffen
121 103 Andreas Steffen
 tpm2_createek -G ecc -c 0x81010002 -u ek_ecc.pub
122 103 Andreas Steffen
123 103 Andreas Steffen
Optionally we saved the public key in a TPM 2.0 proprietary format in the file *ek_ecc.pub*. The fingerprint of the ECC EK private key can be directly displayed with the command
124 105 Andreas Steffen
125 105 Andreas Steffen
<pre>
126 111 Andreas Steffen
pki --print --type priv --keyid 0x81010002
127 104 Andreas Steffen
TPM 2.0 via TSS2 v2 available
128 104 Andreas Steffen
signature algorithm is NULL with ERROR hash
129 103 Andreas Steffen
  privkey:   ECDSA 256 bits
130 103 Andreas Steffen
  keyid:     25:db:73:13:0f:c9:c8:91:68:30:8e:02:89:c1:0d:65:bd:ad:69:2a
131 103 Andreas Steffen
  subjkey:   9c:b9:fb:b0:32:81:24:82:a7:07:b2:bd:bd:d3:7c:2b:22:7f:74:bf
132 103 Andreas Steffen
</pre>
133 103 Andreas Steffen
134 103 Andreas Steffen
h2. Endorsement Key Certificates
135 103 Andreas Steffen
136 115 Andreas Steffen
h3. Fetched via URL
137 1 Andreas Steffen
138 115 Andreas Steffen
Endorsement Key certificates issued for Intel firmware TPMs can be automatically downloaded from an Intel web server using the "tpm2_getcertificate":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_getekcertificate.1.md command:
139 115 Andreas Steffen
140 112 Andreas Steffen
 tpm2_getekcertificate -o ek_ecc.crt -u ek_ecc.pub
141 106 Andreas Steffen
142 121 Andreas Steffen
For successful retrieval the public key *ek_ecc.pub* in the TPM 2.0 proprietary format is required. Using the [[IpsecPki|pki]] tool we can list the downloaded EK certificate belonging to the ECC key:
143 106 Andreas Steffen
<pre>
144 106 Andreas Steffen
pki --print --type x509 --in ek_ecc.crt
145 106 Andreas Steffen
  subject:  ""
146 106 Andreas Steffen
  issuer:   "C=US, ST=CA, L=Santa Clara, O=Intel Corporation, OU=TPM EK intermediate for CNL_EPID_POST_B1LP_PROD_2 pid:9, CN=www.intel.com"
147 106 Andreas Steffen
  validity:  not before Sep 04 02:00:00 2019, ok
148 106 Andreas Steffen
             not after  Jan 01 00:59:59 2050, ok (expires in 10600 days)
149 106 Andreas Steffen
  serial:    07:99:3b:c6:88:aa:7d:72:b0:24:24:05:09:01:bb:42:55:70:1a:43
150 106 Andreas Steffen
  altNames:  tcg-at-tpmManufacturer=id:494E5443, tcg-at-tpmModel=CNL, tcg-at-tpmVersion=id:00020000
151 106 Andreas Steffen
  CRL URIs:  https://trustedservices.intel.com/content/CRL/ekcert/CNLEPIDPOSTB1LPPROD2_EK_Device.crl
152 106 Andreas Steffen
  certificatePolicies:
153 106 Andreas Steffen
             1.2.840.113741.1.5.2.1
154 106 Andreas Steffen
             CPS: https://trustedservices.intel.com/content/CRL/ekcert/EKcertPolicyStatement.pdf
155 106 Andreas Steffen
  authkeyId: 17:a0:05:75:d0:5e:58:e3:88:12:10:bb:98:b1:04:5b:b4:c3:06:39
156 106 Andreas Steffen
  subjkeyId: 9c:b9:fb:b0:32:81:24:82:a7:07:b2:bd:bd:d3:7c:2b:22:7f:74:bf
157 106 Andreas Steffen
  pubkey:    ECDSA 256 bits
158 106 Andreas Steffen
  keyid:     25:db:73:13:0f:c9:c8:91:68:30:8e:02:89:c1:0d:65:bd:ad:69:2a
159 106 Andreas Steffen
  subjkey:   9c:b9:fb:b0:32:81:24:82:a7:07:b2:bd:bd:d3:7c:2b:22:7f:74:bf
160 106 Andreas Steffen
</pre>
161 121 Andreas Steffen
For the RSA 2048 Endorsement Key we first have to extract the public keyfile *ek_rsa.pub* in the TPM 2.0 proprietary format using the "tpm2_readpublic":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_readpublic.1.md command because we forgot to do this in the first place:
162 109 Andreas Steffen
163 110 Andreas Steffen
 tpm2_readpublic -Q -c 0x81010001 -o ek_rsa.pub
164 106 Andreas Steffen
165 110 Andreas Steffen
Now we can retrieve the RSA EK certificate, too:
166 106 Andreas Steffen
167 114 Andreas Steffen
 tpm2_getekcertificate -o ek_rsa.crt -u ek_rsa.pub
168 106 Andreas Steffen
169 106 Andreas Steffen
and view the contents with
170 106 Andreas Steffen
<pre>
171 106 Andreas Steffen
pki --print --type x509 --in ek_rsa.crt
172 106 Andreas Steffen
  subject:  ""
173 106 Andreas Steffen
  issuer:   "C=US, ST=CA, L=Santa Clara, O=Intel Corporation, OU=TPM EK intermediate for CNL_EPID_POST_B1LP_PROD_2 pid:9, CN=www.intel.com"
174 106 Andreas Steffen
  validity:  not before Sep 04 02:00:00 2019, ok
175 106 Andreas Steffen
             not after  Jan 01 00:59:59 2050, ok (expires in 10600 days)
176 106 Andreas Steffen
  serial:    14:26:0b:eb:12:a2:82:87:af:3b:75:e0:a1:a4:87:60:72:95:55:92
177 106 Andreas Steffen
  altNames:  tcg-at-tpmManufacturer=id:494E5443, tcg-at-tpmModel=CNL, tcg-at-tpmVersion=id:00020000
178 106 Andreas Steffen
  CRL URIs:  https://trustedservices.intel.com/content/CRL/ekcert/CNLEPIDPOSTB1LPPROD2_EK_Device.crl
179 106 Andreas Steffen
  certificatePolicies:
180 106 Andreas Steffen
             1.2.840.113741.1.5.2.1
181 106 Andreas Steffen
             CPS: https://trustedservices.intel.com/content/CRL/ekcert/EKcertPolicyStatement.pdf
182 106 Andreas Steffen
  authkeyId: 17:a0:05:75:d0:5e:58:e3:88:12:10:bb:98:b1:04:5b:b4:c3:06:39
183 106 Andreas Steffen
  subjkeyId: df:f2:e9:e7:79:98:f0:d2:0b:62:db:c0:5c:2c:eb:45:73:85:e9:79
184 106 Andreas Steffen
  pubkey:    RSA 2048 bits
185 106 Andreas Steffen
  keyid:     ee:c7:bf:5a:de:0f:11:84:2c:86:2b:69:84:ba:65:b9:81:d2:a9:45
186 106 Andreas Steffen
  subjkey:   df:f2:e9:e7:79:98:f0:d2:0b:62:db:c0:5c:2c:eb:45:73:85:e9:79
187 1 Andreas Steffen
</pre>
188 1 Andreas Steffen
189 115 Andreas Steffen
We can easily check that in both EK certificates the key fingerprints (__keyid__ and __subjkey__) match with those of the EK keys persisted in the TPM.
190 115 Andreas Steffen
191 115 Andreas Steffen
h3. Stored in Non-Volatile RAM
192 115 Andreas Steffen
193 115 Andreas Steffen
Most hardware TPMs are shipped with their Endorsement Key Certificates stored in NV RAM. E.g. on an STMicroelectronics TPM device the following data objects are stored in an NV index:
194 115 Andreas Steffen
<pre>
195 115 Andreas Steffen
tpm2_getcap handles-nv-index
196 115 Andreas Steffen
- 0x1410001
197 115 Andreas Steffen
- 0x1410002
198 115 Andreas Steffen
- 0x1410004
199 115 Andreas Steffen
- 0x1880001
200 115 Andreas Steffen
- 0x1880011
201 115 Andreas Steffen
- 0x1C00002
202 115 Andreas Steffen
- 0x1C0000A
203 115 Andreas Steffen
- 0x1C00012
204 115 Andreas Steffen
- 0x1C10102
205 115 Andreas Steffen
- 0x1C10103
206 115 Andreas Steffen
- 0x1C10104
207 115 Andreas Steffen
- 0x1C101C0
208 115 Andreas Steffen
</pre>
209 115 Andreas Steffen
Using the "tpm2_nvreadpublic":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_nvreadpublic.1.md command we can look for large data objects which are prime candidates for X.509 certificates:
210 115 Andreas Steffen
<pre>
211 115 Andreas Steffen
tpm2_nvreadpublic
212 115 Andreas Steffen
  ...
213 115 Andreas Steffen
0x1c00002:
214 115 Andreas Steffen
  name: 000b5c112bd5f410d0abe96a50e94ff721a005c32567e4b1112ab0a8fb7e0289b7f2
215 115 Andreas Steffen
  hash algorithm:
216 115 Andreas Steffen
    friendly: sha256
217 115 Andreas Steffen
    value: 0xB
218 115 Andreas Steffen
  attributes:
219 115 Andreas Steffen
    friendly: ppwrite|writedefine|write_stclear|ppread|ownerread|authread|no_da|written|platformcreate
220 115 Andreas Steffen
    value: 0x1600762
221 115 Andreas Steffen
  size: 1033
222 115 Andreas Steffen
223 115 Andreas Steffen
0x1c0000a:
224 115 Andreas Steffen
  name: 000b1948300e66afad594b7a8e8368d53ddd36908fb2b46dd7b5a88051b50e4047ab
225 115 Andreas Steffen
  hash algorithm:
226 115 Andreas Steffen
    friendly: sha256
227 115 Andreas Steffen
    value: 0xB
228 115 Andreas Steffen
  attributes:
229 115 Andreas Steffen
    friendly: ppwrite|writedefine|write_stclear|ppread|ownerread|authread|no_da|written|platformcreate
230 115 Andreas Steffen
    value: 0x1600762
231 115 Andreas Steffen
  size: 639
232 115 Andreas Steffen
233 115 Andreas Steffen
0x1c00012:
234 115 Andreas Steffen
  name: 000cde411e123085083eedb1c9312e08dd8d229df6a5e16996035a2e3000d860b372c924de0354a6af4c7886656d2065814f
235 115 Andreas Steffen
  hash algorithm:
236 115 Andreas Steffen
    friendly: sha384
237 115 Andreas Steffen
    value: 0xC
238 115 Andreas Steffen
  attributes:
239 115 Andreas Steffen
    friendly: ppwrite|writedefine|write_stclear|ppread|ownerread|authread|no_da|written|platformcreate
240 115 Andreas Steffen
    value: 0x1600762
241 115 Andreas Steffen
  size: 707
242 115 Andreas Steffen
  ...
243 115 Andreas Steffen
</pre>
244 130 Andreas Steffen
We can use [[IpsecPki|pki]] to directly list the properties of the EK certificates:
245 115 Andreas Steffen
<pre>
246 115 Andreas Steffen
pki --print --type x509 --keyid 0x01c00002
247 115 Andreas Steffen
TPM 2.0 via TSS2 v2 available
248 115 Andreas Steffen
loaded certificate from TPM NV index 0x01c00002
249 115 Andreas Steffen
  subject:  ""
250 115 Andreas Steffen
  issuer:   "C=CH, O=STMicroelectronics NV, CN=STM TPM EK Intermediate CA 06"
251 115 Andreas Steffen
  validity:  not before Feb 11 01:00:00 2020, ok
252 115 Andreas Steffen
             not after  Jan 01 01:00:00 2031, ok (expires in 3650 days)
253 115 Andreas Steffen
  serial:    72:78:a1:2c:87:b6:aa:45:c4:1f:57:ff:d1:3d:cf:93:42:34:b9:c9
254 115 Andreas Steffen
  altNames:  tcg-at-tpmManufacturer=id:53544D20, tcg-at-tpmModel=ST33HTPHAHD4, tcg-at-tpmVersion=id:00010101
255 115 Andreas Steffen
  authkeyId: fb:17:d7:0d:73:48:70:e9:19:c4:e8:e6:03:97:5e:66:4e:0e:43:de
256 115 Andreas Steffen
  subjkeyId: e9:3d:51:32:04:42:73:3e:fc:bb:9e:f8:0c:21:9a:53:ec:73:80:94
257 115 Andreas Steffen
  pubkey:    RSA 2048 bits
258 115 Andreas Steffen
  keyid:     d3:e3:71:79:df:32:53:34:60:0f:1f:38:dc:d4:6d:53:59:1b:c5:3c
259 115 Andreas Steffen
  subjkey:   e9:3d:51:32:04:42:73:3e:fc:bb:9e:f8:0c:21:9a:53:ec:73:80:94
260 115 Andreas Steffen
</pre>
261 115 Andreas Steffen
<pre>
262 115 Andreas Steffen
pki --print --type x509 --keyid 0x01c0000a
263 115 Andreas Steffen
TPM 2.0 via TSS2 v2 available
264 115 Andreas Steffen
loaded certificate from TPM NV index 0x01c0000a
265 115 Andreas Steffen
  subject:  ""
266 115 Andreas Steffen
  issuer:   "C=CH, O=STMicroelectronics NV, CN=STM TPM ECC Intermediate CA 02"
267 115 Andreas Steffen
  validity:  not before Mar 09 01:00:00 2020, ok
268 115 Andreas Steffen
             not after  Jan 01 01:00:00 2031, ok (expires in 3650 days)
269 115 Andreas Steffen
  serial:    51:e8:fc:b2:64:8d:1d:36:a5:bc:d7:c9:63:c1:d6:de:e7:25:09:a4
270 115 Andreas Steffen
  altNames:  tcg-at-tpmManufacturer=id:53544D20, tcg-at-tpmModel=ST33HTPHAHD4, tcg-at-tpmVersion=id:00010101
271 115 Andreas Steffen
  authkeyId: 66:2d:8f:1c:ec:df:f1:47:a8:b6:f0:ea:29:6a:f7:f2:4c:ad:f9:cf
272 115 Andreas Steffen
  subjkeyId: d1:e8:fc:b2:64:8d:1d:36:a5:bc:d7:c9:63:c1:d6:de:e7:25:09:a4
273 115 Andreas Steffen
  pubkey:    ECDSA 256 bits
274 115 Andreas Steffen
  keyid:     8b:62:31:bf:08:9d:39:74:6d:05:fd:35:eb:2e:13:64:12:86:03:16
275 115 Andreas Steffen
  subjkey:   d1:e8:fc:b2:64:8d:1d:36:a5:bc:d7:c9:63:c1:d6:de:e7:25:09:a4
276 115 Andreas Steffen
</pre>
277 115 Andreas Steffen
or we can first retrieve the binary certificate blob from the NV RAM using the "tpm2_nvread":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_nvread.1.md command:
278 115 Andreas Steffen
279 115 Andreas Steffen
 tpm2_nvread 0x01c00012 -C o -o ek_ecc384.crt
280 115 Andreas Steffen
281 115 Andreas Steffen
and then list the properties of the EK certificate file:
282 115 Andreas Steffen
<pre>
283 115 Andreas Steffen
pki --print --type x509 --in ek_ecc384.crt 
284 115 Andreas Steffen
  subject:  ""
285 115 Andreas Steffen
  issuer:   "C=CH, O=STMicroelectronics NV, CN=STM TPM ECC384 Intermediate CA 01"
286 115 Andreas Steffen
  validity:  not before Feb 08 01:00:00 2020, ok
287 115 Andreas Steffen
             not after  Jan 01 01:00:00 2031, ok (expires in 3650 days)
288 115 Andreas Steffen
  serial:    39:ed:ae:d4:89:9e:52:08:9f:42:8a:f5:d5:58:7b:50:a6:24:f3:63
289 115 Andreas Steffen
  altNames:  tcg-at-tpmManufacturer=id:53544D20, tcg-at-tpmModel=ST33HTPHAHD4, tcg-at-tpmVersion=id:00010101
290 115 Andreas Steffen
  authkeyId: bd:96:3e:9a:d5:74:aa:d9:4f:ad:6c:bf:41:6d:d8:5b:4a:55:99:42
291 115 Andreas Steffen
  subjkeyId: b9:ed:ae:d4:89:9e:52:08:9f:42:8a:f5:d5:58:7b:50:a6:24:f3:63
292 115 Andreas Steffen
  pubkey:    ECDSA 384 bits
293 115 Andreas Steffen
  keyid:     04:68:52:c4:00:ab:10:75:82:57:99:45:1e:7c:12:01:5a:8e:50:c9
294 1 Andreas Steffen
  subjkey:   b9:ed:ae:d4:89:9e:52:08:9f:42:8a:f5:d5:58:7b:50:a6:24:f3:63
295 1 Andreas Steffen
</pre>
296 130 Andreas Steffen
We see that the STMicroelectronics device apparently supports 384 bit ECC keys
297 130 Andreas Steffen
<pre>
298 130 Andreas Steffen
TPM 2.0 - manufacturer: STM  () rev: 01.38 2018 FIPS 140-2
299 130 Andreas Steffen
TPM 2.0 - algorithms: RSA SHA1 HMAC AES MGF1 KEYEDHASH XOR SHA256 SHA384 RSASSA RSAES RSAPSS OAEP ECDSA ECDH ECDAA ECSCHNORR KDF1_SP800_56A KDF1_SP800_108 ECC SYMCIPHER SHA3_256 SHA3_384 CTR OFB CBC CFB ECB
300 130 Andreas Steffen
TPM 2.0 - ECC curves: NIST_P256 NIST_P384 BN_P256
301 130 Andreas Steffen
TPM 2.0 - PCR banks: SHA1 SHA256
302 130 Andreas Steffen
</pre>
303 1 Andreas Steffen
304 128 Andreas Steffen
h2. Generate Persistent Attestation Keys
305 107 Andreas Steffen
306 128 Andreas Steffen
h3. RSA Attestation Key
307 128 Andreas Steffen
308 133 Andreas Steffen
A 2048 bit RSA Attestation Key (AK) bound to the RSA EK with handle *0x81010001* can be created with the "tpm2_createak":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_createak.1.md command:
309 25 Andreas Steffen
310 124 Andreas Steffen
  tpm2_createak -C 0x81010001 -G rsa -g sha256 -s rsassa -c ak_rsa.ctx -u ak_rsa.pub -n ak_rsa.name
311 1 Andreas Steffen
312 124 Andreas Steffen
and made persistent under the handle *0x81010003* with the "tpm2_evictcontrol":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_evictcontrol.1.md command:
313 124 Andreas Steffen
<pre>
314 124 Andreas Steffen
tpm2_evictcontrol -C o -c ak_rsa.ctx 0x81010003
315 124 Andreas Steffen
persistent-handle: 0x81010003
316 124 Andreas Steffen
action: persisted
317 124 Andreas Steffen
</pre>
318 125 Andreas Steffen
The properties of the RSA AK which is a signing key can be displayed with the command
319 124 Andreas Steffen
<pre>
320 124 Andreas Steffen
pki --print --type priv --keyid 0x81010003
321 124 Andreas Steffen
TPM 2.0 via TSS2 v2 available
322 124 Andreas Steffen
signature algorithm is RSASSA with SHA256 hash
323 1 Andreas Steffen
  privkey:   RSA 2048 bits
324 124 Andreas Steffen
  keyid:     df:b7:8f:95:61:8f:70:84:f4:03:e8:7e:83:a6:dd:5f:c5:ff:72:b5
325 124 Andreas Steffen
  subjkey:   48:82:62:15:74:a2:10:c5:75:70:c2:d6:7d:59:9f:22:d9:4f:9c:07
326 124 Andreas Steffen
</pre>
327 13 Andreas Steffen
328 128 Andreas Steffen
h3. ECC Attestation Key
329 84 Andreas Steffen
330 132 Andreas Steffen
A 256 bit ECC Attestation Key (AK) bound to the ECC EK with handle *0x81010002* can be created with the "tpm2_createak":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_createak.1.md command:
331 13 Andreas Steffen
332 127 Andreas Steffen
 tpm2_createak -C 0x81010002 -G ecc -g sha256 -s ecdsa -c ak_ecc.ctx -u ak_ecc.pub -n ak_ecc.name
333 1 Andreas Steffen
334 127 Andreas Steffen
and made persistent under the handle *0x81010004* with the "tpm2_evictcontrol":https://github.com/tpm2-software/tpm2-tools/blob/5.0/man/tpm2_evictcontrol.1.md command:
335 127 Andreas Steffen
<pre>
336 127 Andreas Steffen
tpm2_evictcontrol -C o -c ak_ecc.ctx 0x81010004
337 127 Andreas Steffen
persistent-handle: 0x81010004
338 127 Andreas Steffen
action: persisted
339 127 Andreas Steffen
</pre>
340 127 Andreas Steffen
The properties of the ECC AK which is a signing key can be displayed with the command
341 127 Andreas Steffen
<pre>
342 127 Andreas Steffen
pki --print --type priv --keyid 0x81010004
343 127 Andreas Steffen
TPM 2.0 via TSS2 v2 available
344 1 Andreas Steffen
signature algorithm is ECDSA with SHA256 hash
345 127 Andreas Steffen
  privkey:   ECDSA 256 bits
346 1 Andreas Steffen
  keyid:     ba:64:37:a4:0e:c8:42:67:8c:55:5a:f9:1b:2a:eb:ff:5f:40:c3:e3
347 1 Andreas Steffen
  subjkey:   cc:83:49:87:2b:9e:f3:cb:b8:35:12:02:87:ff:14:89:28:44:a6:04
348 127 Andreas Steffen
</pre>
349 127 Andreas Steffen
350 128 Andreas Steffen
h2. Generate PKCS#10 Certificate Requests
351 1 Andreas Steffen
352 128 Andreas Steffen
h3. RSA Certificate Request
353 128 Andreas Steffen
354 134 Andreas Steffen
The [[IpsecPki|pki]] tool can directly generate a PKCS#10 certificate request self-signed by the TPM 2.0 private key and containing the corresponding public key as well as the desired end entity identity: 
355 127 Andreas Steffen
<pre>
356 127 Andreas Steffen
pki --req --type priv --keyid 0x81010003 \
357 127 Andreas Steffen
    --dn "C=CH, O=strongSec GmbH, OU=AK RSA, CN=edu.strongsec.com" \
358 127 Andreas Steffen
    --san edu.strongsec.com --outform pem > ak_rsa_req.pem
359 127 Andreas Steffen
TPM 2.0 via TSS2 v2 available
360 127 Andreas Steffen
signature algorithm is RSASSA with SHA256 hash
361 127 Andreas Steffen
Smartcard PIN: <return>
362 1 Andreas Steffen
</pre>
363 134 Andreas Steffen
Since we didn't configure a password when creating the AK, just press <return> when prompted for the PIN. With *openssl* we can verify the contents of the generated certificate request:
364 127 Andreas Steffen
<pre>
365 127 Andreas Steffen
openssl req -in ak_rsa_req.pem -noout -text
366 127 Andreas Steffen
Certificate Request:
367 127 Andreas Steffen
    Data:
368 127 Andreas Steffen
        Version: 1 (0x0)
369 127 Andreas Steffen
        Subject: C = CH, O = strongSec GmbH, OU = AK RSA, CN = edu.strongsec.com
370 127 Andreas Steffen
        Subject Public Key Info:
371 127 Andreas Steffen
            Public Key Algorithm: rsaEncryption
372 127 Andreas Steffen
                RSA Public-Key: (2048 bit)
373 127 Andreas Steffen
                Modulus:
374 127 Andreas Steffen
                    00:9e:cc:3c:be:0a:37:86:db:ab:a5:01:49:a4:be:
375 127 Andreas Steffen
                    0f:10:0e:32:50:12:27:64:52:85:0f:21:5e:c7:14:
376 127 Andreas Steffen
                    f4:d9:7f:95:0a:22:91:73:9f:60:07:45:d3:8e:4b:
377 127 Andreas Steffen
                    6d:94:00:83:44:ed:9c:f2:c0:14:9c:33:01:46:d0:
378 127 Andreas Steffen
                    78:e4:10:ae:51:3a:9c:c2:b7:a0:c7:04:66:80:bb:
379 127 Andreas Steffen
                    c2:bc:02:5b:d6:de:da:93:98:de:a7:cd:a5:5d:c1:
380 127 Andreas Steffen
                    8a:bb:13:8b:d9:21:88:c0:61:40:d2:30:eb:0d:dd:
381 127 Andreas Steffen
                    63:8d:a4:e0:b0:1a:bb:18:7f:6e:62:e1:bf:b3:39:
382 127 Andreas Steffen
                    fa:c2:80:32:88:6a:da:f0:24:90:5c:16:b6:bb:30:
383 127 Andreas Steffen
                    5d:96:25:24:cf:f2:03:19:0f:56:58:f2:32:00:51:
384 127 Andreas Steffen
                    8b:0a:c3:15:81:db:34:ee:a4:64:5b:b6:3c:e6:d3:
385 127 Andreas Steffen
                    df:e3:16:80:07:0e:13:91:4d:18:9c:b3:fd:ca:72:
386 127 Andreas Steffen
                    78:72:56:e9:13:4c:1d:a2:03:f0:e1:8d:cd:54:1c:
387 127 Andreas Steffen
                    68:ea:46:47:1c:f9:f9:97:7a:f1:59:96:58:6c:d8:
388 127 Andreas Steffen
                    8e:a9:15:fc:4d:93:5d:fa:51:5d:33:5a:bb:77:59:
389 127 Andreas Steffen
                    18:3e:6b:f6:45:f7:92:c2:12:0a:bb:64:af:0b:ff:
390 127 Andreas Steffen
                    0d:08:7a:18:90:d9:10:63:b1:6a:19:78:da:9d:ab:
391 127 Andreas Steffen
                    7a:87
392 127 Andreas Steffen
                Exponent: 65537 (0x10001)
393 127 Andreas Steffen
        Attributes:
394 127 Andreas Steffen
        Requested Extensions:
395 127 Andreas Steffen
            X509v3 Subject Alternative Name: 
396 127 Andreas Steffen
                DNS:edu.strongsec.com
397 127 Andreas Steffen
    Signature Algorithm: sha256WithRSAEncryption
398 127 Andreas Steffen
         35:89:16:59:fc:ab:64:a9:a1:89:cc:d0:e6:a9:06:19:e1:5e:
399 127 Andreas Steffen
         11:98:20:ea:ca:f0:5f:06:3c:11:ff:72:98:96:92:08:91:68:
400 127 Andreas Steffen
         d8:bd:e6:05:ed:ef:49:cf:22:6d:da:ab:2c:10:a7:df:59:a3:
401 127 Andreas Steffen
         0e:e4:bf:f6:8a:62:0b:28:eb:62:89:d0:50:d0:df:2f:5a:2d:
402 127 Andreas Steffen
         39:c6:7b:ac:34:6c:85:93:be:0d:9b:70:15:47:73:2f:00:da:
403 127 Andreas Steffen
         52:e3:65:c2:02:f9:88:0f:b8:f5:24:dc:db:43:15:fe:bc:8c:
404 1 Andreas Steffen
         98:96:81:aa:6d:aa:4c:6e:38:a2:89:27:5c:8d:27:5d:16:1a:
405 1 Andreas Steffen
         fa:3b:e7:81:69:58:db:a9:9a:c7:ea:06:d2:1c:13:ba:ee:92:
406 18 Andreas Steffen
         a4:8a:64:e3:5f:19:2c:d3:54:4f:3c:da:52:fc:9a:35:72:5c:
407 18 Andreas Steffen
         a9:d4:93:7c:e3:69:08:2b:fb:4e:35:84:7e:e3:eb:95:86:2e:
408 1 Andreas Steffen
         5b:e5:01:c1:69:53:86:f9:6b:38:31:83:97:76:8b:ba:3d:9c:
409 18 Andreas Steffen
         28:5b:84:b0:9b:e9:91:8b:db:9e:4d:3b:03:db:f4:84:a6:8d:
410 18 Andreas Steffen
         b2:18:9f:3a:3e:f9:36:64:15:98:4f:69:37:6b:9e:b2:92:a0:
411 18 Andreas Steffen
         9c:ab:05:35:65:28:b8:df:92:4b:fe:d1:40:6d:05:e2:4f:4e:
412 18 Andreas Steffen
         75:15:8c:22
413 18 Andreas Steffen
</pre>
414 18 Andreas Steffen
415 128 Andreas Steffen
h3. ECC Certificate Request
416 18 Andreas Steffen
417 135 Andreas Steffen
We repeat the same for the ECC Attestation Key:
418 18 Andreas Steffen
<pre>
419 128 Andreas Steffen
pki --req --type priv --keyid 0x81010004 \
420 128 Andreas Steffen
    --dn "C=CH, O=strongSec GmbH, OU=AK ECC, CN=edu.strongsec.com" \
421 128 Andreas Steffen
    --san edu.strongsec.com --outform pem > ak_ecc_req.pem
422 128 Andreas Steffen
TPM 2.0 via TSS2 v2 available
423 128 Andreas Steffen
signature algorithm is ECDSA with SHA256 hash
424 128 Andreas Steffen
Smartcard PIN: <return>
425 1 Andreas Steffen
</pre>
426 135 Andreas Steffen
and verify that the certificate request has been self-signed by the ECC AK private-key:
427 128 Andreas Steffen
<pre>
428 128 Andreas Steffen
openssl req -in ak_ecc_req.pem -noout -text
429 128 Andreas Steffen
Certificate Request:
430 128 Andreas Steffen
    Data:
431 128 Andreas Steffen
        Version: 1 (0x0)
432 128 Andreas Steffen
        Subject: C = CH, O = strongSec GmbH, OU = AK ECC, CN = edu.strongsec.com
433 128 Andreas Steffen
        Subject Public Key Info:
434 128 Andreas Steffen
            Public Key Algorithm: id-ecPublicKey
435 128 Andreas Steffen
                Public-Key: (256 bit)
436 128 Andreas Steffen
                pub:
437 128 Andreas Steffen
                    04:80:e7:cd:47:9e:c7:71:08:98:82:22:ed:99:1f:
438 128 Andreas Steffen
                    40:50:bd:44:da:a1:ca:ac:0b:e2:13:7f:f3:ae:63:
439 128 Andreas Steffen
                    99:61:74:a2:b6:15:ae:5c:27:9e:bd:f2:27:91:95:
440 128 Andreas Steffen
                    d1:ee:8f:99:93:ca:7b:4e:4e:87:a1:00:9e:94:24:
441 128 Andreas Steffen
                    b1:13:d1:11:2c
442 128 Andreas Steffen
                ASN1 OID: prime256v1
443 128 Andreas Steffen
                NIST CURVE: P-256
444 128 Andreas Steffen
        Attributes:
445 128 Andreas Steffen
        Requested Extensions:
446 128 Andreas Steffen
            X509v3 Subject Alternative Name: 
447 128 Andreas Steffen
                DNS:edu.strongsec.com
448 128 Andreas Steffen
    Signature Algorithm: ecdsa-with-SHA256
449 128 Andreas Steffen
         30:46:02:21:00:a0:3a:98:28:79:4b:bf:bd:90:92:d0:86:a2:
450 128 Andreas Steffen
         69:34:9c:61:6b:87:8e:d0:30:8b:69:b0:94:bd:20:1a:c2:d8:
451 128 Andreas Steffen
         e8:02:21:00:8e:e1:3d:5a:84:69:a1:dc:eb:c3:68:7d:80:7c:
452 128 Andreas Steffen
         3b:73:c8:40:08:a2:88:56:94:03:9f:49:52:60:40:a1:9a:9f
453 41 Andreas Steffen
</pre>
454 41 Andreas Steffen
455 136 Andreas Steffen
h2. Issuing Attestion Key Certificates
456 1 Andreas Steffen
457 136 Andreas Steffen
h3. Certification Authority
458 136 Andreas Steffen
459 136 Andreas Steffen
X.509 end entity certificates have to be signed by an in-house or official external __Certification Authority__ (CA). In our example we are using the *strongSec 2016 Root CA* which was generated in 2016 with the [[IpsecPki|pki]] command
460 1 Andreas Steffen
<pre>
461 136 Andreas Steffen
pki --gen --type rsa --size 4096 --outform pem > cakey.pem
462 1 Andreas Steffen
</pre>
463 136 Andreas Steffen
creating a 4096 bit RSA key pair and then creating a self-signed CA certificate with a lifetime of 10 years
464 136 Andreas Steffen
<pre>
465 136 Andreas Steffen
pki --self --ca --type rsa --in cakey.pem --dn="C=CH, O=strongSec GmbH, CN=strongSec 2016 Root CA" --lifetime 3652 --outform pem > cacert.pem
466 136 Andreas Steffen
</pre>
467 136 Andreas Steffen
as the following listing shows:
468 136 Andreas Steffen
<pre>
469 136 Andreas Steffen
pki --print --type x509 --in cacert.pem 
470 136 Andreas Steffen
  subject:  "C=CH, O=strongSec GmbH, CN=strongSec 2016 Root CA"
471 136 Andreas Steffen
  issuer:   "C=CH, O=strongSec GmbH, CN=strongSec 2016 Root CA"
472 136 Andreas Steffen
  validity:  not before Sep 02 10:25:01 2016, ok
473 136 Andreas Steffen
             not after  Sep 02 10:25:01 2026, ok (expires in 2067 days)
474 136 Andreas Steffen
  serial:    7c:24:43:4b:b7:dc:ef:7e
475 136 Andreas Steffen
  flags:     CA CRLSign self-signed 
476 136 Andreas Steffen
  subjkeyId: 6d:c2:af:37:49:41:b9:fd:f4:45:8b:aa:e0:03:3b:b9:e5:7b:9c:b5
477 136 Andreas Steffen
  pubkey:    RSA 4096 bits
478 136 Andreas Steffen
  keyid:     6c:79:f3:7a:b0:df:ac:69:03:b2:ac:6a:ed:82:3a:d2:66:93:b1:21
479 136 Andreas Steffen
  subjkey:   6d:c2:af:37:49:41:b9:fd:f4:45:8b:aa:e0:03:3b:b9:e5:7b:9c:b5
480 136 Andreas Steffen
</pre>
481 1 Andreas Steffen
482 136 Andreas Steffen
h3. RSA Attestation Key Certificate
483 136 Andreas Steffen
484 1 Andreas Steffen
<pre>
485 136 Andreas Steffen
pki --print --type x509 --in ak_rsa_cert.der 
486 136 Andreas Steffen
  subject:  "C=CH, O=strongSec GmbH, OU=AK RSA, CN=edu.strongsec.com"
487 136 Andreas Steffen
  issuer:   "C=CH, O=strongSec GmbH, CN=strongSec 2016 Root CA"
488 136 Andreas Steffen
  validity:  not before Dec 23 15:26:22 2020, ok
489 136 Andreas Steffen
             not after  Dec 23 15:26:22 2025, ok (expires in 1825 days)
490 136 Andreas Steffen
  serial:    79:e5:74:2f:a4:df:b8:d2
491 136 Andreas Steffen
  altNames:  edu.strongsec.com
492 136 Andreas Steffen
  flags:     serverAuth 
493 136 Andreas Steffen
  CRL URIs:  http://www.strongsec.com/ca/strongsec.crl
494 136 Andreas Steffen
  authkeyId: 6d:c2:af:37:49:41:b9:fd:f4:45:8b:aa:e0:03:3b:b9:e5:7b:9c:b5
495 136 Andreas Steffen
  subjkeyId: 48:82:62:15:74:a2:10:c5:75:70:c2:d6:7d:59:9f:22:d9:4f:9c:07
496 136 Andreas Steffen
  pubkey:    RSA 2048 bits
497 136 Andreas Steffen
  keyid:     df:b7:8f:95:61:8f:70:84:f4:03:e8:7e:83:a6:dd:5f:c5:ff:72:b5
498 136 Andreas Steffen
  subjkey:   48:82:62:15:74:a2:10:c5:75:70:c2:d6:7d:59:9f:22:d9:4f:9c:07
499 1 Andreas Steffen
</pre>
500 136 Andreas Steffen
501 136 Andreas Steffen
h3. ECC Attestation Key Certificate
502 136 Andreas Steffen
503 136 Andreas Steffen
<pre>
504 136 Andreas Steffen
pki --print --type x509 --in ak_ecc_cert.der 
505 136 Andreas Steffen
  subject:  "C=CH, O=strongSec GmbH, OU=AK ECC, CN=edu.strongsec.com"
506 136 Andreas Steffen
  issuer:   "C=CH, O=strongSec GmbH, CN=strongSec 2016 Root CA"
507 136 Andreas Steffen
  validity:  not before Dec 23 15:27:40 2020, ok
508 136 Andreas Steffen
             not after  Dec 23 15:27:40 2025, ok (expires in 1825 days)
509 136 Andreas Steffen
  serial:    65:fd:5b:98:47:11:f6:45
510 136 Andreas Steffen
  altNames:  edu.strongsec.com
511 136 Andreas Steffen
  flags:     serverAuth 
512 136 Andreas Steffen
  CRL URIs:  http://www.strongsec.com/ca/strongsec.crlq
513 136 Andreas Steffen
  authkeyId: 6d:c2:af:37:49:41:b9:fd:f4:45:8b:aa:e0:03:3b:b9:e5:7b:9c:b5
514 136 Andreas Steffen
  subjkeyId: cc:83:49:87:2b:9e:f3:cb:b8:35:12:02:87:ff:14:89:28:44:a6:04
515 136 Andreas Steffen
  pubkey:    ECDSA 256 bits
516 136 Andreas Steffen
  keyid:     ba:64:37:a4:0e:c8:42:67:8c:55:5a:f9:1b:2a:eb:ff:5f:40:c3:e3
517 136 Andreas Steffen
  subjkey:   cc:83:49:87:2b:9e:f3:cb:b8:35:12:02:87:ff:14:89:28:44:a6:04
518 136 Andreas Steffen
</pre>
519 136 Andreas Steffen
520 41 Andreas Steffen
521 41 Andreas Steffen
h2. Issue an RSA AIK Certificate
522 42 Andreas Steffen
523 41 Andreas Steffen
Based on the RSA AK public key exported from the TPM, the following *pki* command generates an Attestation Identity Key (AIK) certificate signed by the Demo CA
524 42 Andreas Steffen
<pre>
525 41 Andreas Steffen
pki --issue --cacert demoCaCert.pem --cakey demoCaKey.pem --type pub --in ak_rsa_pub.der --dn "C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com" --san raspi5.example.com --lifetime 3651 > raspi5_ak_rsa_Cert.der
526 41 Andreas Steffen
</pre>
527 41 Andreas Steffen
528 47 Andreas Steffen
h2. Issue an ECC AIK Certificate
529 49 Andreas Steffen
530 47 Andreas Steffen
Based on the ECC AK public key exported from the TPM, the following *pki* command generates an Attestation Identity Key (AIK) certificate signed by the Demo CA
531 50 Andreas Steffen
<pre>
532 47 Andreas Steffen
pki --issue --cacert demoCaCert.pem --cakey demoCaKey.pem --type pub --in ak_ecc_pub.der --dn "C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com" --san raspi5.example.com --lifetime 3651 > raspi5_ak_ecc_Cert.der
533 49 Andreas Steffen
</pre>
534 49 Andreas Steffen
535 47 Andreas Steffen
Many certification authorities issue certificates based on PKCS#10 certificate requests. This approach is also possible. First a certificate request is generated on the host the TPM resides on
536 47 Andreas Steffen
<pre>
537 47 Andreas Steffen
 pki --req --keyid 0x81010004 --dn "C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com" --san raspi5.example.com > ak_ecc_req.der
538 54 Andreas Steffen
</pre>
539 54 Andreas Steffen
When you are prompted for a smartcard PIN just press <enter> since this TPM private key is not protected by a PIN. In a second step the CA issues the AIK certificate based on the PKCS#10 certificate request
540 55 Andreas Steffen
<pre>
541 54 Andreas Steffen
pki --issue --cacert demoCaCert.pem --cakey demoCaKey.pem --type pkcs10 --in ak_ecc_req.der --lifetime 3651 > raspi5_ak_ecc_Cert.der
542 54 Andreas Steffen
</pre>
543 63 Andreas Steffen
544 54 Andreas Steffen
h2. Store the ECC AIK Certificate in the NV RAM of the TPM
545 54 Andreas Steffen
546 54 Andreas Steffen
A TPM 2.0 has a certain amount of Non Volatile Random Access Memory (NV RAM) that can be used to store arbitrary data, e.g. the X.509 certificates matching the persistent keys. IF both the certificates and keys are persisted in the TPM then the system disk of the host can be reformatted at any time without loosing the machine or user credentials.As with smartcards the needed amount of memory must be reserved first so we check the size of the X.509 ECC certificate
547 54 Andreas Steffen
<pre>
548 54 Andreas Steffen
ls -l raspi5_ak_ecc_Cert.der
549 54 Andreas Steffen
-rw-r--r-- 1 root root 449 Feb 17  2017 raspi5_ak_ecc_Cert.der
550 54 Andreas Steffen
</pre>
551 54 Andreas Steffen
552 54 Andreas Steffen
We then define a memory location with a size of 449 bytes that can be accessed via the handle 0x01800004 which is also called the NV index
553 70 Andreas Steffen
<pre>
554 54 Andreas Steffen
tpm2_nvdefine -x 0x01800004 -a 0x40000001 -s 449 -t 0x2000A
555 54 Andreas Steffen
</pre>
556 62 Andreas Steffen
557 54 Andreas Steffen
Then we write the certificate file to the NV RAM destination
558 62 Andreas Steffen
<pre>
559 57 Andreas Steffen
tpm2_nvwrite -x 0x01800004 -a 0x40000001 raspi5_ak_ecc_Cert.der
560 57 Andreas Steffen
</pre>
561 57 Andreas Steffen
562 55 Andreas Steffen
h2. List of NV Indexes
563 54 Andreas Steffen
564 54 Andreas Steffen
A list of all defined NV indexes can be obtained with
565 54 Andreas Steffen
566 54 Andreas Steffen
 tpm2_nvlist
567 54 Andreas Steffen
568 54 Andreas Steffen
<pre>
569 54 Andreas Steffen
2 NV indexes defined.
570 54 Andreas Steffen
571 54 Andreas Steffen
  0. NV Index: 0x1500015
572 54 Andreas Steffen
  {
573 54 Andreas Steffen
	Hash algorithm(nameAlg):4
574 54 Andreas Steffen
 	The Index attributes(attributes):0x44040004
575 1 Andreas Steffen
 	The size of the data area(dataSize):4
576 1 Andreas Steffen
   }
577 62 Andreas Steffen
  1. NV Index: 0x1800004
578 62 Andreas Steffen
  {
579 62 Andreas Steffen
	Hash algorithm(nameAlg):11
580 62 Andreas Steffen
 	The Index attributes(attributes):0x2002000a
581 62 Andreas Steffen
 	The size of the data area(dataSize):449
582 62 Andreas Steffen
   }
583 62 Andreas Steffen
</pre>
584 54 Andreas Steffen
585 54 Andreas Steffen
h2. Remove NV Index
586 30 Andreas Steffen
587 1 Andreas Steffen
The memory assigned to a given NV index can be released with the command
588 23 Andreas Steffen
<pre>
589 1 Andreas Steffen
tpm2_nvrelease -x 0x01800001 -a 0x40000001
590 7 Andreas Steffen
</pre>
591 1 Andreas Steffen
592 1 Andreas Steffen
h2. Configure TPM Private Key Access via VICI Interface
593 46 Andreas Steffen
594 1 Andreas Steffen
Configuration of TPM private key access as tokens in the secrets section of *swanctl.conf*
595 1 Andreas Steffen
596 7 Andreas Steffen
 secrets {
597 1 Andreas Steffen
    token_ak_rsa {
598 1 Andreas Steffen
       handle = 81010002
599 46 Andreas Steffen
       pin = 123456
600 30 Andreas Steffen
    }
601 30 Andreas Steffen
    token_ak_ecc {
602 30 Andreas Steffen
       handle = 81010004
603 30 Andreas Steffen
    }
604 30 Andreas Steffen
}
605 30 Andreas Steffen
Since the use of the RSA AK private key is password-protected, the PIN *123456* is added.
606 30 Andreas Steffen
607 30 Andreas Steffen
h2. Define IPsec Connection with RSA AK Client Key
608 30 Andreas Steffen
609 30 Andreas Steffen
This connection configuration in *swanctl.conf* uses the RSA AK certificate for client authentication
610 30 Andreas Steffen
<pre>
611 30 Andreas Steffen
connections {
612 30 Andreas Steffen
   rsa {
613 30 Andreas Steffen
      local_addrs  = 10.10.0.105
614 30 Andreas Steffen
      remote_addrs = 10.10.0.104
615 30 Andreas Steffen
616 30 Andreas Steffen
      local {
617 30 Andreas Steffen
         auth = pubkey 
618 30 Andreas Steffen
         certs = raspi5_ak_rsa_Cert.der
619 30 Andreas Steffen
      }
620 30 Andreas Steffen
      remote {
621 30 Andreas Steffen
         auth = pubkey 
622 30 Andreas Steffen
         id = raspi4.example.com
623 30 Andreas Steffen
      }
624 30 Andreas Steffen
      children {
625 30 Andreas Steffen
         rsa {
626 30 Andreas Steffen
            mode = transport
627 30 Andreas Steffen
            esp_proposals = aes128-sha256-curve25519
628 30 Andreas Steffen
         }
629 30 Andreas Steffen
      }
630 30 Andreas Steffen
      version = 2
631 30 Andreas Steffen
      proposals = aes128-sha256-curve25519
632 58 Andreas Steffen
   }
633 30 Andreas Steffen
}
634 30 Andreas Steffen
</pre>
635 30 Andreas Steffen
636 30 Andreas Steffen
h2. Define IPsec Connection with ECC AK Client Key
637 30 Andreas Steffen
638 30 Andreas Steffen
This connection configuration in *swanctl.conf* references the ECC AK certificate used for client authentication via its handle, i.e. the NV index
639 30 Andreas Steffen
<pre>
640 1 Andreas Steffen
connections {
641 58 Andreas Steffen
   ecc {
642 58 Andreas Steffen
      local_addrs  = 10.10.0.105
643 58 Andreas Steffen
      remote_addrs = 10.10.0.104
644 30 Andreas Steffen
645 30 Andreas Steffen
      local {
646 30 Andreas Steffen
         auth = pubkey
647 30 Andreas Steffen
         cert-tpm {
648 30 Andreas Steffen
            handle = 0x01800004
649 30 Andreas Steffen
         }
650 30 Andreas Steffen
      }
651 30 Andreas Steffen
      remote {
652 30 Andreas Steffen
         auth = pubkey
653 30 Andreas Steffen
         id = raspi4.example.com
654 30 Andreas Steffen
      }
655 30 Andreas Steffen
      children {
656 30 Andreas Steffen
         ecc {
657 30 Andreas Steffen
            mode = transport
658 30 Andreas Steffen
            esp_proposals = aes128-sha256-curve25519
659 30 Andreas Steffen
         }
660 29 Andreas Steffen
      }
661 29 Andreas Steffen
      version = 2
662 29 Andreas Steffen
      proposals = aes128-sha256-curve25519
663 29 Andreas Steffen
   }
664 29 Andreas Steffen
}
665 29 Andreas Steffen
</pre>
666 29 Andreas Steffen
667 29 Andreas Steffen
h2. Starting the strongSwan Daemon
668 44 Andreas Steffen
669 44 Andreas Steffen
<pre>
670 44 Andreas Steffen
systemctl start strongswan-swanctl
671 44 Andreas Steffen
</pre>
672 44 Andreas Steffen
673 1 Andreas Steffen
<pre>
674 1 Andreas Steffen
Feb 19 10:52:01 raspi5 systemd[1]: Starting strongSwan IPsec IKEv1/IKEv2 daemon using swanctl...
675 59 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: loaded plugins: charon-systemd charon-systemd random nonce x509 constraints openssl pem pkcs1 pkcs8 pkcs12 pubkey mgf1 ntru curve25519 eap-identity eap-ttls eap-tnc tnc-tnccs tnc-imc tnccs-20 socket-default kernel-netlink vici tpm
676 1 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: spawning 16 worker threads
677 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: loaded certificate 'C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com'
678 53 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: loaded certificate 'C=US, O=TNC Demo, CN=TNC Demo CA'
679 44 Andreas Steffen
</pre>
680 73 Andreas Steffen
681 44 Andreas Steffen
The RSA AK private key is attached to the *charon-systemd* daemon via the TPM 2.0 resource manager
682 44 Andreas Steffen
<pre>
683 1 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 - manufacturer: IFX (SLB9670) rev: 01.16 2015
684 1 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 - algorithms: RSA SHA1 HMAC AES KEYEDHASH XOR SHA256 RSASSA RSAES RSAPSS OAEP ECDSA ECDH SM2 KDF1_SP800_56A KDF1_SP800_108 ECC SYMCIPHER CFB
685 1 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 - ECC curves: NIST_P256 BN_P256
686 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 via TSS2 v2 available
687 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: AIK signature algorithm is RSASSA with SHA256 hash
688 53 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: loaded RSA private key from token
689 44 Andreas Steffen
F</pre>
690 73 Andreas Steffen
691 1 Andreas Steffen
The ECC AK private key is attached to the *charon-systemd* daemon via the TPM 2.0 resource manager
692 1 Andreas Steffen
<pre>
693 1 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 - manufacturer: IFX (SLB9670) rev: 01.16 2015
694 59 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 - algorithms: RSA SHA1 HMAC AES KEYEDHASH XOR SHA256 RSASSA RSAES RSAPSS OAEP ECDSA ECDH SM2 KDF1_SP800_56A KDF1_SP800_108 ECC SYMCIPHER CFB
695 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 - ECC curves: NIST_P256 BN_P256
696 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 via TSS2 v2 available
697 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: AIK signature algorithm is ECDSA with SHA256 hash
698 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: loaded ECDSA private key from token
699 59 Andreas Steffen
</pre>
700 73 Andreas Steffen
701 60 Andreas Steffen
The ECC AIK certificate is loaded by the *charon-systemd* daemon via the TPM 2.0 resource manager
702 59 Andreas Steffen
<pre>
703 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 - manufacturer: IFX (SLB9670) rev: 01.16 2015
704 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 - algorithms: RSA SHA1 HMAC AES KEYEDHASH XOR SHA256 RSASSA RSAES RSAPSS OAEP ECDSA ECDH SM2 KDF1_SP800_56A KDF1_SP800_108 ECC SYMCIPHER CFB
705 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 - ECC curves: NIST_P256 BN_P256
706 1 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 via TSS2 v2 available
707 1 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: loaded certificate from TPM NV index 0x01800004
708 1 Andreas Steffen
</pre>
709 44 Andreas Steffen
710 59 Andreas Steffen
The two connection definitions are received by the *charon-systemd* daemon from the *swanctl* command line tool via the VICI interface
711 59 Andreas Steffen
<pre>
712 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]:   id not specified, defaulting to cert subject 'C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com'
713 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: added vici connection: rsa
714 44 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]:   id not specified, defaulting to cert subject 'C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com'
715 44 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: added vici connection: ecc
716 44 Andreas Steffen
</pre>
717 44 Andreas Steffen
718 44 Andreas Steffen
The *swanctl* command line tool reports its actions
719 44 Andreas Steffen
<pre>
720 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded certificate from '/etc/swanctl/x509/raspi5_ak_rsa_Cert.der'
721 31 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded certificate from '/etc/swanctl/x509ca/demoCaCert.pem'
722 31 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded key token_ak_rsa from token [keyid: f49e857dde4e67f5fb870398673f207cf33f2b66]
723 31 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded key token_ak_ecc from token [keyid: c70e63f87f6ff65500e5057f5a3e6b6ce7d2d513]
724 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded connection 'rsa'
725 31 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded connection 'ecc'
726 31 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: successfully loaded 2 connections, 0 unloaded
727 31 Andreas Steffen
</pre>
728 31 Andreas Steffen
729 31 Andreas Steffen
<pre>
730 31 Andreas Steffen
Feb 19 10:52:02 raspi5 systemd[1]: Started strongSwan IPsec IKEv1/IKEv2 daemon using swanctl.
731 31 Andreas Steffen
</pre>
732 31 Andreas Steffen
733 31 Andreas Steffen
The following *swanctl* command shows the two loaded connections
734 31 Andreas Steffen
<pre>
735 31 Andreas Steffen
swanctl --list-conns
736 31 Andreas Steffen
</pre>
737 31 Andreas Steffen
738 31 Andreas Steffen
<pre>
739 31 Andreas Steffen
rsa: IKEv2, reauthentication every 10800s, no rekeying
740 31 Andreas Steffen
  local:  10.10.0.105
741 31 Andreas Steffen
  remote: 10.10.0.104
742 31 Andreas Steffen
  local public key authentication:
743 31 Andreas Steffen
    id: C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com
744 31 Andreas Steffen
    certs: C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com
745 31 Andreas Steffen
  remote public key authentication:
746 31 Andreas Steffen
    id: raspi4.example.com
747 31 Andreas Steffen
  rsa: TRANSPORT, rekeying every 3600s or 300000000 bytes or 500000 packets
748 31 Andreas Steffen
    local:  dynamic
749 31 Andreas Steffen
    remote: dynamic
750 31 Andreas Steffen
</pre>
751 31 Andreas Steffen
752 31 Andreas Steffen
<pre>
753 31 Andreas Steffen
ecc: IKEv2, reauthentication every 10800s, no rekeying
754 31 Andreas Steffen
  local:  10.10.0.105
755 31 Andreas Steffen
  remote: 10.10.0.104
756 31 Andreas Steffen
  local public key authentication:
757 32 Andreas Steffen
    id: C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com
758 31 Andreas Steffen
    certs: C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com
759 31 Andreas Steffen
  remote public key authentication:
760 31 Andreas Steffen
    id: raspi4.example.com
761 31 Andreas Steffen
  ecc: TRANSPORT, rekeying every 3600s or 300000000 bytes or 500000 packets
762 31 Andreas Steffen
    local:  dynamic
763 31 Andreas Steffen
    remote: dynamic
764 31 Andreas Steffen
</pre>
765 31 Andreas Steffen
766 31 Andreas Steffen
The loaded certificates can also be displayed
767 31 Andreas Steffen
<pre>
768 31 Andreas Steffen
swanctl --list-certs
769 31 Andreas Steffen
</pre>
770 31 Andreas Steffen
771 31 Andreas Steffen
You can clearly see that the connection between the AK certificates and their matching AK private key has been established (..., has private key)
772 31 Andreas Steffen
<pre>
773 31 Andreas Steffen
List of X.509 End Entity Certificates
774 31 Andreas Steffen
775 31 Andreas Steffen
  subject:  "C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com"
776 31 Andreas Steffen
  issuer:   "C=US, O=TNC Demo, CN=TNC Demo CA"
777 31 Andreas Steffen
  validity:  not before Feb 19 09:33:43 2017, ok
778 31 Andreas Steffen
             not after  Aug 29 10:33:43 2026, ok (expires in 3477 days)
779 31 Andreas Steffen
  serial:    11:57:33:3e:2a:8e:8a:32
780 31 Andreas Steffen
  altNames:  raspi5.example.com
781 31 Andreas Steffen
  authkeyId: 21:02:7e:2d:de:8b:77:48:75:de:56:2f:b5:d4:62:ec:c3:09:15:f2
782 31 Andreas Steffen
  subjkeyId: f4:9e:85:7d:de:4e:67:f5:fb:87:03:98:67:3f:20:7c:f3:3f:2b:66
783 31 Andreas Steffen
  pubkey:    RSA 2048 bits, has private key
784 31 Andreas Steffen
  keyid:     71:21:f5:d4:7e:59:4a:88:16:ca:57:85:98:3d:36:a7:b1:d5:75:fa
785 31 Andreas Steffen
  subjkey:   f4:9e:85:7d:de:4e:67:f5:fb:87:03:98:67:3f:20:7c:f3:3f:2b:66
786 31 Andreas Steffen
787 31 Andreas Steffen
  subject:  "C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com"
788 31 Andreas Steffen
  issuer:   "C=US, O=TNC Demo, CN=TNC Demo CA"
789 31 Andreas Steffen
  validity:  not before Feb 17 23:17:19 2017, ok
790 31 Andreas Steffen
             not after  Aug 30 00:17:19 2026, ok (expires in 3478 days)
791 31 Andreas Steffen
  serial:    52:9d:3e:42:6f:71:63:3d
792 31 Andreas Steffen
  altNames:  raspi5.example.com
793 31 Andreas Steffen
  authkeyId: 21:02:7e:2d:de:8b:77:48:75:de:56:2f:b5:d4:62:ec:c3:09:15:f2
794 31 Andreas Steffen
  subjkeyId: c7:0e:63:f8:7f:6f:f6:55:00:e5:05:7f:5a:3e:6b:6c:e7:d2:d5:13
795 31 Andreas Steffen
  pubkey:    ECDSA 256 bits, has private key
796 31 Andreas Steffen
  keyid:     71:49:7c:42:41:e7:c6:81:bc:31:73:f0:0f:7e:4a:e1:2d:53:00:38
797 31 Andreas Steffen
  subjkey:   c7:0e:63:f8:7f:6f:f6:55:00:e5:05:7f:5a:3e:6b:6c:e7:d2:d5:13
798 1 Andreas Steffen
</pre>
799 32 Andreas Steffen
800 32 Andreas Steffen
<pre>
801 43 Andreas Steffen
List of X.509 CA Certificates
802 32 Andreas Steffen
803 38 Andreas Steffen
  subject:  "C=US, O=TNC Demo, CN=TNC Demo CA"
804 32 Andreas Steffen
  issuer:   "C=US, O=TNC Demo, CN=TNC Demo CA"
805 32 Andreas Steffen
  validity:  not before Aug 31 10:29:27 2016, ok
806 32 Andreas Steffen
             not after  Aug 31 10:29:27 2026, ok (expires in 3479 days)
807 32 Andreas Steffen
  serial:    02:c8:85:e1:ef:fa:8f:20
808 32 Andreas Steffen
  flags:     CA CRLSign self-signed 
809 32 Andreas Steffen
  subjkeyId: 21:02:7e:2d:de:8b:77:48:75:de:56:2f:b5:d4:62:ec:c3:09:15:f2
810 32 Andreas Steffen
  pubkey:    ECDSA 256 bits
811 32 Andreas Steffen
  keyid:     a1:b5:e0:29:d0:4c:a7:62:bd:ca:a3:b4:af:18:42:2c:4a:01:55:9a
812 32 Andreas Steffen
  subjkey:   21:02:7e:2d:de:8b:77:48:75:de:56:2f:b5:d4:62:ec:c3:09:15:f2
813 32 Andreas Steffen
</pre>
814 32 Andreas Steffen
815 32 Andreas Steffen
h2. IKEv2 Authentication with RSA AIK Certificate
816 32 Andreas Steffen
817 45 Andreas Steffen
With the following *swanctl* command the "rsa" connection is established
818 32 Andreas Steffen
<pre>
819 40 Andreas Steffen
swanctl --initiate --child rsa
820 40 Andreas Steffen
</pre>
821 32 Andreas Steffen
822 32 Andreas Steffen
<pre>
823 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: vici initiate 'rsa'
824 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: initiating IKE_SA rsa[1] to 10.10.0.104
825 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: generating IKE_SA_INIT request 0 [ SA KE No N(NATD_S_IP) N(NATD_D_IP) N(FRAG_SUP) N(HASH_ALG) N(REDIR_SUP) V ]
826 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: sending packet: from 10.10.0.105[500] to 10.10.0.104[500] (1257 bytes)
827 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: received packet: from 10.10.0.104[500] to 10.10.0.105[500] (1259 bytes)
828 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: parsed IKE_SA_INIT response 0 [ SA KE No N(NATD_S_IP) N(NATD_D_IP) CERTREQ N(HASH_ALG) V ]
829 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: received strongSwan vendor ID
830 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: received cert request for "C=US, O=TNC Demo, CN=TNC Demo CA"
831 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: sending cert request for "C=US, O=TNC Demo, CN=TNC Demo CA"
832 32 Andreas Steffen
</pre>
833 32 Andreas Steffen
834 32 Andreas Steffen
The RSA AK private key stored in the TPM 2.0 is used to generate an *RSA_EMSA_PKCS1_SHA2_256* signature which is sent in the AUTH payload of the IKE_AUTH request. The matching client certificate is sent int the CERT payload.
835 32 Andreas Steffen
<pre>
836 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: authentication of 'C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com' (myself) with RSA_EMSA_PKCS1_SHA2_256 successful
837 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: sending end entity cert "C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com"
838 32 Andreas Steffen
</pre>
839 32 Andreas Steffen
<pre>
840 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: establishing CHILD_SA rsa
841 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: generating IKE_AUTH request 1 [ IDi CERT CERTREQ IDr AUTH N(USE_TRANSP) SA TSi TSr N(MOBIKE_SUP) N(ADD_6_ADDR) N(EAP_ONLY) N(MSG_ID_SYN_SUP) ]
842 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: sending packet: from 10.10.0.105[4500] to 10.10.0.104[4500] (1296 bytes)
843 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: received packet: from 10.10.0.104[4500] to 10.10.0.105[4500] (752 bytes)
844 38 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: parsed IKE_AUTH response 1 [ IDr CERT AUTH N(USE_TRANSP) SA TSi TSr N(AUTH_LFT) N(MOBIKE_SUP) N(NO_ADD_ADDR) ]
845 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: received end entity cert "C=US, O=TNC Demo, CN=raspi4.example.com"
846 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]:   using certificate "C=US, O=TNC Demo, CN=raspi4.example.com"
847 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]:   using trusted ca certificate "C=US, O=TNC Demo, CN=TNC Demo CA"
848 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]:   reached self-signed root ca with a path length of 0
849 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: authentication of 'raspi4.example.com' with ECDSA_WITH_SHA256_DER successful
850 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: IKE_SA rsa[1] established between 10.10.0.105[C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com]...10.10.0.104[raspi4.example.com]
851 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: scheduling reauthentication in 10507s
852 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: maximum IKE_SA lifetime 11587s
853 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: CHILD_SA rsa{1} established with SPIs c23deb9d_i ce48d08e_o and TS 10.10.0.105/32 === 10.10.0.104/32
854 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: received AUTH_LIFETIME of 10103s, scheduling reauthentication in 9023s
855 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: peer supports MOBIKE
856 32 Andreas Steffen
</pre>
857 32 Andreas Steffen
858 32 Andreas Steffen
The following *swanctl* command shows the established IPsec connection
859 32 Andreas Steffen
<pre>
860 32 Andreas Steffen
 swanctl --list-sas
861 32 Andreas Steffen
</pre>
862 38 Andreas Steffen
<pre>
863 33 Andreas Steffen
rsa: #1, ESTABLISHED, IKEv2, 7ba3b4d06c051ecb_i* 14e1769a8aeb7f28_r
864 33 Andreas Steffen
  local  'C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com' @ 10.10.0.105[4500]
865 33 Andreas Steffen
  remote 'raspi4.example.com' @ 10.10.0.104[4500]
866 33 Andreas Steffen
  AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519
867 33 Andreas Steffen
  established 252s ago, reauth in 8771s
868 33 Andreas Steffen
  rsa: #1, reqid 1, INSTALLED, TRANSPORT, ESP:AES_CBC-128/HMAC_SHA2_256_128
869 33 Andreas Steffen
    installed 252s ago, rekeying in 3258s, expires in 3708s
870 33 Andreas Steffen
    in  c23deb9d,    640 bytes,    10 packets,     3s ago
871 33 Andreas Steffen
    out ce48d08e,    640 bytes,    10 packets,     3s ago
872 33 Andreas Steffen
    local  10.10.0.105/32
873 33 Andreas Steffen
    remote 10.10.0.104/32
874 33 Andreas Steffen
</pre>
875 33 Andreas Steffen
876 33 Andreas Steffen
With this *swanctl* command the "rsa" connection is terminated
877 33 Andreas Steffen
<pre>
878 43 Andreas Steffen
swanctl --terminate --ike rsa
879 32 Andreas Steffen
</pre>
880 38 Andreas Steffen
881 32 Andreas Steffen
<pre>
882 32 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: vici terminate IKE_SA 'rsa'
883 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: deleting IKE_SA rsa[1] between 10.10.0.105[C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com]...10.10.0.104[raspi4.example.com]
884 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: sending DELETE for IKE_SA rsa[1]
885 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: generating INFORMATIONAL request 2 [ D ]
886 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: sending packet: from 10.10.0.105[4500] to 10.10.0.104[4500] (80 bytes)
887 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: received packet: from 10.10.0.104[4500] to 10.10.0.105[4500] (80 bytes)
888 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: parsed INFORMATIONAL response 2 [ ]
889 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: IKE_SA deleted
890 33 Andreas Steffen
</pre>
891 33 Andreas Steffen
892 33 Andreas Steffen
h2. IKEv2 Authentication with ECC AIK Certificate
893 33 Andreas Steffen
894 45 Andreas Steffen
Next we initiate the "ecc" connection
895 33 Andreas Steffen
<pre>
896 40 Andreas Steffen
swanctl --initiate --child ecc
897 40 Andreas Steffen
</pre>
898 33 Andreas Steffen
899 33 Andreas Steffen
<pre>
900 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: vici initiate 'ecc'
901 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: initiating IKE_SA ecc[2] to 10.10.0.104
902 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: generating IKE_SA_INIT request 0 [ SA KE No N(NATD_S_IP) N(NATD_D_IP) N(FRAG_SUP) N(HASH_ALG) N(REDIR_SUP) V ]
903 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: sending packet: from 10.10.0.105[500] to 10.10.0.104[500] (1257 bytes)
904 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: received packet: from 10.10.0.104[500] to 10.10.0.105[500] (1259 bytes)
905 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: parsed IKE_SA_INIT response 0 [ SA KE No N(NATD_S_IP) N(NATD_D_IP) CERTREQ N(HASH_ALG) V ]
906 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: received strongSwan vendor ID
907 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: received cert request for "C=US, O=TNC Demo, CN=TNC Demo CA"
908 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: sending cert request for "C=US, O=TNC Demo, CN=TNC Demo CA"
909 33 Andreas Steffen
</pre>
910 33 Andreas Steffen
911 33 Andreas Steffen
The ECC AK private key stored in the TPM 2.0 is used to generate an *ECDSA_WITH_SHA256_DER* signature which is sent in the AUTH payload of the IKE_AUTH request. The matching client certificate is sent int the CERT payload.
912 33 Andreas Steffen
<pre>
913 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: authentication of 'C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com' (myself) with ECDSA_WITH_SHA256_DER successful
914 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: sending end entity cert "C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com"
915 33 Andreas Steffen
</pre>
916 33 Andreas Steffen
<pre>
917 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: establishing CHILD_SA ecc
918 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: generating IKE_AUTH request 1 [ IDi CERT CERTREQ IDr AUTH N(USE_TRANSP) SA TSi TSr N(MOBIKE_SUP) N(ADD_6_ADDR) N(EAP_ONLY) N(MSG_ID_SYN_SUP) ]
919 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: sending packet: from 10.10.0.105[4500] to 10.10.0.104[4500] (912 bytes)
920 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: received packet: from 10.10.0.104[4500] to 10.10.0.105[4500] (752 bytes)
921 39 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: parsed IKE_AUTH response 1 [ IDr CERT AUTH N(USE_TRANSP) SA TSi TSr N(AUTH_LFT) N(MOBIKE_SUP) N(NO_ADD_ADDR) ]
922 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: received end entity cert "C=US, O=TNC Demo, CN=raspi4.example.com"
923 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]:   using certificate "C=US, O=TNC Demo, CN=raspi4.example.com"
924 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]:   using trusted ca certificate "C=US, O=TNC Demo, CN=TNC Demo CA"
925 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]:   reached self-signed root ca with a path length of 0
926 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: authentication of 'raspi4.example.com' with ECDSA_WITH_SHA256_DER successful
927 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: IKE_SA ecc[2] established between 10.10.0.105[C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com]...10.10.0.104[raspi4.example.com]
928 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: scheduling reauthentication in 10180s
929 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: maximum IKE_SA lifetime 11260s
930 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: CHILD_SA ecc{2} established with SPIs c2c16cd0_i c47ea6f6_o and TS 10.10.0.105/32 === 10.10.0.104/32
931 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: received AUTH_LIFETIME of 9880s, scheduling reauthentication in 8800s
932 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: peer supports MOBIKE
933 33 Andreas Steffen
</pre>
934 33 Andreas Steffen
935 1 Andreas Steffen
The establed IKE and CHILD SAs are displayed
936 1 Andreas Steffen
<pre>
937 34 Andreas Steffen
 swanctl --list-sas
938 34 Andreas Steffen
</pre>
939 39 Andreas Steffen
<pre>
940 34 Andreas Steffen
ecc: #2, ESTABLISHED, IKEv2, b7f2652777b0996a_i* 12282b5964ff0658_r
941 34 Andreas Steffen
  local  'C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com' @ 10.10.0.105[4500]
942 34 Andreas Steffen
  remote 'raspi4.example.com' @ 10.10.0.104[4500]
943 34 Andreas Steffen
  AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519
944 34 Andreas Steffen
  established 126s ago, reauth in 8674s
945 34 Andreas Steffen
  ecc: #2, reqid 2, INSTALLED, TRANSPORT, ESP:AES_CBC-128/HMAC_SHA2_256_128
946 34 Andreas Steffen
    installed 126s ago, rekeying in 3252s, expires in 3834s
947 34 Andreas Steffen
    in  c2c16cd0,    320 bytes,     5 packets,     2s ago
948 34 Andreas Steffen
    out c47ea6f6,    320 bytes,     5 packets,     2s ago
949 34 Andreas Steffen
    local  10.10.0.105/32
950 34 Andreas Steffen
    remote 10.10.0.104/32
951 34 Andreas Steffen
</pre>
952 34 Andreas Steffen
953 34 Andreas Steffen
The IKE and CHILD SAs are terminated
954 34 Andreas Steffen
<pre>
955 34 Andreas Steffen
swanctl --terminate --ike ecc
956 34 Andreas Steffen
</pre>
957 39 Andreas Steffen
958 34 Andreas Steffen
<pre>
959 34 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: vici terminate IKE_SA 'ecc'
960 34 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: deleting IKE_SA ecc[2] between 10.10.0.105[C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com]...10.10.0.104[raspi4.example.com]
961 1 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: sending DELETE for IKE_SA ecc[2]
962 1 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: generating INFORMATIONAL request 2 [ D ]
963 1 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: sending packet: from 10.10.0.105[4500] to 10.10.0.104[4500] (80 bytes)
964 1 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: received packet: from 10.10.0.104[4500] to 10.10.0.105[4500] (80 bytes)
965 1 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: parsed INFORMATIONAL response 2 [ ]
966 1 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: IKE_SA deleted
967 1 Andreas Steffen
</pre>