-
Notifications
You must be signed in to change notification settings - Fork 0
/
shs.spthy
459 lines (410 loc) · 10.5 KB
/
shs.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/*
How secure is secret handshake?
*/
theory SHS_ng
begin
builtins: diffie-hellman, signing, symmetric-encryption
functions: mac/2, h/1
rule Random:
[
Fr(~eph),
!Agent(pkA, ltkA)
]
--[ MkRand(pkA, ~eph) ]->
[ Rand(pkA, ~eph) ]
rule NewProto:
[ Fr(~protoKey) ] --[ NewProto(~protoKey) ]-> [ !Proto(~protoKey), Out(~protoKey) ]
rule NewAgent:
let
pkDH = 'g'^~ltk
pkSign = pk(~ltk)
pk = <pkDH, pkSign>
in
[ Fr(~ltk) ]
--[
IsAgent(pk),
AgentPubkey(pk, pkDH, pkSign),
WithLtk(~ltk),
HasCapability(pk, pk)
]->
[
!Agent(pk, ~ltk),
!Capability(pk, pk)
]
rule Delegate:
[
!Capability(pkDelegator, pkR),
!Agent(pkDelegatee, ~ltk)
]
--[
HasCapability(pkDelegatee, pkR),
Delegator(pkDelegator)
]->
[ !Capability(pkDelegatee, pkR) ]
rule RevealPubkey:
[ !Agent(pk, ~ltk) ]
--[ RevealPublicKey(pk) ]->
[ Out(pk) ]
rule RevealSessionKey:
[ SessionKey(~sid, sk) ]
--[ RevealSessionKey(sk) ]->
[ Out(sk) ]
rule Corrupt_ltk:
[
!Agent(pkA, ltkA)
]
--[ LtkCorrupt(pkA) ]->
[ Out(ltkA) ]
rule Dial:
[
!Agent(pkI, ~ltkI),
!Capability(pkI, pkR),
!Proto(~protoKey),
Rand(pkI, ~ephI),
Fr(~sid)
]
--[
SessionRole(~sid, 'I'),
SessionInitiator(~sid, pkI),
SessionResponder(~sid, pkR),
SessionEphInitiator(~sid, 'g'^~ephI),
SessionProtoKey(~sid, ~protoKey),
SessionLocal(~sid, pkI),
SessionPeer(~sid, pkR)
]->
[ Initiator(pkI, pkR, ~ltkI, ~ephI, ~protoKey, ~sid) ]
rule Listen:
[
!Agent(pkR, ~ltkR),
!Proto(~protoKey),
Rand(pkR, ~ephR),
Fr(~sid)
]
--[
SessionRole(~sid, 'R'),
SessionResponder(~sid, pkR),
SessionEphResponder(~sid, 'g'^~ephR),
SessionProtoKey(~sid, ~protoKey),
SessionLocal(~sid, pkR)
]->
[ ResponderListen(pkR, ~ltkR, ~ephR, ~protoKey, ~sid) ]
// send client challenge
rule Initiator_sendChal:
let
dhI = 'g'^~ephI
keyMac = mac(dhI, h(~protoKey))
tx = <dhI, keyMac>
in
[
Initiator(pkI, pkR, ~ltkI, ~ephI, ~protoKey, ~sid)
]
--[
SessionID(~sid),
// helpful when looking at trace pictures
DHPubkey(fst(pkI)),
DHPubkey(fst(pkR)),
DHPubkey(dhI)
]->
[
Initiator_chalSent(pkI, pkR, ~ltkI, ~ephI, ~protoKey, ~sid),
Out(tx)
]
// send server challenge
rule Responder_recvChal:
let
dhI = 'g'^ephI
dhR = 'g'^~ephR
pkR = <'g'^~ltkR, pk(~ltkR)>
macKeyTx = h(<dhI^~ephR, ~protoKey>)
// macKeyTx = h(~protoKey)<- this is the actual implementation
msgMac = mac('g'^~ephR, macKeyTx)
macKeyRx = h(~protoKey)
rx = <dhI, mac(dhI, macKeyRx)>
tx = <dhR, msgMac>
in
[
ResponderListen(pkR, ~ltkR, ~ephR, ~protoKey, ~sid),
In(rx)
]
--[
SessionID(~sid),
SessionEphInitiator(~sid, dhI),
// helpful when looking at trace pictures
DHPubkey(fst(pkR)),
DHPubkey(dhI),
DHPubkey(dhR)
]->
[
Responder_chalSent(~ltkR, ~ephR, dhI, ~protoKey, ~sid),
Out(tx)
]
// send client auth
rule Initiator_recvChal:
let
dhI = 'g'^~ephI
dhR = 'g'^ephR
pkRdh = 'g'^~ltkR
pkR = <pkRdh, pkRed>
pkI = <pkIdh, pkIed>
ir = dhR^~ephI
iR = pkRdh^~ephI
Ir = dhR^~ltkI
sk = h(<~protoKey, ir, Ir, iR>) // this will be the final secret, but it's not authenticated yet
sigd = <~protoKey, pkR, h(ir)>
sig = sign(sigd, ~ltkI)
iAuth = <pkI,sig> // == H
eKey = h(<~protoKey, ir, iR>)
iEncAuth = senc(iAuth, eKey)
rx = <dhR, mac(dhR, h(<ir, ~protoKey>))> // according to spec
// rx = <dhR, mac(dhR, h(~protoKey))> // actual implementation diverges from spec
in
[
Initiator_chalSent(pkI, pkR, ~ltkI, ~ephI, ~protoKey, ~sid),
In(rx)
]
--[
SessionID(~sid),
SessionEphResponder(~sid, dhR),
SessionKey(~sid, sk),
SessionAll(~sid, 'I', pkI, pkR, dhI, dhR, sk, ~protoKey),
SessionAgreementSet(~sid, 'I', pkI, pkR, sk, ~protoKey),
// helpful for looking at trace pictures
DHPubkey(fst(pkI)),
DHPubkey(fst(pkR)),
DHPubkey(dhI),
DHPubkey(dhR)
]->
[
Initiator_authSent(pkI, pkR, ~ltkI, ~ephI, dhR, ~protoKey, ~sid),
SessionKey(~sid, sk),
Out(iEncAuth)
]
// server: recv client auth
rule Responder_recvAuth:
let
pkRdh = 'g'^~ltkR
pkRed = pk(~ltkR)
dhR = 'g'^~ephR
pkR = <pkRdh, pkRed>
pkIdh = 'g'^ltkI // this is ok due to pattern matching
pkIed = pk(ltkI) // but only for verifying stuff
dhI = 'g'^ephI
pkI = <pkIdh, pkIed>
ir = dhI^~ephR
iR = dhI^~ltkR
Ir = pkIdh^~ephR
dKey = h(<~protoKey, ir, iR>)
sk = h(<~protoKey, ir, Ir, iR>)
rxSigd = <~protoKey, pkR, h(ir)>
rxSig = sign(rxSigd, ltkI) // we only use this signature in pattern matching, we don't send it
auth = <pkI, rxSig> // =H
sig = sign(<~protoKey, auth, h(ir)>, ~ltkR)
rx = senc(auth, dKey)
tx = senc(sig, sk)
in
[
Responder_chalSent(~ltkR, ~ephR, dhI, ~protoKey, ~sid),
In(rx)
]
--[
SessionID(~sid),
SessionInitiator(~sid, pkI),
SessionKey(~sid, sk),
SessionAll(~sid, 'R', pkI, pkR, dhI, dhR, sk, ~protoKey),
SessionAccept(~sid),
SessionAgreementSet(~sid, 'R', pkI, pkR, sk, ~protoKey),
SessionPeer(~sid, pkI),
// helpful for looking at trace pictures
DHPubkey(fst(pkI)),
DHPubkey(fst(pkR)),
DHPubkey(dhI),
DHPubkey(dhR)
]->
[
Out(tx),
SessionKey(~sid, sk)
]
// client recv server auth
rule Initiator_recvAuth:
let
dhI = 'g'^~ephI
dhR = 'g'^ephR
pkRdh = 'g'^ltkR
pkRed = pk(ltkR)
pkR = <pkRdh, pkRed>
pkIdh = 'g'^~ltkI
pkIed = pk(~ltkI)
pkI = <pkIdh, pkIed>
ir = dhR^~ephI
iR = pkRdh^~ephI
Ir = dhR^~ltkI
hmsg = <pkI, sign(<~protoKey, pkR, h(ir)>, ~ltkI)>
rxSigd = <~protoKey, hmsg, h(ir)>
rxSig = sign(rxSigd, ltkR) // we only use this signatur in pattern matching, we don't send it
sk = h(<~protoKey, ir, Ir, iR>)
encAuth = senc(rxSig, sk)
in
[
Initiator_authSent(pkI, pkR, ~ltkI, ~ephI, dhR, ~protoKey, ~sid),
In(encAuth)
]
--[
SessionID(~sid),
SessionAccept(~sid),
// helpful for looking at trace pictures
DHPubkey(fst(pkI)),
DHPubkey(fst(pkR)),
DHPubkey(dhI),
DHPubkey(dhR)
]->
[ ]
//
// Agreement lemmas
//
lemma auth_explicit:
"All sid role pkI pkR k protoKeyR pkRemote #set #accept #remote #mkRemote.
SessionAgreementSet(sid, role, pkI, pkR, k, protoKeyR) @ #set &
SessionAccept(sid) @ #accept &
SessionPeer(sid, pkRemote) @ #remote &
IsAgent(pkRemote) @ #mkRemote &
(not Ex #c. LtkCorrupt(pkRemote) @ #c)
==>
Ex sid2 role2 #set2. (
SessionAgreementSet(sid2, role2, pkI, pkR, k, protoKeyR) @ #set2 &
not role = role2
)"
/* the lemma above should be equivalent, just removed some parens
lemma auth_explicit:
"(
All sid role pkI pkR k protoKeyR pkRemote #set #accept #remote #mkRemote. (
SessionAgreementSet(sid, role, pkI, pkR, k, protoKeyR) @ #set &
SessionAccept(sid) @ #accept &
SessionPeer(sid, pkRemote) @ #remote &
IsAgent(pkRemote) @ #mkRemote &
(not Ex #c. LtkCorrupt(pkRemote) @ #c)
) ==> (
Ex sid2 role2 #set2. (
SessionAgreementSet(sid2, role2, pkI, pkR, k, protoKeyR) @ #set2 &
not role = role2
)
)
)"
*/
lemma cpa_resistance:
"All k sid1 sid2 #secret1 #secret2 #acc1 #acc2.
SessionAccept(sid1) @ acc1 &
SessionAccept(sid2) @ acc2 &
SessionKey(sid1, k) @ #secret1 &
SessionKey(sid2, k) @ #secret2
==>
Ex protoKey #proto1 #proto2.
SessionProtoKey(sid1, protoKey) @ #proto1 &
SessionProtoKey(sid2, protoKey) @ #proto2"
//
// Secrecy lemmas
//
lemma secrecy_sessionkey:
"All sid k pkPeer #accept #peer #secret.
SessionAccept(sid) @ #accept &
SessionKey(sid, k) @ #secret &
SessionPeer(sid, pkPeer) @ #peer &
(Ex #mk. IsAgent(pkPeer) @ #mk) &
not (Ex #c. LtkCorrupt(pkPeer) @ #c & #c < #accept) &
not (Ex #r. RevealSessionKey(k) @ #r)
==>
not Ex #kk. !KU(k) @ #kk"
lemma secrecy_capabilities:
"All pk pkDH pkSign #mk.
IsAgent(pk) @ #mk &
AgentPubkey(pk, pkDH, pkSign) @ #mk &
not (Ex #c. LtkCorrupt(pk) @ #c) &
not (Ex #r. RevealPublicKey(pk) @ #r) &
not ( // pk dialed someone whose ltk got corrupted
Ex isid pkR k2 #dial #gotsecret. (
SessionRole(isid, 'I') @ #dial &
SessionInitiator(isid, pk) @ #dial &
SessionResponder(isid, pkR) @ #dial &
SessionKey(isid, k2) @ #gotsecret &
( // not an agent, or an agent whose ltk got corrupted
All #mk. IsAgent(pkR) @ #mk
==>
Ex #corr. LtkCorrupt(pkR) @ #corr
)
)
)
==>
not (Ex #kpkDH. !KU(pkDH) @ #kpkDH) &
not (Ex #kpkSign. !KU(pkSign) @ #kpkSign)"
//
// Other lemmas
//
lemma uniqueness:
"All k sid1 sid2 sid3 #acc1 #acc2 #acc3 #sec1 #sec2 #sec3.
SessionAccept(sid1) @ #acc1 &
SessionAccept(sid2) @ #acc2 &
SessionAccept(sid3) @ #acc3 &
SessionKey(sid1, k) @ #sec1 &
SessionKey(sid2, k) @ #sec2 &
SessionKey(sid3, k) @ #sec3
==>
((sid1 = sid2) | (sid1 = sid3) | (sid2 = sid3))"
lemma caps_pubkey:
"All pk pkI pkDH pkSign sid1 k #mk #acc1 #init #resp1 #role1 #sec1.
AgentPubkey(pk, pkDH, pkSign) @ #mk &
not (Ex #kpk. !KU(pkSign) @ #kpk) &
not (Ex #kpk. !KU(pkDH) @ #kpk) &
SessionAccept(sid1) @ #acc1 &
SessionResponder(sid1, pk) @ #resp1 &
SessionInitiator(sid1, pkI) @ #init &
SessionRole(sid1, 'R') @ #role1 &
SessionKey(sid1, k) @ #sec1
==> (
(Ex sid2 #role2 #sec2 #t.
SessionRole(sid2, 'I') @ #role2 &
SessionKey(sid2, k) @ #sec2 &
HasCapability(pkI, pk) @ #t &
(All #ku. !KU(k) @ #ku ==> (Ex #r. RevealSessionKey(k) @ #r))
)
)"
lemma delegation_reuse [reuse, use_induction]:
"All sub rsc #cap.
HasCapability(sub, rsc) @ #cap &
not IsAgent(sub) @ #cap
==>
Ex #mk. IsAgent(sub) @ #mk & #mk < #cap"
end
//
// Model sanity
//
// TODO:
// - ???
lemma state_consistency:
"All sid role pk #peer #tRole.
SessionRole(sid, role) @ #tRole &
SessionPeer(sid, pk) @ #peer
==> (
(
role = 'I'
==>
Ex #resp. SessionResponder(sid, pk) @ #resp
) & (
role = 'R'
==>
Ex #init. SessionInitiator(sid, pk) @ #init
)
)"
lemma delegation_sane:
"All sub rsc #cap.
HasCapability(sub, rsc) @ #cap
==>
(
Ex sub2 #del.
Delegator(sub2) @ #cap &
HasCapability(sub2, rsc) @ #del &
#del < #cap
) | (
sub = rsc &
IsAgent(sub) @ #cap
)
"
end