-
Notifications
You must be signed in to change notification settings - Fork 0
/
ikev2.spthy
335 lines (296 loc) · 8.62 KB
/
ikev2.spthy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* Protocol: IKEv2
* Modeler: Tobias Heider & Stefan-Lukas Gazdag & Sophia Grundner-Culemann
* Date: 10/2019
* Status: Done
*/
theory IKEv2
begin
builtins: asymmetric-encryption, diffie-hellman, hashing, signing,
symmetric-encryption
functions: hmac/2
/* Tells Tamarin that whenever a Eq action occurs the two arguments must be equal */
restriction Eq_check_succeed: "All x y #i. Eq(x,y) @ i ==> x = y"
// IKEv2 Protocol
/*
* Static Longterm Key generator
* Keys are bound to an ID i, which is not public
*/
rule generate_static:
[ Fr(~ltk)
]
--[GenStatic(pk(~ltk))]->
[ !PrivKey($I, ~ltk)
, !PubKey($I, pk(~ltk))
, Out(pk(~ltk))
]
/*
* Key Reveals as defined in the adversary model
*/
rule reveal_static:
[ !PrivKey($I, ltk) ]
--[RevLtk($I)]->
[ Out(ltk) ]
rule reveal_dh:
[ !DHtoReveal($I, k) ]
--[RevDH($I)]->
[ Out(k) ]
/*
* IKEv2 Protocol transitions
*/
rule IKE_SA_INIT_I:
let
epI = 'g'^~eI // < Initiator DH public share
msg1 = <~spiI, 'IKE_SA_INIT', '1', 'i', epI, ~nI>
in
[
Fr(~nI) // < Initiator Nonce
, Fr(~spiI) // < Initiator SPI
, Fr(~eI) // < Initiator DH private share
]
-->
[
/*
* HDR, SAi1, KEi, Ni -->
*/
Out(msg1)
, StateInitI($I, $R, ~spiI, ~eI, ~nI, msg1)
, !DHtoReveal($I, ~eI)
]
rule IKE_AUTH_I:
let
/*
* Messages for auth hash
*/
msg2 = <spiI, spiR, 'IKE_SA_INIT', '1', 'r', epR, nR>
/*
* Generate Keying Material
*
* In IKEv2 keys are read bytewise from a procedural generated byte
* output. In the model we have no concept of bytes, thus each key
* is a single block.
*/
k = epR^eI
keymat = h(<nI, nR>, k)
/*
* Authentication and validity of IKE_SA_INIT
*/
signed_octets = <msg1, nR, h(~idI, keymat)>
auth_pl = sign(signed_octets, skI)
/*
* Encryption and Integrity
*/
encr_pl = senc{<~idI, auth_pl, pkI>}keymat
integ_I = hmac(<spiI, spiR, 'IKE_AUTH', '2', 'i', encr_pl>, keymat)
msg3 = <spiI, spiR, 'IKE_AUTH', '2', 'i', encr_pl, integ_I>
in
[ In(msg2)
, Fr(~idI)
, StateInitI($I, $R, spiI, eI, nI, msg1)
, !PrivKey($I, skI)
, !PubKey($I, pkI)
]
--[ Agreed(<spiI, spiR>, $I, 'initiator', <nI, nR>, keymat)
]->
[
/*
* HDR, SK {IDi, AUTH, SAi2, TSi, TSr} -->
*/
Out(msg3)
, StateAuthI($I, $R, ~idI, spiI, spiR, nI, nR, keymat, msg1, msg2, 'g'^eI, epR)
]
rule IKE_AUTH_COMPLETE:
let
signed_octets_R = <msg2, nI, h(idR, keymat)>
encr_pl_I = senc{<idR, spiC, auth_pl_R, pkR>}keymat
integ_I = hmac(<spiI, spiR, 'IKE_AUTH', '2', 'r', encr_pl_I>, keymat)
msg4 = <spiI, spiR, 'IKE_AUTH', '2', 'r', encr_pl_I, integ_I>
/* Confirmation message (models an ESP packet encrypted with the newly
* derived initial Child SA */
ck = hmac(keymat, <nI, nR>)
mTest = <'0', senc('test', ck),
hmac(<'0', senc('test',ck)>, ck)>
in
[ In(msg4)
, StateAuthI($I, $R, idI, spiI, spiR, nI, nR, keymat, msg1, msg2, epI, epR)
, !PubKey($R, pkR)
]
--[ Eq(verify(auth_pl_R, signed_octets_R, pkR), true)
, IKeys($I, $R, spiC, ck)
, Completed(<spiI, spiR>, $I, 'initiator', $R, keymat)
, IdentityLearnt(idI)
]->
[ Out(mTest)
]
rule IKE_SA_INIT_R:
let
epR = 'g'^~eR // < Initiator DH public share
/*
* Generate Keying Material
*
* In IKEv2 keys are read bytewise from a procedural generated byte
* output. In the model we have no concept of bytes, thus each key
* is a single block.
*/
k = epI^~eR
/* This is not actually true, actual keys are derived from this hash */
keymat = h(<nI, ~nR>, k)
/*
* Messages for auth hash
*/
msg1 = <spiI, 'IKE_SA_INIT', '1', 'i', epI, nI>
msg2 = <spiI, ~spiR, 'IKE_SA_INIT', '1', 'r', epR, ~nR>
in
[ In(msg1) // < HDR, SAi1, KEi, Ni
, Fr(~nR) // < Responder Nonce
, Fr(~spiR) // < Responder SPI
, Fr(~eR) // < Responder DH private share
]
--[ Agreed(<spiI, ~spiR>, $R, 'responder', <nI, ~nR>, keymat)
]->
[
Out(msg2) // < HDR, SAr1, KEr, Nr
, StateInitR($I, $R, spiI, ~spiR, nI, ~nR, keymat, msg1, msg2, epI, epR)
, !DHtoReveal($R, ~eR)
]
rule IKE_AUTH_R:
let
/*
* Incoming Payloads
*/
signed_octets_I = <msg1, nR, h(idI, keymat)>
encr_pl_I = senc{<idI, auth_pl_I, pkI>}keymat
integ_I = hmac(<spiI, spiR, 'IKE_AUTH', '2', 'i', encr_pl_I>, keymat)
msg3 = <spiI, spiR, 'IKE_AUTH', '2', 'i', encr_pl_I, integ_I>
/*
* Outgoing Payloads
*/
signed_octets_R = <msg2, nI, h(~idR, keymat)>
auth_pl_R = sign(signed_octets_R, skR)
encr_pl_R = senc{<~idR, ~spiC, auth_pl_R, pkR>}keymat
integ_R = hmac(<spiI, spiR, 'IKE_AUTH', '2', 'r', encr_pl_R>, keymat)
msg4 = <spiI, spiR, 'IKE_AUTH', '2', 'r', encr_pl_R, integ_R>
in
[ In(msg3) // < Incoming message #3
, Fr(~idR)
, Fr(~spiC)
, StateInitR($I, $R, spiI, spiR, nI, nR, keymat, msg1, msg2, epI, epR)
, !PrivKey($R, skR)
, !PubKey($R, pkR)
, !PubKey($I, pkI)
]
--[ Eq(verify(auth_pl_I, signed_octets_I, pkI), true)
, Completed(<spiI, spiR>, $R, 'responder', $I, keymat)
, IdentityLearnt(~idR)
]->
[ Out(msg4)
, ChildSAR($I, $R, ~spiC, hmac(keymat, <nI, nR>))
]
rule ChildSA_Confirm_R:
[ In(<'0', senc('test', ck),
hmac(<'0', senc('test',ck)>, ck)>)
, ChildSAR($I, $R, spiC, ck)
]
--[ RConfirm($I, $R, spiC, ck)
]->
[
]
/*
* == Validity ===
*/
lemma exists_session: exists-trace
"Ex I R spi #i #j keymat.
Completed(spi, R, 'responder', I, keymat) @ #i
& Completed(spi, I, 'initiator', R, keymat) @ #j
& i < j"
lemma exists_two_sessions: exists-trace
"Ex I R spi spi2 ck ck2 #i #j #i2 #j2 .
IKeys(I, R, spi, ck) @ i
& RConfirm(I, R, spi, ck) @ j
& i < j
& IKeys(I, R, spi2, ck2) @ i2
& RConfirm(I, R, spi2, ck2) @ j2
& i2 < j2
& not (ck=ck2)"
/*
* === Authentication ===
*
* Initiator and Responder are able to complete the handshake and agree on a
* common key. This follows the work in "A Hierarchy of Authentication
* Specifications" by Lowe et al.
*/
lemma aliveness[use_induction]:
/* A protocol guarantees to an initiator I aliveness of another agent R if,
* whenever I (acting as initiator) completes a run of the protocol,
* apparently with responder R, then R has previously been running the protocol
*/
"All spi I R keymat #i .
Completed(spi, I, 'initiator', R, keymat) @ #i
& not (Ex #k . RevLtk(R) @ k)
==> (Ex spi2 peer role keymat2 #j . Completed(spi2, R, role, peer, keymat2) @ #j
& #j < #i)"
lemma weak_agreement[use_induction]:
/* A protocol guarantees to an initiator I weak agreement with
* another agent R if, whenever I (acting as initiator) completes a run of
* the protocol, apparently with responder R, then R has previously been running
* the protocol, apparently with I
*/
"All spi I R keymat #i .
Completed(spi, I, 'initiator', R, keymat) @ #i
& not (Ex #k . RevLtk(R) @ k)
& not (Ex #k . RevDH(I) @ k)
& not (Ex #k . RevDH(R) @ k)
==> (Ex spi2 role keymat2 #j . Completed(spi2, R, role, I, keymat2) @ #j
& #j < #i)"
lemma agreement[use_induction]:
/* A protocol guarantees to an initiator I agreement with a responder R on a
* set of zeug if, whenever I (acting as initiator) completes a run
* of the protocol, apparently with responder R, then R has previously been
* running the protocol, apparently with I, and R was acting as responder in his
* run, and the two agents agreed on the data values corresponding to all the
* variables in zeug, and each such run of I corresponds to a unique run of R.
*/
"All spi I R keymat #j .
Completed(spi, I, 'initiator', R, keymat) @ #j
& not (Ex #k . RevLtk(R) @ k)
& not (Ex #k . RevDH(I) @ k)
& not (Ex #k . RevDH(R) @ k)
==> (Ex spi2 #k .
Completed(spi2, R, 'responder', I, keymat) @ #k)"
lemma session_uniqueness:
"All I R spi spi2 keymat role #j #l.
Completed(spi, I, role, R, keymat) @ #j
& Completed(spi2, I, role, R, keymat) @ #l
==> (#j = #l)"
/*
* === Consistency ===
*/
lemma consistency:
"All spi I R keymat keymat2 #i #j .
Completed(spi, I, 'initiator', R, keymat) @ #i
& Completed(spi, R, 'responder', I, keymat2) @ #j
& not (Ex #k . RevLtk(R) @ k)
==> (keymat=keymat2)"
/*
* === Key Secrecy ===
*/
lemma key_secrecy[reuse]:
"All spi I R role keymat #j .
Completed(spi, I, role, R, keymat) @ #j
& not (Ex #m . RevLtk(R) @ #m)
& not (Ex #m . RevDH(I) @ #m)
& not (Ex #m . RevDH(R) @ #m)
==> not (Ex #m . K(keymat) @ #m)"
/*
* === Identity Hiding ===
*/
lemma identity_hiding_R:
"All spi I R keymat id #i .
Completed(spi, R, 'responder', I, keymat) @ #i
& IdentityLearnt(id) @ #i
& not (Ex #k . RevLtk(I) @ #k)
& not (Ex #k . RevDH(I) @ #k)
& not (Ex #k . RevDH(R) @ #k)
==> not (Ex #j . K(id) @ #j)"
end
//vim: ft=spthy