Project

General

Profile

Trusted Platform Module 2.0 » History » Version 93

Andreas Steffen, 01.01.2021 17:45

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 88 Andreas Steffen
h3. Install the tpm2-tss Software Stack and the tpm2-tools Command Set
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 51 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 78 Jean-François Hren
  ./configure --enable-tss-tss2 --enable-tpm  ...
37 7 Andreas Steffen
38 7 Andreas Steffen
h2. TPM 2.0 Algorithm IDs
39 7 Andreas Steffen
40 8 Andreas Steffen
h3. Hash Algorithms
41 8 Andreas Steffen
42 7 Andreas Steffen
|0x0004 |SHA-1     |
43 7 Andreas Steffen
|0x000B |SHA-2_256 |
44 7 Andreas Steffen
|0x000C |SHA-2_384 |
45 1 Andreas Steffen
|0x000D |SHA-2_512 |
46 7 Andreas Steffen
47 28 Andreas Steffen
Currently available TPM 2.0 devices like the Infineon *Optiga SLB 9670 VQ2.0* hardware TPM or Intel's *PTT* firmware TPM integrated into the Management Engine starting with the 4th generation (Haswell) of the *Core* processor family, support the *SHA-1* and *SHA-2_256* algorithms.
48 1 Andreas Steffen
49 8 Andreas Steffen
h3. Public Key Types
50 8 Andreas Steffen
51 8 Andreas Steffen
|0x0001 |RSA |
52 8 Andreas Steffen
|0x0023 |ECC |
53 1 Andreas Steffen
54 22 Andreas Steffen
Currently RSA keys have a modulus size of 2048 bits and ECC keys are based on the 256 bit NIST curve.
55 22 Andreas Steffen
56 11 Andreas Steffen
h3. Signature Schemes
57 11 Andreas Steffen
58 11 Andreas Steffen
|0x0014 |RSASSA |
59 11 Andreas Steffen
|0x0016 |RSAPSS |
60 9 Andreas Steffen
|0x0018 |ECDSA  |
61 64 Andreas Steffen
62 66 Andreas Steffen
h2. TPM 2.0 Attributes
63 66 Andreas Steffen
64 64 Andreas Steffen
h3. Object Attributes
65 64 Andreas Steffen
66 64 Andreas Steffen
|0x00002 |fixedTPM             |
67 64 Andreas Steffen
|0x00004 |stClear              |
68 64 Andreas Steffen
|0x00010 |fixedParent          |
69 64 Andreas Steffen
|0x00020 |sensitiveDataOrigin  |
70 64 Andreas Steffen
|0x00040 |userWithAuth         |
71 64 Andreas Steffen
|0x00080 |adminWithPolicy      |
72 64 Andreas Steffen
|0x00400 |noDA                 |
73 64 Andreas Steffen
|0x00800 |encryptedDuplication |
74 64 Andreas Steffen
|0x10000 |restricted           |
75 64 Andreas Steffen
|0x20000 |decrypt              |
76 64 Andreas Steffen
|0x40000 |sign                 |
77 64 Andreas Steffen
78 65 Andreas Steffen
h3. NV Index Attributes
79 65 Andreas Steffen
80 65 Andreas Steffen
|0x00000001 |NV_PPWRITE        |
81 65 Andreas Steffen
|0x00000002 |NV_OWNERWRITE     |
82 65 Andreas Steffen
|0x00000004 |NV_AUTHWRITE      |
83 65 Andreas Steffen
|0x00000008 |NV_POLICYWRITE    |
84 65 Andreas Steffen
|0x000000F0 |NT                |
85 65 Andreas Steffen
|0x00000400 |NV_POLICY_DELETE  |
86 65 Andreas Steffen
|0x00000800 |NV_WRITELOCKED    |
87 65 Andreas Steffen
|0x00001000 |NV_WRITEALL       |
88 65 Andreas Steffen
|0x00002000 |NV_WRITEDEFINE    |
89 65 Andreas Steffen
|0x00004000 |NV_WRITE_STCLEAR  |
90 65 Andreas Steffen
|0x00008000 |NV_GLOBALLOCK     |
91 65 Andreas Steffen
|0x00010000 |NV_PPEREAD        |
92 65 Andreas Steffen
|0x00020000 |NV_OWNERREAD      |
93 65 Andreas Steffen
|0x00040000 |NV_AUTHREAD       |
94 65 Andreas Steffen
|0x00080000 |NV_POLICYREAD     |
95 65 Andreas Steffen
|0x02000000 |NV_NO_DA          |
96 65 Andreas Steffen
|0x04000000 |NV_ORDERLY        |
97 65 Andreas Steffen
|0x08000000 |NV_CLEAR_STCLEAR  |
98 65 Andreas Steffen
|0x10000000 |NV_READLOCKED     |
99 65 Andreas Steffen
|0x20000000 |NV_WRITTEN        |
100 65 Andreas Steffen
|0x40000000 |NV_PLATFORMCREATE |
101 65 Andreas Steffen
|0x80000000 |NV_READ_STCLEAR   |
102 64 Andreas Steffen
103 20 Andreas Steffen
h2. Derive a Persistent RSA Endorsement Key
104 1 Andreas Steffen
105 25 Andreas Steffen
The following tpm2-tools 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 0x81010001
106 11 Andreas Steffen
107 82 Andreas Steffen
 tpm2_getpubek -H 0x81010001 -g rsa -f ek_rsa.pub
108 9 Andreas Steffen
109 27 Andreas Steffen
The EK public key stored in the ek_rsa.pub file is encoded in a TPM 2.0 proprietary format but the key can be exported from the TPM in the regular PKCS#1 format using the *pki* tool
110 9 Andreas Steffen
111 50 Andreas Steffen
 pki --pub --keyid 0x81010001 --outform pem > ek_rsa_pub.pem
112 9 Andreas Steffen
113 9 Andreas Steffen
The fingerprint of the RSA EK public key can be displayed with the command
114 9 Andreas Steffen
115 9 Andreas Steffen
 pki --print --type pub --in ek_rsa_pub.pem
116 9 Andreas Steffen
  pubkey:    RSA 2048 bits
117 9 Andreas Steffen
  keyid:     d1:f1:49:84:36:44:e6:8c:d2:a6:69:ee:fd:b5:7d:56:2f:39:ff:58
118 1 Andreas Steffen
  subjkey:   c1:1b:8e:f1:c7:f8:8a:1e:9a:dd:7e:82:2f:7a:a3:f5:c0:e2:4d:7d
119 1 Andreas Steffen
120 20 Andreas Steffen
h2. Generate a Persistent RSA Attestation Key
121 11 Andreas Steffen
122 12 Andreas Steffen
A 2048 bit RSA Attestation Key (AK) bound to the EK with handle 0x81010001 can be created and made persistent under the handle 0x81010002 with the following tpm2-tools command
123 1 Andreas Steffen
124 83 Andreas Steffen
 tpm2_getpubak -E 0x81010001 -g rsa -D sha256 -s rsassa -k 0x81010002 -P 123456 -f ak_rsa2.pub -n ak_rsa2.name
125 12 Andreas Steffen
126 46 Andreas Steffen
This AK key is protected by the PIN (-P parameter) *123456*. The AK public key can now be exported in PKCS#1 format from the TPM using the *pki* tool
127 12 Andreas Steffen
128 50 Andreas Steffen
 pki --pub --keyid 0x81010002 --outform pem > ak_rsa_pub.pem
129 12 Andreas Steffen
130 12 Andreas Steffen
The fingerprint of the RSA AK public key can be displayed with the command
131 12 Andreas Steffen
132 12 Andreas Steffen
 pki --print --type pub --in ak_rsa_pub.pem
133 12 Andreas Steffen
  pubkey:    RSA 2048 bits
134 12 Andreas Steffen
  keyid:     71:21:f5:d4:7e:59:4a:88:16:ca:57:85:98:3d:36:a7:b1:d5:75:fa
135 12 Andreas Steffen
  subjkey:   f4:9e:85:7d:de:4e:67:f5:fb:87:03:98:67:3f:20:7c:f3:3f:2b:66
136 11 Andreas Steffen
137 20 Andreas Steffen
h2. Derive a Persistent ECC Endorsement Key
138 1 Andreas Steffen
139 25 Andreas Steffen
The following tpm2-tools command derives a 256 bit ECC 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 0x81010003:
140 1 Andreas Steffen
141 82 Andreas Steffen
 tpm2_getpubek -H 0x81010003 -g ecc -f ek_ecc.pub
142 9 Andreas Steffen
143 67 Andreas Steffen
Without exporting the public key first the fingerprint of the ECC EK private key can be directly displayed with the command
144 9 Andreas Steffen
145 67 Andreas Steffen
 pki --print --type priv --keyid 0x81010003
146 9 Andreas Steffen
  pubkey:    ECDSA 256 bits
147 9 Andreas Steffen
  keyid:     7f:39:ca:e6:83:9b:a9:06:97:40:27:6a:e1:bf:8f:f5:9f:d3:a5:31
148 9 Andreas Steffen
  subjkey:   8b:43:4d:5e:5e:7b:ff:c2:54:4d:ef:88:cb:0c:7c:47:75:28:4d:09
149 9 Andreas Steffen
150 20 Andreas Steffen
h2. Generate a Persistent ECC Attestation Key
151 13 Andreas Steffen
152 13 Andreas Steffen
A 256 bit ECC Attestation Key (AK) bound to the EK with handle 0x81010003 can be created and made persistent under the handle 0x81010004 with the following tpm2-tools command
153 13 Andreas Steffen
154 84 Andreas Steffen
 tpm2_getpubak -E 0x81010003 -g ecc -D sha256 -s ecdsa -k 0x81010004 -f ak_ecc4.pub -n ak_ecc4.name
155 13 Andreas Steffen
156 13 Andreas Steffen
The AK public key can be exported in PKCS#1 format from the TPM using the *pki* tool
157 13 Andreas Steffen
158 50 Andreas Steffen
 pki --pub --keyid 0x81010004 > ak_ecc_pub.der
159 13 Andreas Steffen
160 52 Andreas Steffen
The fingerprint of the ECC AK public key can be displayed with the command
161 13 Andreas Steffen
162 14 Andreas Steffen
 pki --print --type pub --in ak_ecc_pub.der
163 1 Andreas Steffen
  pubkey:    ECDSA 256 bits
164 1 Andreas Steffen
  keyid:     71:49:7c:42:41:e7:c6:81:bc:31:73:f0:0f:7e:4a:e1:2d:53:00:38
165 1 Andreas Steffen
  subjkey:   c7:0e:63:f8:7f:6f:f6:55:00:e5:05:7f:5a:3e:6b:6c:e7:d2:d5:13
166 15 Andreas Steffen
167 20 Andreas Steffen
h2. Generate Another ECC Attestation Key
168 15 Andreas Steffen
169 15 Andreas Steffen
Multiple AK keys bound to a common EK key can be generated
170 15 Andreas Steffen
171 85 Andreas Steffen
 tpm2_getpubak -E 0x81010003 -g ecc -D sha256 -s ecdsa -k 0x81010005 -f ak_ecc5.pub -n ak_ecc5.name
172 15 Andreas Steffen
173 68 Andreas Steffen
The fingerprint of the second ECC AK private key can be displayed with the command
174 15 Andreas Steffen
175 68 Andreas Steffen
 pki --print --type priv --in 0x81010005
176 15 Andreas Steffen
  pubkey:    ECDSA 256 bits
177 15 Andreas Steffen
  keyid:     c4:b4:9c:95:27:9e:ce:81:2f:98:42:c8:1b:f0:54:ff:d4:d1:24:34
178 15 Andreas Steffen
  subjkey:   cf:44:f4:f7:9d:97:09:ad:b1:09:3a:8e:6f:23:eb:9f:2c:35:94:c9
179 15 Andreas Steffen
180 19 Andreas Steffen
h2. Remove a Persistent Key Object
181 15 Andreas Steffen
182 15 Andreas Steffen
Since the non-volatile memory of the TPM is limited any persistent key object can be removed to free storage space.
183 15 Andreas Steffen
The following tpm2-tools command removes the ECC AK key with persistent handle 0x81010005
184 15 Andreas Steffen
185 1 Andreas Steffen
 tpm2_evictcontrol -A o -H 0x81010005 -S 0x81010005
186 18 Andreas Steffen
187 18 Andreas Steffen
h2. List Persistent Objects
188 18 Andreas Steffen
189 18 Andreas Steffen
The following tpm2-tools command lists all persistent objects stored by the TPM in non-volatile memory
190 18 Andreas Steffen
191 18 Andreas Steffen
 tpm2_listpersistent
192 18 Andreas Steffen
193 18 Andreas Steffen
<pre>
194 18 Andreas Steffen
6 persistent objects defined.
195 18 Andreas Steffen
196 18 Andreas Steffen
0. Persistent handle: 0x81000001
197 18 Andreas Steffen
{
198 18 Andreas Steffen
        Type: 0x23
199 18 Andreas Steffen
        Hash algorithm(nameAlg): 0xb
200 18 Andreas Steffen
        Attributes: 0x30072
201 18 Andreas Steffen
}
202 18 Andreas Steffen
1. Persistent handle: 0x81000002
203 18 Andreas Steffen
{
204 18 Andreas Steffen
        Type: 0x23
205 18 Andreas Steffen
        Hash algorithm(nameAlg): 0xb
206 18 Andreas Steffen
        Attributes: 0x60072
207 18 Andreas Steffen
}
208 18 Andreas Steffen
2. Persistent handle: 0x81010001
209 18 Andreas Steffen
{
210 18 Andreas Steffen
        Type: 0x1
211 18 Andreas Steffen
        Hash algorithm(nameAlg): 0xb
212 18 Andreas Steffen
        Attributes: 0x300b2
213 18 Andreas Steffen
}
214 18 Andreas Steffen
3. Persistent handle: 0x81010002
215 18 Andreas Steffen
{
216 18 Andreas Steffen
        Type: 0x1
217 18 Andreas Steffen
        Hash algorithm(nameAlg): 0xb
218 18 Andreas Steffen
        Attributes: 0x50072
219 18 Andreas Steffen
}
220 18 Andreas Steffen
4. Persistent handle: 0x81010003
221 18 Andreas Steffen
{
222 18 Andreas Steffen
        Type: 0x23
223 18 Andreas Steffen
        Hash algorithm(nameAlg): 0xb
224 18 Andreas Steffen
        Attributes: 0x300b2
225 18 Andreas Steffen
}
226 18 Andreas Steffen
5. Persistent handle: 0x81010004
227 18 Andreas Steffen
{
228 18 Andreas Steffen
        Type: 0x23
229 18 Andreas Steffen
        Hash algorithm(nameAlg): 0xb
230 18 Andreas Steffen
        Attributes: 0x50072
231 18 Andreas Steffen
}
232 18 Andreas Steffen
</pre>
233 13 Andreas Steffen
234 41 Andreas Steffen
h2. Create a Demo Root CA
235 41 Andreas Steffen
236 41 Andreas Steffen
The following *pki* command creates a 256 bit ECDSA private key for the Demo CA
237 41 Andreas Steffen
<pre>
238 41 Andreas Steffen
pki --gen --type ecdsa --size 256 --outform pem > demoCaKey.pem
239 41 Andreas Steffen
</pre>
240 41 Andreas Steffen
241 41 Andreas Steffen
Next we create a self-signed Root CA certificate
242 41 Andreas Steffen
<pre>
243 41 Andreas Steffen
pki --self --ca --type ecdsa --in demoCaKey.pem --dn="C=US, O=TNC Demo, CN=TNC Demo CA" --lifetime 3652 --outform pem > demoCaCert.pem
244 41 Andreas Steffen
</pre>
245 41 Andreas Steffen
246 42 Andreas Steffen
h2. Issue an RSA AIK Certificate
247 41 Andreas Steffen
248 42 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
249 41 Andreas Steffen
<pre>
250 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
251 41 Andreas Steffen
</pre>
252 41 Andreas Steffen
253 42 Andreas Steffen
h2. Issue an ECC AIK Certificate
254 41 Andreas Steffen
255 42 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
256 41 Andreas Steffen
<pre>
257 41 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
258 41 Andreas Steffen
</pre>
259 47 Andreas Steffen
260 49 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
261 47 Andreas Steffen
<pre>
262 50 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
263 47 Andreas Steffen
</pre>
264 49 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
265 49 Andreas Steffen
<pre>
266 47 Andreas Steffen
pki --issue --cacert demoCaCert.pem --cakey demoCaKey.pem --type pkcs10 --in ak_ecc_req.der --lifetime 3651 > raspi5_ak_ecc_Cert.der
267 47 Andreas Steffen
</pre>
268 47 Andreas Steffen
269 54 Andreas Steffen
h2. Store the ECC AIK Certificate in the NV RAM of the TPM
270 54 Andreas Steffen
271 55 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
272 54 Andreas Steffen
<pre>
273 54 Andreas Steffen
ls -l raspi5_ak_ecc_Cert.der
274 63 Andreas Steffen
-rw-r--r-- 1 root root 449 Feb 17  2017 raspi5_ak_ecc_Cert.der
275 54 Andreas Steffen
</pre>
276 54 Andreas Steffen
277 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
278 54 Andreas Steffen
<pre>
279 54 Andreas Steffen
tpm2_nvdefine -x 0x01800004 -a 0x40000001 -s 449 -t 0x2000A
280 54 Andreas Steffen
</pre>
281 54 Andreas Steffen
282 54 Andreas Steffen
Then we write the certificate file to the NV RAM destination
283 54 Andreas Steffen
<pre>
284 70 Andreas Steffen
tpm2_nvwrite -x 0x01800004 -a 0x40000001 raspi5_ak_ecc_Cert.der
285 54 Andreas Steffen
</pre>
286 54 Andreas Steffen
287 62 Andreas Steffen
h2. List of NV Indexes
288 54 Andreas Steffen
289 62 Andreas Steffen
A list of all defined NV indexes can be obtained with
290 57 Andreas Steffen
291 57 Andreas Steffen
 tpm2_nvlist
292 57 Andreas Steffen
293 55 Andreas Steffen
<pre>
294 54 Andreas Steffen
2 NV indexes defined.
295 54 Andreas Steffen
296 54 Andreas Steffen
  0. NV Index: 0x1500015
297 54 Andreas Steffen
  {
298 54 Andreas Steffen
	Hash algorithm(nameAlg):4
299 54 Andreas Steffen
 	The Index attributes(attributes):0x44040004
300 54 Andreas Steffen
 	The size of the data area(dataSize):4
301 54 Andreas Steffen
   }
302 54 Andreas Steffen
  1. NV Index: 0x1800004
303 54 Andreas Steffen
  {
304 54 Andreas Steffen
	Hash algorithm(nameAlg):11
305 54 Andreas Steffen
 	The Index attributes(attributes):0x2002000a
306 1 Andreas Steffen
 	The size of the data area(dataSize):449
307 1 Andreas Steffen
   }
308 62 Andreas Steffen
</pre>
309 62 Andreas Steffen
310 62 Andreas Steffen
h2. Remove NV Index
311 62 Andreas Steffen
312 62 Andreas Steffen
The memory assigned to a given NV index can be released with the command
313 62 Andreas Steffen
<pre>
314 62 Andreas Steffen
tpm2_nvrelease -x 0x01800001 -a 0x40000001
315 54 Andreas Steffen
</pre>
316 54 Andreas Steffen
317 30 Andreas Steffen
h2. Configure TPM Private Key Access via VICI Interface
318 1 Andreas Steffen
319 23 Andreas Steffen
Configuration of TPM private key access as tokens in the secrets section of *swanctl.conf*
320 1 Andreas Steffen
321 7 Andreas Steffen
 secrets {
322 1 Andreas Steffen
    token_ak_rsa {
323 1 Andreas Steffen
       handle = 81010002
324 46 Andreas Steffen
       pin = 123456
325 1 Andreas Steffen
    }
326 1 Andreas Steffen
    token_ak_ecc {
327 7 Andreas Steffen
       handle = 81010004
328 1 Andreas Steffen
    }
329 1 Andreas Steffen
}
330 46 Andreas Steffen
Since the use of the RSA AK private key is password-protected, the PIN *123456* is added.
331 30 Andreas Steffen
332 30 Andreas Steffen
h2. Define IPsec Connection with RSA AK Client Key
333 30 Andreas Steffen
334 30 Andreas Steffen
This connection configuration in *swanctl.conf* uses the RSA AK certificate for client authentication
335 30 Andreas Steffen
<pre>
336 30 Andreas Steffen
connections {
337 30 Andreas Steffen
   rsa {
338 30 Andreas Steffen
      local_addrs  = 10.10.0.105
339 30 Andreas Steffen
      remote_addrs = 10.10.0.104
340 30 Andreas Steffen
341 30 Andreas Steffen
      local {
342 30 Andreas Steffen
         auth = pubkey 
343 30 Andreas Steffen
         certs = raspi5_ak_rsa_Cert.der
344 30 Andreas Steffen
      }
345 30 Andreas Steffen
      remote {
346 30 Andreas Steffen
         auth = pubkey 
347 30 Andreas Steffen
         id = raspi4.example.com
348 30 Andreas Steffen
      }
349 30 Andreas Steffen
      children {
350 30 Andreas Steffen
         rsa {
351 30 Andreas Steffen
            mode = transport
352 30 Andreas Steffen
            esp_proposals = aes128-sha256-curve25519
353 30 Andreas Steffen
         }
354 30 Andreas Steffen
      }
355 30 Andreas Steffen
      version = 2
356 30 Andreas Steffen
      proposals = aes128-sha256-curve25519
357 30 Andreas Steffen
   }
358 30 Andreas Steffen
}
359 30 Andreas Steffen
</pre>
360 30 Andreas Steffen
361 30 Andreas Steffen
h2. Define IPsec Connection with ECC AK Client Key
362 30 Andreas Steffen
363 58 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
364 30 Andreas Steffen
<pre>
365 30 Andreas Steffen
connections {
366 30 Andreas Steffen
   ecc {
367 30 Andreas Steffen
      local_addrs  = 10.10.0.105
368 30 Andreas Steffen
      remote_addrs = 10.10.0.104
369 30 Andreas Steffen
370 30 Andreas Steffen
      local {
371 1 Andreas Steffen
         auth = pubkey
372 58 Andreas Steffen
         cert-tpm {
373 58 Andreas Steffen
            handle = 0x01800004
374 58 Andreas Steffen
         }
375 30 Andreas Steffen
      }
376 30 Andreas Steffen
      remote {
377 30 Andreas Steffen
         auth = pubkey
378 30 Andreas Steffen
         id = raspi4.example.com
379 30 Andreas Steffen
      }
380 30 Andreas Steffen
      children {
381 30 Andreas Steffen
         ecc {
382 30 Andreas Steffen
            mode = transport
383 30 Andreas Steffen
            esp_proposals = aes128-sha256-curve25519
384 30 Andreas Steffen
         }
385 30 Andreas Steffen
      }
386 30 Andreas Steffen
      version = 2
387 30 Andreas Steffen
      proposals = aes128-sha256-curve25519
388 30 Andreas Steffen
   }
389 30 Andreas Steffen
}
390 30 Andreas Steffen
</pre>
391 29 Andreas Steffen
392 29 Andreas Steffen
h2. Starting the strongSwan Daemon
393 29 Andreas Steffen
394 29 Andreas Steffen
<pre>
395 29 Andreas Steffen
systemctl start strongswan-swanctl
396 29 Andreas Steffen
</pre>
397 29 Andreas Steffen
398 29 Andreas Steffen
<pre>
399 44 Andreas Steffen
Feb 19 10:52:01 raspi5 systemd[1]: Starting strongSwan IPsec IKEv1/IKEv2 daemon using swanctl...
400 44 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
401 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: spawning 16 worker threads
402 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'
403 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: loaded certificate 'C=US, O=TNC Demo, CN=TNC Demo CA'
404 1 Andreas Steffen
</pre>
405 1 Andreas Steffen
406 59 Andreas Steffen
The RSA AK private key is attached to the *charon-systemd* daemon via the TPM 2.0 resource manager
407 1 Andreas Steffen
<pre>
408 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 - manufacturer: IFX (SLB9670) rev: 01.16 2015
409 53 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
410 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 - ECC curves: NIST_P256 BN_P256
411 73 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 via TSS2 v2 available
412 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: AIK signature algorithm is RSASSA with SHA256 hash
413 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: loaded RSA private key from token
414 1 Andreas Steffen
F</pre>
415 1 Andreas Steffen
416 1 Andreas Steffen
The ECC AK private key is attached to the *charon-systemd* daemon via the TPM 2.0 resource manager
417 44 Andreas Steffen
<pre>
418 44 Andreas Steffen
Feb 19 10:52:01 raspi5 charon-systemd[21165]: TPM 2.0 - manufacturer: IFX (SLB9670) rev: 01.16 2015
419 53 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
420 44 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 - ECC curves: NIST_P256 BN_P256
421 73 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 via TSS2 v2 available
422 1 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: AIK signature algorithm is ECDSA with SHA256 hash
423 1 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: loaded ECDSA private key from token
424 1 Andreas Steffen
</pre>
425 59 Andreas Steffen
426 59 Andreas Steffen
The ECC AIK certificate is loaded by the *charon-systemd* daemon via the TPM 2.0 resource manager
427 59 Andreas Steffen
<pre>
428 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 - manufacturer: IFX (SLB9670) rev: 01.16 2015
429 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
430 59 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 - ECC curves: NIST_P256 BN_P256
431 73 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: TPM 2.0 via TSS2 v2 available
432 60 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: loaded certificate from TPM NV index 0x01800004
433 59 Andreas Steffen
</pre>
434 59 Andreas Steffen
435 59 Andreas Steffen
The two connection definitions are received by the *charon-systemd* daemon from the *swanctl* command line tool via the VICI interface
436 59 Andreas Steffen
<pre>
437 1 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'
438 1 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: added vici connection: rsa
439 1 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'
440 44 Andreas Steffen
Feb 19 10:52:02 raspi5 charon-systemd[21165]: added vici connection: ecc
441 59 Andreas Steffen
</pre>
442 59 Andreas Steffen
443 59 Andreas Steffen
The *swanctl* command line tool reports its actions
444 59 Andreas Steffen
<pre>
445 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded certificate from '/etc/swanctl/x509/raspi5_ak_rsa_Cert.der'
446 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded certificate from '/etc/swanctl/x509ca/demoCaCert.pem'
447 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded key token_ak_rsa from token [keyid: f49e857dde4e67f5fb870398673f207cf33f2b66]
448 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded key token_ak_ecc from token [keyid: c70e63f87f6ff65500e5057f5a3e6b6ce7d2d513]
449 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded connection 'rsa'
450 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: loaded connection 'ecc'
451 44 Andreas Steffen
Feb 19 10:52:02 raspi5 swanctl[21183]: successfully loaded 2 connections, 0 unloaded
452 31 Andreas Steffen
</pre>
453 31 Andreas Steffen
454 31 Andreas Steffen
<pre>
455 44 Andreas Steffen
Feb 19 10:52:02 raspi5 systemd[1]: Started strongSwan IPsec IKEv1/IKEv2 daemon using swanctl.
456 31 Andreas Steffen
</pre>
457 31 Andreas Steffen
458 31 Andreas Steffen
The following *swanctl* command shows the two loaded connections
459 31 Andreas Steffen
<pre>
460 31 Andreas Steffen
swanctl --list-conns
461 31 Andreas Steffen
</pre>
462 31 Andreas Steffen
463 31 Andreas Steffen
<pre>
464 31 Andreas Steffen
rsa: IKEv2, reauthentication every 10800s, no rekeying
465 31 Andreas Steffen
  local:  10.10.0.105
466 31 Andreas Steffen
  remote: 10.10.0.104
467 31 Andreas Steffen
  local public key authentication:
468 31 Andreas Steffen
    id: C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com
469 31 Andreas Steffen
    certs: C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com
470 31 Andreas Steffen
  remote public key authentication:
471 31 Andreas Steffen
    id: raspi4.example.com
472 31 Andreas Steffen
  rsa: TRANSPORT, rekeying every 3600s or 300000000 bytes or 500000 packets
473 31 Andreas Steffen
    local:  dynamic
474 31 Andreas Steffen
    remote: dynamic
475 31 Andreas Steffen
</pre>
476 31 Andreas Steffen
477 31 Andreas Steffen
<pre>
478 31 Andreas Steffen
ecc: IKEv2, reauthentication every 10800s, no rekeying
479 31 Andreas Steffen
  local:  10.10.0.105
480 31 Andreas Steffen
  remote: 10.10.0.104
481 31 Andreas Steffen
  local public key authentication:
482 31 Andreas Steffen
    id: C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com
483 31 Andreas Steffen
    certs: C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com
484 31 Andreas Steffen
  remote public key authentication:
485 31 Andreas Steffen
    id: raspi4.example.com
486 31 Andreas Steffen
  ecc: TRANSPORT, rekeying every 3600s or 300000000 bytes or 500000 packets
487 31 Andreas Steffen
    local:  dynamic
488 32 Andreas Steffen
    remote: dynamic
489 31 Andreas Steffen
</pre>
490 31 Andreas Steffen
491 31 Andreas Steffen
The loaded certificates can also be displayed
492 31 Andreas Steffen
<pre>
493 31 Andreas Steffen
swanctl --list-certs
494 31 Andreas Steffen
</pre>
495 31 Andreas Steffen
496 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)
497 31 Andreas Steffen
<pre>
498 31 Andreas Steffen
List of X.509 End Entity Certificates
499 31 Andreas Steffen
500 31 Andreas Steffen
  subject:  "C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com"
501 31 Andreas Steffen
  issuer:   "C=US, O=TNC Demo, CN=TNC Demo CA"
502 31 Andreas Steffen
  validity:  not before Feb 19 09:33:43 2017, ok
503 31 Andreas Steffen
             not after  Aug 29 10:33:43 2026, ok (expires in 3477 days)
504 31 Andreas Steffen
  serial:    11:57:33:3e:2a:8e:8a:32
505 31 Andreas Steffen
  altNames:  raspi5.example.com
506 31 Andreas Steffen
  authkeyId: 21:02:7e:2d:de:8b:77:48:75:de:56:2f:b5:d4:62:ec:c3:09:15:f2
507 31 Andreas Steffen
  subjkeyId: f4:9e:85:7d:de:4e:67:f5:fb:87:03:98:67:3f:20:7c:f3:3f:2b:66
508 31 Andreas Steffen
  pubkey:    RSA 2048 bits, has private key
509 31 Andreas Steffen
  keyid:     71:21:f5:d4:7e:59:4a:88:16:ca:57:85:98:3d:36:a7:b1:d5:75:fa
510 31 Andreas Steffen
  subjkey:   f4:9e:85:7d:de:4e:67:f5:fb:87:03:98:67:3f:20:7c:f3:3f:2b:66
511 31 Andreas Steffen
512 31 Andreas Steffen
  subject:  "C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com"
513 31 Andreas Steffen
  issuer:   "C=US, O=TNC Demo, CN=TNC Demo CA"
514 31 Andreas Steffen
  validity:  not before Feb 17 23:17:19 2017, ok
515 31 Andreas Steffen
             not after  Aug 30 00:17:19 2026, ok (expires in 3478 days)
516 31 Andreas Steffen
  serial:    52:9d:3e:42:6f:71:63:3d
517 31 Andreas Steffen
  altNames:  raspi5.example.com
518 31 Andreas Steffen
  authkeyId: 21:02:7e:2d:de:8b:77:48:75:de:56:2f:b5:d4:62:ec:c3:09:15:f2
519 31 Andreas Steffen
  subjkeyId: c7:0e:63:f8:7f:6f:f6:55:00:e5:05:7f:5a:3e:6b:6c:e7:d2:d5:13
520 31 Andreas Steffen
  pubkey:    ECDSA 256 bits, has private key
521 31 Andreas Steffen
  keyid:     71:49:7c:42:41:e7:c6:81:bc:31:73:f0:0f:7e:4a:e1:2d:53:00:38
522 31 Andreas Steffen
  subjkey:   c7:0e:63:f8:7f:6f:f6:55:00:e5:05:7f:5a:3e:6b:6c:e7:d2:d5:13
523 31 Andreas Steffen
</pre>
524 31 Andreas Steffen
525 31 Andreas Steffen
<pre>
526 31 Andreas Steffen
List of X.509 CA Certificates
527 31 Andreas Steffen
528 31 Andreas Steffen
  subject:  "C=US, O=TNC Demo, CN=TNC Demo CA"
529 1 Andreas Steffen
  issuer:   "C=US, O=TNC Demo, CN=TNC Demo CA"
530 32 Andreas Steffen
  validity:  not before Aug 31 10:29:27 2016, ok
531 32 Andreas Steffen
             not after  Aug 31 10:29:27 2026, ok (expires in 3479 days)
532 43 Andreas Steffen
  serial:    02:c8:85:e1:ef:fa:8f:20
533 32 Andreas Steffen
  flags:     CA CRLSign self-signed 
534 38 Andreas Steffen
  subjkeyId: 21:02:7e:2d:de:8b:77:48:75:de:56:2f:b5:d4:62:ec:c3:09:15:f2
535 32 Andreas Steffen
  pubkey:    ECDSA 256 bits
536 32 Andreas Steffen
  keyid:     a1:b5:e0:29:d0:4c:a7:62:bd:ca:a3:b4:af:18:42:2c:4a:01:55:9a
537 32 Andreas Steffen
  subjkey:   21:02:7e:2d:de:8b:77:48:75:de:56:2f:b5:d4:62:ec:c3:09:15:f2
538 32 Andreas Steffen
</pre>
539 32 Andreas Steffen
540 32 Andreas Steffen
h2. IKEv2 Authentication with RSA AIK Certificate
541 32 Andreas Steffen
542 32 Andreas Steffen
With the following *swanctl* command the "rsa" connection is established
543 32 Andreas Steffen
<pre>
544 32 Andreas Steffen
swanctl --initiate --child rsa
545 32 Andreas Steffen
</pre>
546 32 Andreas Steffen
547 32 Andreas Steffen
<pre>
548 45 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: vici initiate 'rsa'
549 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: initiating IKE_SA rsa[1] to 10.10.0.104
550 40 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 ]
551 40 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)
552 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)
553 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 ]
554 32 Andreas Steffen
Feb 19 10:52:21 raspi5 charon-systemd[21165]: received strongSwan vendor ID
555 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"
556 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"
557 32 Andreas Steffen
</pre>
558 32 Andreas Steffen
559 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.
560 32 Andreas Steffen
<pre>
561 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
562 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"
563 32 Andreas Steffen
</pre>
564 32 Andreas Steffen
<pre>
565 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: establishing CHILD_SA rsa
566 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) ]
567 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)
568 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)
569 32 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) ]
570 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"
571 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]:   using certificate "C=US, O=TNC Demo, CN=raspi4.example.com"
572 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"
573 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]:   reached self-signed root ca with a path length of 0
574 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: authentication of 'raspi4.example.com' with ECDSA_WITH_SHA256_DER successful
575 38 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]
576 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: scheduling reauthentication in 10507s
577 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: maximum IKE_SA lifetime 11587s
578 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
579 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: received AUTH_LIFETIME of 10103s, scheduling reauthentication in 9023s
580 32 Andreas Steffen
Feb 19 10:52:24 raspi5 charon-systemd[21165]: peer supports MOBIKE
581 32 Andreas Steffen
</pre>
582 32 Andreas Steffen
583 32 Andreas Steffen
The following *swanctl* command shows the established IPsec connection
584 32 Andreas Steffen
<pre>
585 32 Andreas Steffen
 swanctl --list-sas
586 32 Andreas Steffen
</pre>
587 32 Andreas Steffen
<pre>
588 32 Andreas Steffen
rsa: #1, ESTABLISHED, IKEv2, 7ba3b4d06c051ecb_i* 14e1769a8aeb7f28_r
589 32 Andreas Steffen
  local  'C=US, O=TNC Demo, OU=AIK RSA, CN=raspi5.example.com' @ 10.10.0.105[4500]
590 32 Andreas Steffen
  remote 'raspi4.example.com' @ 10.10.0.104[4500]
591 32 Andreas Steffen
  AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519
592 32 Andreas Steffen
  established 252s ago, reauth in 8771s
593 38 Andreas Steffen
  rsa: #1, reqid 1, INSTALLED, TRANSPORT, ESP:AES_CBC-128/HMAC_SHA2_256_128
594 33 Andreas Steffen
    installed 252s ago, rekeying in 3258s, expires in 3708s
595 33 Andreas Steffen
    in  c23deb9d,    640 bytes,    10 packets,     3s ago
596 33 Andreas Steffen
    out ce48d08e,    640 bytes,    10 packets,     3s ago
597 33 Andreas Steffen
    local  10.10.0.105/32
598 33 Andreas Steffen
    remote 10.10.0.104/32
599 33 Andreas Steffen
</pre>
600 33 Andreas Steffen
601 33 Andreas Steffen
With this *swanctl* command the "rsa" connection is terminated
602 33 Andreas Steffen
<pre>
603 33 Andreas Steffen
swanctl --terminate --ike rsa
604 33 Andreas Steffen
</pre>
605 33 Andreas Steffen
606 33 Andreas Steffen
<pre>
607 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: vici terminate IKE_SA 'rsa'
608 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]
609 43 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: sending DELETE for IKE_SA rsa[1]
610 32 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: generating INFORMATIONAL request 2 [ D ]
611 38 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)
612 32 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)
613 32 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: parsed INFORMATIONAL response 2 [ ]
614 33 Andreas Steffen
Feb 19 10:59:16 raspi5 charon-systemd[21165]: IKE_SA deleted
615 33 Andreas Steffen
</pre>
616 33 Andreas Steffen
617 33 Andreas Steffen
h2. IKEv2 Authentication with ECC AIK Certificate
618 33 Andreas Steffen
619 33 Andreas Steffen
Next we initiate the "ecc" connection
620 33 Andreas Steffen
<pre>
621 33 Andreas Steffen
swanctl --initiate --child ecc
622 33 Andreas Steffen
</pre>
623 33 Andreas Steffen
624 33 Andreas Steffen
<pre>
625 45 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: vici initiate 'ecc'
626 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: initiating IKE_SA ecc[2] to 10.10.0.104
627 40 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 ]
628 40 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)
629 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)
630 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 ]
631 33 Andreas Steffen
Feb 19 11:00:32 raspi5 charon-systemd[21165]: received strongSwan vendor ID
632 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"
633 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"
634 33 Andreas Steffen
</pre>
635 33 Andreas Steffen
636 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.
637 33 Andreas Steffen
<pre>
638 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
639 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"
640 33 Andreas Steffen
</pre>
641 33 Andreas Steffen
<pre>
642 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: establishing CHILD_SA ecc
643 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) ]
644 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)
645 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)
646 33 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) ]
647 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"
648 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]:   using certificate "C=US, O=TNC Demo, CN=raspi4.example.com"
649 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"
650 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]:   reached self-signed root ca with a path length of 0
651 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: authentication of 'raspi4.example.com' with ECDSA_WITH_SHA256_DER successful
652 39 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]
653 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: scheduling reauthentication in 10180s
654 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: maximum IKE_SA lifetime 11260s
655 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
656 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: received AUTH_LIFETIME of 9880s, scheduling reauthentication in 8800s
657 33 Andreas Steffen
Feb 19 11:00:34 raspi5 charon-systemd[21165]: peer supports MOBIKE
658 33 Andreas Steffen
</pre>
659 33 Andreas Steffen
660 33 Andreas Steffen
The establed IKE and CHILD SAs are displayed
661 33 Andreas Steffen
<pre>
662 33 Andreas Steffen
 swanctl --list-sas
663 33 Andreas Steffen
</pre>
664 33 Andreas Steffen
<pre>
665 33 Andreas Steffen
ecc: #2, ESTABLISHED, IKEv2, b7f2652777b0996a_i* 12282b5964ff0658_r
666 1 Andreas Steffen
  local  'C=US, O=TNC Demo, OU=AIK ECC, CN=raspi5.example.com' @ 10.10.0.105[4500]
667 1 Andreas Steffen
  remote 'raspi4.example.com' @ 10.10.0.104[4500]
668 34 Andreas Steffen
  AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519
669 34 Andreas Steffen
  established 126s ago, reauth in 8674s
670 39 Andreas Steffen
  ecc: #2, reqid 2, INSTALLED, TRANSPORT, ESP:AES_CBC-128/HMAC_SHA2_256_128
671 34 Andreas Steffen
    installed 126s ago, rekeying in 3252s, expires in 3834s
672 34 Andreas Steffen
    in  c2c16cd0,    320 bytes,     5 packets,     2s ago
673 34 Andreas Steffen
    out c47ea6f6,    320 bytes,     5 packets,     2s ago
674 34 Andreas Steffen
    local  10.10.0.105/32
675 34 Andreas Steffen
    remote 10.10.0.104/32
676 34 Andreas Steffen
</pre>
677 34 Andreas Steffen
678 34 Andreas Steffen
The IKE and CHILD SAs are terminated
679 34 Andreas Steffen
<pre>
680 34 Andreas Steffen
swanctl --terminate --ike ecc
681 34 Andreas Steffen
</pre>
682 34 Andreas Steffen
683 34 Andreas Steffen
<pre>
684 34 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: vici terminate IKE_SA 'ecc'
685 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]
686 34 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: sending DELETE for IKE_SA ecc[2]
687 34 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: generating INFORMATIONAL request 2 [ D ]
688 39 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)
689 34 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)
690 34 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: parsed INFORMATIONAL response 2 [ ]
691 34 Andreas Steffen
Feb 19 11:04:32 raspi5 charon-systemd[21165]: IKE_SA deleted
692 1 Andreas Steffen
</pre>